@@ -24,6 +24,9 @@ module Swarm.Game.State (
24
24
_WinCondition ,
25
25
_Won ,
26
26
RunStatus (.. ),
27
+ GoalStatus (.. ),
28
+ goalNeedsDisplay ,
29
+ markGoalRead ,
27
30
GameState ,
28
31
Seed ,
29
32
initGameState ,
@@ -32,6 +35,7 @@ module Swarm.Game.State (
32
35
33
36
-- ** GameState fields
34
37
creativeMode ,
38
+ gameGoal ,
35
39
winCondition ,
36
40
winSolution ,
37
41
runStatus ,
@@ -162,11 +166,34 @@ data RunStatus
162
166
AutoPause
163
167
deriving (Eq , Show )
164
168
169
+ -- | Status of the scenario goal: whether there is one, and whether it has been
170
+ -- displayed to the user initially.
171
+ data GoalStatus
172
+ = -- | There is no goal.
173
+ NoGoal
174
+ | -- | There is a goal, and we should display it to the user initially.
175
+ UnreadGoal [Text ]
176
+ | -- | There is a goal, and we have already displayed it to the user.
177
+ -- It can be displayed again if the user chooses.
178
+ ReadGoal [Text ]
179
+ deriving (Eq , Show )
180
+
181
+ -- | Do we need to display the goal initially to the user?
182
+ goalNeedsDisplay :: GoalStatus -> Maybe [Text ]
183
+ goalNeedsDisplay (UnreadGoal g) = Just g
184
+ goalNeedsDisplay _ = Nothing
185
+
186
+ -- | Mark the goal as having been read.
187
+ markGoalRead :: GoalStatus -> GoalStatus
188
+ markGoalRead (UnreadGoal g) = ReadGoal g
189
+ markGoalRead gs = gs
190
+
165
191
-- | The main record holding the state for the game itself (as
166
192
-- distinct from the UI). See the lenses below for access to its
167
193
-- fields.
168
194
data GameState = GameState
169
195
{ _creativeMode :: Bool
196
+ , _gameGoal :: GoalStatus
170
197
, _winCondition :: WinCondition
171
198
, _winSolution :: Maybe ProcessedTerm
172
199
, _runStatus :: RunStatus
@@ -220,6 +247,10 @@ let exclude = ['_viewCenter, '_focusedRobotID, '_viewCenterRule, '_activeRobots,
220
247
-- | Is the user in creative mode (i.e. able to do anything without restriction)?
221
248
creativeMode :: Lens' GameState Bool
222
249
250
+ -- | Status of the scenario goal: whether there is one, and whether it
251
+ -- has been displayed to the user initially.
252
+ gameGoal :: Lens' GameState GoalStatus
253
+
223
254
-- | How to determine whether the player has won.
224
255
winCondition :: Lens' GameState WinCondition
225
256
@@ -377,7 +408,7 @@ viewingRegion :: GameState -> (Int64, Int64) -> (W.Coords, W.Coords)
377
408
viewingRegion g (w, h) = (W. Coords (rmin, cmin), W. Coords (rmax, cmax))
378
409
where
379
410
V2 cx cy = g ^. viewCenter
380
- (rmin, rmax) = over both (+ (- cy - h `div` 2 )) (0 , h - 1 )
411
+ (rmin, rmax) = over both (+ (- cy - h `div` 2 )) (0 , h - 1 )
381
412
(cmin, cmax) = over both (+ (cx - w `div` 2 )) (0 , w - 1 )
382
413
383
414
-- | Find out which robot is currently specified by the
@@ -435,6 +466,7 @@ initGameState cmdlineSeed scenarioToLoad toRun = do
435
466
let initState =
436
467
GameState
437
468
{ _creativeMode = False
469
+ , _gameGoal = NoGoal
438
470
, _winCondition = NoWinCondition
439
471
, _winSolution = Nothing
440
472
, _runStatus = Running
@@ -485,6 +517,7 @@ playScenario em scenario userSeed toRun g = do
485
517
return $
486
518
g
487
519
{ _creativeMode = scenario ^. scenarioCreative
520
+ , _gameGoal = maybe NoGoal UnreadGoal (scenario ^. scenarioGoal)
488
521
, _winCondition = theWinCondition
489
522
, _winSolution = scenario ^. scenarioSolution
490
523
, _runStatus = Running
0 commit comments