master
adrido 2016-11-02 07:36:07 +01:00
commit 2e2471bc8f
3 changed files with 129 additions and 0 deletions

9
README.md Normal file
View File

@ -0,0 +1,9 @@
# Minetest mod dumpnodes
This mod writes all nodes with their texture into a nodes.txt file into the world directory.
## Usage:
open the chat and invoke the /dumpnodes command. it requires the server privilege.
You can use the generated nodes.txt file then to generate a colors.txt file for use in minetestmapper.

119
init.lua Normal file
View File

@ -0,0 +1,119 @@
--[[
Minetest Mod dumpnodes
This mod adds a ingame chatcommand to write the nodes with theyr texture to a nodes.txt file.
This file can be used by MinetestMapperGui to generate a colors.txt file of them.
]]
--[[
The functions
__genOrderedIndex(t)
orderedNext(t, state)
and orderedPairs(t)
where taken from
http://lua-users.org/wiki/SortedIteration
All rights to the authors.
]]
function __genOrderedIndex( t )
local orderedIndex = {}
for key in pairs(t) do
table.insert( orderedIndex, key )
end
table.sort( orderedIndex )
return orderedIndex
end
function orderedNext(t, state)
-- Equivalent of the next function, but returns the keys in the alphabetic
-- order. We use a temporary ordered key table that is stored in the
-- table being iterated.
local key = nil
--print("orderedNext: state = "..tostring(state) )
if state == nil then
-- the first time, generate the index
t.__orderedIndex = __genOrderedIndex( t )
key = t.__orderedIndex[1]
else
-- fetch the next value
for i = 1,table.getn(t.__orderedIndex) do
if t.__orderedIndex[i] == state then
key = t.__orderedIndex[i+1]
end
end
end
if key then
return key, t[key]
end
-- no more value to return, cleanup
t.__orderedIndex = nil
return
end
function orderedPairs(t)
-- Equivalent of the pairs() function on tables. Allows to iterate
-- in order
return orderedNext, t, nil
end
local function getTiles(nd)
return nd.tiles or nd.tile_images or nil
end
local function dumpNodes(playerName, param)
local file = minetest.get_worldpath()..DIR_DELIM.."nodes.txt"
--minetest.get_world_dir()
local out, err = io.open(file, 'w')
if not out then
--minetest.chat_send_player(playerName, 'io.open: ' .. err)
return false, "ERROR [dumpnodes]: Could not open file for writing "..err
end
local currentMod = ""
local counter = 0
local header = [[
# This file is generated by dumpnodes.
# You can use this to generate a colors.txt file that can be used by minetestmapper.
# To generate a colors.txt you can use the program you find here:
# Or you use MinetestMapperGui that have the conversation tool builtin.
]]
out:write(header)
for nodeName, def in orderedPairs(minetest.registered_nodes) do
local tiles = getTiles(def)
if(def.drawtype ~="arilike" and tiles) then
local mod, name = nodeName:match('(.*):(.*)')
if mod~="" and name~="" then
local tile = tiles[1]
if type(tile) == 'table' then
tile = tile.name
end
tile = (tile .. '^'):match('(.-)^')
if(mod ~= currentMod)then
out:write('\n# ' .. mod .. '\n')
currentMod = mod
end
out:write(nodeName .. ' ' .. tile .. '\n')
print(nodeName.." : " ..tile)
counter = counter +1 --lua sucks!
end
end
end
if counter >=1 then
return true, "[dumpnodes] ".. counter .." nodes exported to file ".. file
else
return false, "[dumpnodes] Unknown error. 0 nodes exported to file "..file
end
end
minetest.register_chatcommand("dumpnodes", {
params = "",
privs = {server=true},
description = "Writes nods and their texture to a nodes.txt file for use in MinetestMapperGui",
func = dumpNodes
})

1
mod.conf Normal file
View File

@ -0,0 +1 @@
name=dumpnodes