From 75096988888b513d3b3b2ee37e2847281c59fcfa Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Sat, 13 Dec 2025 00:33:11 +0100 Subject: [PATCH 1/7] 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 2/7] 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", From 48325fd78dc24aa76007284b985094b771546c8e Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Wed, 24 Dec 2025 08:58:26 +0100 Subject: [PATCH 3/7] :apply() returns self --- cf-lib/data/Item.lua | 1 + cf-lib/data/Recipe.lua | 1 + cf-lib/data/Technology.lua | 1 + 3 files changed, 3 insertions(+) diff --git a/cf-lib/data/Item.lua b/cf-lib/data/Item.lua index 5934a72..5727408 100644 --- a/cf-lib/data/Item.lua +++ b/cf-lib/data/Item.lua @@ -32,6 +32,7 @@ end --- Applies the item to the game function Item:apply() data:extend({ self.prototype }) + return self end --- Assigns data to the item diff --git a/cf-lib/data/Recipe.lua b/cf-lib/data/Recipe.lua index 213aa14..87c48fd 100644 --- a/cf-lib/data/Recipe.lua +++ b/cf-lib/data/Recipe.lua @@ -32,6 +32,7 @@ end --- Applies the recipe to the game function Recipe:apply() data:extend({ self.prototype }) + return self end --- Assigns data to the recipe diff --git a/cf-lib/data/Technology.lua b/cf-lib/data/Technology.lua index 13a1dd9..3dd3b48 100644 --- a/cf-lib/data/Technology.lua +++ b/cf-lib/data/Technology.lua @@ -40,6 +40,7 @@ end --- Applies the technology to the game function Technology:apply() data:extend({ self.prototype }) + return self end --- Assigns data to the technology From e6b2bbe1548568507166fecca5c063dedd757872 Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Wed, 24 Dec 2025 23:39:48 +0100 Subject: [PATCH 4/7] Add Recipe:addIndicatorIcon() --- cf-lib/data/Item.lua | 2 +- cf-lib/data/Recipe.lua | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/cf-lib/data/Item.lua b/cf-lib/data/Item.lua index 5727408..a7d753c 100644 --- a/cf-lib/data/Item.lua +++ b/cf-lib/data/Item.lua @@ -51,7 +51,7 @@ function Item:merge(data) return self end ---- Sets the weight of the item calculated from given count per rocket. +--- 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 diff --git a/cf-lib/data/Recipe.lua b/cf-lib/data/Recipe.lua index 87c48fd..32a9d67 100644 --- a/cf-lib/data/Recipe.lua +++ b/cf-lib/data/Recipe.lua @@ -226,4 +226,26 @@ function Recipe:clone(name) return Recipe:new(clone) end +--- Adds a small icon in the corner of the regular item +--- It currently assumes an icon_size of 64 +--- @param icon string The filename of the icon +--- @param position string The position of the icon. One of ["top-left", "top-right", "bottom-left", "bottom-right"]. Defaults to "bottom-right". +function Recipe:addIndicatorIcon(icon, position) + local icons = self.prototype.icons or {} + local mainIcon = icons[1] or self.prototype.icon or nil + if not mainIcon then + local result = self.prototype.results[1] + local resultItem = data.raw[result.type][result.name] + icons = resultItem.icons or {{ icon = resultItem.icon }} + end + local shift = { 8, 8 } + if position == "top-left" then shift = { -8, -8 } end + if position == "top-right" then shift = { 8, -8 } end + if position == "bottom-left" then shift = { -8, 8 } end + table.insert(icons, { icon = icon, scale = 0.25, shift = shift }) + self.prototype.icons = icons + log(serpent.block(self.prototype.icons)) + return self +end + return Recipe From ce885fb59571cd5915e148cf888e6557d8a682e4 Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Wed, 24 Dec 2025 23:41:56 +0100 Subject: [PATCH 5/7] 1.3.0 --- 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 a8ccbc2..db76d84 100644 --- a/cf-lib/changelog.txt +++ b/cf-lib/changelog.txt @@ -1,4 +1,10 @@ --------------------------------------------------------------------------------------------------- +Version: 1.3.0 +Date: 24.12.2025 + Changes: + - :apply() returns self + - Add Recipe:addIndicatorIcon() +--------------------------------------------------------------------------------------------------- Version: 1.2.0 Date: 14.12.2025 Changes: diff --git a/cf-lib/info.json b/cf-lib/info.json index 51dbeef..4191509 100644 --- a/cf-lib/info.json +++ b/cf-lib/info.json @@ -1,6 +1,6 @@ { "name": "cf-lib", - "version": "1.2.0", + "version": "1.3.0", "title": "cackling fiends library", "description": "Because I'd like to have my own library :-)", "author": "cackling fiend", From 68b4d0c444057deb279a234eefe2f47938e60e56 Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Mon, 5 Jan 2026 23:43:12 +0100 Subject: [PATCH 6/7] Add Entity.setFilename --- cf-lib/data/Entity.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cf-lib/data/Entity.lua b/cf-lib/data/Entity.lua index 4a21072..10172ad 100644 --- a/cf-lib/data/Entity.lua +++ b/cf-lib/data/Entity.lua @@ -26,4 +26,21 @@ Entity.collisionBox = function(width, height, margin) } end +--- Sets the file name on a picture considering various formats. +--- If sheets or layers are found, use the optional param to select the right one. +--- @param sprite table The sprite to replace the filename in +--- @param filename string The new filename +--- @param sheetLayer number The sheet or layer index to use. Defaults to 1. +Entity.setFilename = function(sprite, filename, sheetLayer) + if sprite.filename then + sprite.filename = filename + elseif sprite.sheet then + sprite.sheet.filename = filename + elseif sprite.sheets then + sprite.sheets[sheetLayer or 1].filename = filename + elseif sprite.layers then + sprite.layers[sheetLayer or 1].filename = filename + end +end + return Entity \ No newline at end of file From 59d2c45ee38f474e442bc74d02d67c61360eae03 Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Sat, 10 Jan 2026 22:50:32 +0100 Subject: [PATCH 7/7] 1.4.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 db76d84..f658edc 100644 --- a/cf-lib/changelog.txt +++ b/cf-lib/changelog.txt @@ -1,4 +1,9 @@ --------------------------------------------------------------------------------------------------- +Version: 1.4.0 +Date: 10.01.2026 + Changes: + - Add Entity.setFilename +--------------------------------------------------------------------------------------------------- Version: 1.3.0 Date: 24.12.2025 Changes: diff --git a/cf-lib/info.json b/cf-lib/info.json index 4191509..77044a6 100644 --- a/cf-lib/info.json +++ b/cf-lib/info.json @@ -1,6 +1,6 @@ { "name": "cf-lib", - "version": "1.3.0", + "version": "1.4.0", "title": "cackling fiends library", "description": "Because I'd like to have my own library :-)", "author": "cackling fiend",