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
+1 -1
View File
File diff suppressed because one or more lines are too long
+3
View File
@@ -312,6 +312,9 @@ stackedInventory =
, megaShellMag
, burstRifle
, megaTinMag 100
, underBarrelSlot
, gLauncher
, megaShellMag
, laser
, makeTypeCraft TRANSFORMER
, teslaGun
+5 -5
View File
@@ -11,7 +11,7 @@ import Dodge.Data.World
import Dodge.DoubleTree
import Dodge.Euse
import Dodge.HeldUse
import Dodge.Hotkey
--import Dodge.Hotkey
import Dodge.Inventory
import Dodge.Item.Grammar
import Dodge.Item.Location
@@ -71,7 +71,7 @@ toggleEquipmentAt invid cr w = case getEquipmentAllocation w of
& crpoint . crEquipment . at newp ?~ invid
& crpoint . crInv . ix invid . itLocation . ilEquipSite ?~ newp
& onequip itm cr
& cWorld . lWorld %~ assignNewHotkey invid
-- & cWorld . lWorld %~ assignNewHotkey invid
MoveEquipment{_allocNewPos = newp, _allocOldPos = oldp} ->
w
& crpoint . crEquipment . at newp ?~ invid
@@ -90,14 +90,14 @@ toggleEquipmentAt invid cr w = case getEquipmentAllocation w of
& crpoint . crInv . ix rid . itLocation . ilEquipSite .~ Nothing
& onremove (itmat rid) cr
& onequip itm cr
& cWorld . lWorld %~ removeHotkey rid
& cWorld . lWorld %~ assignNewHotkey invid
-- & cWorld . lWorld %~ removeHotkey rid
-- & cWorld . lWorld %~ assignNewHotkey invid
RemoveEquipment{_allocOldPos = oldp} ->
w
& crpoint . crEquipment . at oldp .~ Nothing
& crpoint . crInv . ix invid . itLocation . ilEquipSite .~ Nothing
& onremove itm cr
& cWorld . lWorld %~ removeHotkey invid
-- & cWorld . lWorld %~ removeHotkey invid
where
crpoint = cWorld . lWorld . creatures . ix (_crID cr)
itmat i = _crInv cr IM.! i
+4
View File
@@ -30,11 +30,15 @@ data ComposeLinkType
| FunctionChangeLink
| MakeAutoLink
| ProjectileStabiliserLink
| UnderBarrelSlotLink
| UnderBarrelPlatformLink
deriving (Eq, Ord, Show, Read)
data ItemStructuralFunction
= UnloadedWeaponSF
| HeldPlatformSF
| UnderBarrelSlotSF
| UnderBarrelPlatformSF
| EquipmentPlatformSF
| GadgetPlatformSF
| WeaponScopeSF
+1
View File
@@ -74,6 +74,7 @@ data AttachType
| JOYSTICK
| GIMBAL
| GYROSCOPE
| UNDERBARRELSLOT
| REMOTEDETONATOR
| SMOKEREDUCER
| HOMINGMODULE
+1 -1
View File
@@ -60,7 +60,7 @@ data UseFocus
deriving (Eq, Show, Read)
data UseCondition
= MustBeHeld
= UseableWhenAimed
| UseableAnytime
deriving (Eq, Show, Read)
+1 -1
View File
@@ -25,7 +25,7 @@ defaultHeldItem =
, _itLocation = InVoid
, _itUse = defaultHeldUse
, _itParams = NoParams
, _itUseCondition = MustBeHeld
, _itUseCondition = UseableWhenAimed
}
--defaultLeftItem :: Item
+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
+1
View File
@@ -37,6 +37,7 @@ itemFromAmmoMag at = case at of
itemFromAttachType :: AttachType -> Item
itemFromAttachType at = case at of
UNDERBARRELSLOT -> underBarrelSlot
ZOOMSCOPE -> zoomScope
BULLETSYNTH -> bulletSynthesizer
REMOTESCREEN -> remoteScreen
+1
View File
@@ -69,6 +69,7 @@ itemBaseName = \case
showAttachItem :: AttachType -> String
showAttachItem t = case t of
UNDERBARRELSLOT -> "UNDERBARRELSLOT"
ZOOMSCOPE -> "ZOOMSCOPE"
BULLETSYNTH -> "BSYNTH"
REMOTESCREEN -> "REM.SCREEN"
+13 -2
View File
@@ -62,8 +62,12 @@ itemToBreakLists ::
([(ItemStructuralFunction, ComposeLinkType)], [(ItemStructuralFunction, ComposeLinkType)])
itemToBreakLists itm itmf = case (itm ^. itType, itmf) of
(HELD TORCH, _) -> (getAmmoLinks itm, [])
(ATTACH UNDERBARRELSLOT, _) -> ([(UnderBarrelPlatformSF, UnderBarrelPlatformLink)], [])
(_, HeldPlatformSF) ->
( getAmmoLinks itm
<> extraWeaponLinksBelow itm
--( extraWeaponLinksBelow itm
-- <>getAmmoLinks itm
, [(WeaponTargetingSF, WeaponTargetingLink), (WeaponScopeSF, WeaponScopeLink)]
<> getAutoSpringLinks itm
<> extraWeaponLinks itm
@@ -113,6 +117,12 @@ extraWeaponLinks itm = case itm ^. itType of
where
launcherlinks = [(ProjectileStabiliserSF,ProjectileStabiliserLink)]
extraWeaponLinksBelow :: Item -> [(ItemStructuralFunction, ComposeLinkType)]
extraWeaponLinksBelow itm
| Just TwoHandUnder <- itm ^? itUse . heldAim . aimStance
= [(UnderBarrelSlotSF,UnderBarrelSlotLink)]
| otherwise = []
getAmmoLinks :: Item -> [(ItemStructuralFunction, ComposeLinkType)]
getAmmoLinks itm =
map
@@ -123,7 +133,7 @@ itemToFunction :: Item -> ItemStructuralFunction
itemToFunction itm = case itm ^. itType of
HELD LASER -> WeaponTargetingSF
HELD{} -> case itm ^? itUseCondition of
Just MustBeHeld -> HeldPlatformSF
Just UseableWhenAimed -> HeldPlatformSF
--Just MustBeHeld -> UnloadedWeaponSF
_ -> GadgetPlatformSF
_
@@ -139,7 +149,7 @@ itemToFunction itm = case itm ^. itType of
ATTACH ZOOMSCOPE -> WeaponScopeSF
ATTACH HOMINGMODULE -> AmmoTargetingSF LauncherAmmo
ATTACH AUGMENTEDHUD -> AugmentedHUDSF
-- BULLETMOD BulletModTrajectory{} -> AmmoTargetingSF BulletAmmo
ATTACH UNDERBARRELSLOT -> UnderBarrelSlotSF
BULLETMOD BulletModPayload{} -> AmmoPayloadSF BulletAmmo
BULLETMOD BulletModEffect{} -> AmmoEffectSF BulletAmmo
TARGETING{} -> WeaponTargetingSF
@@ -154,6 +164,7 @@ structureToPotentialFunction ::
structureToPotentialFunction ldt = case ldt ^. ldtValue . _1 . itType of
ATTACH GIMBAL -> S.singleton ProjectileStabiliserSF
ATTACH GYROSCOPE -> S.singleton ProjectileStabiliserSF
HELD GLAUNCHER -> S.singleton UnderBarrelPlatformSF
_ -> S.singleton (ldt ^. ldtValue . _2)
baseCI :: Item -> ComposedItem
+2
View File
@@ -29,6 +29,8 @@ itemInvColor ci = case ci ^. _2 of
AmmoEffectSF{} -> aquamarine
FunctionChangeSF -> yellow
ProjectileStabiliserSF -> white
UnderBarrelPlatformSF -> white
UnderBarrelSlotSF -> white
--ammoTypeColor :: AmmoType -> Color
--ammoTypeColor = \case
+4
View File
@@ -1,4 +1,5 @@
module Dodge.Item.Scope (
underBarrelSlot,
gimbal,
gyroscope,
stickyMod,
@@ -84,5 +85,8 @@ gimbal = makeAttach GIMBAL
gyroscope :: Item
gyroscope = makeAttach GYROSCOPE
underBarrelSlot :: Item
underBarrelSlot = makeAttach UNDERBARRELSLOT
smokeReducer :: Item
smokeReducer = makeAttach SMOKEREDUCER
+9 -9
View File
@@ -15,7 +15,7 @@ import Dodge.Creature.Test
import Dodge.Data.Config
import Dodge.Data.World
--import Dodge.Equipment
import Dodge.InputFocus
--import Dodge.InputFocus
import Dodge.SmoothScroll
import Dodge.Viewpoints
import Dodge.WASD
@@ -24,7 +24,7 @@ import Geometry
--import qualified IntMapHelp as IM
import LensHelp
import SDL (MouseButton (..))
import qualified SDL
--import qualified SDL
{- Update the screen camera rotation and position, including any in rold scope/remote camera modifiers;
update where your avatar's view is from. -}
@@ -157,17 +157,17 @@ doWallRotate wl w = rotateUsing $ (argV . uncurry (-.-) $ _wlLine wl) - (w ^. wC
b = a * (4 / pi)
b' = fromIntegral (round b :: Int)
rotateCameraBy :: Float -> World -> World
rotateCameraBy x = wCam . camRot +~ x
--rotateCameraBy :: Float -> World -> World
--rotateCameraBy x = wCam . camRot +~ x
rotateCamera :: Configuration -> World -> World
rotateCamera cfig w
| keydown SDL.ScancodeQ && keydown SDL.ScancodeE = w
| keydown SDL.ScancodeQ = rotateCameraBy 0.025 w
| keydown SDL.ScancodeE = rotateCameraBy (-0.025) w
-- | keydown SDL.ScancodeQ && keydown SDL.ScancodeE = w
-- | keydown SDL.ScancodeQ = rotateCameraBy 0.025 w
-- | keydown SDL.ScancodeE = rotateCameraBy (-0.025) w
| otherwise = ifConfigWallRotate cfig (w ^. input . mouseButtons) w
where
keydown scode = scode `M.member` _pressedKeys (_input w) && not (inTextInputFocus w)
-- where
-- keydown scode = scode `M.member` _pressedKeys (_input w) && not (inTextInputFocus w)
zoomFromItem :: ItZoom -> Float
zoomFromItem ItZoom{_izMax = zMax, _izMin = zMin, _izFac = zFac} =
+221 -214
View File
File diff suppressed because it is too large Load Diff