Skip to content

Commit

Permalink
Made 'undo' undo entire operation
Browse files Browse the repository at this point in the history
Made `undo` undo entire operation, not just 1 block at a time
Some formatting with `help`
  • Loading branch information
Ghoulboy78 committed May 27, 2020
1 parent f3297fc commit dcc07da
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions world-edit.sc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__command()->(help());
__command()->help();
__config()->m(l('stay_loaded','true'),l('scope','global'));
//Global Variables

Expand All @@ -25,8 +25,7 @@ __on_player_right_clicks_block(player, item_tuple, hand, block, face, hitvec)->(

//Command functions

help()->(
print(
help()->print(
'Welcome to World Edit by Ghoulboy!\n'+
'Commands:\n'+
'/world-edit help: Displays this help page\n'+
Expand All @@ -36,12 +35,13 @@ help()->(
'TEMP: As of now, you can\'t enter block properties.\n'+
'/world-edit replace_keep \'replace\'/\'keep\': If it\'s \'replace\', the replace/keep option in the commands will replace all blocks of that type\n'+
'If it\'s \'keep\', it will replace all blocks other than that one.\n'+
'/world-edit undo num: Undoes \'num\' number of moves.\n'//Todo add ability to undo other player moves for operators
)
);
'/world-edit undo num: Undoes \'num\' number of moves.\n'+//Todo add ability to undo other player moves for operators
'/world-edit clear_history: Clears all your undoable history'
);

set_block(block,replace)->(
if(global_positions:player():'positions':0,pos=global_player_data:player():'positions':0,return(print('No position defined')))
global_player_data:player():'history':length(global_player_data:player():'history')=l(l(pos(block),block));//For the Undo function
success=_set_block(pos,block,replace);
if(success,print('Successfully set 1 block'),print('Unable to set block, replacement block found'))
);
Expand All @@ -50,9 +50,11 @@ fill_blocks(block,replace)->(
if(global_player_data:player():'positions':0,l(x1,y1,z1)=global_player_data:player():'positions':0,return(print('No position 1 selected')));
if(global_player_data:player():'positions':1,l(x2,y2,z2)=global_player_data:player():'positions':1,return(print('No position 2 selected')));
success=0;
history=l();
volume(x1,y1,z1,x2,y2,z2,
success+=_set_block(pos(_),block,replace)
);
global_player_data:player():'history':length(global_player_data:player():'history')=history;//For the Undo function
print(str('Successfully filled %d out of %d blocks',success,_vol(global_player_data:player():'positions':0,global_player_data:player():'positions':1)))
)

Expand All @@ -65,8 +67,10 @@ undo(num)->(
return()
);
for(range(1,num+1),//So I don't have to add one at each step
l(pos,block)=global_player_data:player():'history':length(global_player_data:player():'history')-num;
set(pos,block);
for(global_player_data:player():'history':length(global_player_data:player():'history')-num,
l(pos,block)=_;
set(pos,block)
)
delete(global_player_data:player():'history':length(global_player_data:player():'history')-num)
);
print(str('Successfully undid %d operations',num))
Expand All @@ -78,7 +82,6 @@ _vol(pos1,pos2)->return(abs(pos1:0-pos2:0)*abs(pos1:1-pos2:1)*abs(pos1:2-pos2:2)

_set_block(pos,block,replace)->( //So I can have a separate command called set_block
if((block(pos)==replace&&global_player_data:player():'replace_keep'=='replace')||(block(pos)!=replace&&global_player_data:player():'replace_keep'=='keep'),
global_player_data:player():'history':length(global_player_data:player():'history')=l(pos,block(pos));//For the Undo function
set(pos,block);
return(1);
);
Expand Down

0 comments on commit dcc07da

Please sign in to comment.