Start restructuring Item datatype
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user