Commit before attempting to move some data into a "local" world type

This commit is contained in:
2021-11-28 01:32:42 +00:00
parent 3e64e33232
commit 24480bbe52
10 changed files with 47 additions and 21 deletions
+19 -8
View File
@@ -8,7 +8,7 @@ import Dodge.Inventory
import qualified Data.IntMap.Strict as IM
import Control.Lens
import Data.Maybe
--import Data.Maybe
useItem :: Int -> World -> World
useItem cid w = itemEffect cr it w
@@ -25,22 +25,33 @@ itemEffect :: Creature -> Item -> World -> World
itemEffect cr Consumable{_cnEffect=eff } w = maybe w (rmSelectedInvItem (_crID cr)) (eff (_crID cr) w)
itemEffect cr it w = case it ^? itUse of
Just RightUse {_rUse = eff,_useMods = usemods} -> foldr ($) eff usemods it cr w
Just LeftUse {} -> w & creatures . ix (_crID cr) . crLeftInvSel ?~ _crInvSel cr
Just LeftUse {} -> w
& lSelHammerPosition .~ HammerDown
& docycle
_ -> w
where
docycle | _lSelHammerPosition w == HammerUp = creatures . ix (_crID cr) . crLeftInvSel %~ cyclelsel
| otherwise = id
cyclelsel mi = case mi of
Just i | i == _crInvSel cr -> Nothing
_ -> Just $ _crInvSel cr
--this is ugly
useLeftItem :: Int -> World -> World
useLeftItem cid w = case _crInv cr IM.! crinvsel ^? itUse . lUse of
Just f -> f cr crinvsel w & creatures . ix cid . crLeftInvSel ?~ crinvsel
Just f -> f cr crinvsel (w & creatures . ix cid . crLeftInvSel ?~ crinvsel)
Nothing -> case _crLeftInvSel cr of
Just invid -> case _itUse $ _crInv cr IM.! invid of
LeftUse {_lUse = f} -> f cr invid w
_ -> w & creatures . ix cid . crLeftInvSel .~ Nothing
Nothing -> case luse of
Nothing -> w
Just (invid, f) -> f cr invid w & creatures . ix cid . crLeftInvSel ?~ invid
Nothing -> w
-- Nothing -> case luse of
-- Nothing -> w
-- Just (invid, f) -> f cr invid w & creatures . ix cid . crLeftInvSel ?~ invid
where
crinvsel = _crInvSel cr
cr = _creatures w IM.! cid
luses = IM.mapMaybe (^? itUse . lUse) (_crInv cr)
luse = listToMaybe $ IM.toList luses
-- luses = IM.mapMaybe (^? itUse . lUse) (_crInv cr)
-- luse = listToMaybe $ IM.toList luses
--the old code automatically selected the first unused item in the list: not
--sure if I want this behaviour, can probably set it as an option later