add a replace-unkown-with-air-button in order to speed up manual placement

master
Sokomine 2015-07-10 20:40:19 +02:00
parent a6c01cb81c
commit 4fd325d576
2 changed files with 49 additions and 0 deletions

View File

@ -291,6 +291,10 @@ build_chest.update_formspec = function( pos, page, player, fields )
+ (village_pos.y - pos.y ) * (village_pos.x - pos.y )
+ (village_pos.z - pos.z ) * (village_pos.x - pos.z ) ));
-- the statistic is needed for all the replacements later on as it also contains the list of nodenames
if( building_name and building_name~=""and not( build_chest.building[ building_name ].size )) then
build_chest.read_building( building_name );
end
if( page == 'please_remove' ) then
if( build_chest.stages_formspec_page_please_remove ) then
@ -496,6 +500,12 @@ build_chest.on_receive_fields = function(pos, formname, fields, player)
return;
end
local building_name = meta:get_string('building_name' );
-- the statistic is needed for all the replacements later on as it also contains the list of nodenames
if( building_name and building_name~=""and not( build_chest.building[ building_name ].size )) then
build_chest.read_building( building_name );
end
-- general menu handling
-- back button selected
if( fields.back ) then
@ -552,6 +562,8 @@ build_chest.on_receive_fields = function(pos, formname, fields, player)
build_chest.replacements_apply( pos, meta, fields.replace_row_material, fields.replace_row_with );
elseif( fields.replace_rest_with_air ) then
build_chest.replacements_replace_rest_with_air( pos, meta );
elseif( fields.wood_selection ) then
build_chest.replacements_apply_for_group( pos, meta, 'wood', fields.wood_selection, fields.set_wood );

View File

@ -142,6 +142,8 @@ build_chest.replacements_get_list_formspec = function( pos, selected_row )
-- add the proceed-button as soon as all unkown materials have been replaced
if( may_proceed ) then
formspec = formspec.."button[9.9,9.0;2.0,0.5;proceed_with_scaffolding;Proceed]";
else
formspec = formspec.."button[9.9,9.0;3.2,0.5;replace_rest_with_air;Suggest air for unknown]";
end
formspec = formspec.."button[9.9,1.0;2.0,0.5;preview;Preview]";
if( extra_buttons.text and extra_buttons.text ~= "" ) then
@ -163,6 +165,41 @@ build_chest.replacements_get_list_formspec = function( pos, selected_row )
end
-- set replacements for all unknown nodes to air so that the building can be spawned
build_chest.replacements_replace_rest_with_air = function( pos, meta )
local building_name = meta:get_string( 'building_name' );
if( not( building_name ) or not( build_chest.building[ building_name ])) then
return;
end
local replacements_orig = minetest.deserialize( meta:get_string( 'replacements' ));
for i,v in ipairs( build_chest.building[ building_name ].statistic ) do
local name = build_chest.building[ building_name ].nodenames[ v[1]];
-- nodes that are to be ignored do not need to be replaced
if( name ~= 'air' and name ~= 'ignore' and name ~= 'mg:ignore' and v[2] and v[2]>0) then
-- find out if this node name gets replaced
local repl = name;
for j,r in ipairs( replacements_orig ) do
if( r and r[1]==name ) then
repl = r[2];
-- set replacements for inexisting nodes to air
if( not( minetest.registered_nodes[ repl ] )) then
r[2] = 'air';
end
end
end
-- replace nodes that do not exist with air
if( not( repl ) or not( minetest.registered_nodes[ repl ])) then
table.insert( replacements_orig, { name, 'air' });
end
end
end
-- store the new set of replacements
meta:set_string( 'replacements', minetest.serialize( replacements_orig ));
end
build_chest.replacements_apply = function( pos, meta, old_material, new_material )
-- a new value has been entered - we do not need to remember the row any longer
meta:set_int('replace_row', 0 );