diff options
Diffstat (limited to 'src/editor/editor.cpp')
| -rw-r--r-- | src/editor/editor.cpp | 54 |
1 files changed, 37 insertions, 17 deletions
diff --git a/src/editor/editor.cpp b/src/editor/editor.cpp index 72ca4d2..2e76039 100644 --- a/src/editor/editor.cpp +++ b/src/editor/editor.cpp @@ -32,7 +32,7 @@ void editor_clear_gui_state_refs( GAME_EDITOR* e ) { e->gui.header_viewtype = 0; } -void editor_push_undo_action( GAME_EDITOR* e, const EDITOR_UNDO_ACTION& action ) { +void editor_push_undo_action( GAME_EDITOR* e, EDITOR_UNDO_ACTION action ) { if( !e ) return; @@ -267,7 +267,7 @@ void editor_undo_record_create_walls( GAME_EDITOR* e, I32 start_idx, I32 count ) return; EDITOR_UNDO_ACTION action{}; - action.type = EDITOR_UNDO_CREATE_WALLS; + action.typemask = EDITOR_UNDO_CREATE_WALLS; action.create.start_idx = start_idx; for( I32 i = 0; i < count; ++i ) action.create.walls.push( map->walls[start_idx + i] ); @@ -284,7 +284,7 @@ void editor_undo_record_create_poly( GAME_EDITOR* e, I32 start_idx ) { return; EDITOR_UNDO_ACTION action{ - .type = EDITOR_UNDO_CREATE_POLY, + .typemask = EDITOR_UNDO_CREATE_POLY, .create = { .start_idx = start_idx } }; action.create.polys.push( map->polygons[start_idx] ); @@ -301,7 +301,7 @@ void editor_undo_record_create_sprite( GAME_EDITOR* e, I32 start_idx ) { return; EDITOR_UNDO_ACTION action = { - .type = EDITOR_UNDO_CREATE_SPRITES, + .typemask = EDITOR_UNDO_CREATE_SPRITES, .create = { .start_idx = start_idx } }; @@ -319,7 +319,7 @@ void editor_undo_record_create_entity( GAME_EDITOR* e, I32 start_idx ) { return; EDITOR_UNDO_ACTION action{ - .type = EDITOR_UNDO_CREATE_ENTITIES, + .typemask = EDITOR_UNDO_CREATE_ENTITIES, .create = { .start_idx = start_idx } }; action.create.entities.push( map->entities[start_idx] ); @@ -334,7 +334,7 @@ void editor_undo_record_change_prop( GAME_EDITOR* e, FNV1A hash, void* oldv, voi if( !e || !e->map ) return; - EDITOR_UNDO_ACTION rec{ .type = EDITOR_UNDO_EDITPROPS }; + EDITOR_UNDO_ACTION rec{ .typemask = EDITOR_UNDO_EDITPROPS }; for( auto e : e->gui.props->curselect ) { EDITOR_UNDO_PROPS::CHANGES changes{}; @@ -344,16 +344,16 @@ void editor_undo_record_change_prop( GAME_EDITOR* e, FNV1A hash, void* oldv, voi rec.props.changes.push( changes ); } - e->undo_actions.push( rec ); + editor_push_undo_action( e, rec ); } -U8 editor_apply_undo_action_reverse_create( GAME_EDITOR* e, EDITOR_UNDO_ACTION& action ) { +U8 editor_apply_undo_action_reverse_create( GAME_EDITOR* e, EDITOR_UNDO_ACTION action ) { WORLD_MAP* map = e->map; U8 clear_props_select = 0; U8 clear_view_select = 0; U8 clear_view_drag = 0; - switch( action.type ) { + switch( action.typemask ) { case EDITOR_UNDO_CREATE_WALLS: { I32 count = (I32)action.create.walls.size; for( I32 i = count - 1; i >= 0; --i ) { @@ -444,7 +444,7 @@ U8 editor_apply_undo_action_reverse_create( GAME_EDITOR* e, EDITOR_UNDO_ACTION& return 1; } -U8 editor_apply_undo_action_reverse_props( GAME_EDITOR* e, EDITOR_UNDO_ACTION& action ) { +U8 editor_apply_undo_action_reverse_props( GAME_EDITOR* e, EDITOR_UNDO_ACTION action ) { EDITOR_UNDO_PROPS* c = &action.props; for( auto it : c->changes ) { @@ -464,17 +464,37 @@ U8 editor_apply_undo_action_reverse_props( GAME_EDITOR* e, EDITOR_UNDO_ACTION& a return 1; } +U8 editor_apply_undo_action_reverse_mapprop( GAME_EDITOR* e, EDITOR_UNDO_ACTION action ) { + if( !e->map ) + return 0; + + if( action.mapprop.ref.id > e->map->props.size ) { + dlog( "editor_apply_undo_action_reverse_mapprop() : warn: attempted to remove non-existent prop %x\n", action.mapprop.ref.id ); + return 0; + } + + // todo : replace with proper slots + e->map->props.erase( action.mapprop.ref.id ); + editor_update_properties_column( e ); + return 1; +} + U8 editor_apply_undo_action_reverse( GAME_EDITOR* e, EDITOR_UNDO_ACTION& action ) { if( !e || !e->map ) return 0; - if( action.type == EDITOR_UNDO_EDITPROPS ) - return editor_apply_undo_action_reverse_props( e, action ); + U8 ret = 0; + if( action.typemask & EDITOR_UNDO_EDITPROPS ) + ret |= editor_apply_undo_action_reverse_props( e, action ); + if( action.typemask & EDITOR_UNDO_CREATE_MAPPROP ) + ret |= editor_apply_undo_action_reverse_mapprop( e, action ); + if( action.typemask & EDITOR_UNDO_CREATE_EOBJ ) + ret |= editor_apply_undo_action_reverse_create( e, action ); - return editor_apply_undo_action_reverse_create( e, action ); + return ret; } -U8 editor_apply_undo_action_forward_props( GAME_EDITOR* e, EDITOR_UNDO_ACTION& action ) { +U8 editor_apply_undo_action_forward_props( GAME_EDITOR* e, EDITOR_UNDO_ACTION action ) { EDITOR_UNDO_PROPS* c = &action.props; for( auto it : c->changes ) { @@ -494,9 +514,9 @@ U8 editor_apply_undo_action_forward_props( GAME_EDITOR* e, EDITOR_UNDO_ACTION& a return 1; } -U8 editor_apply_undo_action_forward_create( GAME_EDITOR* e, EDITOR_UNDO_ACTION& action ) { +U8 editor_apply_undo_action_forward_create( GAME_EDITOR* e, EDITOR_UNDO_ACTION action ) { WORLD_MAP* map = e->map; - switch( action.type ) { + switch( action.typemask ) { case EDITOR_UNDO_CREATE_WALLS: { if( !action.create.walls.size ) return 0; @@ -542,7 +562,7 @@ U8 editor_apply_undo_action_forward( GAME_EDITOR* e, EDITOR_UNDO_ACTION& action if( !e || !e->map ) return 0; - if( action.type == EDITOR_UNDO_EDITPROPS ) + if( action.typemask == EDITOR_UNDO_EDITPROPS ) return editor_apply_undo_action_forward_props( e, action ); return editor_apply_undo_action_forward_create( e, action ); |
