Files
loop/src/Dodge/Hotkey.hs
T
2025-05-31 08:17:26 +01:00

21 lines
587 B
Haskell

module Dodge.Hotkey (
assignHotkey,
) where
import Control.Lens
import Data.Maybe
import Dodge.Data.World
import NewInt
-- it is not obvious to me whether hotkeys should belong to LWorld, CWorld or
-- World
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