2024-05-16 20:22:09 +02:00
|
|
|
-- nodename -> {r,g,b,a}
|
|
|
|
local node_colors = {}
|
|
|
|
|
|
|
|
-- nodename -> { {r,g,b,a}, {...}, ... }
|
|
|
|
local palette_colors = {}
|
|
|
|
|
2024-05-22 17:12:57 +02:00
|
|
|
-- palette-name -> def
|
|
|
|
local palettes = {}
|
|
|
|
|
2024-05-16 20:22:09 +02:00
|
|
|
local MP = minetest.get_modpath("isogen")
|
|
|
|
local function parse_file(filename)
|
2024-05-23 09:39:21 +02:00
|
|
|
for line in io.lines(filename) do
|
2024-05-16 20:22:09 +02:00
|
|
|
if #line > 2 and line:sub(1,1) ~= "#" then
|
|
|
|
local i = 1
|
|
|
|
local name
|
|
|
|
local color = {}
|
|
|
|
for str in string.gmatch(line, "([^ ]+)") do
|
|
|
|
if i == 1 then name = str end
|
|
|
|
if i == 2 then color.r = tonumber(str) end
|
|
|
|
if i == 3 then color.g = tonumber(str) end
|
|
|
|
if i == 4 then color.b = tonumber(str) end
|
|
|
|
if i == 5 and #str > 0 then color.a = tonumber(str) end
|
|
|
|
|
|
|
|
i = i + 1
|
|
|
|
end
|
|
|
|
node_colors[name] = color
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function parse_palette(name)
|
|
|
|
local f = assert(io.open(MP .. "/colors/" .. name .. ".json", "rb"))
|
|
|
|
local content = f:read("*all")
|
|
|
|
f:close()
|
|
|
|
local def = minetest.parse_json(content)
|
2024-05-22 17:12:57 +02:00
|
|
|
palettes[name] = def
|
2024-05-16 20:22:09 +02:00
|
|
|
|
|
|
|
for line in io.lines(MP .. "/colors/" .. name .. ".txt") do
|
|
|
|
if #line > 2 and line:sub(1,1) ~= "#" then
|
|
|
|
palette_colors[line] = def
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-05-16 20:26:19 +02:00
|
|
|
local function parse_mapcolors()
|
|
|
|
for name, def in pairs(minetest.registered_nodes) do
|
2024-05-22 17:12:57 +02:00
|
|
|
-- mapcolor attribute
|
2024-05-16 20:26:19 +02:00
|
|
|
if def.mapcolor then
|
|
|
|
node_colors[name] = def.mapcolor
|
|
|
|
end
|
2024-05-22 17:12:57 +02:00
|
|
|
|
|
|
|
-- unifieddyes palette
|
|
|
|
if def.palette and def.palette == "unifieddyes_palette_extended.png" then
|
|
|
|
node_colors[name] = nil
|
|
|
|
palette_colors[name] = palettes["unifieddyes_palette_extended"]
|
|
|
|
end
|
2024-05-16 20:26:19 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-05-16 20:22:09 +02:00
|
|
|
local function init()
|
2024-05-23 09:39:21 +02:00
|
|
|
parse_file(MP .. "/colors/" .. "advtrains.txt")
|
|
|
|
parse_file(MP .. "/colors/" .. "everness.txt")
|
|
|
|
parse_file(MP .. "/colors/" .. "mc2.txt")
|
|
|
|
parse_file(MP .. "/colors/" .. "miles.txt")
|
|
|
|
parse_file(MP .. "/colors/" .. "mtg.txt")
|
|
|
|
parse_file(MP .. "/colors/" .. "naturalbiomes.txt")
|
|
|
|
parse_file(MP .. "/colors/" .. "nodecore.txt")
|
|
|
|
parse_file(MP .. "/colors/" .. "scifi_nodes.txt")
|
|
|
|
parse_file(MP .. "/colors/" .. "vanessa.txt")
|
|
|
|
parse_file(MP .. "/colors/" .. "void.txt")
|
2024-05-16 20:22:09 +02:00
|
|
|
parse_palette("unifieddyes_palette_extended")
|
2024-05-16 20:26:19 +02:00
|
|
|
parse_mapcolors()
|
2024-05-23 09:39:21 +02:00
|
|
|
|
|
|
|
-- check for world-specific colors.txt file
|
|
|
|
local world_colors_filename = minetest.get_worldpath() .. "/colors.txt"
|
|
|
|
if io.open(world_colors_filename) then
|
|
|
|
parse_file(world_colors_filename)
|
|
|
|
end
|
2024-05-16 20:22:09 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local is_initialized = false
|
2024-05-19 17:22:30 +02:00
|
|
|
function isogen.get_color(node)
|
2024-05-16 20:22:09 +02:00
|
|
|
if not is_initialized then
|
|
|
|
init()
|
|
|
|
is_initialized = true
|
|
|
|
end
|
|
|
|
|
2024-05-19 17:22:30 +02:00
|
|
|
if palette_colors[node.name] and node.param2 and node.param2 > 0 then
|
2024-05-16 20:22:09 +02:00
|
|
|
-- param2 colored
|
2024-05-19 17:22:30 +02:00
|
|
|
return palette_colors[node.name][node.param2+1]
|
2024-05-16 20:22:09 +02:00
|
|
|
end
|
|
|
|
|
2024-05-19 17:22:30 +02:00
|
|
|
if node_colors[node.name] then
|
2024-05-16 20:22:09 +02:00
|
|
|
-- simple color
|
2024-05-19 17:22:30 +02:00
|
|
|
return node_colors[node.name]
|
2024-05-16 20:22:09 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|