Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scenario menu update after quitting to menu #1243

Merged
merged 2 commits into from
May 3, 2023
Merged

Conversation

kostmo
Copy link
Member

@kostmo kostmo commented May 3, 2023

Ensures that the "played" status and the "best scores" get updated in the scenario menu after "Quit to menu" is selected from within a scenario.

This bug appeared after merging #974.

@kostmo kostmo added the Bug The observed behaviour is incorrect or unexpected. label May 3, 2023
@kostmo kostmo changed the title Fix scenario menu update bug after quitting to menu Fix scenario menu update after quitting to menu May 3, 2023
@@ -454,56 +454,81 @@ getNormalizedCurrentScenarioPath =
gs <- use $ gameState . scenarios
Just <$> liftIO (normalizeScenarioPath gs p')

saveScenarioInfoOnFinish :: (MonadIO m, MonadState AppState m) => FilePath -> m (Maybe ScenarioInfo)
saveScenarioInfoOnFinish p = do
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a cut-and-paste of the body of saveScenarioInfoOnFinishNocheat (formerly saveScenarioInfoOnFinish).


-- | Write the @ScenarioInfo@ out to disk when exiting a game.
saveScenarioInfoOnQuit :: (MonadIO m, MonadState AppState m) => m ()
saveScenarioInfoOnQuit = do
saveScenarioInfoOnFinish
Copy link
Member Author

@kostmo kostmo May 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function call is moved 8 lines down to make use of the "cheat" check, which was formerly implemented redundantly.

@kostmo kostmo marked this pull request as ready for review May 3, 2023 17:37
@kostmo kostmo requested a review from byorgey May 3, 2023 17:51
Copy link
Member

@byorgey byorgey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish the code for dealing with the "new game" menu was simpler, it has been a fertile source of bugs. Maybe someday we'll figure out a nice refactoring that simplifies things...

@kostmo kostmo added the merge me Trigger the merge process of the Pull request. label May 3, 2023
@mergify mergify bot merged commit 6555a41 into main May 3, 2023
9 checks passed
@mergify mergify bot deleted the scenario-menu-bugfix branch May 3, 2023 18:42
mergify bot pushed a commit that referenced this pull request Jun 5, 2023
I believe that since #1277 the progress has not been saved when exiting a scenario back to the menu.

It is because `getNormalizedCurrentScenarioPath`, which is utilized by `saveScenarioInfoOnQuit`, was returning `Nothing`, in turn because `currentScenarioPath` was `Nothing`.  This is because `scenarioToAppState` was clearing it immediately after being set inside `startGameWithSeed`.

Foreshadowed by this comment: #1243 (review) .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug The observed behaviour is incorrect or unexpected. merge me Trigger the merge process of the Pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants