Skip to content

Commit 9013879

Browse files
authored
Remove dye combining from script
Turns out that dye mixing does not like there being multiple units and/or stacks in a bag and it bugs out - removing dyes altogether for now
1 parent 18c93d8 commit 9013879

1 file changed

Lines changed: 10 additions & 19 deletions

File tree

combine.lua

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -182,24 +182,15 @@ local function stack_type_new(type_vals)
182182
return stack_type
183183
end
184184

185-
local function dye_profile_key(item)
186-
-- signature of an item's dye_profile, so that dyes/dye-mixes with different
187-
-- profiles are not treated as the same comparable item and merged together
188-
-- (which would ruin the mix and revert it to a component color).
189-
-- empty profiles (plain powders like flour) yield '', preserving the
190-
-- original behavior for everything that isn't a mixed dye.
191-
local ok, sig = pcall(function()
192-
local dp = item.dye_profile
193-
if dp.color_index == -1 and #dp.dye_material == 0 then return '' end
194-
local parts = {'c' .. dp.color_index}
195-
for _, v in ipairs(dp.dye_material) do parts[#parts+1] = 'm' .. v end
196-
for _, v in ipairs(dp.dye_matg) do parts[#parts+1] = 'g' .. v end
197-
for _, v in ipairs(dp.degree) do parts[#parts+1] = 'd' .. v end
198-
for _, v in ipairs(dp.target_index) do parts[#parts+1] = 't' .. v end
199-
return '+' .. table.concat(parts, ',')
185+
local function isDye(item)
186+
-- Dyes should not be combined as this will cause bugs when mixing them together
187+
if item:getType() ~= df.item_type.POWDER_MISC then return false end
188+
-- pcall guards items/materials that can't be decoded or lack the flag
189+
local ok, is_dye = pcall(function()
190+
local mat = dfhack.matinfo.decode(item.mat_type, item.mat_index)
191+
return mat and mat.material.flags.IS_DYE or false
200192
end)
201-
-- pcall guards item types in this branch that have no dye_profile field
202-
return (ok and sig) or ''
193+
return ok and is_dye or false
203194
end
204195

205196
local function stacks_add_item(stockpile, stacks, stack_type, item, container)
@@ -219,7 +210,7 @@ local function stacks_add_item(stockpile, stacks, stack_type, item, container)
219210
comp_key = ('%s+%s+%s+%s'):format(stack_type.type_id, item.mat_type, item.mat_index, item:getQuality())
220211
end
221212
else
222-
comp_key = ('%s+%s+%s%s'):format(stack_type.type_id, item.mat_type, item.mat_index, dye_profile_key(item))
213+
comp_key = ('%s+%s+%s'):format(stack_type.type_id, item.mat_type, item.mat_index)
223214
end
224215

225216
if not stack_type.comp_items[comp_key] then
@@ -456,7 +447,7 @@ local function stacks_add_items(stockpile, stacks, items, container, ind)
456447
local stack_type = stacks.stack_types[type_id]
457448

458449
-- item type in list of included types?
459-
if stack_type and not item:isSand() and not item:isPlaster() and isValidPart(item) then
450+
if stack_type and not item:isSand() and not item:isPlaster() and not isDye(item) and isValidPart(item) then
460451
if not isRestrictedItem(item) and item.stack_size <= stack_type.max_stack_qty then
461452

462453
stacks_add_item(stockpile, stacks, stack_type, item, container)

0 commit comments

Comments
 (0)