Saving worldmap position on unstable tiles#3766
Conversation
|
@tobbi Hi! I was wondering if you could check my PR as a few weeks have passed since I opened it. I would also like to know what can I do for the 2 failing checks to pass. |
|
Can you please rebase against master? |
8df7886 to
8546b2c
Compare
| m_worldmap->set_passive_message({}, 0.0f); | ||
| } | ||
|
|
||
| if (const auto level = worldmap_sector->at_object<LevelTile>(); level) |
There was a problem hiding this comment.
[...]
; level[...]
Pardon?
In general, I would avoid declaring variables in if statements to improve clarity. Even with that in mind, it doesn't even seem like it is necessary in this case.
| if (const auto level = worldmap_sector->at_object<LevelTile>(); level) | |
| if (worldmap_sector->at_object<LevelTile>()) |
| if (const auto level = worldmap_sector->at_object<LevelTile>(); level) | ||
| { | ||
| m_last_level_tile_pos = m_tile_pos; | ||
| m_last_level_back_direction = m_back_direction; | ||
| m_last_stable_tile_pos = m_tile_pos; | ||
| m_last_stable_back_direction = m_back_direction; | ||
| } | ||
| else if (!m_ghost_mode) | ||
| { | ||
| m_last_stable_tile_pos = m_tile_pos; | ||
| m_last_stable_back_direction = m_back_direction; | ||
| } | ||
| else | ||
| { | ||
| m_last_stable_tile_pos = m_last_level_tile_pos; | ||
| m_last_stable_back_direction = m_last_level_back_direction; | ||
| } |
There was a problem hiding this comment.
In fact, I believe this could be written in a more concise manner.
| if (const auto level = worldmap_sector->at_object<LevelTile>(); level) | |
| { | |
| m_last_level_tile_pos = m_tile_pos; | |
| m_last_level_back_direction = m_back_direction; | |
| m_last_stable_tile_pos = m_tile_pos; | |
| m_last_stable_back_direction = m_back_direction; | |
| } | |
| else if (!m_ghost_mode) | |
| { | |
| m_last_stable_tile_pos = m_tile_pos; | |
| m_last_stable_back_direction = m_back_direction; | |
| } | |
| else | |
| { | |
| m_last_stable_tile_pos = m_last_level_tile_pos; | |
| m_last_stable_back_direction = m_last_level_back_direction; | |
| } | |
| if (worldmap_sector->at_object<LevelTile>() != nullptr) | |
| { | |
| m_last_level_tile_pos = m_tile_pos; | |
| m_last_level_back_direction = m_back_direction; | |
| } | |
| m_last_stable_tile_pos = m_ghost_mode ? m_last_level_tile_pos : m_tile_pos; | |
| m_last_stable_back_direction = m_ghost_mode ? m_last_level_back_direction : m_back_direction; |
Please make sure to double-check this logic.
When leaving to the main menu, the game saves Tux's current worldmap position even if he is mid-path or on a non-stable tile. Upon reloading, Tux is restored to that invalid position. Save Tux on the last valid "stable" tile (such as a stop or level tile) instead of the current one. Also store the corresponding back direction to keep movement consistent after loading. In ghost mode, avoid persisting invalid tiles by falling back to the last valid level tile. This ensures Tux always respawns on a valid, navigable position.
2601804 to
9f7cd6c
Compare
|
Hey @MatusGuy, I did the changes you asked me to. Could you check it please? |
| tux.set("x", sector.m_tux->get_tile_pos().x); | ||
| tux.set("y", sector.m_tux->get_tile_pos().y); | ||
| tux.set("back", direction_to_string(sector.m_tux->m_back_direction)); | ||
| tux.set("x", save_pos.x); | ||
| tux.set("y", save_pos.y); | ||
| tux.set("back", direction_to_string(save_back)); |
There was a problem hiding this comment.
Huh? Which one is it? I'm assuming it's the new one...
| tux.set("x", sector.m_tux->get_tile_pos().x); | |
| tux.set("y", sector.m_tux->get_tile_pos().y); | |
| tux.set("back", direction_to_string(sector.m_tux->m_back_direction)); | |
| tux.set("x", save_pos.x); | |
| tux.set("y", save_pos.y); | |
| tux.set("back", direction_to_string(save_back)); | |
| tux.set("x", save_pos.x); | |
| tux.set("y", save_pos.y); | |
| tux.set("back", direction_to_string(save_back)); |
9f7cd6c to
c5557b9
Compare
|
hey @MatusGuy can you check it now? I believe I did everything you asked me to. |
MatusGuy
left a comment
There was a problem hiding this comment.
LGTM (code). Thanks for your contribution!! Just a few code style/formatting nitpicks
Co-authored-by: MatusGuy <85036874+MatusGuy@users.noreply.github.com>
Co-authored-by: MatusGuy <85036874+MatusGuy@users.noreply.github.com>
When leaving to the main menu, the game saves Tux's current worldmap position even if he is mid-path or on a non-stable tile. Upon reloading, Tux is restored to that invalid position. Save Tux on the last valid "stable" tile (such as a stop or level tile) instead of the current one. Also store the corresponding back direction to keep movement consistent after loading. In ghost mode, avoid persisting invalid tiles by falling back to the last valid level tile. This ensures Tux always respawns on a valid, navigable position.
Closes #3728