2014-03-14 22:05:35 +01:00
|
|
|
==FILE== mods/dumpnodes/init.lua
|
|
|
|
local function nd_get_tiles(nd)
|
|
|
|
if nd.tiles then
|
|
|
|
return nd.tiles
|
|
|
|
elseif nd.tile_images then
|
|
|
|
return nd.tile_images
|
|
|
|
end
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2016-01-14 21:52:15 +01:00
|
|
|
local function pairs_s(dict)
|
|
|
|
local keys = {}
|
|
|
|
for k in pairs(dict) do
|
|
|
|
table.insert(keys, k)
|
|
|
|
end
|
|
|
|
table.sort(keys)
|
|
|
|
return ipairs(keys)
|
|
|
|
end
|
|
|
|
|
2014-03-14 22:05:35 +01:00
|
|
|
minetest.register_chatcommand("dumpnodes", {
|
|
|
|
params = "",
|
|
|
|
description = "",
|
|
|
|
func = function(plname, param)
|
|
|
|
local n = 0
|
|
|
|
local ntbl = {}
|
2016-01-14 21:52:15 +01:00
|
|
|
for _, nn in pairs_s(minetest.registered_nodes) do
|
|
|
|
local nd = minetest.registered_nodes[nn]
|
2014-03-14 22:05:35 +01:00
|
|
|
local prefix, name = nn:match('(.*):(.*)')
|
|
|
|
if prefix == nil or name == nil or prefix == '' or name == '' then
|
2016-01-14 21:52:15 +01:00
|
|
|
print("ignored(1): " .. nn)
|
2014-03-14 22:05:35 +01:00
|
|
|
else
|
|
|
|
if ntbl[prefix] == nil then
|
|
|
|
ntbl[prefix] = {}
|
|
|
|
end
|
|
|
|
ntbl[prefix][name] = nd
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local out, err = io.open('nodes.txt', 'wb')
|
|
|
|
if not out then
|
2016-01-14 21:52:15 +01:00
|
|
|
return true, "io.open(): " .. err
|
2014-03-14 22:05:35 +01:00
|
|
|
end
|
2016-01-14 21:52:15 +01:00
|
|
|
for _, prefix in pairs_s(ntbl) do
|
|
|
|
local nodes = ntbl[prefix]
|
2014-03-14 22:05:35 +01:00
|
|
|
out:write('# ' .. prefix .. '\n')
|
2016-01-14 21:52:15 +01:00
|
|
|
for _, name in pairs_s(nodes) do
|
|
|
|
local nd = nodes[name]
|
2014-03-14 22:05:35 +01:00
|
|
|
if nd.drawtype ~= 'airlike' and nd_get_tiles(nd) ~= nil then
|
|
|
|
local tl = nd_get_tiles(nd)[1]
|
|
|
|
if type(tl) == 'table' then
|
|
|
|
tl = tl.name
|
|
|
|
end
|
|
|
|
tl = (tl .. '^'):match('(.-)^')
|
|
|
|
out:write(prefix .. ':' .. name .. ' ' .. tl .. '\n')
|
|
|
|
n = n + 1
|
2016-01-14 21:52:15 +01:00
|
|
|
else
|
|
|
|
print("ignored(2): " .. prefix .. ':' .. name)
|
2014-03-14 22:05:35 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
out:write('\n')
|
|
|
|
end
|
|
|
|
out:close()
|
2016-01-14 21:52:15 +01:00
|
|
|
return true, n .. " nodes dumped."
|
2014-03-14 22:05:35 +01:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
==FILE== avgcolor.py
|
|
|
|
#!/usr/bin/env python
|
|
|
|
import sys
|
|
|
|
from PIL import Image
|
|
|
|
|
2016-01-14 21:52:15 +01:00
|
|
|
def tsum(a, b):
|
|
|
|
return tuple(sum(e) for e in zip(a, b))
|
2014-03-14 22:05:35 +01:00
|
|
|
|
2016-01-14 21:52:15 +01:00
|
|
|
if len(sys.argv) < 2:
|
|
|
|
print("Prints average color (RGB) of input image")
|
2014-03-14 22:05:35 +01:00
|
|
|
print("Usage: %s <input>" % sys.argv[0])
|
2016-01-14 21:52:15 +01:00
|
|
|
exit(1)
|
|
|
|
|
|
|
|
inp = Image.open(sys.argv[1])
|
|
|
|
inp = inp.convert('RGBA')
|
|
|
|
ind = inp.load()
|
|
|
|
|
|
|
|
cl = (0, 0, 0)
|
|
|
|
counted = 0
|
|
|
|
for x in range(inp.size[0]):
|
|
|
|
for y in range(inp.size[1]):
|
|
|
|
px = ind[x, y]
|
|
|
|
if px[3] < 128:
|
|
|
|
continue
|
|
|
|
cl = tsum(cl, px[:3])
|
|
|
|
counted = counted + 1
|
|
|
|
|
|
|
|
if counted == 0:
|
|
|
|
sys.stderr.write("didn't find avg. color for %s\n" % sys.argv[1])
|
|
|
|
print("0 0 0")
|
|
|
|
exit(0)
|
|
|
|
|
|
|
|
cl = tuple(int(n / counted) for n in cl)
|
|
|
|
print("%d %d %d" % cl)
|
|
|
|
==SCRIPT==
|
|
|
|
#!/bin/bash -e
|
|
|
|
|
|
|
|
AVGCOLOR_PATH=/path/to/avgcolor.py
|
|
|
|
MTGAME_PATH=/path/to/minetest_game
|
|
|
|
NODESTXT_PATH=./nodes.txt
|
|
|
|
COLORSTXT_PATH=./colors.txt
|
2014-03-14 22:05:35 +01:00
|
|
|
|
|
|
|
while read -r p; do
|
|
|
|
set -- junk $p
|
|
|
|
shift
|
|
|
|
if [[ ! $1 == "#" && ! $1 == "" ]]; then
|
2016-01-14 21:52:15 +01:00
|
|
|
echo $1 `python $AVGCOLOR_PATH $(find $MTGAME_PATH -type f -name $2)`
|
2015-05-01 11:44:54 +02:00
|
|
|
echo $1 1>&2
|
2016-01-14 21:52:15 +01:00
|
|
|
else
|
|
|
|
echo "$p"
|
2014-03-14 22:05:35 +01:00
|
|
|
fi
|
2016-01-14 21:52:15 +01:00
|
|
|
done < $NODESTXT_PATH > $COLORSTXT_PATH
|
|
|
|
# Use nicer colors for water and lava:
|
|
|
|
sed -re 's/^default:(river_)?water_([a-z]+) [0-9 ]+$/default:\1water_\2 39 66 106 128 224/g' $COLORSTXT_PATH -i
|
|
|
|
sed -re 's/^default:lava_([a-z]+) [0-9 ]+$/default:lava_\1 255 100 0/g' $COLORSTXT_PATH -i
|
|
|
|
# Add transparency to glass nodes:
|
|
|
|
sed -re 's/^default:([a-z_]*glass) ([0-9 ]+)$/default:\1 \2 64 16/g' $COLORSTXT_PATH -i
|
|
|
|
sed -re 's/^doors:([a-z_]*glass[a-z_]*) ([0-9 ]+)$/doors:\1 \2 64 16/g' $COLORSTXT_PATH -i
|
|
|
|
sed -re 's/^xpanes:(pane_[0-9]+|bar_[0-9]+) ([0-9 ]+)$/xpanes:\1 \2 64 16/g' $COLORSTXT_PATH -i
|
2014-03-14 22:05:35 +01:00
|
|
|
==INSTRUCTIONS==
|
2014-03-26 17:36:23 +01:00
|
|
|
1) Make sure avgcolors.py outputs the usage instructions
|
2014-03-14 22:05:35 +01:00
|
|
|
2) Add the dumpnodes mod to Minetest
|
|
|
|
3) Create a world and load dumpnodes & all mods you want to have a color entry for
|
|
|
|
4) Execute /dumpnodes ingame
|
2016-01-14 21:52:15 +01:00
|
|
|
5) Run the script to generate colors.txt (make sure to replace /path/to/... with the actual path)
|