Allow for customizing and not overwriting nodecolors.conf on updates

master
entuland 2018-06-06 12:57:22 +02:00
parent 3ec975d620
commit f272a1b210
3 changed files with 30 additions and 3 deletions

View File

@ -134,4 +134,4 @@ A couple considerations:
# Changing default colors assigned to nodes
The file [nodecolors.conf](/nodecolors.conf) contains the `modname:nodename = color` associations for all the nodes that get loaded in a minetest_game world. You're free to alter them or to add to this list as you please, just make sure you stick to wool colors cause any invalid color will be replaced by "air".
The file [default.nodecolors.conf](/default.nodecolors.conf) contains the `modname:nodename = color` associations for all the nodes that get loaded in a minetest_game world. This file will be copied over to `nodecolors.conf` at startup (if no such file exists); in `nodecolors.conf` you're free to alter existing colors and to add new nodes, just make sure you stick to wool colors cause any invalid color will be replaced by "air". Do not store your changes into `default.nodecolors.conf` cause it will be overwritten updating the mod (and it wouldn't get used anyway if a `nodecolors.conf` file is there at all).

View File

@ -140,8 +140,17 @@ function wesh._init_colors()
-- The following loop will fill the nodename_to_color table with custom values
local file = io.open(wesh.modpath .. "/nodecolors.conf", "rb")
if not file then
minetest.debug("[wesh] Unable to load nodecolors.conf file from mod folder")
return
minetest.debug("[wesh] Copying default.nodecolors.conf to nodecolors.conf")
local success, err = wesh.copy_file(wesh.modpath .. "/default.nodecolors.conf", wesh.modpath .. "/nodecolors.conf")
if not success then
minetest.debug("[wesh] " .. err)
return
end
file = io.open(wesh.modpath .. "/nodecolors.conf", "rb")
if not file then
minetest.debug("[wesh] Unable to load nodecolors.conf file from mod folder")
return
end
end
local content = file:read("*all")
@ -732,6 +741,24 @@ function wesh.check_plain(text)
return text:gsub("[^%w]+", "_"):lower()
end
function wesh.copy_file(source, dest)
local src_file = io.open(source, "rb")
if not src_file then
return false, "copy_file() unable to open source for reading"
end
local src_data = src_file:read("*all")
src_file:close()
local dest_file = io.open(dest, "wb")
if not dest_file then
return false, "copy_file() unable to open dest for writing"
end
dest_file:write(src_data)
dest_file:close()
return true, "files copied successfully"
end
function wesh.merge_tables(t1, t2)
for _, value in pairs(t2) do
table.insert(t1, value)