Change the way textures are copied

This commit is contained in:
Pierre-Yves Rollo 2015-09-01 10:39:35 +02:00
parent 1e5545eb91
commit 073c3e73bb
3 changed files with 17 additions and 86 deletions

View File

@ -4,7 +4,6 @@ by P.Y. Rollo dev@pyrollo.com
Distributed under the terms of the GNU General Public License v3 Distributed under the terms of the GNU General Public License v3
]]-- ]]--
print(dump(minetest))
local modpath = minetest.get_modpath("webcrag") local modpath = minetest.get_modpath("webcrag")
@ -13,27 +12,6 @@ dofile(modpath.."/config.lua")
datafile = "mtdata.json" 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) function convert_craft(craft)
local ret = {} local ret = {}
local width = craft.width local width = craft.width
@ -70,28 +48,6 @@ function webcrag_export()
local export_start = os.clock() 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) local function register_item(name)
if export.items[name] == nil then if export.items[name] == nil then
nitems = nitems + 1 nitems = nitems + 1
@ -112,13 +68,22 @@ function webcrag_export()
print ("[webcrag] Starting data eport") print ("[webcrag] Starting data eport")
os.execute("mkdir -p "..webcrag_exportdir.."img/")
export.items = {} export.items = {}
export.groups = {} 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 for name, data in pairs(minetest.registered_items) do
if not (data.type == "none" or name == "ignore" or name == "air") then if not (data.type == "none" or name == "ignore" or name == "air") then
register_item(name) register_item(name)
export.items[name].name = data.name export.items[name].name = data.name
export.items[name].type = data.type export.items[name].type = data.type
@ -132,31 +97,10 @@ function webcrag_export()
table.insert(export.groups[group].items, name) table.insert(export.groups[group].items, name)
end end
-- Copy images -- Display
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
export.items[name].inventory_image = data.inventory_image export.items[name].inventory_image = data.inventory_image
export.items[name].tiles = data.tiles export.items[name].tiles = data.tiles
export.items[name].node_box = data.node_box
-- Crafts -- Crafts
local crafts = minetest.get_all_craft_recipes(name) local crafts = minetest.get_all_craft_recipes(name)

View File

@ -3,7 +3,7 @@
$wwwimgpath = realpath('img'); $wwwimgpath = realpath('img');
$maxsize = 128; $maxsize = 128;
$sizes = array( 32, 64, 128 ); $sizes = array( 32, 128 );
function list_images($images) { function list_images($images) {
$ret = array(); $ret = array();

View File

@ -1,7 +1,7 @@
<?php <?php
include 'config.php'; include 'config.php';
$mtimgpath = realpath($exportdir.'/img'); $mtimgpath = realpath($exportdir.'/textures');
$mtdata = json_decode(file_get_contents($exportdir.'/mtdata.json'), true); $mtdata = json_decode(file_get_contents($exportdir.'/mtdata.json'), true);
include 'image.php'; include 'image.php';
@ -213,28 +213,15 @@ function render_item_index() {
global $mtdata; global $mtdata;
$ret = "<h1>Item index</h1>"; $ret = "<h1>Item index</h1>";
foreach ($mtdata['items'] as $name => $item){ 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); $ret.= render_item($name);
} }
} }
return $ret; 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 '<p><img src="img/test.png"/ border=1></p>';
}
$q=$_GET["q"]; $q=$_GET["q"];
$type=$_GET["type"]; $type=$_GET["type"];