restore metadata for .we and .wem files

master
Sokomine 2015-07-06 18:01:02 +02:00
parent 6c1d8ab6fe
commit e01ee6fe53
5 changed files with 52 additions and 12 deletions

View File

@ -160,7 +160,7 @@ handle_schematics.analyze_mts_file = function( path )
id = id+1;
if( id ~= is_air ) then
scm[y][x][z] = {id, p2}; -- TODO: handle possible meta values contained in another file
scm[y][x][z] = {id, p2};
end
end
end

View File

@ -32,6 +32,7 @@ handle_schematics.analyze_we_file = function(scm, we_origin)
scm = {}
local maxx, maxy, maxz = -1, -1, -1
local all_meta = {};
for i = 1, #nodes do
local ent = nodes[i]
ent.x = ent.x + 1
@ -55,11 +56,27 @@ handle_schematics.analyze_we_file = function(scm, we_origin)
if ent.param2 == nil then
ent.param2 = 0
end
if ent.meta == nil then
ent.meta = {fields={}, inventory={}}
-- metadata is only of intrest if it is not empty
if( ent.meta and (ent.meta.fields or ent.meta.inventory)) then
local has_meta = false;
for _,v in pairs( ent.meta.fields ) do
has_meta = true;
end
for _,v in pairs(ent.meta.inventory) do
has_meta = true;
end
if( has_meta == true ) then
all_meta[ #all_meta+1 ] = {
x=ent.x,
y=ent.y,
z=ent.z,
fields = ent.meta.fields,
inventory = ent.meta.inventory};
end
end
scm[ent.y][ent.x][ent.z] = { nodenames_id[ ent.name ], ent.param2 }; --TODO ent.meta
scm[ent.y][ent.x][ent.z] = { nodenames_id[ ent.name ], ent.param2 };
end
@ -79,5 +96,5 @@ handle_schematics.analyze_we_file = function(scm, we_origin)
size.x = math.max(maxx,0);
size.z = math.max(maxz,0);
return { size = { x=size.x, y=size.y, z=size.z}, nodenames = nodenames, on_constr = {}, after_place_node = {}, rotated=0, burried=0, scm_data_cache = scm };
return { size = { x=size.x, y=size.y, z=size.z}, nodenames = nodenames, on_constr = {}, after_place_node = {}, rotated=0, burried=0, scm_data_cache = scm, metadata = all_meta };
end

View File

@ -67,6 +67,7 @@ build_chest.read_building = function( building_name )
build_chest.building[ building_name ].nodenames = res.nodenames;
build_chest.building[ building_name ].rotated = res.rotated;
build_chest.building[ building_name ].burried = res.burried;
build_chest.building[ building_name ].metadata = res.metadata;
-- scm_data_cache is not stored as that would take up too much storage space
--build_chest.building[ building_name ].scm_data_cache = res.scm_data_cache;
@ -609,7 +610,8 @@ mirror = nil;
if( save_restore.file_exists( 'schems/'..backup_file..'.mts' )) then
filename = minetest.get_worldpath()..'/schems/'..backup_file..'.mts';
minetest.place_schematic( start_pos, filename, "0", {}, true );
handle_schematics.restore_meta( backup_file );
-- no rotation needed - the metadata can be applied as-is (with the offset applied)
handle_schematics.restore_meta( backup_file, nil, start_pos, end_pos, 0, nil);
meta:set_string('backup', nil );
end
end

View File

@ -97,7 +97,7 @@ handle_schematics.save_meta = function( start_pos, end_pos, filename )
for x=p.x, p.x+p.sizex do
for y=p.y, p.y+p.sizey do
for z=p.z, p.z+p.sizez do
handle_schematics_get_meta_table( {x=x, y=y, z=z}, all_meta, p );
handle_schematics_get_meta_table( {x=x-p.x, y=y-p.y, z=z-p.z}, all_meta, p );
end
end
end
@ -123,12 +123,25 @@ end
-- restore metadata from file
-- TODO: use relative instead of absolute positions
handle_schematics.restore_meta = function( filename )
-- TODO: use relative instead of absolute positions (already done for .we files)
-- TODO: handle mirror
handle_schematics.restore_meta = function( filename, all_meta, start_pos, end_pos, rotate, mirror )
local all_meta = save_restore.restore_data( 'schems/'..filename..'.meta' );
if( not( all_meta ) and filename ) then
all_meta = save_restore.restore_data( 'schems/'..filename..'.meta' );
end
for _,pos in ipairs( all_meta ) do
local meta = minetest.get_meta( {x=pos.x, y=pos.y, z=pos.z} );
local p = {};
if( rotate == 0 ) then
p = {x=start_pos.x+pos.x-1, y=start_pos.y+pos.y-1, z=start_pos.z+pos.z-1};
elseif( rotate == 1 ) then
p = {x=start_pos.x+pos.z-1, y=start_pos.y+pos.y-1, z=end_pos.z -pos.x+1};
elseif( rotate == 2 ) then
p = {x=end_pos.x -pos.x+1, y=start_pos.y+pos.y-1, z=end_pos.z -pos.z+1};
elseif( rotate == 3 ) then
p = {x=end_pos.x -pos.z+1, y=start_pos.y+pos.y-1, z=start_pos.z+pos.x-1};
end
local meta = minetest.get_meta( p );
meta:from_table( {inventory = pos.inventory, fields = pos.fields });
end
end

View File

@ -784,7 +784,15 @@ handle_schematics.place_building_from_file = function( start_pos, end_pos, build
end
end
end
-- TODO: handle metadata (if any is provided)
if( binfo.metadata ) then
-- if it is a .we/.wem file, metadata was included directly
handle_schematics.restore_meta( nil, binfo.metadata, start_pos, end_pos, start_pos.brotate, mirror);
else
-- .mts files come with extra .meta file (if such a .meta file was created)
-- TODO: restore metadata for .mts files
--handle_schematics.restore_meta( filename, nil, binfo.metadata, start_pos, end_pos, start_pos.brotate, mirror);
end
end