From 073c3e73bb194b18dc0a7f3366c9ea8b7b843dda Mon Sep 17 00:00:00 2001 From: Pierre-Yves Rollo Date: Tue, 1 Sep 2015 10:39:35 +0200 Subject: [PATCH] Change the way textures are copied --- minetest-mod/webcrag/init.lua | 80 ++++++----------------------------- webserver/image.php | 2 +- webserver/index.php | 21 ++------- 3 files changed, 17 insertions(+), 86 deletions(-) diff --git a/minetest-mod/webcrag/init.lua b/minetest-mod/webcrag/init.lua index 4d959f1..7019fd2 100644 --- a/minetest-mod/webcrag/init.lua +++ b/minetest-mod/webcrag/init.lua @@ -4,7 +4,6 @@ by P.Y. Rollo dev@pyrollo.com Distributed under the terms of the GNU General Public License v3 ]]-- -print(dump(minetest)) local modpath = minetest.get_modpath("webcrag") @@ -13,27 +12,6 @@ dofile(modpath.."/config.lua") datafile = "mtdata.json" -function copy_file(src, dest) - local size = 2^13 -- 8K buffer - local s = io.open(src,"r") - - if s == nil then return false end - - local t = assert(io.open(dest,"w")) - - if t == nil then io.close(s) return false end - - while true do - local block = s:read(size) - if not block then break end - t:write(block) - end - - io.close(s) - io.close(t) - return true -end - function convert_craft(craft) local ret = {} local width = craft.width @@ -70,28 +48,6 @@ function webcrag_export() local export_start = os.clock() - local function copy_image(mod, name) - local function try(path) - if copy_file(path, webcrag_exportdir.."img/"..name) then - copiedimages[name] = path - return true - end - return false - end - - for part in name:gmatch("[^/^]*") do - if part ~= '' then - if copiedimages[part] == nil then - if not try(minetest.get_modpath(mod).."/textures/"..part) then - if not try(minetest.get_modpath("default").."/textures/"..part) then - print (("[webcrag] unable to copy image %s."):format(part)); - end - end - end - end - end - end - local function register_item(name) if export.items[name] == nil then nitems = nitems + 1 @@ -112,13 +68,22 @@ function webcrag_export() print ("[webcrag] Starting data eport") - os.execute("mkdir -p "..webcrag_exportdir.."img/") export.items = {} export.groups = {} + -- Copy textures + os.execute("mkdir -p "..webcrag_exportdir.."textures/") + + for _, name in ipairs(minetest.get_modnames()) do + os.execute("cp -u "..minetest.get_modpath(name).."/textures/* "..webcrag_exportdir.."/textures/ > /dev/null 2>&1") + end + + -- Export item data + for name, data in pairs(minetest.registered_items) do if not (data.type == "none" or name == "ignore" or name == "air") then + register_item(name) export.items[name].name = data.name export.items[name].type = data.type @@ -132,31 +97,10 @@ function webcrag_export() table.insert(export.groups[group].items, name) end - -- Copy images - if data.inventory_image ~= nil and data.inventory_image ~= "" then - if type(data.inventory_image) == 'string' then - for part in data.inventory_image:gmatch("[^/^]*") do - if part ~= '' then - copy_image(export.items[name].mod, part) - end - end - end - else - if data.tiles ~= nil then - for _,tile in pairs(data.tiles) do - if type(tile) == 'string' then - for part in tile:gmatch("[^/^]*") do - if part ~= '' then - copy_image(export.items[name].mod, part) - end - end - end - end - end - end - + -- Display export.items[name].inventory_image = data.inventory_image export.items[name].tiles = data.tiles + export.items[name].node_box = data.node_box -- Crafts local crafts = minetest.get_all_craft_recipes(name) diff --git a/webserver/image.php b/webserver/image.php index be05c7b..4564c46 100644 --- a/webserver/image.php +++ b/webserver/image.php @@ -3,7 +3,7 @@ $wwwimgpath = realpath('img'); $maxsize = 128; -$sizes = array( 32, 64, 128 ); +$sizes = array( 32, 128 ); function list_images($images) { $ret = array(); diff --git a/webserver/index.php b/webserver/index.php index d4f922e..084c53f 100644 --- a/webserver/index.php +++ b/webserver/index.php @@ -1,7 +1,7 @@ Item index"; foreach ($mtdata['items'] as $name => $item){ - if ($item['description'] && $name != 'air') { + if ($item['description'] + && $name != 'air' + && !array_key_exists('not_in_creative_inventory', $item['groups'])) { $ret.= render_item($name); } } return $ret; } - -function mytest() { - $mtimgpath = realpath('mtdata/img'); - $wwwimgpath = realpath('img'); - prepare_bloc_image( - 'default_stone.png', - 'default_stone.png', - 'default_stone.png', - 'default_stone.png', - 'default_stone.png', - 'default_stone.png', - 'test.png'); - return '

'; -} - $q=$_GET["q"]; $type=$_GET["type"];