Mario Editor: add land type switching

This commit is contained in:
zv0n 2021-05-31 14:03:11 +02:00
parent af94cc0e03
commit cd0a301e52
6 changed files with 145 additions and 31 deletions

View File

@ -80,6 +80,13 @@ void MarioBlock::custom_move(int ticks) {
} }
} }
void MarioBlock::setType(LandType::Value type) {
_type = type;
}
LandType::Value MarioBlock::getType() const {
return _type;
}
const std::vector< uint64_t > possibleBlocks = { const std::vector< uint64_t > possibleBlocks = {
FLOOR_ID, FLOOR_ID,
STEP_ID, STEP_ID,
@ -149,6 +156,13 @@ const std::vector< uint64_t > possibleCharacters = {
MARIO_ID, MARIO_ID,
}; };
const std::vector< LandType::Value > possibleLands = {
LandType::OVERWORLD,
LandType::UNDERWORLD,
LandType::WATER,
LandType::BOWSER
};
const std::unordered_map< uint64_t, const SDL_Rect * > block_mapping = { const std::unordered_map< uint64_t, const SDL_Rect * > block_mapping = {
{ FLOOR_ID, &FLOOR_SRC }, { FLOOR_ID, &FLOOR_SRC },
{ HILL_INCLINE_ID, &HILL_INCLINE_SRC }, { HILL_INCLINE_ID, &HILL_INCLINE_SRC },

View File

@ -4,6 +4,10 @@
#include "../sdlpp/sdlpp_rectrenderer.hpp" #include "../sdlpp/sdlpp_rectrenderer.hpp"
#include <memory> #include <memory>
struct LandType {
enum Value { OVERWORLD = 0, UNDERWORLD = 1, WATER = 2, BOWSER = 4 };
};
class MarioBlock : public SDLPP::RectangleRender { class MarioBlock : public SDLPP::RectangleRender {
public: public:
MarioBlock( int x, int y, std::shared_ptr< SDLPP::Renderer > renderer, MarioBlock( int x, int y, std::shared_ptr< SDLPP::Renderer > renderer,
@ -13,6 +17,8 @@ public:
void setTerrain( bool terrain = true ); void setTerrain( bool terrain = true );
void bounce(); void bounce();
virtual void custom_move(int ticks) override; virtual void custom_move(int ticks) override;
void setType(LandType::Value type);
LandType::Value getType() const;
private: private:
bool _tool = false; bool _tool = false;
@ -22,15 +28,13 @@ private:
const int bounce_ticks = 100; const int bounce_ticks = 100;
int ticks_to_bounce = bounce_ticks; int ticks_to_bounce = bounce_ticks;
SDLPP::Vec2D<double> og_pos = {}; SDLPP::Vec2D<double> og_pos = {};
LandType::Value _type;
}; };
extern const std::vector< uint64_t > possibleBlocks; extern const std::vector< uint64_t > possibleBlocks;
extern const std::vector< uint64_t > possibleMods; extern const std::vector< uint64_t > possibleMods;
extern const std::vector< uint64_t > possibleCharacters; extern const std::vector< uint64_t > possibleCharacters;
extern const std::vector< LandType::Value > possibleLands;
struct LandType {
enum Value { OVERWORLD = 0, UNDERWORLD = 1, WATER = 2, BOWSER = 4 };
};
struct BlockRole { struct BlockRole {
enum Value { enum Value {

View File

@ -36,14 +36,16 @@
#define CHARACTER_RIGHT_ENABLED_FLAG 0x00000200 #define CHARACTER_RIGHT_ENABLED_FLAG 0x00000200
#define TOOLS_WIDTH 4 #define TOOLS_WIDTH 4
#define CHARACTER_WIDTH 3 #define CHARACTER_WIDTH 2
#define MOD_WIDTH 3 #define MOD_WIDTH 2
#define OVERWORLD_WIDTH 2
struct ToolType { struct ToolType {
enum Value { enum Value {
BLOCK, BLOCK,
MOD, MOD,
CHARACTER, CHARACTER,
WORLD,
}; };
}; };
@ -83,6 +85,7 @@ struct GlobalVars {
std::vector< std::shared_ptr< SDLPP::RenderObject > > tool_boxes; std::vector< std::shared_ptr< SDLPP::RenderObject > > tool_boxes;
std::vector< std::shared_ptr< SDLPP::RenderObject > > mod_boxes; std::vector< std::shared_ptr< SDLPP::RenderObject > > mod_boxes;
std::vector< std::shared_ptr< SDLPP::RenderObject > > character_boxes; std::vector< std::shared_ptr< SDLPP::RenderObject > > character_boxes;
enum LandType::Value current_world_type;
std::shared_ptr< SDLPP::RenderObject > current_tool; std::shared_ptr< SDLPP::RenderObject > current_tool;
std::shared_ptr< SDLPP::Texture > translucent_terrain_texture; std::shared_ptr< SDLPP::Texture > translucent_terrain_texture;
std::shared_ptr< SDLPP::Texture > translucent_mario_texture; std::shared_ptr< SDLPP::Texture > translucent_mario_texture;
@ -93,7 +96,6 @@ struct GlobalVars {
GlobalVars global_vars; GlobalVars global_vars;
std::mutex destruction_mutex; std::mutex destruction_mutex;
enum LandType::Value g_current_world_type = LandType::OVERWORLD;
void updateTool() { void updateTool() {
auto tool_index = global_vars.tool.index; auto tool_index = global_vars.tool.index;
@ -126,7 +128,7 @@ void updateTool() {
break; break;
} }
global_vars.current_tool->setTexture( global_vars.current_tool->setTexture(
target_texture, getSourceRectByID( tool_id, g_current_world_type ) ); target_texture, getSourceRectByID( tool_id, global_vars.current_world_type ) );
global_vars.current_tool->setId( tool_id ); global_vars.current_tool->setId( tool_id );
global_vars.current_tool->getCollisions()[0]->setId( tool_id ); global_vars.current_tool->getCollisions()[0]->setId( tool_id );
} }
@ -159,7 +161,9 @@ void setToolColor( const std::string &color ) {
case ToolType::CHARACTER: case ToolType::CHARACTER:
multiplier = CHARACTER_WIDTH; multiplier = CHARACTER_WIDTH;
store = &global_vars.character_boxes; store = &global_vars.character_boxes;
break;
default: default:
store = nullptr;
break; break;
} }
auto index = global_vars.tool.index % ( 2 * multiplier ); auto index = global_vars.tool.index % ( 2 * multiplier );
@ -390,6 +394,19 @@ bool getFlag( uint64_t flag ) {
return global_vars.flags & flag; return global_vars.flags & flag;
} }
void updateWorld() {
for(auto &block : global_vars.tools) {
block->setTextureSourceRect(getSourceRectByID(block->getId(), global_vars.current_world_type));
dynamic_cast<MarioBlock *>(block.get())->setType(global_vars.current_world_type);
}
for(auto &block : global_vars.characters) {
block->setTextureSourceRect(getSourceRectByID(block->getId(), global_vars.current_world_type));
dynamic_cast<MarioBlock *>(block.get())->setType(global_vars.current_world_type);
}
global_vars.current_tool->setTextureSourceRect(getSourceRectByID(global_vars.current_tool->getId(), global_vars.current_world_type));
dynamic_cast<MarioBlock *>(global_vars.current_tool.get())->setType(global_vars.current_world_type);
}
// TODO add mouse wheel control for modifiers // TODO add mouse wheel control for modifiers
void handleKeyUp( SDL_Keycode key, SDLPP::Scene &scene ) { void handleKeyUp( SDL_Keycode key, SDLPP::Scene &scene ) {
switch ( key ) { switch ( key ) {
@ -408,6 +425,22 @@ void handleKeyUp( SDL_Keycode key, SDLPP::Scene &scene ) {
case SDLK_s: case SDLK_s:
selectLowerTool(); selectLowerTool();
break; break;
case SDLK_1:
global_vars.current_world_type = possibleLands[0];
updateWorld();
break;
case SDLK_2:
global_vars.current_world_type = possibleLands[1];
updateWorld();
break;
case SDLK_3:
global_vars.current_world_type = possibleLands[2];
updateWorld();
break;
case SDLK_4:
global_vars.current_world_type = possibleLands[3];
updateWorld();
break;
case SDLK_r: case SDLK_r:
scene.getRenderer().setRenderColiders( scene.getRenderer().setRenderColiders(
!scene.getRenderer().getRenderColiders() ); !scene.getRenderer().getRenderColiders() );
@ -506,6 +539,7 @@ void placeTool( SDLPP::Scene &scene ) {
std::lock_guard< std::mutex > lock( destruction_mutex ); std::lock_guard< std::mutex > lock( destruction_mutex );
ToolVisitor visitor; ToolVisitor visitor;
visitor.setSourceType(global_vars.current_world_type);
auto tool_type = getBlockRole( global_vars.current_tool->getId() ); auto tool_type = getBlockRole( global_vars.current_tool->getId() );
switch ( tool_type ) { switch ( tool_type ) {
case BlockRole::TERRAIN: case BlockRole::TERRAIN:
@ -521,7 +555,7 @@ void placeTool( SDLPP::Scene &scene ) {
auto &obj = getSelectedObject(); auto &obj = getSelectedObject();
switch ( visitor.getVisitorType() ) { switch ( visitor.getVisitorType() ) {
case VisitorType::Terrain: case VisitorType::Terrain:
std::get< MapObject::TERRAIN_TYPE >( obj ) = LandType::OVERWORLD; std::get< MapObject::TERRAIN_TYPE >( obj ) = global_vars.current_world_type;
std::get< MapObject::TERRAIN_ID >( obj ) = 0; std::get< MapObject::TERRAIN_ID >( obj ) = 0;
break; break;
case VisitorType::Modifier: case VisitorType::Modifier:
@ -540,12 +574,12 @@ void placeTool( SDLPP::Scene &scene ) {
std::shared_ptr< SDLPP::RenderObject > new_obj = nullptr; std::shared_ptr< SDLPP::RenderObject > new_obj = nullptr;
switch ( visitor.getVisitorType() ) { switch ( visitor.getVisitorType() ) {
case VisitorType::Terrain: case VisitorType::Terrain:
std::get< MapObject::TERRAIN_TYPE >( obj ) = LandType::OVERWORLD; std::get< MapObject::TERRAIN_TYPE >( obj ) = global_vars.current_world_type;
std::get< MapObject::TERRAIN_ID >( obj ) = std::get< MapObject::TERRAIN_ID >( obj ) =
global_vars.current_tool->getId(); global_vars.current_tool->getId();
// TODO why 1 +? // TODO why 1 +?
new_obj = createTerrainBlock( new_obj = createTerrainBlock(
global_vars.current_tool->getId(), LandType::OVERWORLD, global_vars.current_tool->getId(), global_vars.current_world_type,
renderer, 1 + global_vars.mouse.edit_box.getX(), renderer, 1 + global_vars.mouse.edit_box.getX(),
global_vars.mouse.edit_box.getY(), true ); global_vars.mouse.edit_box.getY(), true );
new_obj->getCollisions()[0]->setId( EDITOR_TERRAIN_ID ); new_obj->getCollisions()[0]->setId( EDITOR_TERRAIN_ID );
@ -553,11 +587,11 @@ void placeTool( SDLPP::Scene &scene ) {
case VisitorType::Modifier: case VisitorType::Modifier:
if ( tool_type == BlockRole::MARIO ) { if ( tool_type == BlockRole::MARIO ) {
std::get< MapObject::CHARACTER_TYPE >( obj ) = std::get< MapObject::CHARACTER_TYPE >( obj ) =
LandType::OVERWORLD; global_vars.current_world_type;
std::get< MapObject::CHARACTER_ID >( obj ) = MARIO_ID; std::get< MapObject::CHARACTER_ID >( obj ) = MARIO_ID;
std::get< MapObject::MODIFIER_TYPE >( obj ) = 0; std::get< MapObject::MODIFIER_TYPE >( obj ) = 0;
std::get< MapObject::MODIFIER_DATA >( obj ) = 0; std::get< MapObject::MODIFIER_DATA >( obj ) = 0;
new_obj = createMario( LandType::OVERWORLD, renderer, new_obj = createMario( global_vars.current_world_type, renderer,
1 + global_vars.mouse.edit_box.getX(), 1 + global_vars.mouse.edit_box.getX(),
global_vars.mouse.edit_box.getY() ); global_vars.mouse.edit_box.getY() );
// remove mario if exists // remove mario if exists
@ -573,7 +607,7 @@ void placeTool( SDLPP::Scene &scene ) {
global_vars.current_tool->getId(); global_vars.current_tool->getId();
std::get< MapObject::MODIFIER_DATA >( obj ) = 0; std::get< MapObject::MODIFIER_DATA >( obj ) = 0;
new_obj = createTerrainBlock( new_obj = createTerrainBlock(
global_vars.current_tool->getId(), LandType::OVERWORLD, global_vars.current_tool->getId(), global_vars.current_world_type,
renderer, 1 + global_vars.mouse.edit_box.getX(), renderer, 1 + global_vars.mouse.edit_box.getX(),
global_vars.mouse.edit_box.getY(), global_vars.mouse.edit_box.getY(),
global_vars.translucent_terrain_texture, true ); global_vars.translucent_terrain_texture, true );
@ -637,12 +671,18 @@ void pollEvents( SDLPP::Scene &scene ) {
multiplier = 2 * CHARACTER_WIDTH; multiplier = 2 * CHARACTER_WIDTH;
max_index = global_vars.characters.size(); max_index = global_vars.characters.size();
cur_page = global_vars.tool.cur_page_characters; cur_page = global_vars.tool.cur_page_characters;
break;
case ToolType::WORLD:
multiplier = 2 * OVERWORLD_WIDTH;
default: default:
break; break;
} }
size_t index = size_t index =
tool_box.getY() * ( multiplier / 2 ) + tool_box.getX(); tool_box.getY() * ( multiplier / 2 ) + tool_box.getX();
if ( index < max_index ) { if(global_vars.mouse.tool_type == ToolType::WORLD) {
global_vars.current_world_type = possibleLands[index];
updateWorld();
} else if ( index < max_index ) {
global_vars.tool.type = global_vars.mouse.tool_type; global_vars.tool.type = global_vars.mouse.tool_type;
updateToolIndex( cur_page * multiplier + index ); updateToolIndex( cur_page * multiplier + index );
} }
@ -738,7 +778,7 @@ void populateToolGrid(
ToolType::Value type, const std::vector< uint64_t > &blocks, ToolType::Value type, const std::vector< uint64_t > &blocks,
std::vector< std::shared_ptr< SDLPP::RenderObject > > &tool_store, std::vector< std::shared_ptr< SDLPP::RenderObject > > &tool_store,
std::vector< std::shared_ptr< SDLPP::RenderObject > > &tool_box_store, std::vector< std::shared_ptr< SDLPP::RenderObject > > &tool_box_store,
std::shared_ptr< SDLPP::Scene > &scene ) { std::shared_ptr< SDLPP::Scene > &scene, const std::string &title, const std::shared_ptr<SDLPP::FontConfiguration> &font_config ) {
auto renderer = scene->getRendererShared(); auto renderer = scene->getRendererShared();
for ( int j = 0; j < count_y; j++ ) { for ( int j = 0; j < count_y; j++ ) {
for ( int i = 0; i < count_x; i++ ) { for ( int i = 0; i < count_x; i++ ) {
@ -753,12 +793,14 @@ void populateToolGrid(
case ToolType::CHARACTER: case ToolType::CHARACTER:
if ( block == MARIO_ID ) if ( block == MARIO_ID )
tool_store.push_back( tool_store.push_back(
createMario( LandType::OVERWORLD, renderer, 0, 0 ) ); createMario( global_vars.current_world_type, renderer, 0, 0 ) );
else else
case ToolType::BLOCK: case ToolType::BLOCK:
case ToolType::MOD: case ToolType::MOD:
tool_store.push_back( createTerrainBlock( tool_store.push_back( createTerrainBlock(
block, LandType::OVERWORLD, renderer, false ) ); block, global_vars.current_world_type, renderer, false ) );
default:
break;
} }
tool_store.back()->setHidden( true ); tool_store.back()->setHidden( true );
tool_store.back()->setPermanent(); tool_store.back()->setPermanent();
@ -779,6 +821,40 @@ void populateToolGrid(
tool_box_store.push_back( tool_box ); tool_box_store.push_back( tool_box );
} }
} }
auto tool_text = std::make_shared<SDLPP::TextRenderer>(start_x - BLOCK_SIZE, start_y - BLOCK_SIZE, (count_x + 2) * BLOCK_SIZE, BLOCK_SIZE, renderer, title, font_config, SDLPP_TEXT_CENTER);
tool_text->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
tool_text->setPermanent();
scene->addObject(tool_text);
}
void populateWorldType(
int count_x, int count_y, float start_x, float start_y,
std::shared_ptr< SDLPP::Scene > &scene, const std::string &title, const std::shared_ptr<SDLPP::FontConfiguration> &font_config ) {
auto renderer = scene->getRendererShared();
for ( int j = 0; j < count_y; j++ ) {
for ( int i = 0; i < count_x; i++ ) {
auto tool_box = std::make_shared< ToolBox >( i, j, start_x, start_y,
renderer );
tool_box->setType(ToolType::WORLD);
scene->addObject( tool_box );
}
}
int tool_index = 0;
for ( auto &type : possibleLands ) {
auto land = createTerrainBlock( BRICK_ID, type, renderer, false );
auto x = tool_index % count_x;
auto y = tool_index / count_x;
land->setId(EDITOR_WORLD_CHANGE_ID);
land->setPermanent();
land->setPos( start_x + x * BLOCK_SIZE,
start_y + y * BLOCK_SIZE );
scene->addObject( land );
tool_index = ( tool_index + 1 ) % ( 2 * count_x );
}
auto tool_text = std::make_shared<SDLPP::TextRenderer>(start_x, start_y - BLOCK_SIZE, count_x * BLOCK_SIZE, BLOCK_SIZE, renderer, title, font_config, SDLPP_TEXT_CENTER);
tool_text->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
tool_text->setPermanent();
scene->addObject(tool_text);
} }
void checkArrowsEnabled( uint64_t cur_page, uint64_t max_page, void checkArrowsEnabled( uint64_t cur_page, uint64_t max_page,
@ -846,6 +922,8 @@ int main() {
bg->setId( 1 ); bg->setId( 1 );
scene->addObject( bg ); scene->addObject( bg );
global_vars.current_world_type = LandType::OVERWORLD;
// TODO file name // TODO file name
loadMap( scene, global_vars.mario, "test_binary.bin", renderer, loadMap( scene, global_vars.mario, "test_binary.bin", renderer,
global_vars.objects ); global_vars.objects );
@ -875,7 +953,7 @@ int main() {
// tools // tools
populateToolGrid( TOOLS_WIDTH, 2, ( MAP_WIDTH - TOOLS_WIDTH ) * BLOCK_SIZE, populateToolGrid( TOOLS_WIDTH, 2, ( MAP_WIDTH - TOOLS_WIDTH ) * BLOCK_SIZE,
BLOCK_SIZE, ToolType::BLOCK, possibleBlocks, BLOCK_SIZE, ToolType::BLOCK, possibleBlocks,
global_vars.tools, global_vars.tool_boxes, scene ); global_vars.tools, global_vars.tool_boxes, scene, "TERRAIN", font_config );
arrows = createArrowControls( ( MAP_WIDTH - TOOLS_WIDTH - 1 ) * BLOCK_SIZE, arrows = createArrowControls( ( MAP_WIDTH - TOOLS_WIDTH - 1 ) * BLOCK_SIZE,
MAP_WIDTH * BLOCK_SIZE, BLOCK_SIZE, MAP_WIDTH * BLOCK_SIZE, BLOCK_SIZE,
2 * BLOCK_SIZE, EDITOR_LEFT_TOOL_ID, 2 * BLOCK_SIZE, EDITOR_LEFT_TOOL_ID,
@ -885,30 +963,34 @@ int main() {
createGrid( ( MAP_WIDTH - TOOLS_WIDTH ) * BLOCK_SIZE, BLOCK_SIZE, createGrid( ( MAP_WIDTH - TOOLS_WIDTH ) * BLOCK_SIZE, BLOCK_SIZE,
TOOLS_WIDTH, 2, scene ); TOOLS_WIDTH, 2, scene );
// mods // mods
populateToolGrid( MOD_WIDTH, 2, 2 * BLOCK_SIZE, BLOCK_SIZE, ToolType::MOD, populateToolGrid( MOD_WIDTH, 2, 4 * BLOCK_SIZE, BLOCK_SIZE, ToolType::MOD,
possibleMods, global_vars.mods, global_vars.mod_boxes, possibleMods, global_vars.mods, global_vars.mod_boxes,
scene ); scene, "MODS", font_config );
arrows = createArrowControls( arrows = createArrowControls(
BLOCK_SIZE, ( MOD_WIDTH + 2 ) * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE, 3 * BLOCK_SIZE, ( MOD_WIDTH + 4 ) * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE,
EDITOR_LEFT_MOD_ID, EDITOR_RIGHT_MOD_ID, scene, font_config ); EDITOR_LEFT_MOD_ID, EDITOR_RIGHT_MOD_ID, scene, font_config );
auto left_mod_arrow = arrows.first; auto left_mod_arrow = arrows.first;
auto right_mod_arrow = arrows.second; auto right_mod_arrow = arrows.second;
createGrid( 2 * BLOCK_SIZE, BLOCK_SIZE, MOD_WIDTH, 2, scene ); createGrid( 4 * BLOCK_SIZE, BLOCK_SIZE, MOD_WIDTH, 2, scene );
// characters // characters
populateToolGrid( CHARACTER_WIDTH, 2, ( MOD_WIDTH + 5 ) * BLOCK_SIZE, populateToolGrid( CHARACTER_WIDTH, 2, ( MOD_WIDTH + 7 ) * BLOCK_SIZE,
BLOCK_SIZE, ToolType::CHARACTER, possibleCharacters, BLOCK_SIZE, ToolType::CHARACTER, possibleCharacters,
global_vars.characters, global_vars.character_boxes, global_vars.characters, global_vars.character_boxes,
scene ); scene, "CHARACTERS", font_config );
arrows = createArrowControls( arrows = createArrowControls(
( MOD_WIDTH + 4 ) * BLOCK_SIZE, ( MOD_WIDTH + 6 ) * BLOCK_SIZE,
( MOD_WIDTH + 5 + CHARACTER_WIDTH ) * BLOCK_SIZE, BLOCK_SIZE, ( MOD_WIDTH + 7 + CHARACTER_WIDTH ) * BLOCK_SIZE, BLOCK_SIZE,
2 * BLOCK_SIZE, EDITOR_LEFT_CHARACTER_ID, EDITOR_RIGHT_CHARACTER_ID, 2 * BLOCK_SIZE, EDITOR_LEFT_CHARACTER_ID, EDITOR_RIGHT_CHARACTER_ID,
scene, font_config ); scene, font_config );
auto left_char_arrow = arrows.first; auto left_char_arrow = arrows.first;
auto right_char_arrow = arrows.second; auto right_char_arrow = arrows.second;
createGrid( ( MOD_WIDTH + 5 ) * BLOCK_SIZE, BLOCK_SIZE, CHARACTER_WIDTH, 2, createGrid( ( MOD_WIDTH + 7 ) * BLOCK_SIZE, BLOCK_SIZE, CHARACTER_WIDTH, 2,
scene ); scene );
// world type
populateWorldType(OVERWORLD_WIDTH, 2, 0, BLOCK_SIZE, scene, "WORLD", font_config);
createGrid( 0, BLOCK_SIZE, OVERWORLD_WIDTH, 2, scene );
global_vars.map.max_page = global_vars.objects.size() - MAP_WIDTH; global_vars.map.max_page = global_vars.objects.size() - MAP_WIDTH;
global_vars.tool.max_page_tools = global_vars.tool.max_page_tools =
@ -936,7 +1018,7 @@ int main() {
renderer, "sprites/mario.png", MARIO_OVERWORLD_COLORKEY ); renderer, "sprites/mario.png", MARIO_OVERWORLD_COLORKEY );
global_vars.translucent_mario_texture->setAlpha( 100 ); global_vars.translucent_mario_texture->setAlpha( 100 );
global_vars.current_tool = createTerrainBlock( global_vars.current_tool = createTerrainBlock(
possibleBlocks[global_vars.tool.index], LandType::OVERWORLD, renderer, possibleBlocks[global_vars.tool.index], global_vars.current_world_type, renderer,
global_vars.translucent_terrain_texture, false ); global_vars.translucent_terrain_texture, false );
global_vars.current_tool->addCollision( global_vars.current_tool->addCollision(
SDLPP::RectColider( 0.1, 0.1, 0.8, 0.8 ) ); SDLPP::RectColider( 0.1, 0.1, 0.8, 0.8 ) );

View File

@ -1,5 +1,6 @@
#include "editor_visitor.hpp" #include "editor_visitor.hpp"
#include "../sdlpp/sdlpp_renderobject.hpp" #include "../sdlpp/sdlpp_renderobject.hpp"
#include "blocks.hpp"
#include "objectids.hpp" #include "objectids.hpp"
#include "edit_box.hpp" #include "edit_box.hpp"
#include "tool_box.hpp" #include "tool_box.hpp"
@ -91,18 +92,25 @@ bool MouseVisitor::moveCharactersRight( uint64_t flags ) {
void ToolVisitor::visit( const SDLPP::RenderObject &obj ) { void ToolVisitor::visit( const SDLPP::RenderObject &obj ) {
auto id = obj.getCollisions()[0]->getId(); auto id = obj.getCollisions()[0]->getId();
switch ( id ) { switch ( id ) {
case EDITOR_TERRAIN_ID: case EDITOR_TERRAIN_ID: {
const MarioBlock &m_obj = dynamic_cast<const MarioBlock&>(obj);
remove_block = true; remove_block = true;
if ( obj.getId() == source_id && if ( obj.getId() == source_id &&
m_obj.getType() == source_type &&
getVisitorType() == VisitorType::Terrain ) { getVisitorType() == VisitorType::Terrain ) {
add_block = false; add_block = false;
} }
case EDITOR_CHARACTER_ID: }
break;
case EDITOR_CHARACTER_ID: {
const MarioBlock &m_obj = dynamic_cast<const MarioBlock&>(obj);
remove_block = true; remove_block = true;
if ( obj.getId() == source_id && if ( obj.getId() == source_id &&
m_obj.getType() == source_type &&
getVisitorType() == VisitorType::Modifier ) { getVisitorType() == VisitorType::Modifier ) {
add_block = false; add_block = false;
} }
}
default: default:
break; break;
} }

View File

@ -3,6 +3,7 @@
#include "../sdlpp/sdlpp_visitor.hpp" #include "../sdlpp/sdlpp_visitor.hpp"
#include "../sdlpp/sdlpp_geometry.hpp" #include "../sdlpp/sdlpp_geometry.hpp"
#include "blocks.hpp"
#include <memory> #include <memory>
struct VisitorType { struct VisitorType {
@ -80,6 +81,9 @@ public:
virtual uint64_t getVisitorType() override { virtual uint64_t getVisitorType() override {
return _type; return _type;
} }
void setSourceType(LandType::Value type) {
source_type = type;
}
bool addBlock(); bool addBlock();
bool removeBlock(); bool removeBlock();
@ -88,6 +92,7 @@ private:
bool add_block = true; bool add_block = true;
uint64_t source_id = 0; uint64_t source_id = 0;
uint64_t _type = 0; uint64_t _type = 0;
LandType::Value source_type;
}; };
#endif #endif

View File

@ -91,6 +91,7 @@
#define EDITOR_RIGHT_MOD_ID 0xF00B #define EDITOR_RIGHT_MOD_ID 0xF00B
#define EDITOR_LEFT_CHARACTER_ID 0xF00C #define EDITOR_LEFT_CHARACTER_ID 0xF00C
#define EDITOR_RIGHT_CHARACTER_ID 0xF00D #define EDITOR_RIGHT_CHARACTER_ID 0xF00D
#define EDITOR_WORLD_CHANGE_ID 0xF00E
#define MOUSE_VISITOR_TYPE 0xE003 #define MOUSE_VISITOR_TYPE 0xE003
#define MARIO_VISITOR_TYPE 0xE004 #define MARIO_VISITOR_TYPE 0xE004