From fe37f208daeeaa175b575ceac84bb5221a787ab4 Mon Sep 17 00:00:00 2001 From: justin Date: Sat, 27 Nov 2021 11:49:23 +0000 Subject: [PATCH] Add files, minimal working rewind gun that must be equipped to charge --- src/Dodge/Item/Weapon/Utility.hs | 7 +++++-- src/ListHelp.hs | 9 +++++++++ src/MaybeHelp.hs | 15 +++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 src/ListHelp.hs create mode 100644 src/MaybeHelp.hs diff --git a/src/Dodge/Item/Weapon/Utility.hs b/src/Dodge/Item/Weapon/Utility.hs index e2f21c5b9..ecce5818a 100644 --- a/src/Dodge/Item/Weapon/Utility.hs +++ b/src/Dodge/Item/Weapon/Utility.hs @@ -26,8 +26,11 @@ rewindGun = defaultGun , _itUse = Left $ \cr invid -> useRewindGun (_crInv cr IM.! invid) cr } rewindEffect :: ItEffect -> Creature -> Int -> World -> World -rewindEffect _ cr invid w = w & rewindWorlds %~ (take 250 . (w' : )) - & creatures . ix (_crID cr) . crInv . ix invid . wpLoadedAmmo .~ length (_rewindWorlds w) +rewindEffect _ cr invid w + | Just invid == _crLeftInvSel cr = w & rewindWorlds %~ (take 250 . (w' : )) + & creatures . ix (_crID cr) . crInv . ix invid . wpLoadedAmmo .~ length (_rewindWorlds w) + | otherwise = w & rewindWorlds .~ [] + & creatures . ix (_crID cr) . crInv . ix invid . wpLoadedAmmo .~ 0 where w' = w & rewindWorlds .~ [] & rewinding .~ True diff --git a/src/ListHelp.hs b/src/ListHelp.hs new file mode 100644 index 000000000..7669c8bc1 --- /dev/null +++ b/src/ListHelp.hs @@ -0,0 +1,9 @@ +module ListHelp + (module Data.List + ,initOrNull + )where +import Data.List + +initOrNull :: [a] -> [a] +initOrNull [] = [] +initOrNull xs = init xs diff --git a/src/MaybeHelp.hs b/src/MaybeHelp.hs new file mode 100644 index 000000000..11be7d46d --- /dev/null +++ b/src/MaybeHelp.hs @@ -0,0 +1,15 @@ +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE StrictData #-} +module MaybeHelp where +import Control.Lens + +-- | Strict maybe +data Maybe' a + = Just' {_Just' :: a } + | Nothing' + +fromJust' :: Maybe' a -> a +fromJust' mx = case mx of + Just' x -> x + Nothing' -> error "no fromJust'" +makeLenses ''Maybe'