Mario editor: started refactoring
This commit is contained in:
+22
-12
@@ -2,14 +2,15 @@
|
||||
#include "global_vars.hpp"
|
||||
#include "objectids.hpp"
|
||||
#include "sprites.hpp"
|
||||
#include "editor_visitor.hpp"
|
||||
#include <unordered_map>
|
||||
|
||||
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 && _terrain && visitor.getVisitorType() == TOOL_VISITOR_TYPE) {
|
||||
if(!_tool && _terrain && visitor.getVisitorType() == VisitorType::Terrain) {
|
||||
destroy();
|
||||
}
|
||||
if(!_tool && !_terrain && visitor.getVisitorType() == MODIFIER_VISITOR_TYPE) {
|
||||
if(!_tool && !_terrain && visitor.getVisitorType() == VisitorType::Modifier) {
|
||||
destroy();
|
||||
}
|
||||
visitor.visit(*this);
|
||||
@@ -137,56 +138,65 @@ createBlock( std::shared_ptr< SDLPP::Renderer > &renderer, int x, int y,
|
||||
return block;
|
||||
}
|
||||
|
||||
SDL_Rect getSourceRectByID( uint64_t id, BlockType type ) {
|
||||
SDL_Rect getSourceRectByID( uint64_t id, LandType::Value type ) {
|
||||
if(block_mapping.find(id) == block_mapping.end())
|
||||
return {};
|
||||
SDL_Rect ret_src = *block_mapping.at(id);
|
||||
switch ( type ) {
|
||||
case OVERWORLD:
|
||||
case LandType::OVERWORLD:
|
||||
ret_src.x += OVERWORLD_SHIFT.getX();
|
||||
ret_src.y += OVERWORLD_SHIFT.getY();
|
||||
break;
|
||||
case UNDERWORLD:
|
||||
case LandType::UNDERWORLD:
|
||||
ret_src.x += UNDERWORLD_SHIFT.getX();
|
||||
ret_src.y += UNDERWORLD_SHIFT.getY();
|
||||
break;
|
||||
case WATER:
|
||||
case LandType::WATER:
|
||||
ret_src.x += WATER_SHIFT.getX();
|
||||
ret_src.y += WATER_SHIFT.getY();
|
||||
break;
|
||||
case BOWSER:
|
||||
case LandType::BOWSER:
|
||||
ret_src.x += BOWSER_SHIFT.getX();
|
||||
ret_src.y += BOWSER_SHIFT.getY();
|
||||
break;
|
||||
}
|
||||
return ret_src;
|
||||
}
|
||||
std::shared_ptr<SDLPP::RectangleRender> createTerrainBlock( uint64_t block_id, BlockType type, std::shared_ptr<SDLPP::Renderer> &renderer, int x, int y, std::shared_ptr<SDLPP::Texture> texture, bool collision ) {
|
||||
std::shared_ptr<SDLPP::RectangleRender> createTerrainBlock( uint64_t block_id, LandType::Value type, std::shared_ptr<SDLPP::Renderer> &renderer, int x, int y, std::shared_ptr<SDLPP::Texture> texture, bool collision ) {
|
||||
return createBlock( renderer, x, y, texture,
|
||||
getSourceRectByID( block_id, type ), block_id,
|
||||
collision );
|
||||
}
|
||||
std::shared_ptr<SDLPP::RectangleRender> createTerrainBlock( uint64_t block_id, BlockType type, std::shared_ptr<SDLPP::Renderer> &renderer, std::shared_ptr<SDLPP::Texture> texture, bool collision ) {
|
||||
std::shared_ptr<SDLPP::RectangleRender> createTerrainBlock( uint64_t block_id, LandType::Value type, std::shared_ptr<SDLPP::Renderer> &renderer, std::shared_ptr<SDLPP::Texture> texture, bool collision ) {
|
||||
return createTerrainBlock( block_id, type, renderer, 0, 0, texture, collision );
|
||||
}
|
||||
|
||||
std::shared_ptr< SDLPP::RectangleRender >
|
||||
createTerrainBlock( uint64_t block_id, BlockType type,
|
||||
createTerrainBlock( uint64_t block_id, LandType::Value type,
|
||||
std::shared_ptr< SDLPP::Renderer > &renderer, int x,
|
||||
int y, bool collision ) {
|
||||
return createTerrainBlock(block_id, type, renderer, x, y, g_terrain_texture, collision);
|
||||
}
|
||||
|
||||
std::shared_ptr< SDLPP::RectangleRender >
|
||||
createTerrainBlock( uint64_t block_id, BlockType type,
|
||||
createTerrainBlock( uint64_t block_id, LandType::Value type,
|
||||
std::shared_ptr< SDLPP::Renderer > &renderer,
|
||||
bool collision ) {
|
||||
return createTerrainBlock(block_id, type, renderer, g_terrain_texture, collision);
|
||||
}
|
||||
|
||||
std::shared_ptr<SDLPP::RectangleRender> createMario( BlockType type, std::shared_ptr<SDLPP::Renderer> &renderer, int x, int y ) {
|
||||
std::shared_ptr<SDLPP::RectangleRender> createMario( LandType::Value type, std::shared_ptr<SDLPP::Renderer> &renderer, int x, int y ) {
|
||||
//TODO add type additions
|
||||
auto mario = createBlock( renderer, x, y, g_mario_texture, MARIO_STANDING_SRC, MARIO_ID, true );
|
||||
dynamic_cast<MarioBlock&>(*mario).setTerrain(false);
|
||||
return mario;
|
||||
}
|
||||
|
||||
enum BlockRole::Value getBlockRole(uint64_t id) {
|
||||
if(id >= 0x7000)
|
||||
return BlockRole::TERRAIN;
|
||||
if(id == MARIO_ID)
|
||||
return BlockRole::MARIO;
|
||||
//TODO modifier/character
|
||||
return BlockRole::MODIFIER;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user