Fix space leak when assigning targeted creature

This commit is contained in:
2021-12-10 02:56:14 +00:00
parent e5db9ba5d0
commit 15e1fbc060
7 changed files with 33 additions and 18 deletions
+5 -4
View File
@@ -8,7 +8,7 @@ import Dodge.Data
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
@@ -17,9 +17,10 @@ useItem cid w = itemEffect cr it w
it = _crInv cr IM.! _crInvSel cr
tryUseItem :: Creature -> World -> World
tryUseItem cr' w = case w ^? creatures . ix (_crID cr') of
Just cr -> itemEffect cr (_crInv cr IM.! _crInvSel cr) w
Nothing -> w
tryUseItem cr' w = fromMaybe w $ do
cr <- w ^? creatures . ix (_crID cr')
it <- cr ^? crInv . ix (_crInvSel cr)
return $ itemEffect cr it w
itemEffect :: Creature -> Item -> World -> World
itemEffect cr it w = case it ^? itUse of