From e6b2bbe1548568507166fecca5c063dedd757872 Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Wed, 24 Dec 2025 23:39:48 +0100 Subject: [PATCH] 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