Mario Editor: change edit boxes' indexing to 1-based

As the left map arrow is on position 0 * BLOCK_SIZE and the first edit
box is on position 1 * BLOCK_SIZE, indexing them from 1 causes slightly
more readable code
This commit is contained in:
zvon 2021-05-31 16:08:14 +02:00
parent 26cbdd0f8e
commit 2b405c5d31

View File

@ -375,7 +375,8 @@ void selectNextTool() {
break;
}
int addition = 1;
if ( global_vars.tool.index % multiplier == static_cast<uint64_t>( multiplier - 1 ) )
if ( global_vars.tool.index % multiplier ==
static_cast< uint64_t >( multiplier - 1 ) )
addition = multiplier + 1;
if ( global_vars.tool.index == max_index )
return;
@ -464,14 +465,16 @@ void getMousePositionFlags( SDLPP::Scene &scene ) {
MouseVisitor visitor;
scene.visitCollisions( *mouse, visitor );
global_vars.mouse.cur_flags = visitor.getFlags();
global_vars.mouse.edit_box = visitor.getEditBoxIndexes();
// + 1 because the left map arrow is on position 0
global_vars.mouse.edit_box =
visitor.getEditBoxIndexes() + SDLPP::Vec2D< int >( 1, 0 );
global_vars.mouse.tool_box = visitor.getToolBoxIndexes();
global_vars.mouse.tool_type =
static_cast< ToolType::Value >( visitor.getToolType() );
// if we found an edit box, move tool icon to that box
if ( visitor.foundEditBox() ) {
const auto &box = global_vars.mouse.edit_box;
global_vars.current_tool->setPos( BLOCK_SIZE + box.getX() * BLOCK_SIZE,
global_vars.current_tool->setPos( box.getX() * BLOCK_SIZE,
( MAP_WIDTH - MAP_HEIGHT + 2 ) *
BLOCK_SIZE +
box.getY() * BLOCK_SIZE );
@ -532,8 +535,9 @@ void mouseUpAction( uint64_t flags, SDLPP::Scene &scene ) {
}
SDLPP::Vec2D< int > getSelectedObjectPosition() {
// -1 because we're indexing edit boxes from 1 (due to left arrow on map)
return global_vars.mouse.edit_box +
SDLPP::Vec2D< int >( global_vars.map.cur_page, 0 );
SDLPP::Vec2D< int >( global_vars.map.cur_page - 1, 0 );
}
mapObjectType &getSelectedObject() {
@ -585,11 +589,10 @@ void placeTool( SDLPP::Scene &scene ) {
global_vars.current_world_type;
std::get< MapObject::TERRAIN_ID >( obj ) =
global_vars.current_tool->getId();
// TODO why 1 +?
new_obj =
createTerrainBlock( global_vars.current_tool->getId(),
global_vars.current_world_type, renderer,
1 + global_vars.mouse.edit_box.getX(),
global_vars.mouse.edit_box.getX(),
global_vars.mouse.edit_box.getY(), true );
new_obj->getCollisions()[0]->setId( EDITOR_TERRAIN_ID );
break;
@ -601,7 +604,7 @@ void placeTool( SDLPP::Scene &scene ) {
std::get< MapObject::MODIFIER_TYPE >( obj ) = 0;
std::get< MapObject::MODIFIER_DATA >( obj ) = 0;
new_obj = createMario( global_vars.current_world_type, renderer,
1 + global_vars.mouse.edit_box.getX(),
global_vars.mouse.edit_box.getX(),
global_vars.mouse.edit_box.getY() );
// remove mario if exists
removeMario();
@ -618,7 +621,7 @@ void placeTool( SDLPP::Scene &scene ) {
new_obj = createTerrainBlock(
global_vars.current_tool->getId(),
global_vars.current_world_type, renderer,
1 + global_vars.mouse.edit_box.getX(),
global_vars.mouse.edit_box.getX(),
global_vars.mouse.edit_box.getY(),
global_vars.translucent_terrain_texture, true );
new_obj->getCollisions()[0]->setId( EDITOR_TERRAIN_ID );
@ -658,7 +661,7 @@ void pollEvents( SDLPP::Scene &scene ) {
if ( global_vars.mouse.cur_flags == global_vars.mouse.prev_flags ) {
mouseUpAction( global_vars.mouse.cur_flags, scene );
}
if ( global_vars.mouse.edit_box.getX() != -1 ) {
if ( global_vars.mouse.edit_box.getX() != 0 ) {
placeTool( scene );
}
if ( global_vars.mouse.tool_box.getX() != -1 ) {