Handle missing tiles in dumpnodes

closes #104
This commit is contained in:
sfan5 2025-02-19 10:24:56 +01:00
parent 0f51edcb1f
commit ad403975fd

View File

@ -2,9 +2,20 @@ local function get_tile(tiles, n)
local tile = tiles[n] local tile = tiles[n]
if type(tile) == 'table' then if type(tile) == 'table' then
return tile.name or tile.image return tile.name or tile.image
end elseif type(tile) == 'string' then
return tile return tile
end end
end
local function strip_texture(tex)
tex = (tex .. '^'):match('%(*(.-)%)*^') -- strip modifiers
if tex:find("[combine", 1, true) then
tex = tex:match('.-=([^:]-)') -- extract first texture
elseif tex:find("[png", 1, true) then
return nil -- can't
end
return tex
end
local function pairs_s(dict) local function pairs_s(dict)
local keys = {} local keys = {}
@ -20,7 +31,7 @@ core.register_chatcommand("dumpnodes", {
func = function() func = function()
local ntbl = {} local ntbl = {}
for _, nn in pairs_s(minetest.registered_nodes) do for _, nn in pairs_s(minetest.registered_nodes) do
local prefix, name = nn:match('(.*):(.*)') local prefix, name = nn:match('(.-):(.*)')
if prefix == nil or name == nil then if prefix == nil or name == nil then
print("ignored(1): " .. nn) print("ignored(1): " .. nn)
else else
@ -45,14 +56,15 @@ core.register_chatcommand("dumpnodes", {
print("ignored(2): " .. nn) print("ignored(2): " .. nn)
else else
local tex = get_tile(tiles, 1) local tex = get_tile(tiles, 1)
tex = (tex .. '^'):match('%(*(.-)%)*^') -- strip modifiers tex = tex and strip_texture(tex)
if tex:find("[combine", 1, true) then if not tex then
tex = tex:match('.-=([^:]-)') -- extract first texture print("ignored(3): " .. nn)
end else
out:write(nn .. ' ' .. tex .. '\n') out:write(nn .. ' ' .. tex .. '\n')
n = n + 1 n = n + 1
end end
end end
end
out:write('\n') out:write('\n')
end end
out:close() out:close()