Move hotkeys out of Creature into LWorld
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -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
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -36,7 +36,7 @@ defaultCreature =
|
||||
, _crPastDamage = 0
|
||||
-- , _crInvEquipped = mempty
|
||||
, _crEquipment = M.empty
|
||||
, _crInvHotkeys = mempty
|
||||
-- , _crInvHotkeys = mempty
|
||||
-- , _crHotkeys = M.empty
|
||||
, _crStance =
|
||||
Stance
|
||||
|
||||
@@ -149,6 +149,7 @@ defaultLWorld =
|
||||
, _lTestString = []
|
||||
, _lTestInt = 0
|
||||
, _hotkeys = mempty
|
||||
, _imHotkeys = mempty
|
||||
}
|
||||
|
||||
defaultHUD :: HUD
|
||||
|
||||
@@ -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
@@ -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)
|
||||
)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user