Make hotkeys assignable to any item, use item id

This commit is contained in:
2024-12-31 09:20:53 +00:00
parent 1e7dcbfded
commit e12e4777b2
8 changed files with 37 additions and 59 deletions
+6 -3
View File
@@ -2,6 +2,7 @@ module Dodge.Creature.YourControl (
yourControl,
) where
import NewInt
import Control.Monad
import Data.Foldable
import qualified Data.Map.Strict as M
@@ -51,8 +52,9 @@ handleHotkeys w
where
thehotkeys = M.mapKeys hotkeyToScancode $ w ^. cWorld . lWorld . hotkeys
useHotkey :: World -> Int -> World
useHotkey w invid = fromMaybe w $ do
useHotkey :: World -> NewInt ItmInt -> World
useHotkey w (NInt itid) = fromMaybe w $ do
invid <- w ^? cWorld . lWorld . itemLocations . ix itid . ilInvID
cr <- w ^? cWorld . lWorld . creatures . ix 0
itmloc <- allInvLocs (cr ^. crInv) ^? ix invid . _2 . locLDT
return $ heldEffectNoHammerCheck (bimap (^. iatType) (^. _1) itmloc) cr w
@@ -96,7 +98,8 @@ tryAssignHotkey w sc = fromMaybe w $ do
pt <- w ^? input . pressedKeys . ix sc
guard (pt == InitialPress)
cr <- w ^? cWorld . lWorld . creatures . ix 0
itid <- cr ^? crManipulation . manObject . imSelectedItem
invid <- cr ^? crManipulation . manObject . imSelectedItem
itid <- cr ^? crInv . ix invid . itID
--return $ w & cWorld . lWorld . creatures . ix 0 %~ assignHotkey itid (scancodeToHotkey sc)
return $ w & cWorld . lWorld %~ assignHotkey itid (scancodeToHotkey sc)