Add support for left click actions

This commit is contained in:
2021-05-25 14:23:04 +02:00
parent 62c4baaec8
commit f737897b18
9 changed files with 141 additions and 34 deletions
+13 -1
View File
@@ -5,7 +5,7 @@ import Dodge.Inventory
import qualified Data.IntMap as IM
import Control.Lens
--import Data.Maybe (maybe)
import Data.Maybe
useItem :: Int -> World -> World
useItem n w = itemEffect c it w
@@ -35,3 +35,15 @@ itemEffect cr Consumable{_cnEffect=eff } w = maybe w (rmSelectedInvItem (_crID c
itemEffect cr Weapon{_itUse=eff} w = eff cr w
itemEffect cr Throwable{_itUse = eff} w = eff cr w
itemEffect _ _ w = w
useLeftItem
:: Int
-> World
-> World
useLeftItem cid w = case luse of
Nothing -> w
Just (invid, f) -> f cr invid w
where
cr = _creatures w IM.! cid
luses = IM.mapMaybe (^? itLeftClickUse . _Just) (_crInv cr)
luse = listToMaybe $ IM.toList luses