cleaned up analyze_*_file
This commit is contained in:
parent
ddf8bfcfbe
commit
e5ad6a1933
@ -256,3 +256,18 @@ handle_schematics.store_mts_file = function( path, data )
|
||||
file.close(file);
|
||||
print('SAVING '..path..'.mts (converted from .we).');
|
||||
end
|
||||
|
||||
|
||||
-- read .mts and .we files
|
||||
handle_schematics.analyze_file = function( file_name, origin_offset, store_as_mts )
|
||||
res = handle_schematics.analyze_mts_file( file_name );
|
||||
-- alternatively, read the mts file
|
||||
if( not( res )) then
|
||||
res = handle_schematics.analyze_we_file( file_name, origin_offset );
|
||||
-- convert to .mts for later usage
|
||||
if( res and store_as_mts ) then
|
||||
handle_schematics.store_mts_file( store_as_mts, res );
|
||||
end
|
||||
end
|
||||
return res;
|
||||
end
|
||||
|
@ -1,4 +1,4 @@
|
||||
mg_villages.analyze_we_file = function(scm, we_origin)
|
||||
handle_schematics.analyze_we_file = function(scm, we_origin)
|
||||
local c_ignore = minetest.get_content_id("ignore")
|
||||
|
||||
-- this table will contain the nodes read
|
||||
@ -63,28 +63,21 @@ mg_villages.analyze_we_file = function(scm, we_origin)
|
||||
|
||||
end
|
||||
|
||||
local c_air = minetest.get_content_id("air")
|
||||
for x = 1, maxx do
|
||||
for y = 1, maxy do
|
||||
for z = 1, maxz do
|
||||
if scm[y] == nil then
|
||||
scm[y] = {}
|
||||
end
|
||||
if scm[y][x] == nil then
|
||||
scm[y][x] = {}
|
||||
end
|
||||
-- if scm[y][x][z] == nil then
|
||||
-- scm[y][x][z] = c_air
|
||||
-- end
|
||||
for y = 1, maxy do
|
||||
if scm[y] == nil then
|
||||
scm[y] = {}
|
||||
end
|
||||
for x = 1, maxx do
|
||||
if scm[y][x] == nil then
|
||||
scm[y][x] = {}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local size = {};
|
||||
size.y = #scm;
|
||||
size.x = #scm[1];
|
||||
size.z = #scm[1][1];
|
||||
size.y = math.max(maxy,0);
|
||||
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 };
|
||||
end
|
||||
|
@ -98,12 +98,9 @@ end
|
||||
|
||||
build_chest.read_building = function( building_name )
|
||||
-- read data
|
||||
local res = handle_schematics.analyze_mts_file( building_name );
|
||||
local res = handle_schematics.analyze_file( building_name, nil, nil );
|
||||
if( not( res )) then
|
||||
res = mg_villages.analyze_we_file( building_name, nil );
|
||||
if( not( res )) then
|
||||
return;
|
||||
end
|
||||
return;
|
||||
end
|
||||
build_chest.building[ building_name ].size = res.size;
|
||||
build_chest.building[ building_name ].nodenames = res.nodenames;
|
||||
@ -684,13 +681,14 @@ build_chest.on_receive_fields = function(pos, formname, fields, player)
|
||||
-- TODO: use scaffolding here (exchange some replacements)
|
||||
local replacement_list = minetest.deserialize( meta:get_string( 'replacements' ));
|
||||
local rotate = meta:get_string('rotate');
|
||||
local mirror = meta:get_string('mirror');
|
||||
local axis = build_chest.building[ building_name ].axis;
|
||||
local no_plotmarker = 1;
|
||||
-- actually place the building
|
||||
--minetest.place_schematic( start_pos, building_name..'.mts', rotate, replacement_list, true );
|
||||
local error_msg = mg_villages.place_building_from_file( start_pos, end_pos, building_name, replacement_list, rotate, axis, mirror, no_plotmarker );
|
||||
if( error_msg ) then
|
||||
formspec = formspec.."label[3,3;Error: "..minetest.formspec_escape( error_msg ).."]";
|
||||
fields.error_msg = mg_villages.place_building_from_file( start_pos, end_pos, building_name, replacement_list, rotate, axis, mirror, no_plotmarker );
|
||||
if( fields.error_msg ) then
|
||||
fields.error_msg = 'Error: '..tostring( fields.error_msg );
|
||||
end
|
||||
|
||||
-- restore the original landscape
|
||||
|
@ -305,16 +305,9 @@ mg_villages.add_building = function( building_data )
|
||||
|
||||
-- determine the size of the building
|
||||
local res = nil;
|
||||
-- read the size of the building
|
||||
res = handle_schematics.analyze_mts_file( file_name );
|
||||
-- alternatively, read the mts file
|
||||
if( not( res )) then
|
||||
res = mg_villages.analyze_we_file( file_name, building_data.we_origin );
|
||||
-- convert to .mts for later usage
|
||||
if( res ) then
|
||||
handle_schematics.store_mts_file( building_data.mts_path .. building_data.scm, res );
|
||||
end
|
||||
end
|
||||
-- read the size of the building;
|
||||
-- convert to .mts for later usage if necessary
|
||||
res = handle_schematics.analyze_file( file_name, building_data.we_origin, building_data.mts_path .. building_data.scm );
|
||||
|
||||
if( not( res )) then
|
||||
mg_villages.print(mg_villages.DEBUG_LEVEL_WARNING, 'SKIPPING '..tostring( building_data.scm )..' due to import failure.');
|
||||
|
4
init.lua
4
init.lua
@ -28,13 +28,13 @@ mg_villages.mg_generated_map = save_restore.restore_data( 'mg_generated_map.data
|
||||
|
||||
dofile(mg_villages.modpath.."/config.lua")
|
||||
|
||||
dofile(mg_villages.modpath.."/worldedit_file.lua") -- deserialize worldedit savefiles
|
||||
dofile(mg_villages.modpath.."/analyze_we_file.lua")
|
||||
dofile(mg_villages.modpath.."/rotate.lua")
|
||||
|
||||
-- read size from schematics files directly
|
||||
-- analyze_mts_file.lua uses handle_schematics.* namespace
|
||||
dofile(mg_villages.modpath.."/worldedit_file.lua") -- deserialize worldedit savefiles
|
||||
dofile(mg_villages.modpath.."/analyze_mts_file.lua")
|
||||
dofile(mg_villages.modpath.."/analyze_we_file.lua")
|
||||
|
||||
-- adds a special gravel node which will neither fall nor be griefed by mapgen
|
||||
dofile(mg_villages.modpath.."/nodes.lua")
|
||||
|
@ -665,12 +665,9 @@ mg_villages.place_building_from_file = function( start_pos, end_pos, building_na
|
||||
return "No file name given. Cannot find the schematic.";
|
||||
end
|
||||
|
||||
local binfo = handle_schematics.analyze_mts_file( building_name );
|
||||
local binfo = handle_schematics.analyze_file( building_name, nil, nil );
|
||||
if( not( binfo )) then
|
||||
binfo = mg_villages.analyze_we_file( building_name, nil );
|
||||
if( not( binfo )) then
|
||||
return "Failed to import schematic. Only .mts and .we are supported!";
|
||||
end
|
||||
return "Failed to import schematic. Only .mts and .we are supported!";
|
||||
end
|
||||
|
||||
-- nodenames and scm_data_cache can be used directly;
|
||||
|
Loading…
x
Reference in New Issue
Block a user