Mario editor: don't delete characters when changing terrain

This commit is contained in:
2021-05-02 14:43:15 +02:00
parent 8b8f3b7f06
commit ad7f737e16
3 changed files with 16 additions and 7 deletions
+8 -2
View File
@@ -6,7 +6,8 @@
MarioBlock::MarioBlock(int x, int y, std::shared_ptr<SDLPP::Renderer> renderer, std::shared_ptr<SDLPP::Texture> texture, SDL_Rect src) : RectangleRender( x * BLOCK_SIZE, 1 - (16-y) * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, renderer, texture, src ) {}
void MarioBlock::visit( SDLPP::Visitor &visitor ) {
if(!_tool && visitor.getVisitorType() == TOOL_VISITOR_TYPE) {
// TODO if character don't
if(!_tool && !_character && visitor.getVisitorType() == TOOL_VISITOR_TYPE) {
destroy();
}
visitor.visit(*this);
@@ -14,6 +15,9 @@ void MarioBlock::visit( SDLPP::Visitor &visitor ) {
void MarioBlock::setTool(bool tool) {
_tool = tool;
}
void MarioBlock::setCharacter(bool character) {
_character = character;
}
const std::vector< uint64_t > possibleBlocks = { FLOOR_ID,
HILL_INCLINE_ID,
@@ -105,5 +109,7 @@ createTerrainBlock( uint64_t block_id, BlockType type,
std::shared_ptr<SDLPP::RectangleRender> createMario( BlockType type, std::shared_ptr<SDLPP::Renderer> &renderer, int x, int y ) {
//TODO add type additions
return createBlock( renderer, x, y, g_mario_texture, MARIO_STANDING_SRC, MARIO_ID, true );
auto mario = createBlock( renderer, x, y, g_mario_texture, MARIO_STANDING_SRC, MARIO_ID, true );
dynamic_cast<MarioBlock&>(*mario).setCharacter();
return mario;
}