From 9923897fe242a1b1b7fb1fe22e44b171db12896c Mon Sep 17 00:00:00 2001 From: justin Date: Fri, 18 Feb 2022 11:45:17 +0000 Subject: [PATCH] Rewinding fixes --- src/Dodge/Data.hs | 1 + src/Dodge/Default/World.hs | 1 + src/Dodge/Item/Weapon/Utility.hs | 5 ++++- src/Dodge/Update.hs | 6 ++++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Dodge/Data.hs b/src/Dodge/Data.hs index 449e8f91a..197547ddc 100644 --- a/src/Dodge/Data.hs +++ b/src/Dodge/Data.hs @@ -123,6 +123,7 @@ data World = World , _distortions :: [Distortion] , _worldBounds :: Bounds , _gameRooms :: [GameRoom] -- consider using and IntMap + , _maybeWorld :: Maybe' World , _rewindWorlds :: [World] , _rewinding :: Bool , _worldClock :: Int diff --git a/src/Dodge/Default/World.hs b/src/Dodge/Default/World.hs index 35ae0572d..91baa65bc 100644 --- a/src/Dodge/Default/World.hs +++ b/src/Dodge/Default/World.hs @@ -85,6 +85,7 @@ defaultWorld = World , _gameRooms = [] , _worldClock = 0 , _worldBounds = defaultBounds + , _maybeWorld = Nothing' , _rewindWorlds = [] , _rewinding = False , _lSelHammerPosition = HammerUp diff --git a/src/Dodge/Item/Weapon/Utility.hs b/src/Dodge/Item/Weapon/Utility.hs index 96c591c53..154749889 100644 --- a/src/Dodge/Item/Weapon/Utility.hs +++ b/src/Dodge/Item/Weapon/Utility.hs @@ -43,13 +43,16 @@ rewindEffect _ cr invid w useRewindGun :: Item -> Creature -> World -> World useRewindGun _ _ w = case _rewindWorlds w of [w'] -> rewindusing w' [] + (w':ws) -> rewindusing w' ws (_:w':ws) -> rewindusing w' ws _ -> w where - rewindusing w' ws = w' + rewindusing w' ws = w + & maybeWorld .~ Just' ( w' -- & creatures . ix (_crID cr) .~ cr & upbuts & rewindWorlds .~ ws + ) upbuts = (keys .~ _keys w) . (mouseButtons .~ _mouseButtons w) -- needs to shift this item to the current inventory slot diff --git a/src/Dodge/Update.hs b/src/Dodge/Update.hs index 25a13da67..d1aeeb122 100644 --- a/src/Dodge/Update.hs +++ b/src/Dodge/Update.hs @@ -46,6 +46,7 @@ updateUniverse u = case _menuLayers u of functionalUpdate :: Configuration -> World -> World functionalUpdate cfig w = checkEndGame . (worldClock +~ 1) + . doRewind . updateDistortions . updateCreatureSoundPositions . ppEvents @@ -80,6 +81,11 @@ functionalUpdate cfig w = checkEndGame where (x,y) = cloudZoneOfPoint $ stripZ $ _clPos cl +doRewind :: World -> World +doRewind w = case _maybeWorld w of + Just' w' -> w' + Nothing' -> w + zoneCreatures :: World -> World zoneCreatures w = w & creaturesZone . znObjects .~