Move hotkeys out of Creature into LWorld

This commit is contained in:
2024-12-19 15:29:20 +00:00
parent 4526119fcd
commit 910c683eac
11 changed files with 24 additions and 19 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -56,7 +56,7 @@ data Creature = Creature
, _crInvLock :: Bool
-- , _crInvEquipped :: IM.IntMap EquipPosition
, _crEquipment :: M.Map EquipPosition Int
, _crInvHotkeys :: IM.IntMap Hotkey
-- , _crInvHotkeys :: IM.IntMap Hotkey
-- , _crHotkeys :: M.Map Hotkey Int
, _crState :: CreatureState
, _crCorpse :: CreatureCorpse --Creature -> Corpse -> SPic
+1
View File
@@ -143,6 +143,7 @@ data LWorld = LWorld
, _lTestString :: [String]
, _lTestInt :: Int
, _hotkeys :: M.Map Hotkey Int
, _imHotkeys :: IM.IntMap Hotkey
}
--data WorldBeams = WorldBeams
-- { _blockingBeams :: [Beam]
+1 -1
View File
@@ -36,7 +36,7 @@ defaultCreature =
, _crPastDamage = 0
-- , _crInvEquipped = mempty
, _crEquipment = M.empty
, _crInvHotkeys = mempty
-- , _crInvHotkeys = mempty
-- , _crHotkeys = M.empty
, _crStance =
Stance
+1
View File
@@ -149,6 +149,7 @@ defaultLWorld =
, _lTestString = []
, _lTestInt = 0
, _hotkeys = mempty
, _imHotkeys = mempty
}
defaultHUD :: HUD
+2 -1
View File
@@ -181,7 +181,8 @@ updateDisplaySections w cfig =
mapMaybe (closeItemToSelectionItem w) (w ^. hud . closeItems)
invitems =
IM.mapWithKey
(\k (indent, x) -> invSelectionItem indent cr k (x ^. locLDT . ldtValue))
(\k (indent, x) -> invSelectionItem indent (w ^. cWorld . lWorld)
k (x ^. locLDT . ldtValue))
(fmap (first removeindentiffiltering) . allInvLocs $ _crInv cr)
removeindentiffiltering =
if maybe False (not . null) (w ^? hud . hudElement . diInvFilter . _Just)
+4 -4
View File
@@ -41,16 +41,16 @@ assignHotkey invid hk lw = fromMaybe lw $ do
moveOldHotkey :: Int -> Hotkey -> LWorld -> LWorld
moveOldHotkey invid hk w = fromMaybe w $ do
oldhk <- w ^? creatures . ix 0 . crInvHotkeys . ix invid
oldhk <- w ^? imHotkeys . ix invid
oldid <- w ^? hotkeys . ix hk
return $ w & setHotkey oldid oldhk
setHotkey :: Int -> Hotkey -> LWorld -> LWorld
setHotkey i hk = (creatures . ix 0 . crInvHotkeys . at i ?~ hk) . (hotkeys . at hk ?~ i)
setHotkey i hk = (imHotkeys . at i ?~ hk) . (hotkeys . at hk ?~ i)
removeHotkey :: Int -> LWorld -> LWorld
removeHotkey invid w = w & creatures . ix 0 . crInvHotkeys . at invid .~ Nothing
removeHotkey invid w = w & imHotkeys . at invid .~ Nothing
& fromMaybe id (do
hk <- w ^? creatures . ix 0 . crInvHotkeys . ix invid
hk <- w ^? imHotkeys . ix invid
return (hotkeys . at hk .~ Nothing)
)
+3 -3
View File
@@ -71,8 +71,8 @@ rmInvItem cid invid w =
& removeanyactivation
-- & pointcid . crHotkeys . each %~ g
& cWorld . lWorld . hotkeys . each %~ g
& pointcid . crInvHotkeys %~ IM.delete invid
& pointcid . crInvHotkeys %~ IM.mapKeys g
& cWorld . lWorld . imHotkeys %~ IM.delete invid
& cWorld . lWorld . imHotkeys %~ IM.mapKeys g
& updateselection
& updateselectionextra
& pointcid %~ updateRootItemID
@@ -101,7 +101,7 @@ rmInvItem cid invid w =
. itLocation . ilEquipPosition . _Just
return $ pointcid . crEquipment . at epos .~ Nothing
removeanyactivation = fromMaybe id $ do
epos <- w ^? cWorld . lWorld . creatures . ix cid . crInvHotkeys . ix invid
epos <- w ^? cWorld . lWorld . imHotkeys . ix invid
--return $ pointcid . crHotkeys . at epos .~ Nothing
return $ cWorld . lWorld . hotkeys . at epos .~ Nothing
maxk = fmap fst $ IM.lookupMax $ cr ^. crInv
+4 -3
View File
@@ -19,8 +19,8 @@ import NewInt
import Padding
import Picture.Base
invSelectionItem :: Int -> Creature -> Int -> ComposedItem -> SelectionItem ()
invSelectionItem indent cr i ci =
invSelectionItem :: Int -> LWorld -> Int -> ComposedItem -> SelectionItem ()
invSelectionItem indent lw i ci =
SelectionItem
{ _siPictures = pics & ix 0 %~ (++ anyequippos ++ anyhotkey)
, _siHeight = itInvHeight $ ci ^. _1
@@ -31,7 +31,8 @@ invSelectionItem indent cr i ci =
, _siPayload = ()
}
where
anyhotkey = maybe [] ((' ' :) . hotkeyToString) (cr ^? crInvHotkeys . ix i)
cr = lw ^?! creatures . ix 0
anyhotkey = maybe [] ((' ' :) . hotkeyToString) (lw ^? imHotkeys . ix i)
anyequippos = maybe [] (rightPad 8 ' ' . (' ' :) . eqPosText)
(ci ^? _1 . itLocation . ilEquipPosition . _Just)
col = itemInvColor ci
+3 -2
View File
@@ -58,17 +58,18 @@ swapInvItems f i w = fromMaybe w $ do
-- . (crInvEquipped %~ IM.safeSwapKeys i k)
. swapSite i k
. swapSite k i
. (crInvHotkeys %~ IM.safeSwapKeys i k)
-- . (crInvHotkeys %~ IM.safeSwapKeys i k)
swaphotkeys k =
swapSite' i k
. swapSite' k i
. (cWorld . lWorld . imHotkeys %~ IM.safeSwapKeys i k)
cr = you w
--swapSite a b = case cr ^? crInvEquipped . ix a of
swapSite a b = case cr ^? crInv . ix a . itLocation . ilEquipPosition . _Just of
Just epos -> crEquipment . ix epos .~ b
Nothing -> id
--swapSite' a b = case cr ^? crInvHotkeys . ix a of
swapSite' a b = case w ^? cWorld . lWorld . creatures . ix 0 . crInvHotkeys . ix a of
swapSite' a b = case w ^? cWorld . lWorld . imHotkeys . ix a of
Just epos -> cWorld . lWorld . hotkeys . ix epos .~ b
Nothing -> id
+3 -3
View File
@@ -52,10 +52,10 @@ chargeIfInInventory itm cr w =
maxcharge = itm ^?! itUse . leftConsumption . wpMaxCharge
chargeIfEquipped :: Item -> Creature -> World -> World
chargeIfEquipped itm cr
| invid `IM.member` (cr ^. crInvHotkeys) =
chargeIfEquipped itm cr w
| invid `IM.member` (w ^. cWorld . lWorld . imHotkeys) = w &
ptrWpCharge %~ (min maxcharge . (+ 1))
| otherwise = ptrWpCharge .~ 0
| otherwise = w & ptrWpCharge .~ 0
where
invid = _ilInvID $ _itLocation itm
ptrWpCharge = cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix invid . itUse . leftConsumption . wpCharge