proper handling of 89-color "split" palette in craft helper

This commit is contained in:
Vanessa Dannenberg 2018-08-22 20:01:03 -04:00
parent 4847b926d5
commit 5557178cb4

@ -185,22 +185,42 @@ end
local function register_c(craft, hue, sat, val) local function register_c(craft, hue, sat, val)
local color = "" local color = ""
if val then if val then
if craft.palette == "wallmounted" then if craft.palette ~= "extended" then
color = "dye:"..val..hue..sat color = val..hue..sat
else else
color = "dye:"..val..hue[1]..sat color = val..hue[1]..sat
end end
else else
color = "dye:"..hue -- if val is nil, then it's grey. color = hue -- if val is nil, then it's grey.
end end
local dye = "dye:"..color
local recipe = minetest.serialize(craft.recipe) local recipe = minetest.serialize(craft.recipe)
recipe = string.gsub(recipe, "MAIN_DYE", color) recipe = string.gsub(recipe, "MAIN_DYE", dye)
recipe = string.gsub(recipe, "NEUTRAL_NODE", craft.neutral_node) recipe = string.gsub(recipe, "NEUTRAL_NODE", craft.neutral_node)
local newrecipe = minetest.deserialize(recipe) local newrecipe = minetest.deserialize(recipe)
local output = craft.output
if craft.output_prefix then
if craft.palette ~= true then
output = craft.output_prefix..color..craft.output_suffix
else
if hue == "white" or hue == "black" or string.find(hue, "grey") then
output = craft.output_prefix.."grey"..craft.output_suffix
else
output = craft.output_prefix..hue..craft.output_suffix
end
end
end
local colored_itemstack = local colored_itemstack =
unifieddyes.make_colored_itemstack(craft.output, craft.palette, color) unifieddyes.make_colored_itemstack(output, craft.palette, dye)
if string.find(output, "coloredwood") and string.find(output, "outer") then
print("[UD] register craft: "..craft.neutral_node.." ("..color..")")
print("[UD] register craft: --> "..output)
end
minetest.register_craft({ minetest.register_craft({
output = colored_itemstack, output = colored_itemstack,
@ -211,28 +231,24 @@ local function register_c(craft, hue, sat, val)
end end
function unifieddyes.register_color_craft(craft) function unifieddyes.register_color_craft(craft)
if not craft or not craft.recipe or not craft.output or not craft.neutral_node then return end local hues_table = unifieddyes.HUES
local hues_table = unifieddyes.HUES_EXTENDED
local sats_table = unifieddyes.SATS local sats_table = unifieddyes.SATS
local vals_table = unifieddyes.VALS_EXTENDED local vals_table = unifieddyes.VALS
local greys_table = unifieddyes.GREYS_EXTENDED local greys_table = unifieddyes.GREYS
if not craft.palette then if craft.palette == "wallmounted" then
hues_table = unifieddyes.HUES
sats_table = unifieddyes.SATS
vals_table = unifieddyes.VALS
greys_table = unifieddyes.GREYS
elseif craft.palette == "wallmounted" then
hues_table = unifieddyes.HUES_WALLMOUNTED hues_table = unifieddyes.HUES_WALLMOUNTED
sats_table = {""} sats_table = {""}
vals_table = unifieddyes.VALS vals_table = unifieddyes.VALS
greys_table = unifieddyes.GREYS elseif craft.palette == "extended" then
hues_table = unifieddyes.HUES_EXTENDED
vals_table = unifieddyes.VALS_EXTENDED
greys_table = unifieddyes.GREYS_EXTENDED
end end
for _,hue in ipairs(hues_table) do for _, hue in ipairs(hues_table) do
for _,val in ipairs(vals_table) do for _, val in ipairs(vals_table) do
for _,sat in ipairs(sats_table) do for _, sat in ipairs(sats_table) do
if sat == "_s50" and val ~= "" and val ~= "medium_" and val ~= "dark_" then break end if sat == "_s50" and val ~= "" and val ~= "medium_" and val ~= "dark_" then break end
register_c(craft, hue, sat, val) register_c(craft, hue, sat, val)
@ -244,6 +260,7 @@ function unifieddyes.register_color_craft(craft)
for _, grey in ipairs(greys_table) do for _, grey in ipairs(greys_table) do
register_c(craft, grey) register_c(craft, grey)
end end
end end
-- code borrowed from homedecor -- code borrowed from homedecor