Start restructuring Item datatype

This commit is contained in:
2021-11-27 12:48:23 +00:00
parent fe37f208da
commit bfdac2fad5
16 changed files with 56 additions and 55 deletions
+7 -7
View File
@@ -32,23 +32,23 @@ itemEffect
-> 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 (Right eff) -> foldr ($) eff (_itUseModifiers it) it cr w
Just (Left _ ) -> w & creatures . ix (_crID cr) . crLeftInvSel ?~ _crInvSel cr
Nothing -> w
Just (RightUse eff) -> foldr ($) eff (_itUseModifiers it) it cr w
Just (LeftUse _ ) -> w & creatures . ix (_crID cr) . crLeftInvSel ?~ _crInvSel cr
_ -> w
--this is ugly
useLeftItem :: Int -> World -> World
useLeftItem cid w = case _crInv cr IM.! crinvsel ^? itUse . _Left of
useLeftItem cid w = case _crInv cr IM.! crinvsel ^? itUse . lUse of
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
Left f -> f cr invid w
Right _ -> w & creatures . ix cid . crLeftInvSel .~ Nothing
LeftUse 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
where
crinvsel = _crInvSel cr
cr = _creatures w IM.! cid
luses = IM.mapMaybe (^? itUse . _Left) (_crInv cr)
luses = IM.mapMaybe (^? itUse . lUse) (_crInv cr)
luse = listToMaybe $ IM.toList luses