Mario: fix modifier deletion

This commit is contained in:
2021-08-07 12:13:23 +02:00
parent 7b1ef25f37
commit 6238022ed2
8 changed files with 88 additions and 77 deletions
+26 -19
View File
@@ -51,11 +51,11 @@ struct ToolType {
};
struct MouseInfo {
uint64_t cur_flags;
uint64_t prev_flags;
uint64_t cur_flags{};
uint64_t prev_flags{};
SDLPP::Vec2D< int > edit_box;
SDLPP::Vec2D< int > tool_box;
ToolType::Value tool_type;
ToolType::Value tool_type{};
};
struct MapInfo {
@@ -76,10 +76,10 @@ struct ToolInfo {
};
struct GlobalVars {
MouseInfo mouse;
MapInfo map;
ToolInfo tool;
uint64_t flags;
MouseInfo mouse{};
MapInfo map{};
ToolInfo tool{};
uint64_t flags{};
std::vector< mapColumnType > objects;
std::vector< std::shared_ptr< MarioBlock > > tools;
std::vector< std::shared_ptr< MarioBlock > > mods;
@@ -87,7 +87,7 @@ struct GlobalVars {
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 > > character_boxes;
enum LandType::Value current_world_type;
enum LandType::Value current_world_type{};
std::shared_ptr< MarioBlock > coin_tool;
std::shared_ptr< MarioBlock > generic_tool;
std::shared_ptr< MarioBlock > current_tool;
@@ -151,8 +151,9 @@ void updateTool() {
}
void removeMario() {
if ( !global_vars.mario )
if ( !global_vars.mario ) {
return;
}
global_vars
.objects[global_vars.mario_pos.getX()][global_vars.mario_pos.getY()]
.unsetCharacter();
@@ -160,7 +161,7 @@ void removeMario() {
}
void setToolColor( const std::string &color ) {
std::vector< std::shared_ptr< SDLPP::RenderObject > > *store;
std::vector< std::shared_ptr< SDLPP::RenderObject > > *store = nullptr;
int multiplier = 0;
switch ( global_vars.tool.type ) {
case ToolType::BLOCK:
@@ -174,13 +175,12 @@ void setToolColor( const std::string &color ) {
case ToolType::CHARACTER:
multiplier = CHARACTER_WIDTH;
store = &global_vars.character_boxes;
break;
default:
store = nullptr;
break;
}
if ( store == nullptr )
if ( store == nullptr ) {
return;
}
auto index = global_vars.tool.index % ( 2 * multiplier );
store->at( index )->setColor( color );
}
@@ -216,8 +216,9 @@ void updateToolSelection( int prev_index, ToolType::Value type ) {
default:
break;
}
if ( tool_vec == nullptr )
if ( tool_vec == nullptr ) {
return;
}
auto cur = cur_page * multiplier;
size_t prev = prev_index * multiplier;
for ( size_t i = prev;
@@ -369,8 +370,9 @@ void selectPrevTool() {
break;
}
int subtraction = 1;
if ( global_vars.tool.index % multiplier == 0 )
if ( global_vars.tool.index % multiplier == 0 ) {
subtraction = multiplier + 1;
}
if ( global_vars.tool.index == 0 ||
global_vars.tool.index - subtraction >
static_cast< uint64_t >( -multiplier ) ) {
@@ -399,12 +401,15 @@ void selectNextTool() {
}
int addition = 1;
if ( global_vars.tool.index % multiplier ==
static_cast< uint64_t >( multiplier - 1 ) )
static_cast< uint64_t >( multiplier - 1 ) ) {
addition = multiplier + 1;
if ( global_vars.tool.index == max_index )
}
if ( global_vars.tool.index == max_index ) {
return;
if ( global_vars.tool.index + addition > max_index )
}
if ( global_vars.tool.index + addition > max_index ) {
addition = 1;
}
updateToolIndex( global_vars.tool.index + addition );
}
@@ -566,6 +571,7 @@ void placeTool( SDLPP::Scene &scene ) {
ToolVisitor visitor;
visitor.setSourceType( global_vars.current_world_type );
visitor.setSourceData( global_vars.current_tool->getData() );
auto tool_type = getBlockRole( global_vars.current_tool->getId() );
switch ( tool_type ) {
case BlockRole::TERRAIN:
@@ -578,6 +584,7 @@ void placeTool( SDLPP::Scene &scene ) {
scene.visitCollisions( *global_vars.current_tool, visitor );
auto &obj = getSelectedObject();
std::cout << "Remove? " << (visitor.removeBlock() ? "YES" : "NO") << ", Add?" << (visitor.addBlock() ? "YES" : "NO") << std::endl;
if ( visitor.removeBlock() && !visitor.addBlock() ) {
switch ( visitor.getVisitorType() ) {
case VisitorType::Terrain:
@@ -591,7 +598,7 @@ void placeTool( SDLPP::Scene &scene ) {
}
} else if ( visitor.addBlock() ) {
auto renderer = scene.getRendererShared();
int z_index = 1;
uint64_t z_index = 1;
std::shared_ptr< MarioBlock > new_obj = nullptr;
switch ( visitor.getVisitorType() ) {
case VisitorType::Terrain: