Add Recipe:addIndicatorIcon()

This commit is contained in:
Simon Brodtmann 2025-12-24 23:39:48 +01:00
parent 48325fd78d
commit e6b2bbe154
2 changed files with 23 additions and 1 deletions

View file

@ -51,7 +51,7 @@ function Item:merge(data)
return self return self
end 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 --- @param count number The amount of items that fit into a rocket
function Item:itemsPerRocket(count) function Item:itemsPerRocket(count)
self.prototype.weight = (1000 / count) * kg self.prototype.weight = (1000 / count) * kg

View file

@ -226,4 +226,26 @@ function Recipe:clone(name)
return Recipe:new(clone) return Recipe:new(clone)
end 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 return Recipe