add API option for "colorwallmounted" paramtype2

(pass "wallmounted" to the "is_color_fdir" field where needed)

Comes with an abridged, 32-color version of the master palette,
containing Red, Orange, Yellow, Green, Cyan, Blue, Violet, and Magenta,
in three shades each, plus the usual black/three greys/white, plus pink
and brown in two of the extrs spaces.
This commit is contained in:
Vanessa Ezekowitz 2017-01-28 21:51:46 -05:00
parent 966166b1b9
commit 8ea8b01dcc
2 changed files with 51 additions and 8 deletions

@ -147,6 +147,14 @@ function unifieddyes.getpaletteidx(color, is_color_fdir)
["black"] = 5, ["black"] = 5,
} }
local grayscale_wallmounted = {
["white"] = 0,
["light_grey"] = 1,
["grey"] = 2,
["dark_grey"] = 3,
["black"] = 4,
}
local hues = { local hues = {
["red"] = 1, ["red"] = 1,
["orange"] = 2, ["orange"] = 2,
@ -162,6 +170,17 @@ function unifieddyes.getpaletteidx(color, is_color_fdir)
["redviolet"] = 12, ["redviolet"] = 12,
} }
local hues_wallmounted = {
["red"] = 0,
["orange"] = 1,
["yellow"] = 2,
["green"] = 3,
["cyan"] = 4,
["blue"] = 5,
["violet"] = 6,
["magenta"] = 7
}
local shades = { local shades = {
[""] = 1, [""] = 1,
["s50"] = 2, ["s50"] = 2,
@ -172,6 +191,12 @@ function unifieddyes.getpaletteidx(color, is_color_fdir)
["darks50"] = 7, ["darks50"] = 7,
} }
local shades_wallmounted = {
[""] = 1,
["medium"] = 2,
["dark"] = 3
}
if string.sub(color,1,4) == "dye:" then if string.sub(color,1,4) == "dye:" then
color = string.sub(color,5,-1) color = string.sub(color,5,-1)
elseif string.sub(color,1,12) == "unifieddyes:" then elseif string.sub(color,1,12) == "unifieddyes:" then
@ -183,8 +208,12 @@ function unifieddyes.getpaletteidx(color, is_color_fdir)
color = aliases[color] or color color = aliases[color] or color
local idx local idx
if is_color_fdir == "wallmounted" then
if grayscale_wallmounted[color] then
return (grayscale_wallmounted[color] * 64), 0
end
elseif is_color_fdir then
if grayscale[color] then if grayscale[color] then
if is_color_fdir then
return (grayscale[color] * 32), 0 return (grayscale[color] * 32), 0
else else
return grayscale[color], 0 return grayscale[color], 0
@ -207,11 +236,17 @@ function unifieddyes.getpaletteidx(color, is_color_fdir)
color = string.sub(color,1,-5) color = string.sub(color,1,-5)
end end
if hues[color] and shades[shade] then if is_color_fdir == "wallmounted" then
if not is_color_fdir then if shade == "dark" and color == "orange" then return 48,1 -- brown
return (hues[color] * 8 + shades[shade]), hues[color] elseif shade == "light" and color == "red" then return 56,7 -- pink
else elseif hues_wallmounted[color] and shades_wallmounted[shade] then
return (shades_wallmounted[shade] * 64 + hues_wallmounted[color] * 8), hues_wallmounted[color]
end
elseif hues[color] and shades[shade] then
if is_color_fdir then
return (shades[shade] * 32), hues[color] return (shades[shade] * 32), hues[color]
else
return (hues[color] * 8 + shades[shade]), hues[color]
end end
end end
end end
@ -282,7 +317,9 @@ function unifieddyes.on_rightclick(pos, node, player, stack, pointed_thing, newn
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 then -- we probably need to change the hue of the node too if is_color_fdir == "wallmounted" then
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
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
@ -308,7 +345,9 @@ function unifieddyes.on_rightclick(pos, node, player, stack, pointed_thing, newn
minetest.swap_node(pos, node) minetest.swap_node(pos, node)
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 then if is_color_fdir == "wallmounted" then
newnode.param2 = paletteidx + (minetest.get_node(pos).param2 % 8)
elseif is_color_fdir then
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])
@ -333,6 +372,10 @@ function unifieddyes.on_rightclick(pos, node, player, stack, pointed_thing, newn
local dir = minetest.yaw_to_dir(yaw-1.5) local dir = minetest.yaw_to_dir(yaw-1.5)
local fdir = minetest.dir_to_facedir(dir) local fdir = minetest.dir_to_facedir(dir)
if is_color_fdir == "wallmounted" then
fdir = minetest.dir_to_wallmounted(dir)
end
minetest.set_node(pos2, { name = placeable_node.name, param2 = fdir }) minetest.set_node(pos2, { name = placeable_node.name, param2 = fdir })
if not creative_mode then if not creative_mode then
stack:take_item() stack:take_item()

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 B