Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
xsebek committed Feb 18, 2023
1 parent 28a4bdc commit e3d251b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/Swarm/Game/ScenarioInfo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module Swarm.Game.ScenarioInfo (
scenarioStatus,
scenarioBestTime,
scenarioBestTicks,
updateScenarioInfoOnQuit,
updateScenarioInfoOnFinish,
ScenarioInfoPair,

-- * Scenario collection
Expand Down Expand Up @@ -153,13 +153,13 @@ scenarioBestTime :: Lens' ScenarioInfo ScenarioStatus
-- | The best status of the scenario, measured in game ticks.
scenarioBestTicks :: Lens' ScenarioInfo ScenarioStatus

-- | Update the current @ScenarioInfo@ record when quitting a game.
-- | Update the current @ScenarioInfo@ record when finishing a game.
--
-- Note that when comparing "best" times, shorter is not always better!
-- As long as the scenario is not completed (e.g. some do not have win condition)
-- we consider having fun _longer_ to be better.
updateScenarioInfoOnQuit :: ZonedTime -> Integer -> Bool -> ScenarioInfo -> ScenarioInfo
updateScenarioInfoOnQuit z ticks completed (ScenarioInfo p s bTime bTicks) = case s of
updateScenarioInfoOnFinish :: ZonedTime -> Integer -> Bool -> ScenarioInfo -> ScenarioInfo
updateScenarioInfoOnFinish z ticks completed si@(ScenarioInfo p s bTime bTicks) = case s of
InProgress start _ _ ->
let el = (diffUTCTime `on` zonedTimeToUTC) z start
cur = (if completed then Complete else InProgress) start el ticks
Expand All @@ -168,7 +168,7 @@ updateScenarioInfoOnQuit z ticks completed (ScenarioInfo p s bTime bTicks) = cas
InProgress {} | not completed && f b > f cur -> b -- keep longer progress (fun!)
_ -> cur -- otherwise update with current
in ScenarioInfo p cur (best _scenarioElapsed bTime) (best _scenarioElapsedTicks bTicks)
_ -> error "Logical error: trying to quit scenario which is not in progress!"
_ -> si

-- ----------------------------------------------------------------------------
-- Scenario Item
Expand Down
2 changes: 1 addition & 1 deletion src/Swarm/TUI/Controller.hs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ saveScenarioInfoOnFinish = do
ts <- use $ gameState . ticks
let currentScenarioInfo :: Traversal' AppState ScenarioInfo
currentScenarioInfo = gameState . scenarios . scenarioItemByPath p . _SISingle . _2
currentScenarioInfo %= updateScenarioInfoOnQuit t ts won
currentScenarioInfo %= updateScenarioInfoOnFinish t ts won
status <- preuse currentScenarioInfo
case status of
Nothing -> return ()
Expand Down

0 comments on commit e3d251b

Please sign in to comment.