Add detection and setting of new palette

(with any luck, all that's left now is to update the mods that use
Unified Dyes, where the new palette is wanted)
This commit is contained in:
Vanessa Ezekowitz 2017-02-24 18:38:15 -05:00
parent 9ad1f28ae1
commit 50013d21d1

143
init.lua

@ -87,6 +87,9 @@ local HUES_EXTENDED = {
{ "crimson", 0xff, 0x00, 0x40 } { "crimson", 0xff, 0x00, 0x40 }
} }
for _, i in ipairs(HUES_EXTENDED) do
print("[\""..i[1].."\"] =,")
end
local SATS = { local SATS = {
"", "",
"_s50" "_s50"
@ -256,9 +259,18 @@ function unifieddyes.get_hsv(name) -- expects a node/item name
return hue, sat, val return hue, sat, val
end end
-- code borrowed from cheapie's plasticbox mod -- code partially borrowed from cheapie's plasticbox mod
-- in the function below, color is just a color string, while
-- palette_type can be:
--
-- false/nil = standard 89 color palette
-- true = 89 color palette split into pieces for colorfacedir
-- "wallmounted" = 32-color abridged palette
-- "extended" = 256 color palette
function unifieddyes.getpaletteidx(color, palette_type)
function unifieddyes.getpaletteidx(color, is_color_fdir)
local origcolor = color local origcolor = color
local aliases = { local aliases = {
["pink"] = "light_red", ["pink"] = "light_red",
@ -273,6 +285,28 @@ function unifieddyes.getpaletteidx(color, is_color_fdir)
["black"] = 5, ["black"] = 5,
} }
local grayscale_extended = {
["white"] = 0,
["grey_14"] = 1,
["grey_13"] = 2,
["grey_12"] = 3,
["light_grey"] = 3,
["grey_11"] = 4,
["grey_10"] = 5,
["grey_9"] = 6,
["grey_8"] = 7,
["grey"] = 7,
["grey_7"] = 8,
["grey_6"] = 9,
["grey_5"] = 10,
["grey_4"] = 11,
["dark_grey"] = 11,
["grey_3"] = 12,
["grey_2"] = 13,
["grey_1"] = 14,
["black"] = 15,
}
local grayscale_wallmounted = { local grayscale_wallmounted = {
["white"] = 0, ["white"] = 0,
["light_grey"] = 1, ["light_grey"] = 1,
@ -296,6 +330,33 @@ function unifieddyes.getpaletteidx(color, is_color_fdir)
["redviolet"] = 12, ["redviolet"] = 12,
} }
local hues_extended = {
["red"] = 0,
["vermilion"] = 1,
["orange"] = 2,
["amber"] = 3,
["yellow"] = 4,
["lime"] = 5,
["chartreuse"] = 6,
["harlequin"] = 7,
["green"] = 8,
["malachite"] = 9,
["spring"] = 10,
["turquoise"] = 11,
["cyan"] = 12,
["cerulean"] = 13,
["azure"] = 14,
["sapphire"] = 15,
["blue"] = 16,
["indigo"] = 17,
["violet"] = 18,
["mulberry"] = 19,
["magenta"] = 20,
["fuchsia"] = 21,
["rose"] = 22,
["crimson"] = 23,
}
local hues_wallmounted = { local hues_wallmounted = {
["red"] = 0, ["red"] = 0,
["orange"] = 1, ["orange"] = 1,
@ -317,6 +378,19 @@ function unifieddyes.getpaletteidx(color, is_color_fdir)
["darks50"] = 7, ["darks50"] = 7,
} }
local shades_extended = {
["faint"] = 1,
["pastel"] = 2,
["light"] = 3,
["bright"] = 4,
[""] = 5,
["s50"] = 6,
["medium"] = 7,
["mediums50"] = 8,
["dark"] = 9,
["darks50"] = 10,
}
local shades_wallmounted = { local shades_wallmounted = {
[""] = 1, [""] = 1,
["medium"] = 2, ["medium"] = 2,
@ -331,24 +405,37 @@ function unifieddyes.getpaletteidx(color, is_color_fdir)
return return
end end
if is_color_fdir == "wallmounted" then if palette_type == "wallmounted" then
if grayscale_wallmounted[color] then if grayscale_wallmounted[color] then
return (grayscale_wallmounted[color] * 8), 0 return (grayscale_wallmounted[color] * 8), 0
end end
elseif is_color_fdir then elseif palette_type == true then
if grayscale[color] then if grayscale[color] then
return (grayscale[color] * 32), 0 return (grayscale[color] * 32), 0
end end
elseif palette_type == "extended" then
if grayscale_extended[color] then
return grayscale_extended[color], 0
end
else else
if grayscale[color] then if grayscale[color] then
return grayscale[color], 0 return grayscale[color], 0
end end
end end
local shade = "" local shade = "" -- assume full
if string.sub(color,1,6) == "light_" then if string.sub(color,1,6) == "faint_" then
shade = "faint"
color = string.sub(color,7,-1)
elseif string.sub(color,1,7) == "pastel_" then
shade = "pastel"
color = string.sub(color,8,-1)
elseif string.sub(color,1,6) == "light_" then
shade = "light" shade = "light"
color = string.sub(color,7,-1) color = string.sub(color,7,-1)
elseif string.sub(color,1,7) == "bright_" then
shade = "bright"
color = string.sub(color,8,-1)
elseif string.sub(color,1,7) == "medium_" then elseif string.sub(color,1,7) == "medium_" then
shade = "medium" shade = "medium"
color = string.sub(color,8,-1) color = string.sub(color,8,-1)
@ -361,7 +448,7 @@ function unifieddyes.getpaletteidx(color, is_color_fdir)
color = string.sub(color,1,-5) color = string.sub(color,1,-5)
end end
if is_color_fdir == "wallmounted" then if palette_type == "wallmounted" then
if color == "brown" then return 48,1 if color == "brown" then return 48,1
elseif color == "pink" then return 56,7 elseif color == "pink" then return 56,7
elseif color == "blue" and shade == "light" then return 40,5 elseif color == "blue" and shade == "light" then return 40,5
@ -376,10 +463,16 @@ function unifieddyes.getpaletteidx(color, is_color_fdir)
color = "red" color = "red"
shade = "light" shade = "light"
end end
if palette_type == true then -- it's colorfacedir
if hues[color] and shades[shade] then if hues[color] and shades[shade] then
if is_color_fdir then
return (shades[shade] * 32), hues[color] return (shades[shade] * 32), hues[color]
else end
elseif palette_type == "extended" then
if hues_extended[color] and shades_extended[shade] then
return (hues_extended[color] + shades_extended[shade]*24), hues_extended[color]
end
else -- it's the 89-color palette
if hues[color] and shades[shade] then
return (hues[color] * 8 + shades[shade]), hues[color] return (hues[color] * 8 + shades[shade]), hues[color]
end end
end end
@ -433,14 +526,18 @@ function unifieddyes.on_use(itemstack, player, pointed_thing)
end end
local newnode = nodedef.ud_replacement_node local newnode = nodedef.ud_replacement_node
local is_color_fdir local palette_type
if nodedef.paramtype2 == "color" then if nodedef.paramtype2 == "color" then
is_color_fdir = false if nodedef.palette == "unifieddyes_palette_extended.png" then
elseif nodedef.paramtype2 == "colorfacedir" palette_type = "extended"
then is_color_fdir = true else
elseif nodedef.paramtype2 == "colorwallmounted" palette_type = false
then is_color_fdir = "wallmounted" end
elseif nodedef.paramtype2 == "colorfacedir" then
palette_type = true
elseif nodedef.paramtype2 == "colorwallmounted" then
palette_type = "wallmounted"
end end
if minetest.is_protected(pos, playername) and not minetest.check_player_privs(playername, {protection_bypass=true}) then if minetest.is_protected(pos, playername) and not minetest.check_player_privs(playername, {protection_bypass=true}) then
@ -450,7 +547,7 @@ function unifieddyes.on_use(itemstack, player, pointed_thing)
local stackname = itemstack:get_name() local stackname = itemstack:get_name()
local pos2 = unifieddyes.select_node(pointed_thing) local pos2 = unifieddyes.select_node(pointed_thing)
local paletteidx, hue = unifieddyes.getpaletteidx(stackname, is_color_fdir) local paletteidx, hue = unifieddyes.getpaletteidx(stackname, palette_type)
if paletteidx then if paletteidx then
@ -478,7 +575,7 @@ function unifieddyes.on_use(itemstack, player, pointed_thing)
node.param2 = paletteidx node.param2 = paletteidx
local oldpaletteidx, oldhuenum = unifieddyes.getpaletteidx(prevdye, is_color_fdir) local oldpaletteidx, oldhuenum = unifieddyes.getpaletteidx(prevdye, palette_type)
local oldnode = minetest.get_node(pos) local oldnode = minetest.get_node(pos)
local oldhue = nil local oldhue = nil
@ -491,9 +588,9 @@ function unifieddyes.on_use(itemstack, player, pointed_thing)
end end
if newnode then -- this path is used when the calling mod want to supply a replacement node if newnode then -- this path is used when the calling mod want to supply a replacement node
if is_color_fdir == "wallmounted" then if palette_type == "wallmounted" then
node.param2 = paletteidx + (minetest.get_node(pos).param2 % 8) node.param2 = paletteidx + (minetest.get_node(pos).param2 % 8)
elseif is_color_fdir then -- we probably need to change the hue of the node too elseif palette_type == true then -- it's colorfacedir
if oldhue ~=0 then -- it's colored, not grey if oldhue ~=0 then -- it's colored, not grey
if oldhue ~= nil then -- it's been painted before if oldhue ~= nil then -- it's been painted before
if hue ~= 0 then -- the player's wielding a colored dye if hue ~= 0 then -- the player's wielding a colored dye
@ -512,7 +609,7 @@ function unifieddyes.on_use(itemstack, player, pointed_thing)
end end
end end
node.param2 = paletteidx + (minetest.get_node(pos).param2 % 32) node.param2 = paletteidx + (minetest.get_node(pos).param2 % 32)
else else -- it's the 89-color palette, or the extended palette
node.param2 = paletteidx node.param2 = paletteidx
end end
node.name = newnode node.name = newnode
@ -522,9 +619,9 @@ function unifieddyes.on_use(itemstack, player, pointed_thing)
end end
else -- this path is used when you're just painting an existing node, rather than replacing one. else -- this path is used when you're just painting an existing node, rather than replacing one.
newnode = oldnode -- note that here, newnode/oldnode are a full node, not just the name. newnode = oldnode -- note that here, newnode/oldnode are a full node, not just the name.
if is_color_fdir == "wallmounted" then if palette_type == "wallmounted" then
newnode.param2 = paletteidx + (minetest.get_node(pos).param2 % 8) newnode.param2 = paletteidx + (minetest.get_node(pos).param2 % 8)
elseif is_color_fdir then elseif palette_type == true then -- it's colorfacedir
if oldhue then if oldhue then
if hue ~= 0 then if hue ~= 0 then
newnode.name = string.gsub(newnode.name, "_"..oldhue, "_"..HUES[hue]) newnode.name = string.gsub(newnode.name, "_"..oldhue, "_"..HUES[hue])
@ -535,7 +632,7 @@ function unifieddyes.on_use(itemstack, player, pointed_thing)
newnode.name = string.gsub(newnode.name, "_grey", "_"..HUES[hue]) newnode.name = string.gsub(newnode.name, "_grey", "_"..HUES[hue])
end end
newnode.param2 = paletteidx + (minetest.get_node(pos).param2 % 32) newnode.param2 = paletteidx + (minetest.get_node(pos).param2 % 32)
else else -- it's the 89-color palette, or the extended palette
newnode.param2 = paletteidx newnode.param2 = paletteidx
end end
minetest.swap_node(pos, newnode) minetest.swap_node(pos, newnode)