Mario: add MapObject and use that instead of tuples
This commit is contained in:
+64
-72
@@ -136,13 +136,9 @@ void updateTool() {
|
||||
void removeMario() {
|
||||
if ( !global_vars.mario )
|
||||
return;
|
||||
auto prev = global_vars.objects[global_vars.mario_pos.getX()]
|
||||
[global_vars.mario_pos.getY()];
|
||||
// remove character/modifiers
|
||||
global_vars
|
||||
.objects[global_vars.mario_pos.getX()][global_vars.mario_pos.getY()] = {
|
||||
std::get< 0 >( prev ), std::get< 1 >( prev ), 0, 0, 0, 0
|
||||
};
|
||||
.objects[global_vars.mario_pos.getX()][global_vars.mario_pos.getY()]
|
||||
.unsetCharacter();
|
||||
global_vars.mario->destroy();
|
||||
}
|
||||
|
||||
@@ -166,7 +162,7 @@ void setToolColor( const std::string &color ) {
|
||||
store = nullptr;
|
||||
break;
|
||||
}
|
||||
if(store == nullptr)
|
||||
if ( store == nullptr )
|
||||
return;
|
||||
auto index = global_vars.tool.index % ( 2 * multiplier );
|
||||
store->at( index )->setColor( color );
|
||||
@@ -203,7 +199,7 @@ 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;
|
||||
@@ -291,7 +287,7 @@ void updateToolIndex( uint64_t new_index, ToolType::Value new_type ) {
|
||||
}
|
||||
|
||||
void updateToolIndex( uint64_t new_index ) {
|
||||
updateToolIndex(new_index, global_vars.tool.type);
|
||||
updateToolIndex( new_index, global_vars.tool.type );
|
||||
}
|
||||
|
||||
void selectLowerTool() {
|
||||
@@ -549,7 +545,7 @@ SDLPP::Vec2D< int > getSelectedObjectIndexes() {
|
||||
SDLPP::Vec2D< int >( global_vars.map.cur_page - 1, 0 );
|
||||
}
|
||||
|
||||
mapObjectType &getSelectedObject() {
|
||||
MapObject &getSelectedObject() {
|
||||
auto pos = getSelectedObjectIndexes();
|
||||
return global_vars.objects[pos.getX()][pos.getY()];
|
||||
}
|
||||
@@ -570,48 +566,36 @@ void placeTool( SDLPP::Scene &scene ) {
|
||||
}
|
||||
|
||||
scene.visitCollisions( *global_vars.current_tool, visitor );
|
||||
auto &obj = getSelectedObject();
|
||||
if ( visitor.removeBlock() && !visitor.addBlock() ) {
|
||||
auto &obj = getSelectedObject();
|
||||
switch ( visitor.getVisitorType() ) {
|
||||
case VisitorType::Terrain:
|
||||
std::get< MapObject::TERRAIN_TYPE >( obj ) =
|
||||
global_vars.current_world_type;
|
||||
std::get< MapObject::TERRAIN_ID >( obj ) = 0;
|
||||
obj.unsetTerrain();
|
||||
break;
|
||||
case VisitorType::Modifier:
|
||||
std::get< MapObject::CHARACTER_TYPE >( obj ) = 0;
|
||||
std::get< MapObject::CHARACTER_ID >( obj ) = 0;
|
||||
std::get< MapObject::MODIFIER_TYPE >( obj ) = 0;
|
||||
std::get< MapObject::MODIFIER_DATA >( obj ) = 0;
|
||||
obj.unsetModifier();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if ( visitor.addBlock() ) {
|
||||
auto &obj = getSelectedObject();
|
||||
auto renderer = scene.getRendererShared();
|
||||
int z_index = 1;
|
||||
std::shared_ptr< SDLPP::RenderObject > new_obj = nullptr;
|
||||
switch ( visitor.getVisitorType() ) {
|
||||
case VisitorType::Terrain:
|
||||
std::get< MapObject::TERRAIN_TYPE >( obj ) =
|
||||
global_vars.current_world_type;
|
||||
std::get< MapObject::TERRAIN_ID >( obj ) =
|
||||
global_vars.current_tool->getId();
|
||||
new_obj =
|
||||
createTerrainBlock( global_vars.current_tool->getId(),
|
||||
global_vars.current_world_type, renderer,
|
||||
global_vars.mouse.edit_box.getX(),
|
||||
global_vars.mouse.edit_box.getY(), false, true );
|
||||
obj.setTerrain( global_vars.current_tool->getId(),
|
||||
global_vars.current_world_type );
|
||||
new_obj = createTerrainBlock(
|
||||
obj.getTerrainId(),
|
||||
obj.getTerrainType(), renderer,
|
||||
global_vars.mouse.edit_box.getX(),
|
||||
global_vars.mouse.edit_box.getY(), false, true );
|
||||
new_obj->getCollisions()[0]->setId( EDITOR_TERRAIN_ID );
|
||||
break;
|
||||
case VisitorType::Modifier:
|
||||
if ( tool_type == BlockRole::MARIO ) {
|
||||
std::get< MapObject::CHARACTER_TYPE >( obj ) =
|
||||
global_vars.current_world_type;
|
||||
std::get< MapObject::CHARACTER_ID >( obj ) = MARIO_ID;
|
||||
std::get< MapObject::MODIFIER_TYPE >( obj ) = 0;
|
||||
std::get< MapObject::MODIFIER_DATA >( obj ) = 0;
|
||||
obj.setCharacter(MARIO_ID, global_vars.current_world_type);
|
||||
new_obj = createMario( global_vars.current_world_type, renderer,
|
||||
global_vars.mouse.edit_box.getX(),
|
||||
global_vars.mouse.edit_box.getY() );
|
||||
@@ -624,12 +608,10 @@ void placeTool( SDLPP::Scene &scene ) {
|
||||
// TODO BlockRole::Character
|
||||
} else {
|
||||
// TODO data
|
||||
std::get< MapObject::MODIFIER_TYPE >( obj ) =
|
||||
global_vars.current_tool->getId();
|
||||
std::get< MapObject::MODIFIER_DATA >( obj ) = 0;
|
||||
obj.setModifier(global_vars.current_tool->getId(), 0);
|
||||
new_obj = createTerrainBlock(
|
||||
global_vars.current_tool->getId(),
|
||||
global_vars.current_world_type, renderer,
|
||||
obj.getModifierId(),
|
||||
LandType::OVERWORLD, renderer,
|
||||
global_vars.mouse.edit_box.getX(),
|
||||
global_vars.mouse.edit_box.getY(),
|
||||
global_vars.translucent_terrain_texture, false, true );
|
||||
@@ -705,7 +687,8 @@ void pollEvents( SDLPP::Scene &scene ) {
|
||||
global_vars.current_world_type = possibleLands[index];
|
||||
updateWorld();
|
||||
} else if ( index < max_index ) {
|
||||
updateToolIndex( cur_page * multiplier + index, global_vars.mouse.tool_type );
|
||||
updateToolIndex( cur_page * multiplier + index,
|
||||
global_vars.mouse.tool_type );
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -820,8 +803,9 @@ void populateToolGrid(
|
||||
// fall through
|
||||
case ToolType::BLOCK:
|
||||
case ToolType::MOD:
|
||||
tool_store.push_back( createTerrainBlock(
|
||||
block, global_vars.current_world_type, renderer, false, true ) );
|
||||
tool_store.push_back(
|
||||
createTerrainBlock( block, global_vars.current_world_type,
|
||||
renderer, false, true ) );
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -952,7 +936,7 @@ int main() {
|
||||
global_vars.current_world_type = LandType::OVERWORLD;
|
||||
|
||||
// TODO file name
|
||||
loadMap( scene, global_vars.mario, "test_binary.bin", renderer,
|
||||
loadMap( scene, global_vars.mario, "test_binary.bin",
|
||||
global_vars.objects, true, MAP_WIDTH );
|
||||
|
||||
auto font = std::make_shared< SDLPP::Font >( "testfont.ttf", 36 );
|
||||
@@ -962,9 +946,9 @@ int main() {
|
||||
// create grids and arrow controls
|
||||
// map
|
||||
auto arrows = createArrowControls(
|
||||
0, ( MAP_WIDTH + 1 ) * BLOCK_SIZE,
|
||||
1 - MAP_HEIGHT * BLOCK_SIZE, MAP_HEIGHT * BLOCK_SIZE,
|
||||
EDITOR_LEFT_MAP_ID, EDITOR_RIGHT_MAP_ID, scene, font_config );
|
||||
0, ( MAP_WIDTH + 1 ) * BLOCK_SIZE, 1 - MAP_HEIGHT * BLOCK_SIZE,
|
||||
MAP_HEIGHT * BLOCK_SIZE, EDITOR_LEFT_MAP_ID, EDITOR_RIGHT_MAP_ID, scene,
|
||||
font_config );
|
||||
auto left_map_arrow = arrows.first;
|
||||
auto right_map_arrow = arrows.second;
|
||||
createGrid( BLOCK_SIZE, 1 - MAP_HEIGHT * BLOCK_SIZE, MAP_WIDTH, MAP_HEIGHT,
|
||||
@@ -973,53 +957,61 @@ int main() {
|
||||
for ( int i = 0; i < MAP_WIDTH; i++ ) {
|
||||
for ( int j = 0; j < MAP_HEIGHT; j++ ) {
|
||||
scene->addObject( std::make_shared< EditBox >(
|
||||
i, j, BLOCK_SIZE, 1 - MAP_HEIGHT * BLOCK_SIZE, MAP_WIDTH, MAP_HEIGHT, renderer ) );
|
||||
i, j, BLOCK_SIZE, 1 - MAP_HEIGHT * BLOCK_SIZE, MAP_WIDTH,
|
||||
MAP_HEIGHT, renderer ) );
|
||||
}
|
||||
}
|
||||
|
||||
// tools
|
||||
populateToolGrid( TOOLS_WIDTH, 2, ( MAP_WIDTH - TOOLS_WIDTH ) * BLOCK_SIZE,
|
||||
1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, ToolType::BLOCK, possibleBlocks,
|
||||
global_vars.tools, global_vars.tool_boxes, scene,
|
||||
"TERRAIN", font_config );
|
||||
arrows = createArrowControls( ( MAP_WIDTH - TOOLS_WIDTH - 1 ) * BLOCK_SIZE,
|
||||
MAP_WIDTH * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE,
|
||||
2 * BLOCK_SIZE, EDITOR_LEFT_TOOL_ID,
|
||||
EDITOR_RIGHT_TOOL_ID, scene, font_config );
|
||||
1 - ( MAP_HEIGHT + 3 ) * BLOCK_SIZE, ToolType::BLOCK,
|
||||
possibleBlocks, global_vars.tools, global_vars.tool_boxes,
|
||||
scene, "TERRAIN", font_config );
|
||||
arrows = createArrowControls(
|
||||
( MAP_WIDTH - TOOLS_WIDTH - 1 ) * BLOCK_SIZE, MAP_WIDTH * BLOCK_SIZE,
|
||||
1 - ( MAP_HEIGHT + 3 ) * BLOCK_SIZE, 2 * BLOCK_SIZE,
|
||||
EDITOR_LEFT_TOOL_ID, EDITOR_RIGHT_TOOL_ID, scene, font_config );
|
||||
auto left_tool_arrow = arrows.first;
|
||||
auto right_tool_arrow = arrows.second;
|
||||
createGrid( ( MAP_WIDTH - TOOLS_WIDTH ) * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE,
|
||||
TOOLS_WIDTH, 2, scene );
|
||||
createGrid( ( MAP_WIDTH - TOOLS_WIDTH ) * BLOCK_SIZE,
|
||||
1 - ( MAP_HEIGHT + 3 ) * BLOCK_SIZE, TOOLS_WIDTH, 2, scene );
|
||||
// mods
|
||||
populateToolGrid( MOD_WIDTH, 2, 5 * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, ToolType::MOD,
|
||||
populateToolGrid( MOD_WIDTH, 2, 5 * BLOCK_SIZE,
|
||||
1 - ( MAP_HEIGHT + 3 ) * BLOCK_SIZE, ToolType::MOD,
|
||||
possibleMods, global_vars.mods, global_vars.mod_boxes,
|
||||
scene, "MODS", font_config );
|
||||
arrows =
|
||||
createArrowControls( 4 * BLOCK_SIZE, ( MOD_WIDTH + 5 ) * BLOCK_SIZE,
|
||||
1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, 2 * BLOCK_SIZE, EDITOR_LEFT_MOD_ID,
|
||||
EDITOR_RIGHT_MOD_ID, scene, font_config );
|
||||
arrows = createArrowControls(
|
||||
4 * BLOCK_SIZE, ( MOD_WIDTH + 5 ) * BLOCK_SIZE,
|
||||
1 - ( MAP_HEIGHT + 3 ) * BLOCK_SIZE, 2 * BLOCK_SIZE, EDITOR_LEFT_MOD_ID,
|
||||
EDITOR_RIGHT_MOD_ID, scene, font_config );
|
||||
auto left_mod_arrow = arrows.first;
|
||||
auto right_mod_arrow = arrows.second;
|
||||
createGrid( 5 * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, MOD_WIDTH, 2, scene );
|
||||
createGrid( 5 * BLOCK_SIZE, 1 - ( MAP_HEIGHT + 3 ) * BLOCK_SIZE, MOD_WIDTH,
|
||||
2, scene );
|
||||
// characters
|
||||
populateToolGrid( CHARACTER_WIDTH, 2, ( MOD_WIDTH + 8 ) * BLOCK_SIZE,
|
||||
1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, ToolType::CHARACTER, possibleCharacters,
|
||||
global_vars.characters, global_vars.character_boxes,
|
||||
scene, "CHARACTERS", font_config );
|
||||
arrows = createArrowControls(
|
||||
( MOD_WIDTH + 7 ) * BLOCK_SIZE,
|
||||
( MOD_WIDTH + 8 + CHARACTER_WIDTH ) * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE,
|
||||
2 * BLOCK_SIZE, EDITOR_LEFT_CHARACTER_ID, EDITOR_RIGHT_CHARACTER_ID,
|
||||
scene, font_config );
|
||||
1 - ( MAP_HEIGHT + 3 ) * BLOCK_SIZE, ToolType::CHARACTER,
|
||||
possibleCharacters, global_vars.characters,
|
||||
global_vars.character_boxes, scene, "CHARACTERS",
|
||||
font_config );
|
||||
arrows =
|
||||
createArrowControls( ( MOD_WIDTH + 7 ) * BLOCK_SIZE,
|
||||
( MOD_WIDTH + 8 + CHARACTER_WIDTH ) * BLOCK_SIZE,
|
||||
1 - ( MAP_HEIGHT + 3 ) * BLOCK_SIZE,
|
||||
2 * BLOCK_SIZE, EDITOR_LEFT_CHARACTER_ID,
|
||||
EDITOR_RIGHT_CHARACTER_ID, scene, font_config );
|
||||
auto left_char_arrow = arrows.first;
|
||||
auto right_char_arrow = arrows.second;
|
||||
createGrid( ( MOD_WIDTH + 8 ) * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, CHARACTER_WIDTH, 2,
|
||||
createGrid( ( MOD_WIDTH + 8 ) * BLOCK_SIZE,
|
||||
1 - ( MAP_HEIGHT + 3 ) * BLOCK_SIZE, CHARACTER_WIDTH, 2,
|
||||
scene );
|
||||
|
||||
// world type
|
||||
populateWorldType( OVERWORLD_WIDTH, 2, BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, scene, "WORLD",
|
||||
populateWorldType( OVERWORLD_WIDTH, 2, BLOCK_SIZE,
|
||||
1 - ( MAP_HEIGHT + 3 ) * BLOCK_SIZE, scene, "WORLD",
|
||||
font_config );
|
||||
createGrid( BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, OVERWORLD_WIDTH, 2, scene );
|
||||
createGrid( BLOCK_SIZE, 1 - ( MAP_HEIGHT + 3 ) * BLOCK_SIZE,
|
||||
OVERWORLD_WIDTH, 2, scene );
|
||||
|
||||
global_vars.map.max_page = global_vars.objects.size() - MAP_WIDTH;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user