Commit before making hotkeys attach to item ids, not inv ids

This commit is contained in:
2024-12-31 00:34:47 +00:00
parent 87f068f01a
commit 1e7dcbfded
15 changed files with 283 additions and 246 deletions
+16 -13
View File
@@ -1,31 +1,34 @@
module Dodge.Hotkey (
assignHotkey,
assignNewHotkey,
-- assignNewHotkey,
removeHotkey,
) where
import Control.Lens
import Data.List
import qualified Data.Map.Strict as M
--import Data.List
--import qualified Data.Map.Strict as M
import Data.Maybe
import Dodge.Data.World
import Control.Monad
--import Control.Monad
assignNewHotkey :: Int -> LWorld -> LWorld
assignNewHotkey invid w = assignHotkey invid (newHotkey w) w
--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]
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
-- guard $ lw ^? creatures . ix 0 . crInv . ix invid . itUseCondition
-- == Just UseableAnytime
return $ (setHotkey invid hk . moveOldHotkey invid hk) lw
moveOldHotkey :: Int -> Hotkey -> LWorld -> LWorld