From f5604ef4290b688d71bf9b75e52cb102d493d4eb Mon Sep 17 00:00:00 2001 From: justin Date: Mon, 25 Jul 2022 12:23:21 +0100 Subject: [PATCH] Make concrete world read/showable --- src/Dodge/Data.hs | 6 +++--- src/Dodge/ItEffect.hs | 7 ++++--- src/Dodge/Luse.hs | 6 +++--- src/Dodge/Update.hs | 4 ++-- src/FoldlHelp.hs | 3 ++- src/MaybeHelp.hs | 2 +- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/Dodge/Data.hs b/src/Dodge/Data.hs index a42aa5177..ebc7b245d 100644 --- a/src/Dodge/Data.hs +++ b/src/Dodge/Data.hs @@ -291,8 +291,8 @@ data CWorld = CWorld , _worldBounds :: Bounds , _gameRooms :: [GameRoom] -- consider using an IntMap , _roomClipping :: [ConvexPoly] - , _maybeWorld :: Maybe' World - , _rewindWorlds :: [World] + , _maybeWorld :: Maybe' CWorld + , _rewindWorlds :: [CWorld] , _timeFlow :: TimeFlowStatus , _worldClock :: Int , _hammers :: M.Map WorldHammer HammerPosition @@ -305,7 +305,7 @@ data CWorld = CWorld , _lSelect :: Point2 , _rSelect :: Point2 } - --deriving (Eq,Show,Read) + deriving (Eq,Show,Read) data TimeFlowStatus = RewindingNow | RewindingLastFrame diff --git a/src/Dodge/ItEffect.hs b/src/Dodge/ItEffect.hs index 09ee22f25..74fe5ee02 100644 --- a/src/Dodge/ItEffect.hs +++ b/src/Dodge/ItEffect.hs @@ -29,7 +29,7 @@ onOffEff f g it rewindEffect :: Item -> Creature -> World -> World rewindEffect itm cr w - | Just invid == _crLeftInvSel cr = w & cWorld . rewindWorlds %~ (take maxcharge . (w' : )) + | Just invid == _crLeftInvSel cr = w & cWorld . rewindWorlds %~ (take maxcharge . (cw : )) & ptrWpCharge .~ length (_rewindWorlds (_cWorld w)) | otherwise = w & cWorld . rewindWorlds .~ [] & ptrWpCharge .~ 0 @@ -37,8 +37,9 @@ rewindEffect itm cr w invid = _ipInvID $ _itPos itm ptrWpCharge = cWorld . creatures . ix (_crID cr) . crInv . ix invid . itConsumption . wpCharge maxcharge = _wpMaxCharge . _itConsumption $ itm - w' = w & cWorld . rewindWorlds .~ [] - & cWorld . timeFlow .~ NormalTimeFlow + cw = _cWorld w + & rewindWorlds .~ [] + & timeFlow .~ NormalTimeFlow resetAttachmentEffect :: Item -> Creature -> World -> World resetAttachmentEffect itm cr w diff --git a/src/Dodge/Luse.hs b/src/Dodge/Luse.hs index dfcc16d5f..87212e404 100644 --- a/src/Dodge/Luse.hs +++ b/src/Dodge/Luse.hs @@ -21,13 +21,13 @@ useRewindGun _ _ w = case _rewindWorlds (_cWorld w) of (w':ws) -> rewindusing w' ws _ -> w where + rewindusing :: CWorld -> [CWorld] -> World rewindusing w' ws = w & cWorld . maybeWorld .~ Just' ( w' --- & creatures . ix (_crID cr) .~ cr & upbuts - & cWorld . rewindWorlds .~ ws + & rewindWorlds .~ ws ) - upbuts = (cWorld . keys .~ _keys (_cWorld w)) . (cWorld . mouseButtons .~ _mouseButtons (_cWorld w)) + upbuts = (keys .~ _keys (_cWorld w)) . (mouseButtons .~ _mouseButtons (_cWorld w)) -- be careful changing this around; potential problems include updating the -- creature but using the old crInvSel value diff --git a/src/Dodge/Update.hs b/src/Dodge/Update.hs index 6a38d9735..723795996 100644 --- a/src/Dodge/Update.hs +++ b/src/Dodge/Update.hs @@ -199,8 +199,8 @@ setOldPos cr = cr doRewind :: World -> World doRewind w = case _maybeWorld (_cWorld w) of - Just' w' -> w' & cWorld . timeFlow .~ RewindingLastFrame - Nothing' -> w & cWorld . timeFlow .~ NormalTimeFlow + Just' cw -> w & cWorld .~ (cw & timeFlow .~ RewindingLastFrame) + Nothing' -> w & cWorld . timeFlow .~ NormalTimeFlow zoneCreatures :: World -> World zoneCreatures w = w diff --git a/src/FoldlHelp.hs b/src/FoldlHelp.hs index 58d7bbab4..32f89b447 100644 --- a/src/FoldlHelp.hs +++ b/src/FoldlHelp.hs @@ -4,8 +4,9 @@ module FoldlHelp , module Control.Foldl ) where import Control.Foldl +import MaybeHelp -data Maybe' a = Just' !a | Nothing' +--data Maybe' a = Just' !a | Nothing' data Pair a b = !a :!: !b minimumOn :: Ord b => (a -> b) -> Fold a (Maybe a) diff --git a/src/MaybeHelp.hs b/src/MaybeHelp.hs index aabe087d9..4acd63b52 100644 --- a/src/MaybeHelp.hs +++ b/src/MaybeHelp.hs @@ -4,7 +4,7 @@ module MaybeHelp where import Control.Lens data Maybe' a = Just' {__Just' :: a} | Nothing' - deriving (Eq,Ord,Show) + deriving (Eq,Ord,Show,Read) fromJust' :: Maybe' a -> a fromJust' mx = case mx of