From 77a4f3d4013071859a2fe5a9256087e5a91d114b Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Sat, 15 Feb 2025 23:12:56 +0100 Subject: [PATCH 01/32] Bugfix in table.removeValue --- cf-lib/util/table.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cf-lib/util/table.lua b/cf-lib/util/table.lua index 1cdfc11..aa92228 100644 --- a/cf-lib/util/table.lua +++ b/cf-lib/util/table.lua @@ -46,7 +46,7 @@ end table.removeValue = function(target, value) for i, v in ipairs(target) do if v == value then - target.remove(target, i) + table.remove(target, i) return target end end From 39dca1c3b2ab7804b80eb6004230cb6f3349ddeb Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Sat, 15 Feb 2025 23:13:42 +0100 Subject: [PATCH 02/32] 0.0.6 --- cf-lib/changelog.txt | 5 +++++ cf-lib/info.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cf-lib/changelog.txt b/cf-lib/changelog.txt index e8398e4..45439a5 100644 --- a/cf-lib/changelog.txt +++ b/cf-lib/changelog.txt @@ -1,4 +1,9 @@ --------------------------------------------------------------------------------------------------- +Version: 0.0.6 +Date: 15.02.2025 + Bug Fixes: + - Bugfix in table.removeValue +--------------------------------------------------------------------------------------------------- Version: 0.0.5 Date: 15.02.2025 Changes: diff --git a/cf-lib/info.json b/cf-lib/info.json index 72690c3..055c48e 100644 --- a/cf-lib/info.json +++ b/cf-lib/info.json @@ -1,6 +1,6 @@ { "name": "cf-lib", - "version": "0.0.5", + "version": "0.0.6", "title": "cackling fiends library", "description": "Because I'd like to have my own library :-)", "author": "cackling fiend", From f8c4b941658149057c45374cea1981d009b6ab2d Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Wed, 19 Feb 2025 00:11:13 +0100 Subject: [PATCH 03/32] Add table.concat --- cf-lib/util/table.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cf-lib/util/table.lua b/cf-lib/util/table.lua index aa92228..3f829a0 100644 --- a/cf-lib/util/table.lua +++ b/cf-lib/util/table.lua @@ -68,4 +68,19 @@ function table.filter(target, predicate) end end return result +end + +--- Concatenates two tables into a new table. +--- @param table1 table The first table +--- @param table2 table The second table +--- @return table The concatenated table +function table.concat(table1, table2) + local result = {} + for _, v in pairs(table1) do + table.insert(result, v) + end + for _, v in pairs(table2) do + table.insert(result, v) + end + return result end \ No newline at end of file From acd86bfe2b526f23d228e8e2528ca522fcc882c9 Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Wed, 26 Feb 2025 19:52:16 +0100 Subject: [PATCH 04/32] Recipe: Fix a bug --- cf-lib/data/Recipe.lua | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/cf-lib/data/Recipe.lua b/cf-lib/data/Recipe.lua index 17ba8c0..52e453b 100644 --- a/cf-lib/data/Recipe.lua +++ b/cf-lib/data/Recipe.lua @@ -11,16 +11,15 @@ function Recipe:new(value) if type(value) == "string" then name = value recipe = data.raw.recipe[name] + if not recipe then + log("Recipe not found: " .. name) + return nil + end elseif type(value) == "table" then name = value.name recipe = value end - if not recipe then - log("Recipe not found: " .. name) - return nil - end - local obj = { prototype = recipe } @@ -150,4 +149,4 @@ function Recipe:clone(name) return Recipe:new(clone) end -return Recipe \ No newline at end of file +return Recipe From 0a394221e565be7fe75cbeda479c150c45dda28b Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Wed, 26 Feb 2025 22:24:07 +0100 Subject: [PATCH 05/32] 0.0.7 --- cf-lib/changelog.txt | 7 +++++++ cf-lib/info.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cf-lib/changelog.txt b/cf-lib/changelog.txt index 45439a5..a655106 100644 --- a/cf-lib/changelog.txt +++ b/cf-lib/changelog.txt @@ -1,4 +1,11 @@ --------------------------------------------------------------------------------------------------- +Version: 0.0.7 +Date: 15.02.2025 + Changes: + - Add table.concat + Bug Fixes: + - Bugfix in Recipe +--------------------------------------------------------------------------------------------------- Version: 0.0.6 Date: 15.02.2025 Bug Fixes: diff --git a/cf-lib/info.json b/cf-lib/info.json index 055c48e..c592ff6 100644 --- a/cf-lib/info.json +++ b/cf-lib/info.json @@ -1,6 +1,6 @@ { "name": "cf-lib", - "version": "0.0.6", + "version": "0.0.7", "title": "cackling fiends library", "description": "Because I'd like to have my own library :-)", "author": "cackling fiend", From cd9886bb347e57e1f85d56f786b5562505172bc0 Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Wed, 26 Feb 2025 22:26:01 +0100 Subject: [PATCH 06/32] changelog --- cf-lib/changelog.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cf-lib/changelog.txt b/cf-lib/changelog.txt index a655106..d0fe45a 100644 --- a/cf-lib/changelog.txt +++ b/cf-lib/changelog.txt @@ -1,6 +1,6 @@ --------------------------------------------------------------------------------------------------- Version: 0.0.7 -Date: 15.02.2025 +Date: 26.02.2025 Changes: - Add table.concat Bug Fixes: From 0390af3d420abce1e262c1ab3e7f9c05995933c8 Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Fri, 28 Feb 2025 09:39:21 +0100 Subject: [PATCH 07/32] Add table.trim --- cf-lib/util/table.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cf-lib/util/table.lua b/cf-lib/util/table.lua index 3f829a0..0e8f32b 100644 --- a/cf-lib/util/table.lua +++ b/cf-lib/util/table.lua @@ -83,4 +83,13 @@ function table.concat(table1, table2) table.insert(result, v) end return result +end + +--- Trims nil values from a table. +--- @param target table The table to trim +--- @return table The trimmed table +function table.trim(target) + return table.filter(target, function(v) + return v ~= nil + end) end \ No newline at end of file From bcd8c953887b81ec4e5aa65e9dc32dfd9eaa723b Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Fri, 28 Feb 2025 09:40:01 +0100 Subject: [PATCH 08/32] 0.0.8 --- cf-lib/changelog.txt | 5 +++++ cf-lib/info.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cf-lib/changelog.txt b/cf-lib/changelog.txt index d0fe45a..4b31875 100644 --- a/cf-lib/changelog.txt +++ b/cf-lib/changelog.txt @@ -1,4 +1,9 @@ --------------------------------------------------------------------------------------------------- +Version: 0.0.8 +Date: 28.02.2025 + Changes: + - Add table.trim +--------------------------------------------------------------------------------------------------- Version: 0.0.7 Date: 26.02.2025 Changes: diff --git a/cf-lib/info.json b/cf-lib/info.json index c592ff6..0eb9de6 100644 --- a/cf-lib/info.json +++ b/cf-lib/info.json @@ -1,6 +1,6 @@ { "name": "cf-lib", - "version": "0.0.7", + "version": "0.0.8", "title": "cackling fiends library", "description": "Because I'd like to have my own library :-)", "author": "cackling fiend", From be0781340ae5521d4f17320b7ac9715c3f256061 Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Fri, 28 Feb 2025 23:16:17 +0100 Subject: [PATCH 09/32] Rename `table.concat` to `table.concatTables` to resolve conflict --- cf-lib/changelog.txt | 5 +++++ cf-lib/info.json | 2 +- cf-lib/util/table.lua | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cf-lib/changelog.txt b/cf-lib/changelog.txt index 4b31875..b9642fa 100644 --- a/cf-lib/changelog.txt +++ b/cf-lib/changelog.txt @@ -1,4 +1,9 @@ --------------------------------------------------------------------------------------------------- +Version: 0.0.9 +Date: 28.02.2025 + Bug Fixes: + - Rename `table.concat` to `table.concatTables` to resolve conflict +--------------------------------------------------------------------------------------------------- Version: 0.0.8 Date: 28.02.2025 Changes: diff --git a/cf-lib/info.json b/cf-lib/info.json index 0eb9de6..652f221 100644 --- a/cf-lib/info.json +++ b/cf-lib/info.json @@ -1,6 +1,6 @@ { "name": "cf-lib", - "version": "0.0.8", + "version": "0.0.9", "title": "cackling fiends library", "description": "Because I'd like to have my own library :-)", "author": "cackling fiend", diff --git a/cf-lib/util/table.lua b/cf-lib/util/table.lua index 0e8f32b..e44b559 100644 --- a/cf-lib/util/table.lua +++ b/cf-lib/util/table.lua @@ -74,7 +74,7 @@ end --- @param table1 table The first table --- @param table2 table The second table --- @return table The concatenated table -function table.concat(table1, table2) +function table.concatTables(table1, table2) local result = {} for _, v in pairs(table1) do table.insert(result, v) From 27d9dd6c68abb3f69dea7aaec250b45ae096e4b6 Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Fri, 14 Mar 2025 18:13:37 +0100 Subject: [PATCH 10/32] Recipe: addIngredient amount defaults to 1 --- cf-lib/data/Recipe.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cf-lib/data/Recipe.lua b/cf-lib/data/Recipe.lua index 52e453b..4bbd0f1 100644 --- a/cf-lib/data/Recipe.lua +++ b/cf-lib/data/Recipe.lua @@ -43,8 +43,9 @@ end --- Adds an ingredient to the recipe --- @param ingredientName string The name of the ingredient ---- @param amount number The amount of the ingredient +--- @param amount number The amount of the ingredient (default: 1) function Recipe:addIngredient(ingredientName, amount) + amount = amount or 1 local ingredientType = data.raw.item[ingredientName] and "item" or data.raw.module[ingredientName] and "item" or data.raw.fluid[ingredientName] and "fluid" From ea7785c761d0cdc7efa03590626423274e203b3d Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Sun, 16 Mar 2025 18:40:40 +0100 Subject: [PATCH 11/32] Functions are chainable --- cf-lib/data/Recipe.lua | 12 +++++++++--- cf-lib/data/Technology.lua | 18 +++++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/cf-lib/data/Recipe.lua b/cf-lib/data/Recipe.lua index 4bbd0f1..1a5c67e 100644 --- a/cf-lib/data/Recipe.lua +++ b/cf-lib/data/Recipe.lua @@ -39,6 +39,7 @@ end ---- @param data table The data to assign function Recipe:assign(data) table.assign(self.prototype, data) + return self end --- Adds an ingredient to the recipe @@ -65,6 +66,7 @@ function Recipe:addIngredient(ingredientName, amount) end end table.insert(self.prototype.ingredients, { name = ingredientName, amount = amount, type = ingredientType }) + return self end --- Replaces an existing ingredient by name with a new ingredient or adjusts the amount @@ -81,10 +83,11 @@ function Recipe:replaceIngredient(old, new, amount) if result.name == old then result.name = new result.amount = amount or result.amount - return + return self end end end + return self end --- Removes an existing ingredient by name @@ -94,10 +97,11 @@ function Recipe:removeIngredient(ingredientName) for i, result in pairs(self.prototype.ingredients) do if result.name == ingredientName then self.prototype.ingredients[i] = nil - return + return self end end end + return self end --- Replaces an existing result by name with a new result @@ -122,6 +126,7 @@ function Recipe:replaceResult(old, new, amount, expensiveAmount) table.main_product = new end end + return self end --- Adds the recipe to a technology @@ -136,10 +141,11 @@ function Recipe:unlockedByTechnology(technology) end for _, effect in pairs(technology.effects) do if effect.type == "unlock-recipe" and effect.recipe == self.prototype.name then - return + return self end end table.insert(technology.effects, { type = "unlock-recipe", recipe = self.prototype.name }) + return self end ---- Clones the recipe diff --git a/cf-lib/data/Technology.lua b/cf-lib/data/Technology.lua index 2c641d5..f30d739 100644 --- a/cf-lib/data/Technology.lua +++ b/cf-lib/data/Technology.lua @@ -47,12 +47,14 @@ end --- @param data table The data to assign function Technology:assign(data) table.assign(self.prototype, data) + return self end --- Sets the prerequisite for the technology --- @param prerequisites table The names of the prerequisites function Technology:setPrerequisites(prerequisites) self.prototype.prerequisites = prerequisites + return self end --- Adds a prerequisite to the technology @@ -63,6 +65,7 @@ function Technology:addPrerequisite(prerequisite) if (not table.contains(self.prototype.prerequisites, _prerequisite)) then table.insert(self.prototype.prerequisites, _prerequisite) end + return self end --- Adds multiple prerequisites to the technology @@ -75,6 +78,7 @@ function Technology:addPrerequisites(prerequisites) table.insert(self.prototype.prerequisites, _prerequisite) end end + return self end --- Replaces a prerequisite in a technology @@ -88,6 +92,7 @@ function Technology:replacePrerequisite(old, new) self.prototype.prerequisites[i] = _new end end + return self end --- Removes a prerequisite from the technology @@ -97,9 +102,10 @@ function Technology:removePrerequisite(prerequisite) for i, techPrerequisite in pairs(self.prototype.prerequisites) do if techPrerequisite == _prerequisite then table.remove(self.prototype.prerequisites, i) - return + return self end end + return self end --- Adds an ingredient to the technology @@ -109,6 +115,7 @@ function Technology:addIngredient(ingredientName, amount) self.prototype.unit = self.prototype.unit or { ingredients = {} } self.prototype.unit.ingredients = self.prototype.unit.ingredients or {} table.insert(self.prototype.unit.ingredients, { ingredientName, amount or 1 }) + return self end --- Adds a list of ingredients to the technology with the default amount of 1 @@ -117,6 +124,7 @@ function Technology:addIngredients(ingredientNames) for _, ingredientName in pairs(ingredientNames) do self:addIngredient(ingredientName) end + return self end --- Removes an existing ingredient by name @@ -129,6 +137,7 @@ function Technology:removeIngredient(ingredientName) end end end + return self end --- Adds a recipe unlock to the technology @@ -136,16 +145,18 @@ end function Technology:addRecipe(recipeName) for _, effect in pairs(self.prototype.effects) do if effect.type == "unlock-recipe" and effect.recipe == recipeName then - return + return self end end table.insert(self.prototype.effects, { type = "unlock-recipe", recipe = recipeName }) + return self end --- Adds an effect to the technology --- @param effect table The effect to add function Technology:addEffect(effect) table.insert(self.prototype.effects, effect) + return self end --- Removes a recipe unlock from the technology @@ -154,9 +165,10 @@ function Technology:removeRecipe(recipeName) for i, effect in pairs(self.prototype.effects) do if effect.type == "unlock-recipe" and effect.recipe == recipeName then table.remove(self.prototype.effects, i) - return + return self end end + return self end --- Clones the technology From 620c9f48cfe455f3a655f64837224297c8711489 Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Sun, 16 Mar 2025 18:42:02 +0100 Subject: [PATCH 12/32] 0.0.10 --- cf-lib/changelog.txt | 6 ++++++ cf-lib/info.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cf-lib/changelog.txt b/cf-lib/changelog.txt index b9642fa..2fc199a 100644 --- a/cf-lib/changelog.txt +++ b/cf-lib/changelog.txt @@ -1,4 +1,10 @@ --------------------------------------------------------------------------------------------------- +Version: 0.0.10 +Date: 16.03.2025 + Changes: + - Recipe: addIngredient amount defaults to 1 + - Functions are chainable +--------------------------------------------------------------------------------------------------- Version: 0.0.9 Date: 28.02.2025 Bug Fixes: diff --git a/cf-lib/info.json b/cf-lib/info.json index 652f221..eeda71c 100644 --- a/cf-lib/info.json +++ b/cf-lib/info.json @@ -1,6 +1,6 @@ { "name": "cf-lib", - "version": "0.0.9", + "version": "0.0.10", "title": "cackling fiends library", "description": "Because I'd like to have my own library :-)", "author": "cackling fiend", From c36fd418abadc389ce2808a8b5ecdedd127783e8 Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Fri, 28 Mar 2025 18:54:28 +0100 Subject: [PATCH 13/32] Add Technology:setIngredients --- cf-lib/data/Technology.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cf-lib/data/Technology.lua b/cf-lib/data/Technology.lua index f30d739..bf950c8 100644 --- a/cf-lib/data/Technology.lua +++ b/cf-lib/data/Technology.lua @@ -140,6 +140,15 @@ function Technology:removeIngredient(ingredientName) return self end +--- Sets the ingredients for the technology +--- @param ingredientNames table The names of the ingredients +function Technology:setIngredients(ingredients) + self.prototype.unit = self.prototype.unit or {} + self.prototype.unit.ingredients = {} + self:addIngredients(ingredients) + return self +end + --- Adds a recipe unlock to the technology --- @param recipeName string The name of the recipe to unlock function Technology:addRecipe(recipeName) From bbcc58612897530178664eed9e87661f44995709 Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Fri, 28 Mar 2025 18:55:11 +0100 Subject: [PATCH 14/32] 0.0.11 --- cf-lib/changelog.txt | 5 +++++ cf-lib/info.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cf-lib/changelog.txt b/cf-lib/changelog.txt index 2fc199a..ac1dd2f 100644 --- a/cf-lib/changelog.txt +++ b/cf-lib/changelog.txt @@ -1,4 +1,9 @@ --------------------------------------------------------------------------------------------------- +Version: 0.0.11 +Date: 28.03.2025 + Changes: + - Add Technology:setIngredients +--------------------------------------------------------------------------------------------------- Version: 0.0.10 Date: 16.03.2025 Changes: diff --git a/cf-lib/info.json b/cf-lib/info.json index eeda71c..b6047b0 100644 --- a/cf-lib/info.json +++ b/cf-lib/info.json @@ -1,6 +1,6 @@ { "name": "cf-lib", - "version": "0.0.10", + "version": "0.0.11", "title": "cackling fiends library", "description": "Because I'd like to have my own library :-)", "author": "cackling fiend", From 36dba7614eef7b2d845931db58eabeaef4b950b9 Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Sun, 6 Apr 2025 16:43:21 +0200 Subject: [PATCH 15/32] Add table.count --- cf-lib/util/table.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cf-lib/util/table.lua b/cf-lib/util/table.lua index e44b559..865d683 100644 --- a/cf-lib/util/table.lua +++ b/cf-lib/util/table.lua @@ -92,4 +92,15 @@ function table.trim(target) return table.filter(target, function(v) return v ~= nil end) +end + +--- Counts the entries of given table. +--- @param target table Table to count +--- @return number Amount of entries +function table.count(target) + local count = 0 + for _ in pairs(target) do + count = count + 1 + end + return count end \ No newline at end of file From 3ce2d83c228fa9d1759d427aaed5af2e77dcc5c9 Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Sun, 6 Apr 2025 16:43:54 +0200 Subject: [PATCH 16/32] 0.0.12 --- cf-lib/changelog.txt | 5 +++++ cf-lib/info.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cf-lib/changelog.txt b/cf-lib/changelog.txt index ac1dd2f..bb6d348 100644 --- a/cf-lib/changelog.txt +++ b/cf-lib/changelog.txt @@ -1,4 +1,9 @@ --------------------------------------------------------------------------------------------------- +Version: 0.0.12 +Date: 06.04.2025 + Changes: + Add table.count +--------------------------------------------------------------------------------------------------- Version: 0.0.11 Date: 28.03.2025 Changes: diff --git a/cf-lib/info.json b/cf-lib/info.json index b6047b0..7691c7a 100644 --- a/cf-lib/info.json +++ b/cf-lib/info.json @@ -1,6 +1,6 @@ { "name": "cf-lib", - "version": "0.0.11", + "version": "0.0.12", "title": "cackling fiends library", "description": "Because I'd like to have my own library :-)", "author": "cackling fiend", From 8e637400a57e723b43f65b02092bfbe46fedcbfd Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Fri, 23 May 2025 21:03:59 +0200 Subject: [PATCH 17/32] Add class Item --- cf-lib/data/Item.lua | 52 ++++++++++++++++++++++++++++++++++++++++++ cf-lib/data/Recipe.lua | 20 ++++++++-------- 2 files changed, 62 insertions(+), 10 deletions(-) create mode 100644 cf-lib/data/Item.lua diff --git a/cf-lib/data/Item.lua b/cf-lib/data/Item.lua new file mode 100644 index 0000000..e7cc877 --- /dev/null +++ b/cf-lib/data/Item.lua @@ -0,0 +1,52 @@ +--- Utility class for a single item +--- @class Item +local Item = {} + +--- Pass an item name or an item table to get a Item object +--- @param value string|table The name of the item or the item table +function Item:new(value) + local name + local item + + if type(value) == "string" then + name = value + item = data.raw.item[name] + if not item then + log("Item not found: " .. name) + return nil + end + elseif type(value) == "table" then + name = value.name + item = value + end + + local obj = { + prototype = item + } + + setmetatable(obj, self) + self.__index = self + return obj +end + +--- Applies the item to the game +function Item:apply() + data:extend({ self.prototype }) +end + +--- Assigns data to the item +--- Shorthand for table.assign(item.prototype, data) +--- @param data table The data to assign +function Item:assign(data) + table.assign(self.prototype, data) + return self +end + +--- Sets the weight of the item calculated from given count per rocket. +--- @param count number The amount of items that fit into a rocket +function Item:itemsPerRocket(count) + self.prototype.weight = (1000 / count) * kg + return self +end + +return Item \ No newline at end of file diff --git a/cf-lib/data/Recipe.lua b/cf-lib/data/Recipe.lua index 1a5c67e..6ca5192 100644 --- a/cf-lib/data/Recipe.lua +++ b/cf-lib/data/Recipe.lua @@ -1,9 +1,9 @@ ----- Utility class for a single recipe ----- @class Recipe +--- Utility class for a single recipe +--- @class Recipe local Recipe = {} ----- Pass a recipe name or a recipe table to get a Recipe object ----- @param value string|table The name of the recipe or the recipe table +--- Pass a recipe name or a recipe table to get a Recipe object +--- @param value string|table The name of the recipe or the recipe table function Recipe:new(value) local name local recipe @@ -29,14 +29,14 @@ function Recipe:new(value) return obj end ----- Applies the recipe to the game +--- Applies the recipe to the game function Recipe:apply() data:extend({ self.prototype }) end ----- Assigns data to the recipe ----- Shorthand for table.assign(recipe.prototype, data) ----- @param data table The data to assign +--- Assigns data to the recipe +--- Shorthand for table.assign(recipe.prototype, data) +--- @param data table The data to assign function Recipe:assign(data) table.assign(self.prototype, data) return self @@ -148,8 +148,8 @@ function Recipe:unlockedByTechnology(technology) return self end ----- Clones the recipe ----- @param name string The name of the new recipe +--- Clones the recipe +--- @param name string The name of the new recipe function Recipe:clone(name) local clone = table.deepcopy(self.prototype) clone.name = name From a9457f7c386156b3221fb661010c47db5fed2550 Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Fri, 23 May 2025 21:04:51 +0200 Subject: [PATCH 18/32] 0.0.13 --- cf-lib/changelog.txt | 5 +++++ cf-lib/info.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cf-lib/changelog.txt b/cf-lib/changelog.txt index bb6d348..9955581 100644 --- a/cf-lib/changelog.txt +++ b/cf-lib/changelog.txt @@ -1,4 +1,9 @@ --------------------------------------------------------------------------------------------------- +Version: 0.0.13 +Date: 23.05.2025 + Changes: + Add Item class +--------------------------------------------------------------------------------------------------- Version: 0.0.12 Date: 06.04.2025 Changes: diff --git a/cf-lib/info.json b/cf-lib/info.json index 7691c7a..d87420a 100644 --- a/cf-lib/info.json +++ b/cf-lib/info.json @@ -1,6 +1,6 @@ { "name": "cf-lib", - "version": "0.0.12", + "version": "0.0.13", "title": "cackling fiends library", "description": "Because I'd like to have my own library :-)", "author": "cackling fiend", From 9878331df58188b5a46b08dc58cec6ac22c9f743 Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Sat, 31 May 2025 22:55:18 +0200 Subject: [PATCH 19/32] Add :merge --- cf-lib/data/Item.lua | 8 ++++++++ cf-lib/data/Recipe.lua | 10 +++++++++- cf-lib/data/Technology.lua | 8 ++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/cf-lib/data/Item.lua b/cf-lib/data/Item.lua index e7cc877..1cfffcf 100644 --- a/cf-lib/data/Item.lua +++ b/cf-lib/data/Item.lua @@ -42,6 +42,14 @@ function Item:assign(data) return self end +--- Deeply merges data with the item +--- Shorthand for table.merge(item.prototype, data) +--- @param data table The data to merge +function Item:merge(data) + table.merge(self.prototype, data) + return self +end + --- Sets the weight of the item calculated from given count per rocket. --- @param count number The amount of items that fit into a rocket function Item:itemsPerRocket(count) diff --git a/cf-lib/data/Recipe.lua b/cf-lib/data/Recipe.lua index 6ca5192..6eca2b6 100644 --- a/cf-lib/data/Recipe.lua +++ b/cf-lib/data/Recipe.lua @@ -42,6 +42,14 @@ function Recipe:assign(data) return self end +--- Deeply merges data with the recipe +--- Shorthand for table.merge(recipe.prototype, data) +--- @param data table The data to merge +function Recipe:merge(data) + table.merge(self.prototype, data) + return self +end + --- Adds an ingredient to the recipe --- @param ingredientName string The name of the ingredient --- @param amount number The amount of the ingredient (default: 1) @@ -62,7 +70,7 @@ function Recipe:addIngredient(ingredientName, amount) ingredient.amount_min = nil ingredient.amount_max = nil ingredient.probability = nil - return + return self end end table.insert(self.prototype.ingredients, { name = ingredientName, amount = amount, type = ingredientType }) diff --git a/cf-lib/data/Technology.lua b/cf-lib/data/Technology.lua index bf950c8..13a1dd9 100644 --- a/cf-lib/data/Technology.lua +++ b/cf-lib/data/Technology.lua @@ -50,6 +50,14 @@ function Technology:assign(data) return self end +--- Deeply merges data with the technology +--- Shorthand for table.merge(technology.prototype, data) +--- @param data table The data to merge +function Technology:merge(data) + table.merge(self.prototype, data) + return self +end + --- Sets the prerequisite for the technology --- @param prerequisites table The names of the prerequisites function Technology:setPrerequisites(prerequisites) From 8ded39211b544387704167a614b8fec8fef5fe95 Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Tue, 10 Jun 2025 19:47:34 +0200 Subject: [PATCH 20/32] 0.0.14 --- cf-lib/changelog.txt | 5 +++++ cf-lib/info.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cf-lib/changelog.txt b/cf-lib/changelog.txt index 9955581..ae8b83d 100644 --- a/cf-lib/changelog.txt +++ b/cf-lib/changelog.txt @@ -1,4 +1,9 @@ --------------------------------------------------------------------------------------------------- +Version: 0.0.14 +Date: 10.06.2025 + Changes: + Add :merge +--------------------------------------------------------------------------------------------------- Version: 0.0.13 Date: 23.05.2025 Changes: diff --git a/cf-lib/info.json b/cf-lib/info.json index d87420a..c22dbfa 100644 --- a/cf-lib/info.json +++ b/cf-lib/info.json @@ -1,6 +1,6 @@ { "name": "cf-lib", - "version": "0.0.13", + "version": "0.0.14", "title": "cackling fiends library", "description": "Because I'd like to have my own library :-)", "author": "cackling fiend", From e4ad298324fd64dc3002421a9f7b72ef8c6b5c5e Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Mon, 15 Sep 2025 18:14:02 +0200 Subject: [PATCH 21/32] Add Discord link --- cf-lib/info.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cf-lib/info.json b/cf-lib/info.json index c22dbfa..15a2c72 100644 --- a/cf-lib/info.json +++ b/cf-lib/info.json @@ -4,7 +4,7 @@ "title": "cackling fiends library", "description": "Because I'd like to have my own library :-)", "author": "cackling fiend", - "homepage": "", + "homepage": "https://discord.gg/ufvFUJtVwk", "factorio_version": "2.0", "dependencies": [ "base" From 6ca603418608debc341767efdb6eb56bc6d6a708 Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Wed, 12 Nov 2025 00:31:56 +0100 Subject: [PATCH 22/32] Add table.filterKey --- cf-lib/util/table.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cf-lib/util/table.lua b/cf-lib/util/table.lua index 865d683..57c7fa2 100644 --- a/cf-lib/util/table.lua +++ b/cf-lib/util/table.lua @@ -70,6 +70,18 @@ function table.filter(target, predicate) return result end +--- Filters a table by removing given key. +--- @param target table The table to filter +--- @param key string The key to remove +function table.filterKey(target, key) + return table.filter( + target, + function(_, currentKey) + return currentKey ~= key + end + ) +end + --- Concatenates two tables into a new table. --- @param table1 table The first table --- @param table2 table The second table From c2392a687c85890c4c409d2618f61b6638e2201e Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Wed, 12 Nov 2025 00:32:17 +0100 Subject: [PATCH 23/32] Add class Settings --- cf-lib/settings/Settings.lua | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 cf-lib/settings/Settings.lua diff --git a/cf-lib/settings/Settings.lua b/cf-lib/settings/Settings.lua new file mode 100644 index 0000000..582292b --- /dev/null +++ b/cf-lib/settings/Settings.lua @@ -0,0 +1,38 @@ +--- Utility class for manipulating settings +--- @class Settings +local Settings = {} + +local settingTypes = { "bool-setting", "int-setting", "double-setting", "string-setting", "color-setting" } + +local function getSetting(name) + for _, settingType in pairs(settingTypes) do + local setting = data.raw[settingType][name] + if setting then return setting end + end + error("getSetting: Setting with name '" .. name .. "' not found.") +end + +Settings.getSetting = getSetting + +function Settings.force(name, value) + local setting = getSetting(name) + setting.hidden = true + if setting.type == "bool-setting" or setting.type == "color-setting" then + setting.forced_value = value + else + setting.allowed_values = { value } + end +end + +function Settings.default(name, value) + local setting = getSetting(name) + setting.default_value = value +end + +function Settings.forceDefault(name) + local setting = getSetting(name) + local value = setting.default_value + Settings.force(name, value) +end + +return Settings \ No newline at end of file From 7a18ca0c3b3ab0054532823cde1221b6374ffa1b Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Wed, 12 Nov 2025 10:22:20 +0100 Subject: [PATCH 24/32] Add Recipe:removeResult --- cf-lib/data/Recipe.lua | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/cf-lib/data/Recipe.lua b/cf-lib/data/Recipe.lua index 6eca2b6..01358d5 100644 --- a/cf-lib/data/Recipe.lua +++ b/cf-lib/data/Recipe.lua @@ -102,9 +102,9 @@ end --- @param ingredientName string The name of the ingredient function Recipe:removeIngredient(ingredientName) if self.prototype.ingredients then - for i, result in pairs(self.prototype.ingredients) do - if result.name == ingredientName then - self.prototype.ingredients[i] = nil + for i, ingredient in pairs(self.prototype.ingredients) do + if ingredient.name == ingredientName then + table.remove(self.prototype.ingredients, i) return self end end @@ -137,6 +137,20 @@ function Recipe:replaceResult(old, new, amount, expensiveAmount) return self end +--- Removes an existing result by name +--- @param resultName string The name of the result +function Recipe:removeResult(resultName) + if self.prototype.results then + for i, result in pairs(self.prototype.results) do + if result.name == resultName then + table.remove(self.prototype.results, i) + return self + end + end + end + return self +end + --- Adds the recipe to a technology --- @param technology string|table The name of the technology or the technology table function Recipe:unlockedByTechnology(technology) From a9782564bfc10bb2cfcf5475983384c9fcb2c302 Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Sun, 23 Nov 2025 19:02:28 +0100 Subject: [PATCH 25/32] Add Recipe:addResult --- cf-lib/data/Recipe.lua | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/cf-lib/data/Recipe.lua b/cf-lib/data/Recipe.lua index 01358d5..199005c 100644 --- a/cf-lib/data/Recipe.lua +++ b/cf-lib/data/Recipe.lua @@ -112,14 +112,50 @@ function Recipe:removeIngredient(ingredientName) return self end +--- Adds a result to the recipe +--- @param resultName string The name of the result +--- @param amount number|table The amount of the result (default: 1) or a table with custom properties +function Recipe:addResult(resultName, amount) + local props = amount + if type(props) == "string" then + props = { amount = props } + end + if not props.amount then + props.amount = 1 + end + local resultType = data.raw.item[resultName] and "item" + or data.raw.module[resultName] and "item" + or data.raw.fluid[resultName] and "fluid" + or nil + if not resultType then + log("Unknown result: " .. resultName) + return + end + self.prototype.results = self.prototype.results or {} + for _, result in pairs(self.prototype.results) do + if result.name == resultName then + result.amount = nil + result.amount_min = nil + result.amount_max = nil + result.probability = nil + for k, v in pairs(props) do + result[k] = v + end + return self + end + end + props.name = resultName + props.type = resultType + table.insert(self.prototype.results, props) + return self +end + --- Replaces an existing result by name with a new result --- @param old string The name of the existing result --- @param new? string The name of the new result --- @param amount? number The amount of the new result (keeps the old value if not set) ---- @param expensiveAmount? number The amount of the new result for the expensive recipe (uses amount if not set) -function Recipe:replaceResult(old, new, amount, expensiveAmount) +function Recipe:replaceResult(old, new, amount) if type(new) == "number" then - expensiveAmount = amount amount = new new = old end From bf7d05e3beaddd4687907dcff9f1615d77ebe3d7 Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Sun, 23 Nov 2025 19:02:37 +0100 Subject: [PATCH 26/32] 1.0.0 --- cf-lib/changelog.txt | 14 +++++++++++--- cf-lib/info.json | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cf-lib/changelog.txt b/cf-lib/changelog.txt index ae8b83d..3c59ed4 100644 --- a/cf-lib/changelog.txt +++ b/cf-lib/changelog.txt @@ -1,18 +1,26 @@ --------------------------------------------------------------------------------------------------- +Version: 1.0.0 +Date: 23.11.2025 + Changes: + - Add table.filterKey + - Add class Settings + - Add Recipe:removeResult + - Add Recipe:addResult +--------------------------------------------------------------------------------------------------- Version: 0.0.14 Date: 10.06.2025 Changes: - Add :merge + - Add :merge --------------------------------------------------------------------------------------------------- Version: 0.0.13 Date: 23.05.2025 Changes: - Add Item class + - Add Item class --------------------------------------------------------------------------------------------------- Version: 0.0.12 Date: 06.04.2025 Changes: - Add table.count + - Add table.count --------------------------------------------------------------------------------------------------- Version: 0.0.11 Date: 28.03.2025 diff --git a/cf-lib/info.json b/cf-lib/info.json index 15a2c72..e023b1e 100644 --- a/cf-lib/info.json +++ b/cf-lib/info.json @@ -1,6 +1,6 @@ { "name": "cf-lib", - "version": "0.0.14", + "version": "1.0.0", "title": "cackling fiends library", "description": "Because I'd like to have my own library :-)", "author": "cackling fiend", From a6f495af8b9ad96e45b6ce19636345c4235cfbda Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Fri, 12 Dec 2025 18:36:15 +0100 Subject: [PATCH 27/32] Add Item:defaultImportLocation --- cf-lib/data/Item.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cf-lib/data/Item.lua b/cf-lib/data/Item.lua index 1cfffcf..5934a72 100644 --- a/cf-lib/data/Item.lua +++ b/cf-lib/data/Item.lua @@ -57,4 +57,11 @@ function Item:itemsPerRocket(count) return self end +--- Sets the default import location for space platforms +--- @param planetName string The name of the planet +function Item:defaultImportLocation(planetName) + self.prototype.default_import_location = planetName + return self +end + return Item \ No newline at end of file From 6de1a8f1c770a3bb4acb1f26ec1a7cad1b206359 Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Fri, 12 Dec 2025 18:36:25 +0100 Subject: [PATCH 28/32] Add Recipe:addCategory --- cf-lib/data/Recipe.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cf-lib/data/Recipe.lua b/cf-lib/data/Recipe.lua index 199005c..213aa14 100644 --- a/cf-lib/data/Recipe.lua +++ b/cf-lib/data/Recipe.lua @@ -187,6 +187,17 @@ function Recipe:removeResult(resultName) return self end +--- Adds an additional crafting category +--- @param categoryName string The name of the crafting category +function Recipe:addCategory(categoryName) + local categories = self.prototype.additional_categories or {} + self.prototype.additional_categories = categories + if not table.contains(categories, categoryName) then + table.insert(categories, categoryName) + end + return self +end + --- Adds the recipe to a technology --- @param technology string|table The name of the technology or the technology table function Recipe:unlockedByTechnology(technology) From 5507f65131dbe51863ac4b9dedf704e7ee8108bb Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Fri, 12 Dec 2025 18:52:56 +0100 Subject: [PATCH 29/32] Settings.force also sets default_value --- cf-lib/settings/Settings.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/cf-lib/settings/Settings.lua b/cf-lib/settings/Settings.lua index 582292b..0f1ce40 100644 --- a/cf-lib/settings/Settings.lua +++ b/cf-lib/settings/Settings.lua @@ -21,6 +21,7 @@ function Settings.force(name, value) setting.forced_value = value else setting.allowed_values = { value } + setting.default_value = value end end From cd5bdaa59f01221334b79c79506ea9cdd4fdb94c Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Fri, 12 Dec 2025 23:13:08 +0100 Subject: [PATCH 30/32] 1.1.0 --- cf-lib/changelog.txt | 8 ++++++++ cf-lib/info.json | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cf-lib/changelog.txt b/cf-lib/changelog.txt index 3c59ed4..d9e2ead 100644 --- a/cf-lib/changelog.txt +++ b/cf-lib/changelog.txt @@ -1,4 +1,12 @@ --------------------------------------------------------------------------------------------------- +Version: 1.1.0 +Date: 12.12.2025 + Changes: + - Add Item:defaultImportLocation + - Add Recipe:addCategory + Bug Fixes: + - Settings.force also sets default_value +--------------------------------------------------------------------------------------------------- Version: 1.0.0 Date: 23.11.2025 Changes: diff --git a/cf-lib/info.json b/cf-lib/info.json index e023b1e..69d149c 100644 --- a/cf-lib/info.json +++ b/cf-lib/info.json @@ -1,6 +1,6 @@ { "name": "cf-lib", - "version": "1.0.0", + "version": "1.1.0", "title": "cackling fiends library", "description": "Because I'd like to have my own library :-)", "author": "cackling fiend", From 75096988888b513d3b3b2ee37e2847281c59fcfa Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Sat, 13 Dec 2025 00:33:11 +0100 Subject: [PATCH 31/32] Add class Entity --- cf-lib/data/Entity.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 cf-lib/data/Entity.lua diff --git a/cf-lib/data/Entity.lua b/cf-lib/data/Entity.lua new file mode 100644 index 0000000..4a21072 --- /dev/null +++ b/cf-lib/data/Entity.lua @@ -0,0 +1,29 @@ +--- Utility class for entity prototype definitions +--- @class Entity +local Entity = {} + +--- Generates a selection box definition using width and height of the entity in tiles. +--- @param width number The width of the entity in tiles +--- @param height number The height of the entity in tiles +--- @return table A table containing the selection box definition +Entity.selectionBox = function(width, height) + return { + { -width / 2, -height / 2 }, + { width / 2, height / 2 } + } +end + +--- Generates a collision box definition using width and height of the entity in tiles. +--- @param width number The width of the entity in tiles +--- @param height number The height of the entity in tiles +--- @param margin number The margin to apply to the collision box compared to the selection box (default: 0.3) +--- @return table A table containing the collision box definition +Entity.collisionBox = function(width, height, margin) + margin = margin or 0.1 + return { + { -width / 2 + margin, -height / 2 + margin }, + { width / 2 - margin, height / 2 - margin } + } +end + +return Entity \ No newline at end of file From 5a0f1975ef7ef9351fc85ea90f8fb7cf8a8453ab Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Sun, 14 Dec 2025 18:22:36 +0100 Subject: [PATCH 32/32] 1.2.0 --- cf-lib/changelog.txt | 5 +++++ cf-lib/info.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cf-lib/changelog.txt b/cf-lib/changelog.txt index d9e2ead..a8ccbc2 100644 --- a/cf-lib/changelog.txt +++ b/cf-lib/changelog.txt @@ -1,4 +1,9 @@ --------------------------------------------------------------------------------------------------- +Version: 1.2.0 +Date: 14.12.2025 + Changes: + - Add class Entity +--------------------------------------------------------------------------------------------------- Version: 1.1.0 Date: 12.12.2025 Changes: diff --git a/cf-lib/info.json b/cf-lib/info.json index 69d149c..51dbeef 100644 --- a/cf-lib/info.json +++ b/cf-lib/info.json @@ -1,6 +1,6 @@ { "name": "cf-lib", - "version": "1.1.0", + "version": "1.2.0", "title": "cackling fiends library", "description": "Because I'd like to have my own library :-)", "author": "cackling fiend",