Copyright | Brent Yorgey |
---|---|
License | BSD-3-Clause |
Maintainer | byorgey@gmail.com |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Saving and loading info about scenarios (status, path, etc.) as well as loading recursive scenario collections.
Synopsis
- data ScenarioStatus
- _NotStarted :: Prism' ScenarioStatus ()
- _InProgress :: Prism' ScenarioStatus (ZonedTime, NominalDiffTime, Integer)
- _Complete :: Prism' ScenarioStatus (ZonedTime, NominalDiffTime, Integer)
- data ScenarioInfo = ScenarioInfo {}
- scenarioPath :: Lens' ScenarioInfo FilePath
- scenarioStatus :: Lens' ScenarioInfo ScenarioStatus
- scenarioBestTime :: Lens' ScenarioInfo ScenarioStatus
- scenarioBestTicks :: Lens' ScenarioInfo ScenarioStatus
- updateScenarioInfoOnQuit :: ZonedTime -> Integer -> Bool -> ScenarioInfo -> ScenarioInfo
- data ScenarioCollection = SC {}
- scenarioCollectionToList :: ScenarioCollection -> [ScenarioItem]
- scenarioItemByPath :: FilePath -> Traversal' ScenarioCollection ScenarioItem
- normalizeScenarioPath :: ScenarioCollection -> FilePath -> IO FilePath
- data ScenarioItem
- scenarioItemName :: ScenarioItem -> Text
- _SISingle :: Prism' ScenarioItem (Scenario, ScenarioInfo)
- loadScenarios :: Has (Lift IO) sig m => EntityMap -> m (Either Text ScenarioCollection)
- loadScenarioInfo :: (Has (Lift IO) sig m, Has (Throw Text) sig m) => FilePath -> m ScenarioInfo
- saveScenarioInfo :: FilePath -> ScenarioInfo -> IO ()
- module Swarm.Game.Scenario
Scenario info
data ScenarioStatus Source #
A ScenarioStatus
stores the status of a scenario along with
appropriate metadata: not started, in progress, or complete.
Note that "in progress" is currently a bit of a misnomer since
games cannot be saved; at the moment it really means more like
"you played this scenario before but didn't win".
NotStarted | |
InProgress | |
| |
Complete | |
|
Instances
_NotStarted :: Prism' ScenarioStatus () Source #
data ScenarioInfo Source #
A ScenarioInfo
record stores metadata about a scenario: its
canonical path, most recent status, and best-ever status.
Instances
scenarioPath :: Lens' ScenarioInfo FilePath Source #
The path of the scenario, relative to data/scenarios
.
scenarioStatus :: Lens' ScenarioInfo ScenarioStatus Source #
The status of the scenario.
scenarioBestTime :: Lens' ScenarioInfo ScenarioStatus Source #
The best status of the scenario, measured in real world time.
scenarioBestTicks :: Lens' ScenarioInfo ScenarioStatus Source #
The best status of the scenario, measured in game ticks.
updateScenarioInfoOnQuit :: ZonedTime -> Integer -> Bool -> ScenarioInfo -> ScenarioInfo Source #
Update the current ScenarioInfo
record when quitting 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.
Scenario collection
data ScenarioCollection Source #
A scenario collection is a tree of scenarios, keyed by name, together with an optional order. Invariant: every item in the scOrder exists as a key in the scMap.
Instances
Show ScenarioCollection Source # | |
Defined in Swarm.Game.ScenarioInfo showsPrec :: Int -> ScenarioCollection -> ShowS # show :: ScenarioCollection -> String # showList :: [ScenarioCollection] -> ShowS # | |
Eq ScenarioCollection Source # | |
Defined in Swarm.Game.ScenarioInfo (==) :: ScenarioCollection -> ScenarioCollection -> Bool # (/=) :: ScenarioCollection -> ScenarioCollection -> Bool # |
scenarioCollectionToList :: ScenarioCollection -> [ScenarioItem] Source #
Convert a scenario collection to a list of scenario items.
scenarioItemByPath :: FilePath -> Traversal' ScenarioCollection ScenarioItem Source #
Access and modify ScenarioItems in collection based on their path.
normalizeScenarioPath :: ScenarioCollection -> FilePath -> IO FilePath Source #
Canonicalize a scenario path, making it usable as a unique key.
data ScenarioItem Source #
A scenario item is either a specific scenario, or a collection of scenarios (*e.g.* the scenarios contained in a subdirectory).
Instances
Show ScenarioItem Source # | |
Defined in Swarm.Game.ScenarioInfo showsPrec :: Int -> ScenarioItem -> ShowS # show :: ScenarioItem -> String # showList :: [ScenarioItem] -> ShowS # | |
Eq ScenarioItem Source # | |
Defined in Swarm.Game.ScenarioInfo (==) :: ScenarioItem -> ScenarioItem -> Bool # (/=) :: ScenarioItem -> ScenarioItem -> Bool # |
scenarioItemName :: ScenarioItem -> Text Source #
Retrieve the name of a scenario item.
Loading and saving scenarios
loadScenarios :: Has (Lift IO) sig m => EntityMap -> m (Either Text ScenarioCollection) Source #
Load all the scenarios from the scenarios data directory.
loadScenarioInfo :: (Has (Lift IO) sig m, Has (Throw Text) sig m) => FilePath -> m ScenarioInfo Source #
Load saved info about played scenario from XDG data directory.
saveScenarioInfo :: FilePath -> ScenarioInfo -> IO () Source #
Save info about played scenario to XDG data directory.
Re-exports
module Swarm.Game.Scenario