Move past/future worlds outside of serialised data structure
This commit is contained in:
+1
-1
@@ -118,7 +118,7 @@ updateRenderSplit win u = do
|
|||||||
return $! updateUniverse u
|
return $! updateUniverse u
|
||||||
|
|
||||||
playSoundUnlessRewinding :: Universe -> IO (M.Map SoundOrigin Sound)
|
playSoundUnlessRewinding :: Universe -> IO (M.Map SoundOrigin Sound)
|
||||||
playSoundUnlessRewinding u = case w ^. cWorld . timeFlow of
|
playSoundUnlessRewinding u = case w ^. timeFlow of
|
||||||
NormalTimeFlow -> playSoundAndUpdate (_soundData $ _preloadData u) (_playingSounds w) (_toPlaySounds w)
|
NormalTimeFlow -> playSoundAndUpdate (_soundData $ _preloadData u) (_playingSounds w) (_toPlaySounds w)
|
||||||
_ -> stopAllSounds >> return M.empty
|
_ -> stopAllSounds >> return M.empty
|
||||||
where
|
where
|
||||||
|
|||||||
@@ -27,33 +27,12 @@ data CWorld = CWorld
|
|||||||
, _cwCamPos :: CamPos
|
, _cwCamPos :: CamPos
|
||||||
, _cwGen :: CWGen
|
, _cwGen :: CWGen
|
||||||
, _cClock :: Int
|
, _cClock :: Int
|
||||||
, _pastWorlds :: [LWorld]
|
|
||||||
, _timeFlow :: TimeFlowStatus
|
|
||||||
, _seenWalls :: IS.IntSet
|
, _seenWalls :: IS.IntSet
|
||||||
, _cwTiles :: [Tile]
|
, _cwTiles :: [Tile]
|
||||||
, _pathGraph :: Gr Point2 PathEdge
|
, _pathGraph :: Gr Point2 PathEdge
|
||||||
, _numberFloorVerxs :: Int
|
, _numberFloorVerxs :: Int
|
||||||
}
|
}
|
||||||
|
|
||||||
data TimeFlowStatus
|
|
||||||
= DeathTime
|
|
||||||
{ _deathDelay :: Int }
|
|
||||||
| NormalTimeFlow
|
|
||||||
| ScrollTimeFlow
|
|
||||||
{ _scrollSmoothing :: Int
|
|
||||||
, _reverseAmount :: Int
|
|
||||||
, _futureWorlds :: [LWorld]
|
|
||||||
, _scrollItemLocation :: Int
|
|
||||||
}
|
|
||||||
| RewindLeftClick
|
|
||||||
{ _reverseAmount :: Int
|
|
||||||
, _scrollItemLocation :: Int
|
|
||||||
}
|
|
||||||
| PausedTimeFlow
|
|
||||||
{ _timeFlowCharge :: Int
|
|
||||||
, _scrollItemLocation :: Int
|
|
||||||
}
|
|
||||||
|
|
||||||
data CWGen = CWGen
|
data CWGen = CWGen
|
||||||
{ _cwgParams :: GenParams
|
{ _cwgParams :: GenParams
|
||||||
, _cwgWorldBounds :: Bounds
|
, _cwgWorldBounds :: Bounds
|
||||||
@@ -67,11 +46,10 @@ data CWGen = CWGen
|
|||||||
|
|
||||||
makeLenses ''CWorld
|
makeLenses ''CWorld
|
||||||
makeLenses ''CWGen
|
makeLenses ''CWGen
|
||||||
makeLenses ''TimeFlowStatus
|
|
||||||
concat
|
concat
|
||||||
<$> mapM
|
<$> mapM
|
||||||
(deriveJSON defaultOptions)
|
(deriveJSON defaultOptions)
|
||||||
[ ''CWGen
|
[ ''CWGen
|
||||||
, ''CWorld
|
, ''CWorld
|
||||||
, ''TimeFlowStatus
|
-- , ''TimeFlowStatus
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ data WorldEventFlag = InventoryChange
|
|||||||
|
|
||||||
data World = World
|
data World = World
|
||||||
{ _cWorld :: CWorld
|
{ _cWorld :: CWorld
|
||||||
|
, _pastWorlds :: [LWorld]
|
||||||
|
, _timeFlow :: TimeFlowStatus
|
||||||
, _randGen :: StdGen
|
, _randGen :: StdGen
|
||||||
, _toPlaySounds :: M.Map SoundOrigin Sound
|
, _toPlaySounds :: M.Map SoundOrigin Sound
|
||||||
, _playingSounds :: M.Map SoundOrigin Sound
|
, _playingSounds :: M.Map SoundOrigin Sound
|
||||||
@@ -50,6 +52,27 @@ data World = World
|
|||||||
, _gsZoning :: IntMap (IntMap IntSet)
|
, _gsZoning :: IntMap (IntMap IntSet)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data TimeFlowStatus
|
||||||
|
= DeathTime
|
||||||
|
{ _deathDelay :: Int }
|
||||||
|
| NormalTimeFlow
|
||||||
|
| ScrollTimeFlow
|
||||||
|
{ _scrollSmoothing :: Int
|
||||||
|
, _reverseAmount :: Int
|
||||||
|
, _futureWorlds :: [LWorld]
|
||||||
|
, _scrollItemLocation :: Int
|
||||||
|
}
|
||||||
|
| RewindLeftClick
|
||||||
|
{ _reverseAmount :: Int
|
||||||
|
, _scrollItemLocation :: Int
|
||||||
|
}
|
||||||
|
| PausedTimeFlow
|
||||||
|
{ _timeFlowCharge :: Int
|
||||||
|
, _scrollItemLocation :: Int
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
-- deriving (Eq, Ord, Show, Read) --Generic, Flat)
|
-- deriving (Eq, Ord, Show, Read) --Generic, Flat)
|
||||||
|
|
||||||
|
makeLenses ''TimeFlowStatus
|
||||||
makeLenses ''World
|
makeLenses ''World
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ defaultWorld :: World
|
|||||||
defaultWorld =
|
defaultWorld =
|
||||||
World
|
World
|
||||||
{ _cWorld = defaultCWorld
|
{ _cWorld = defaultCWorld
|
||||||
|
, _pastWorlds = mempty
|
||||||
|
, _timeFlow = NormalTimeFlow
|
||||||
, _input = defaultInput
|
, _input = defaultInput
|
||||||
, _toPlaySounds = M.empty
|
, _toPlaySounds = M.empty
|
||||||
, _playingSounds = M.empty
|
, _playingSounds = M.empty
|
||||||
@@ -81,8 +83,6 @@ defaultCWorld =
|
|||||||
, _lWorld = defaultLWorld
|
, _lWorld = defaultLWorld
|
||||||
, _cwGen = defaultCWGen
|
, _cwGen = defaultCWGen
|
||||||
, _cClock = 0
|
, _cClock = 0
|
||||||
, _pastWorlds = []
|
|
||||||
, _timeFlow = NormalTimeFlow
|
|
||||||
, _seenWalls = mempty
|
, _seenWalls = mempty
|
||||||
, _pathGraph = Data.Graph.Inductive.Graph.empty
|
, _pathGraph = Data.Graph.Inductive.Graph.empty
|
||||||
, _cwTiles = mempty
|
, _cwTiles = mempty
|
||||||
|
|||||||
+3
-3
@@ -23,14 +23,14 @@ useL lu = case lu of
|
|||||||
|
|
||||||
useStopWatch :: Item -> Creature -> World -> World
|
useStopWatch :: Item -> Creature -> World -> World
|
||||||
useStopWatch itm _ w = w
|
useStopWatch itm _ w = w
|
||||||
& cWorld . timeFlow .~ PausedTimeFlow
|
& timeFlow .~ PausedTimeFlow
|
||||||
{ _timeFlowCharge = itm ^?! itUse . leftConsumption . wpCharge
|
{ _timeFlowCharge = itm ^?! itUse . leftConsumption . wpCharge
|
||||||
, _scrollItemLocation = _itID itm
|
, _scrollItemLocation = _itID itm
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
useTimeScrollGun :: Item -> Creature -> World -> World
|
useTimeScrollGun :: Item -> Creature -> World -> World
|
||||||
useTimeScrollGun itm _ w = w & cWorld . timeFlow .~ ScrollTimeFlow
|
useTimeScrollGun itm _ w = w & timeFlow .~ ScrollTimeFlow
|
||||||
{ _scrollSmoothing = 0
|
{ _scrollSmoothing = 0
|
||||||
, _reverseAmount = itm ^?! itUse . leftConsumption . wpCharge
|
, _reverseAmount = itm ^?! itUse . leftConsumption . wpCharge
|
||||||
, _futureWorlds = []
|
, _futureWorlds = []
|
||||||
@@ -40,7 +40,7 @@ useTimeScrollGun itm _ w = w & cWorld . timeFlow .~ ScrollTimeFlow
|
|||||||
|
|
||||||
useRewindGun :: Item -> Creature -> World -> World
|
useRewindGun :: Item -> Creature -> World -> World
|
||||||
useRewindGun itm _ w = w
|
useRewindGun itm _ w = w
|
||||||
& cWorld . timeFlow .~ RewindLeftClick
|
& timeFlow .~ RewindLeftClick
|
||||||
{ _reverseAmount = itm ^?! itUse . leftConsumption . wpCharge
|
{ _reverseAmount = itm ^?! itUse . leftConsumption . wpCharge
|
||||||
, _scrollItemLocation = _itID itm
|
, _scrollItemLocation = _itID itm
|
||||||
}
|
}
|
||||||
|
|||||||
+31
-30
@@ -129,17 +129,17 @@ updateUniverseMid u = case _uvScreenLayers u of
|
|||||||
[] -> timeFlowUpdate u
|
[] -> timeFlowUpdate u
|
||||||
|
|
||||||
timeFlowUpdate :: Universe -> Universe
|
timeFlowUpdate :: Universe -> Universe
|
||||||
timeFlowUpdate u = case u ^. uvWorld . cWorld . timeFlow of
|
timeFlowUpdate u = case u ^. uvWorld . timeFlow of
|
||||||
NormalTimeFlow -> functionalUpdate u
|
NormalTimeFlow -> functionalUpdate u
|
||||||
ScrollTimeFlow smoothing _ _ _ -> over uvWorld (doTimeScroll smoothing) u
|
ScrollTimeFlow smoothing _ _ _ -> over uvWorld (doTimeScroll smoothing) u
|
||||||
RewindLeftClick 0 _ -> u & uvWorld . cWorld . timeFlow .~ NormalTimeFlow
|
RewindLeftClick 0 _ -> u & uvWorld . timeFlow .~ NormalTimeFlow
|
||||||
RewindLeftClick _ _ -> over uvWorld scrollTimeBack u -- & uvWorld . cWorld . timeFlow .~ NormalTimeFlow
|
RewindLeftClick _ _ -> over uvWorld scrollTimeBack u -- & uvWorld . cWorld . timeFlow .~ NormalTimeFlow
|
||||||
DeathTime{} -> u
|
DeathTime{} -> u
|
||||||
PausedTimeFlow _ itmloc -> over uvWorld (pauseTime itmloc) u
|
PausedTimeFlow _ itmloc -> over uvWorld (pauseTime itmloc) u
|
||||||
|
|
||||||
pauseTime :: Int -> World -> World
|
pauseTime :: Int -> World -> World
|
||||||
pauseTime itmloc w
|
pauseTime itmloc w
|
||||||
| justPressedButtonLeft || outofcharge = w & cWorld . timeFlow .~ NormalTimeFlow
|
| justPressedButtonLeft || outofcharge = w & timeFlow .~ NormalTimeFlow
|
||||||
| otherwise = w & pointerToItemLocation (w ^?! cWorld . lWorld . itemLocations . ix itmloc) . itUse . leftConsumption . wpCharge -~ 1
|
| otherwise = w & pointerToItemLocation (w ^?! cWorld . lWorld . itemLocations . ix itmloc) . itUse . leftConsumption . wpCharge -~ 1
|
||||||
where
|
where
|
||||||
justPressedButtonLeft = w ^? input . mouseButtons . ix ButtonLeft == Just False
|
justPressedButtonLeft = w ^? input . mouseButtons . ix ButtonLeft == Just False
|
||||||
@@ -148,48 +148,48 @@ pauseTime itmloc w
|
|||||||
|
|
||||||
doTimeScroll :: Int -> World -> World
|
doTimeScroll :: Int -> World -> World
|
||||||
doTimeScroll smoothing w = case w ^? input . mouseButtons . ix ButtonLeft of
|
doTimeScroll smoothing w = case w ^? input . mouseButtons . ix ButtonLeft of
|
||||||
Just False -> w & cWorld . timeFlow .~ NormalTimeFlow
|
Just False -> w & timeFlow .~ NormalTimeFlow
|
||||||
_ -> doTimeScroll' smoothing w
|
_ -> doTimeScroll' smoothing w
|
||||||
|
|
||||||
doTimeScroll' :: Int -> World -> World
|
doTimeScroll' :: Int -> World -> World
|
||||||
doTimeScroll' smoothing w = case w ^. input . scrollAmount of
|
doTimeScroll' smoothing w = case w ^. input . scrollAmount of
|
||||||
x | x > 1 -> w & scrollTimeBack & cWorld . timeFlow . scrollSmoothing .~ 20
|
x | x > 1 -> w & scrollTimeBack & timeFlow . scrollSmoothing .~ 20
|
||||||
x | x > 0 -> w & scrollTimeBack & cWorld . timeFlow . scrollSmoothing %~ max 0
|
x | x > 0 -> w & scrollTimeBack & timeFlow . scrollSmoothing %~ max 0
|
||||||
x | x < (-1) -> w & scrollTimeForward & cWorld . timeFlow . scrollSmoothing .~ negate 20
|
x | x < (-1) -> w & scrollTimeForward & timeFlow . scrollSmoothing .~ negate 20
|
||||||
x | x < 0 -> w & scrollTimeForward & cWorld . timeFlow . scrollSmoothing %~ min 0
|
x | x < 0 -> w & scrollTimeForward & timeFlow . scrollSmoothing %~ min 0
|
||||||
_ | smoothing > 0 -> scrollTimeBack w & cWorld . timeFlow . scrollSmoothing -~ 1
|
_ | smoothing > 0 -> scrollTimeBack w & timeFlow . scrollSmoothing -~ 1
|
||||||
_ | smoothing < 0 -> scrollTimeForward w & cWorld . timeFlow . scrollSmoothing +~ 1
|
_ | smoothing < 0 -> scrollTimeForward w & timeFlow . scrollSmoothing +~ 1
|
||||||
_ -> w
|
_ -> w
|
||||||
|
|
||||||
scrollTimeBack :: World -> World
|
scrollTimeBack :: World -> World
|
||||||
scrollTimeBack w = case w ^? cWorld . pastWorlds . _head of
|
scrollTimeBack w = case w ^? pastWorlds . _head of
|
||||||
Nothing -> w
|
Nothing -> w
|
||||||
Just lw -> case w ^?! cWorld . timeFlow . reverseAmount of
|
Just lw -> case w ^?! timeFlow . reverseAmount of
|
||||||
x
|
x
|
||||||
| x > 0 ->
|
| x > 0 ->
|
||||||
w & cWorld . pastWorlds %~ tail
|
w & pastWorlds %~ tail
|
||||||
& cWorld . timeFlow . futureWorlds .:~ (w ^. cWorld . lWorld)
|
& timeFlow . futureWorlds .:~ (w ^. cWorld . lWorld)
|
||||||
& cWorld . timeFlow . reverseAmount -~ 1
|
& timeFlow . reverseAmount -~ 1
|
||||||
& cWorld . lWorld .~ lw
|
& cWorld . lWorld .~ lw
|
||||||
& pointituse . leftConsumption . wpCharge .~ (x -1)
|
& pointituse . leftConsumption . wpCharge .~ (x -1)
|
||||||
& pointituse . leftHammer .~ HammerDown
|
& pointituse . leftHammer .~ HammerDown
|
||||||
_ -> w
|
_ -> w
|
||||||
where
|
where
|
||||||
pointituse = pointerToItemLocation (w ^?! cWorld . lWorld . itemLocations . ix i) . itUse
|
pointituse = pointerToItemLocation (w ^?! cWorld . lWorld . itemLocations . ix i) . itUse
|
||||||
i = w ^?! cWorld . timeFlow . scrollItemLocation
|
i = w ^?! timeFlow . scrollItemLocation
|
||||||
|
|
||||||
scrollTimeForward :: World -> World
|
scrollTimeForward :: World -> World
|
||||||
scrollTimeForward w = case w ^? cWorld . timeFlow . futureWorlds . _head of
|
scrollTimeForward w = case w ^? timeFlow . futureWorlds . _head of
|
||||||
Nothing -> w
|
Nothing -> w
|
||||||
Just lw ->
|
Just lw ->
|
||||||
w & cWorld . timeFlow . futureWorlds %~ tail
|
w & timeFlow . futureWorlds %~ tail
|
||||||
& cWorld . pastWorlds .:~ (w ^. cWorld . lWorld)
|
& pastWorlds .:~ (w ^. cWorld . lWorld)
|
||||||
& cWorld . lWorld .~ lw
|
& cWorld . lWorld .~ lw
|
||||||
& cWorld . timeFlow . reverseAmount .~ ramount
|
& timeFlow . reverseAmount .~ ramount
|
||||||
& pointerToItemLocation (w ^?! cWorld . lWorld . itemLocations . ix i) . itUse . leftConsumption . wpCharge .~ ramount
|
& pointerToItemLocation (w ^?! cWorld . lWorld . itemLocations . ix i) . itUse . leftConsumption . wpCharge .~ ramount
|
||||||
where
|
where
|
||||||
i = w ^?! cWorld . timeFlow . scrollItemLocation
|
i = w ^?! timeFlow . scrollItemLocation
|
||||||
ramount = (w ^?! cWorld . timeFlow . reverseAmount) + 1
|
ramount = (w ^?! timeFlow . reverseAmount) + 1
|
||||||
|
|
||||||
-- | The update step.
|
-- | The update step.
|
||||||
functionalUpdate :: Universe -> Universe
|
functionalUpdate :: Universe -> Universe
|
||||||
@@ -242,7 +242,7 @@ functionalUpdate w =
|
|||||||
. over uvWorld zoneClouds
|
. over uvWorld zoneClouds
|
||||||
. over uvWorld zoneCreatures
|
. over uvWorld zoneCreatures
|
||||||
-- . over uvWorld updateInventorySelectionList
|
-- . over uvWorld updateInventorySelectionList
|
||||||
$ over (uvWorld . cWorld) updatePastWorlds w
|
$ over uvWorld updatePastWorlds w
|
||||||
|
|
||||||
updateWheelEvents :: World -> World
|
updateWheelEvents :: World -> World
|
||||||
updateWheelEvents w
|
updateWheelEvents w
|
||||||
@@ -257,8 +257,8 @@ advanceScrollAmount u =
|
|||||||
& uvWorld . input . previousScrollAmount .~ _scrollAmount (_input $ _uvWorld u)
|
& uvWorld . input . previousScrollAmount .~ _scrollAmount (_input $ _uvWorld u)
|
||||||
& uvWorld . input . scrollAmount .~ 0
|
& uvWorld . input . scrollAmount .~ 0
|
||||||
|
|
||||||
updatePastWorlds :: CWorld -> CWorld
|
updatePastWorlds :: World -> World
|
||||||
updatePastWorlds w = w & pastWorlds %~ (forceFoldable . take 100 . ((w ^. lWorld) :))
|
updatePastWorlds w = w & pastWorlds %~ (forceFoldable . take 100 . ((w ^. cWorld . lWorld) :))
|
||||||
|
|
||||||
--updatePastWorlds w = w & pastWorlds .~ []
|
--updatePastWorlds w = w & pastWorlds .~ []
|
||||||
|
|
||||||
@@ -354,8 +354,9 @@ setOldPos cr =
|
|||||||
-- Nothing' -> w & timeFlow .~ NormalTimeFlow
|
-- Nothing' -> w & timeFlow .~ NormalTimeFlow
|
||||||
|
|
||||||
zoneCreatures :: World -> World
|
zoneCreatures :: World -> World
|
||||||
zoneCreatures w = w & crZoning
|
zoneCreatures w =
|
||||||
.~ foldl' (flip zoneCreature) mempty (w ^. cWorld . lWorld . creatures)
|
w & crZoning
|
||||||
|
.~ foldl' (flip zoneCreature) mempty (w ^. cWorld . lWorld . creatures)
|
||||||
|
|
||||||
-- foldl' (flip $ updateZoning (\cr -> IM.insert (_crID cr) cr))
|
-- foldl' (flip $ updateZoning (\cr -> IM.insert (_crID cr) cr))
|
||||||
-- zn (_creatures w)
|
-- zn (_creatures w)
|
||||||
@@ -567,12 +568,12 @@ markWallSeen w i = w & cWorld . seenWalls . at i ?~ ()
|
|||||||
--markSeen wl = wl{_wlSeen = True}
|
--markSeen wl = wl{_wlSeen = True}
|
||||||
|
|
||||||
checkEndGame :: Universe -> Universe
|
checkEndGame :: Universe -> Universe
|
||||||
checkEndGame uv = case w ^? cWorld . timeFlow . deathDelay of
|
checkEndGame uv = case w ^? timeFlow . deathDelay of
|
||||||
Just x
|
Just x
|
||||||
| x < 0 ->
|
| x < 0 ->
|
||||||
uv & uvScreenLayers .~ [gameOverMenu uv]
|
uv & uvScreenLayers .~ [gameOverMenu uv]
|
||||||
Just _ -> uv & uvWorld . cWorld . timeFlow . deathDelay -~ 1
|
Just _ -> uv & uvWorld . timeFlow . deathDelay -~ 1
|
||||||
_ | _crHP (you w) < 1 -> uv & uvWorld . cWorld . timeFlow .~ DeathTime 50
|
_ | _crHP (you w) < 1 -> uv & uvWorld . timeFlow .~ DeathTime 50
|
||||||
_ -> uv
|
_ -> uv
|
||||||
where
|
where
|
||||||
w = _uvWorld uv
|
w = _uvWorld uv
|
||||||
|
|||||||
Reference in New Issue
Block a user