Make hotkeys assignable to any item, use item id
This commit is contained in:
+10
-37
@@ -1,48 +1,21 @@
|
||||
module Dodge.Hotkey (
|
||||
assignHotkey,
|
||||
-- assignNewHotkey,
|
||||
removeHotkey,
|
||||
) where
|
||||
|
||||
import NewInt
|
||||
import Control.Lens
|
||||
--import Data.List
|
||||
--import qualified Data.Map.Strict as M
|
||||
import Data.Maybe
|
||||
import Dodge.Data.World
|
||||
--import Control.Monad
|
||||
|
||||
--assignNewHotkey :: Int -> LWorld -> LWorld
|
||||
--assignNewHotkey invid w = assignHotkey invid (newHotkey w) w
|
||||
--
|
||||
--newHotkey :: LWorld -> Hotkey
|
||||
--newHotkey lw = fromMaybe maxBound $
|
||||
-- find
|
||||
-- (not . (`M.member` (lw ^. hotkeys)))
|
||||
-- [minBound .. maxBound]
|
||||
|
||||
-- it is not obvious to me whether hotkeys should belong to LWorld, CWorld or
|
||||
-- World
|
||||
|
||||
-- this will not remove the hotkey from its old slot, assumes there is a hotkey
|
||||
-- to swap with instead
|
||||
assignHotkey :: Int -> Hotkey -> LWorld -> LWorld
|
||||
assignHotkey invid hk lw = fromMaybe lw $ do
|
||||
-- guard $ lw ^? creatures . ix 0 . crInv . ix invid . itUseCondition
|
||||
-- == Just UseableAnytime
|
||||
return $ (setHotkey invid hk . moveOldHotkey invid hk) lw
|
||||
|
||||
moveOldHotkey :: Int -> Hotkey -> LWorld -> LWorld
|
||||
moveOldHotkey invid hk w = fromMaybe w $ do
|
||||
oldhk <- w ^? imHotkeys . ix invid
|
||||
oldid <- w ^? hotkeys . ix hk
|
||||
return $ w & setHotkey oldid oldhk
|
||||
|
||||
setHotkey :: Int -> Hotkey -> LWorld -> LWorld
|
||||
setHotkey i hk = (imHotkeys . at i ?~ hk) . (hotkeys . at hk ?~ i)
|
||||
|
||||
removeHotkey :: Int -> LWorld -> LWorld
|
||||
removeHotkey invid w = w & imHotkeys . at invid .~ Nothing
|
||||
& fromMaybe id (do
|
||||
hk <- w ^? imHotkeys . ix invid
|
||||
return (hotkeys . at hk .~ Nothing)
|
||||
)
|
||||
assignHotkey :: NewInt ItmInt -> Hotkey -> LWorld -> LWorld
|
||||
assignHotkey (NInt itid) hk lw = lw
|
||||
& handleoldposition
|
||||
& hotkeys . at hk ?~ NInt itid
|
||||
& imHotkeys . unNIntMap . at itid ?~ hk
|
||||
where
|
||||
handleoldposition = fromMaybe id $ do
|
||||
olditid <- lw ^? hotkeys . ix hk . unNInt
|
||||
return $ imHotkeys . unNIntMap . at olditid .~ Nothing
|
||||
|
||||
Reference in New Issue
Block a user