Cleanup
This commit is contained in:
@@ -1,18 +1,16 @@
|
|||||||
module Dodge.AssignHotkey (assignHotkey) where
|
module Dodge.AssignHotkey (assignHotkey) where
|
||||||
|
|
||||||
import Dodge.Data.Equipment.Misc
|
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
|
import Dodge.Data.Equipment.Misc
|
||||||
import Dodge.Data.World
|
import Dodge.Data.World
|
||||||
import NewInt
|
import NewInt
|
||||||
|
|
||||||
-- it is not obvious to me whether hotkeys should belong to LWorld, CWorld or
|
|
||||||
-- World
|
|
||||||
assignHotkey :: NewInt ItmInt -> Hotkey -> LWorld -> LWorld
|
assignHotkey :: NewInt ItmInt -> Hotkey -> LWorld -> LWorld
|
||||||
assignHotkey i hk lw = lw
|
assignHotkey i hk lw =
|
||||||
|
lw
|
||||||
& handleoldposition
|
& handleoldposition
|
||||||
& hotkeys . at hk ?~ i
|
& hotkeys . at hk ?~ i
|
||||||
-- & imHotkeys . unNIntMap . at itid ?~ hk
|
|
||||||
& imHotkeys . at i ?~ hk
|
& imHotkeys . at i ?~ hk
|
||||||
where
|
where
|
||||||
handleoldposition = fromMaybe id $ do
|
handleoldposition = fromMaybe id $ do
|
||||||
|
|||||||
@@ -1,20 +1,18 @@
|
|||||||
{-# LANGUAGE LambdaCase #-}
|
{-# LANGUAGE LambdaCase #-}
|
||||||
|
|
||||||
module Dodge.Creature.YourControl (
|
module Dodge.Creature.YourControl (yourControl) where
|
||||||
yourControl,
|
|
||||||
) where
|
|
||||||
|
|
||||||
import qualified Data.IntMap.Strict as IM
|
|
||||||
import Dodge.Creature.MoveType
|
|
||||||
import Dodge.Data.Equipment.Misc
|
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
|
import qualified Data.IntMap.Strict as IM
|
||||||
import qualified Data.Map.Strict as M
|
import qualified Data.Map.Strict as M
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
|
import Dodge.AssignHotkey
|
||||||
import Dodge.Creature.Impulse.Movement
|
import Dodge.Creature.Impulse.Movement
|
||||||
import Dodge.Creature.Impulse.UseItem
|
import Dodge.Creature.Impulse.UseItem
|
||||||
|
import Dodge.Creature.MoveType
|
||||||
import Dodge.Data.AimStance
|
import Dodge.Data.AimStance
|
||||||
|
import Dodge.Data.Equipment.Misc
|
||||||
import Dodge.Data.World
|
import Dodge.Data.World
|
||||||
import Dodge.AssignHotkey
|
|
||||||
import Dodge.InputFocus
|
import Dodge.InputFocus
|
||||||
import Dodge.Inventory
|
import Dodge.Inventory
|
||||||
import Dodge.Item.AimStance
|
import Dodge.Item.AimStance
|
||||||
@@ -35,26 +33,24 @@ yourControl _ w
|
|||||||
& cWorld . lWorld . creatures . ix 0 %~ wasdWithAiming w
|
& cWorld . lWorld . creatures . ix 0 %~ wasdWithAiming w
|
||||||
& tryClickUse pkeys
|
& tryClickUse pkeys
|
||||||
& handleHotkeys
|
& handleHotkeys
|
||||||
| otherwise =
|
| otherwise = w & cWorld . lWorld . creatures . ix 0 %~ wasdWithAiming w
|
||||||
w & cWorld . lWorld . creatures . ix 0 %~ wasdWithAiming w
|
|
||||||
where
|
where
|
||||||
f NoSubInventory = True
|
f = \case
|
||||||
f ExamineInventory = True
|
NoSubInventory -> True
|
||||||
f _ = False
|
ExamineInventory -> True
|
||||||
|
_ -> False
|
||||||
pkeys = w ^. input . mouseButtons
|
pkeys = w ^. input . mouseButtons
|
||||||
|
|
||||||
|
-- the following only works because modifier keys are ordered after scancode "hotkeys"
|
||||||
handleHotkeys :: World -> World
|
handleHotkeys :: World -> World
|
||||||
handleHotkeys w
|
handleHotkeys w
|
||||||
| ispressed SDL.ScancodeLShift || ispressed SDL.ScancodeRShift
|
| ispressed SDL.ScancodeLShift || ispressed SDL.ScancodeRShift
|
||||||
, Just hk <-
|
, (hk:_) <- mapMaybe scancodeToHotkey . M.keys $ pkeys
|
||||||
listToMaybe . mapMaybe scancodeToHotkey . M.keys $ w ^. input . pressedKeys
|
|
||||||
, Just invid <- lw ^? creatures . ix 0 . crManipulation . manObject . imSelectedItem
|
, Just invid <- lw ^? creatures . ix 0 . crManipulation . manObject . imSelectedItem
|
||||||
, Just itid <- lw ^? creatures . ix 0 . crInv . ix invid =
|
, Just itid <- lw ^? creatures . ix 0 . crInv . ix invid =
|
||||||
w & cWorld . lWorld %~ assignHotkey (NInt itid) hk
|
w & cWorld . lWorld %~ assignHotkey (NInt itid) hk
|
||||||
| ispressed SDL.ScancodeLCtrl || ispressed SDL.ScancodeRCtrl
|
| ispressed SDL.ScancodeLCtrl || ispressed SDL.ScancodeRCtrl
|
||||||
, Just hk <-
|
, (hk:_) <- mapMaybe scancodeToHotkey . M.keys $ pkeys
|
||||||
listToMaybe . mapMaybe scancodeToHotkey . M.keys $
|
|
||||||
w ^. input . pressedKeys
|
|
||||||
, Just itid <- lw ^? hotkeys . ix hk . unNInt
|
, Just itid <- lw ^? hotkeys . ix hk . unNInt
|
||||||
, Just invid <- lw ^? items . ix itid . itLocation . ilInvID =
|
, Just invid <- lw ^? items . ix itid . itLocation . ilInvID =
|
||||||
w & invSetSelectionPos 0 (_unNInt invid)
|
w & invSetSelectionPos 0 (_unNInt invid)
|
||||||
@@ -64,17 +60,26 @@ handleHotkeys w
|
|||||||
w
|
w
|
||||||
(M.intersectionWith (,) thehotkeys (w ^. input . pressedKeys))
|
(M.intersectionWith (,) thehotkeys (w ^. input . pressedKeys))
|
||||||
where
|
where
|
||||||
|
pkeys = w ^. input . pressedKeys
|
||||||
ispressed k = k `M.member` _pressedKeys (_input w)
|
ispressed k = k `M.member` _pressedKeys (_input w)
|
||||||
thehotkeys = M.mapKeys hotkeyToScancode $ w ^. cWorld . lWorld . hotkeys
|
thehotkeys = M.mapKeys hotkeyToScancode $ w ^. cWorld . lWorld . hotkeys
|
||||||
lw = w ^. cWorld . lWorld
|
lw = w ^. cWorld . lWorld
|
||||||
|
|
||||||
|
--modifierKeys :: S.Set SDL.Scancode
|
||||||
|
--modifierKeys = S.fromList
|
||||||
|
-- [ SDL.ScancodeLShift
|
||||||
|
-- , SDL.ScancodeRShift
|
||||||
|
-- , SDL.ScancodeRCtrl
|
||||||
|
-- , SDL.ScancodeLCtrl
|
||||||
|
-- ]
|
||||||
|
|
||||||
useHotkey :: World -> (NewInt ItmInt, Int) -> World
|
useHotkey :: World -> (NewInt ItmInt, Int) -> World
|
||||||
useHotkey w (NInt itid, pt) = fromMaybe w $ do
|
useHotkey w (NInt itid, pt) = fromMaybe w $ do
|
||||||
invid <- w ^? cWorld . lWorld . items . ix itid . itLocation . ilInvID . unNInt
|
invid <- w ^? cWorld . lWorld . items . ix itid . itLocation . ilInvID . unNInt
|
||||||
useItem invid pt w
|
useItem invid pt w
|
||||||
|
|
||||||
hotkeyToScancode :: Hotkey -> SDL.Scancode
|
hotkeyToScancode :: Hotkey -> SDL.Scancode
|
||||||
hotkeyToScancode x = case x of
|
hotkeyToScancode = \case
|
||||||
HotkeyQ -> SDL.ScancodeQ
|
HotkeyQ -> SDL.ScancodeQ
|
||||||
HotkeyE -> SDL.ScancodeE
|
HotkeyE -> SDL.ScancodeE
|
||||||
HotkeyR -> SDL.ScancodeE
|
HotkeyR -> SDL.ScancodeE
|
||||||
@@ -94,7 +99,7 @@ hotkeyToScancode x = case x of
|
|||||||
Hotkey0 -> SDL.Scancode0
|
Hotkey0 -> SDL.Scancode0
|
||||||
|
|
||||||
scancodeToHotkey :: SDL.Scancode -> Maybe Hotkey
|
scancodeToHotkey :: SDL.Scancode -> Maybe Hotkey
|
||||||
scancodeToHotkey x = case x of
|
scancodeToHotkey = \case
|
||||||
SDL.ScancodeQ -> Just HotkeyQ
|
SDL.ScancodeQ -> Just HotkeyQ
|
||||||
SDL.ScancodeE -> Just HotkeyE
|
SDL.ScancodeE -> Just HotkeyE
|
||||||
SDL.ScancodeR -> Just HotkeyR
|
SDL.ScancodeR -> Just HotkeyR
|
||||||
@@ -129,8 +134,8 @@ wasdAim inp w cr
|
|||||||
| Just 0 <- inp ^? mouseButtons . ix SDL.ButtonRight
|
| Just 0 <- inp ^? mouseButtons . ix SDL.ButtonRight
|
||||||
, Nothing <- inp ^? mouseButtons . ix SDL.ButtonLeft =
|
, Nothing <- inp ^? mouseButtons . ix SDL.ButtonLeft =
|
||||||
setAimPosture (w ^. cWorld . lWorld . items) cr
|
setAimPosture (w ^. cWorld . lWorld . items) cr
|
||||||
| SDL.ButtonRight `M.member` _mouseButtons inp = aimTurn (w ^. cWorld . lWorld)
|
| SDL.ButtonRight `M.member` _mouseButtons inp =
|
||||||
mousedir cr
|
aimTurn (w ^. cWorld . lWorld) mousedir cr
|
||||||
| Aiming <- cr ^. crStance . posture = removeAimPosture m cr
|
| Aiming <- cr ^. crStance . posture = removeAimPosture m cr
|
||||||
| otherwise = creatureTurnTowardDir (_crMvAim cr) 0.2 cr
|
| otherwise = creatureTurnTowardDir (_crMvAim cr) 0.2 cr
|
||||||
where
|
where
|
||||||
@@ -231,6 +236,7 @@ tryClickUse pkeys w = fromMaybe w $ do
|
|||||||
^? cWorld . lWorld . creatures . ix 0
|
^? cWorld . lWorld . creatures . ix 0
|
||||||
. crManipulation
|
. crManipulation
|
||||||
. manObject
|
. manObject
|
||||||
. imSelectedItem . unNInt of
|
. imSelectedItem
|
||||||
|
. unNInt of
|
||||||
Just invid -> useItem invid ltime w
|
Just invid -> useItem invid ltime w
|
||||||
Nothing -> interactWithCloseObj <$> getSelectedCloseObj w ?? w
|
Nothing -> interactWithCloseObj <$> getSelectedCloseObj w ?? w
|
||||||
|
|||||||
@@ -31,11 +31,7 @@ import NewInt
|
|||||||
import Data.Foldable
|
import Data.Foldable
|
||||||
|
|
||||||
testStringInit :: Universe -> [String]
|
testStringInit :: Universe -> [String]
|
||||||
testStringInit u = map show
|
testStringInit _ = mempty
|
||||||
( u ^.. uvWorld . cWorld . lWorld . items . each . itLocation . ilEquipSite)
|
|
||||||
<> ["---"] <> map show
|
|
||||||
( u ^.. uvWorld . cWorld . lWorld . items . each . itID)
|
|
||||||
<> ["---"] <> map show (M.toList $ fold $ u ^? uvWorld . cWorld . lWorld . creatures . ix 0 . crEquipment)
|
|
||||||
-- map f (IM.toList $ u ^. uvWorld . cWorld . lWorld . items)
|
-- map f (IM.toList $ u ^. uvWorld . cWorld . lWorld . items)
|
||||||
-- <> ["---"]
|
-- <> ["---"]
|
||||||
-- <> map show (IM.toList . fold $ u ^? uvWorld . cWorld . lWorld . creatures . ix 0 . crInv . unNIntMap)
|
-- <> map show (IM.toList . fold $ u ^? uvWorld . cWorld . lWorld . creatures . ix 0 . crInv . unNIntMap)
|
||||||
|
|||||||
Reference in New Issue
Block a user