Start implementing attachable scroll items

This commit is contained in:
2023-11-08 18:39:38 +00:00
parent 8f0dd8cd1b
commit f26d380c1b
20 changed files with 119 additions and 116 deletions
+10
View File
@@ -1,8 +1,10 @@
module Dodge.Base.You where
import Dodge.Data.World
import Dodge.HeldScroll
import qualified IntMapHelp as IM
import Control.Lens
import Control.Monad
you :: World -> Creature
you w = w ^?! cWorld . lWorld . creatures . ix 0
@@ -15,6 +17,14 @@ yourItem w = do
i <- you w ^? crManipulation . manObject . inInventory . ispItem
_crInv (you w) IM.!? i
yourScrollAttachment :: World -> Maybe (Int,ScrollAttachParams)
yourScrollAttachment w = do
i <- you w ^? crManipulation . manObject . inInventory . ispItem
itm <- _crInv (you w) IM.!? i
atparams <- you w ^? crInv . ix (i - 1) . itUse . attachParams . scrollAttachParams
guard (canHeldScrollAttach itm atparams)
return (i - 1, atparams)
yourInv :: World -> IM.IntMap Item
yourInv = _crInv . you
+10
View File
@@ -25,6 +25,7 @@ module Dodge.Creature.Test (
) where
--import MaybeHelp
--import Control.Applicative
import Control.Lens
import Data.List (find)
import Data.Maybe
@@ -46,6 +47,15 @@ crWeaponReady cr = fromMaybe False $ do
AboveSource -> do
x <- cr ^? crInv . ix (i - 1) . itUse . equipEffect . eeUse . euseAmmoAmount
return (x > 0)
BelowSource -> do
x <- cr ^? crInv . ix (i + 1) . itUse . equipEffect . eeUse . euseAmmoAmount
return (x > 0)
EitherSource -> return $
justIsPositive (cr ^? crInv . ix (i - 1) . itUse . equipEffect . eeUse . euseAmmoAmount)
|| justIsPositive (cr ^? crInv . ix (i + 1) . itUse . equipEffect . eeUse . euseAmmoAmount)
where
justIsPositive Nothing = False
justIsPositive (Just x) = x > 0
crCanSeeCr :: Creature -> (World, Creature) -> Bool
crCanSeeCr tcr (w, cr) = hasLOS (_crPos cr) (_crPos tcr) w
+2 -1
View File
@@ -137,7 +137,8 @@ wasdWithAiming w speed cr
(argV (_mousePos (_input w)) + (w ^. wCam . camRot))
$ do
itRef <- cr ^? crManipulation . manObject . inInventory . ispItem
_ <- cr ^? crInv . ix itRef . itScope . scopePos
-- _ <- cr ^? crInv . ix itRef . itScope . scopePos
_ <- cr ^? crInv . ix itRef . itScope . remotePos
return . argV $ mouseWorldPos (w ^. input) (w ^. wCam) -.- _crPos cr
aimTurn :: Float -> Creature -> Creature
-21
View File
@@ -1,21 +0,0 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TemplateHaskell #-}
module Dodge.Data.Item.HeldScroll where
import Control.Lens
import Data.Aeson
import Data.Aeson.TH
import qualified Data.Sequence as Seq
data HeldScroll
= HeldScrollDoNothing
| HeldScrollZoom
| HeldScrollCharMode
{_hsCharMode :: Seq.Seq Char}
deriving (Eq, Ord, Show, Read) --Generic, Flat)
makeLenses ''HeldScroll
deriveJSON defaultOptions ''HeldScroll
+9 -11
View File
@@ -14,18 +14,16 @@ data Scope
= NoScope
| RemoteScope
{ -- | a camera offset
_scopePos :: Point2
, _scopeZoom :: Float
, -- | if the camera offset is also the center of vision
_scopeIsCamera :: Bool
}
| ZoomScope
{ -- | a camera offset
_scopePos :: Point2
-- , _scopeZoomChange :: Int
, _scopeZoom :: Float
, _scopeDefaultZoom :: Float
_remotePos :: Point2
, _remoteZoom :: Float
}
-- | ZoomScope
-- { -- | a camera offset
-- _scopePos :: Point2
---- , _scopeZoomChange :: Int
-- , _scopeZoom :: Float
-- , _scopeDefaultZoom :: Float
-- }
deriving (Eq, Show, Read) --Generic, Flat)
makeLenses ''Scope
+17 -5
View File
@@ -7,19 +7,18 @@ module Dodge.Data.Item.Use (
module Dodge.Data.Item.Use,
module Dodge.Data.Item.Use.Equipment,
module Dodge.Data.Item.HeldUse,
module Dodge.Data.Item.HeldScroll,
module Dodge.Data.Item.HeldDelay,
module Dodge.Data.Item.Use.Consumption,
module Dodge.Data.Hammer,
module Dodge.Data.Item.Targeting,
) where
import Linear
import Geometry.Data
import Control.Lens
import Data.Aeson
import Data.Aeson.TH
import qualified Data.Sequence as Seq
import Dodge.Data.Hammer
import Dodge.Data.Item.HeldScroll
import Dodge.Data.Item.HeldUse
import Dodge.Data.Item.Use.Consumption
import Dodge.Data.Item.Use.Equipment
@@ -33,7 +32,6 @@ data ItemUse
, _heldMods :: HeldMod
, _heldHammer :: HammerPosition
, _heldAim :: AimParams
, _heldScroll :: HeldScroll
, _heldConsumption :: HeldConsumption
-- , _useTargeting :: Maybe TargetType
}
@@ -59,9 +57,20 @@ data ItemUse
--deriving (Eq, Show, Read) --Generic, Flat)
data AttachParams
= ZoomScopeParams
= ScrollAttachParams {_scrollAttachParams :: ScrollAttachParams}
| AmmoAttachParams
data ScrollAttachParams
= ZoomScrollParams
{ -- | a camera offset
_opticPos :: Point2
-- , _scopeZoomChange :: Int
, _opticZoom :: Float
, _opticDefaultZoom :: Float
}
| CharScrollParams
{ _scrollChar :: Seq.Seq Char}
data ItemUse'
= ItemHeld HeldUse'
| ItemEquip EquipUse'
@@ -110,8 +119,11 @@ makeLenses ''ItemUse
makeLenses ''AimParams
makeLenses ''ItZoom
makeLenses ''Muzzle
makeLenses ''AttachParams
makeLenses ''ScrollAttachParams
deriveJSON defaultOptions ''Muzzle
deriveJSON defaultOptions ''AimStance
deriveJSON defaultOptions ''ScrollAttachParams
deriveJSON defaultOptions ''AttachParams
deriveJSON defaultOptions ''ItZoom
deriveJSON defaultOptions ''AimParams
+2
View File
@@ -29,6 +29,8 @@ data HeldConsumption
data AmmoSource
= InternalSource InternalAmmo
| AboveSource
| BelowSource
| EitherSource
deriving (Eq, Show, Read) --Generic, Flat)
data ExternalSourceType = BulletClip
-1
View File
@@ -34,6 +34,5 @@ defaultHeldUse =
, _heldMods = HeldModNothing
, _heldHammer = HammerUp
, _heldAim = defaultAimParams
, _heldScroll = HeldScrollDoNothing
, _heldConsumption = defaultLoadable
}
+8 -14
View File
@@ -1,25 +1,16 @@
module Dodge.HeldScroll (
doHeldScroll,
canHeldScrollAttach,
) where
--import Dodge.Base.You
import Control.Lens hiding ((<|), (|>))
import Data.Sequence
import Dodge.Data.Creature
import Dodge.Data.World
import Data.Maybe
--import LensHelp hiding ((|>), (<|))
-- should be able to just import data.item
doHeldScroll :: HeldScroll -> Float -> Creature -> World -> World
doHeldScroll hs = case hs of
HeldScrollDoNothing -> const . const id
HeldScrollZoom -> const . const id
HeldScrollCharMode{} -> overYourItem $ \x _ -> itUse . heldScroll . hsCharMode %~ cycleSignum x
where
overYourItem f x cr w = fromMaybe w $ do
i <- cr ^? crManipulation . manObject . inInventory . ispItem
return $ w & cWorld . lWorld . creatures . ix 0 . crInv . ix i %~ f x cr
doHeldScroll :: Int -> ScrollAttachParams -> Float -> World -> World
doHeldScroll invid hs x w = case hs of
ZoomScrollParams{}-> w
CharScrollParams{} -> w & cWorld . lWorld . creatures . ix 0 . crInv . ix invid . itUse . attachParams . scrollAttachParams . scrollChar %~ cycleSignum x
cycleSignum :: Float -> Seq a -> Seq a
cycleSignum x
@@ -31,3 +22,6 @@ cycleL (x :<| xs) = xs |> x
cycleL xs = xs
cycleR (xs :|> x) = x <| xs
cycleR xs = xs
canHeldScrollAttach :: Item -> ScrollAttachParams -> Bool
canHeldScrollAttach _ _ = True
+7 -7
View File
@@ -4,7 +4,7 @@ module Dodge.Inventory (
rmSelectedInvItem,
rmInvItem,
updateCloseObjects,
closeObjScrollDir,
--closeObjScrollDir,
changeSwapSel,
scrollAugInvSel,
crNumFreeSlots,
@@ -31,7 +31,7 @@ import Geometry
import qualified IntMapHelp as IM
import LensHelp
import ListHelp
import Padding
--import Padding
-- TODO check what happens to selection index when dropping non-selected items
@@ -134,11 +134,11 @@ updateCloseObjects w =
updatebyid (Right btid) = fmap Right $ w ^? cWorld . lWorld . buttons . ix (_btID btid)
closeObjScrollDir :: Float -> World -> World
closeObjScrollDir x
| x > 0 = over (hud . closeObjects) rotU
| x < 0 = over (hud . closeObjects) rotD
| otherwise = id
--closeObjScrollDir :: Float -> World -> World
--closeObjScrollDir x
-- | x > 0 = over (hud . closeObjects) rotU
-- | x < 0 = over (hud . closeObjects) rotD
-- | otherwise = id
changeSwapSel :: Int -> World -> World
changeSwapSel yi w
+1 -1
View File
@@ -17,5 +17,5 @@ beltMag = tinMag & itType . iyBase .~ AMMO BULLETBELT
zoomScope :: Item
zoomScope = tinMag
& itType . iyBase .~ ATTACH ZOOMSCOPE
& itUse .~ AttachUse ZoomScopeParams
& itUse .~ AttachUse (ScrollAttachParams (ZoomScrollParams {_opticPos = 0, _opticZoom = 1, _opticDefaultZoom = 0.5}))
+1 -1
View File
@@ -155,7 +155,7 @@ showReloadProgress cr itm = case ic ^? laSource of
Just (InternalSource ia) -> case ia ^? iaProgress . _Just . ix 0 of
Nothing -> maybe "" show $ ic ^? laSource . _InternalSource . iaLoaded
Just la -> showLoadActionType la (_laSource ic)
Just AboveSource -> fromMaybe "||||" $ do
Just AboveSource -> fromMaybe "^^^^" $ do
i <- fmap (subtract 1) $ itm ^? itLocation . ipInvID
_ <- cr ^? crInv . ix i . itUse . equipEffect . eeUse . euseAmmoAmount
return ""
+1 -1
View File
@@ -59,7 +59,7 @@ remoteLauncher =
launcher
& itType . iyBase .~ HELD REMOTELAUNCHER
& itUse . heldUse .~ HeldFireRemoteShell --fireRemoteShell
& itScope .~ RemoteScope (V2 0 0) 1 True
& itScope .~ RemoteScope (V2 0 0) 1
& itUse . heldConsumption . laAmmoType . amPjDraw .~ DrawRemoteShell
basicAmPjMoves :: IM.IntMap TweakParam
+6 -6
View File
@@ -68,12 +68,12 @@ sniperRifle =
& itType . iyBase .~ HELD SNIPERRIFLE
& itUse . heldAim . aimMuzzles . ix 0 . mzInaccuracy .~ 0
& itUse . heldAim . aimZoom .~ defaultItZoom{_izMax = 0.5, _izMin = 0.5,_izFac = 1}
& itUse . heldScroll .~ HeldScrollZoom -- zoomLongGun
& itScope .~ ZoomScope
{ _scopePos = (V2 0 0)
, _scopeZoom = 1
, _scopeDefaultZoom = 0.5
}
-- & itUse . heldScroll .~ HeldScrollZoom -- zoomLongGun
-- & itScope .~ ZoomScope
-- { _scopePos = (V2 0 0)
-- , _scopeZoom = 1
-- , _scopeDefaultZoom = 0.5
-- }
& itType . iyModules . at ModTarget ?~ TARGET TargetLaser
-- & itUse . useTargeting ?~ TargetLaser
+6 -6
View File
@@ -26,16 +26,16 @@ latchkey _ = defaultHeldItem
binoculars :: Item
binoculars =
defaultHeldItem
& itScope .~ ZoomScope
{ _scopePos = (V2 0 0)
, _scopeZoom = 1
, _scopeDefaultZoom = 0.5
}
-- & itScope .~ ZoomScope
-- { _scopePos = (V2 0 0)
-- , _scopeZoom = 1
-- , _scopeDefaultZoom = 0.5
-- }
& itType . iyBase .~ HELD BINOCULARS
-- & itUse . heldAim . aimHandlePos .~ 5
-- & itUse . heldAim . aimMuzPos .~ 10
& itUse . heldAim . aimStance .~ TwoHandFlat
& itUse . heldScroll .~ HeldScrollZoom -- zoomLongGun
-- & itUse . heldScroll .~ HeldScrollZoom -- zoomLongGun
& itUse . heldAim . aimZoom .~ defaultItZoom{_izMax = 0.5, _izMin = 0.5, _izFac = 1}
+1 -12
View File
@@ -1,6 +1,5 @@
module Dodge.Item.Weapon.Remote (
setRemoteScope,
setRemoteBombScope,
) where
import Control.Lens
@@ -8,22 +7,12 @@ import Dodge.Data.World
import Dodge.Default
import Geometry
setRemoteBombScope :: Int -> Prop -> World -> World
setRemoteBombScope itid pj w = case w ^?! cWorld . lWorld . itemLocations . ix itid of
InInv cid invid ->
w
& cWorld . lWorld . creatures . ix cid . crInv . ix invid . itScope
. scopePos
.~ (_prPos pj -.- (w ^?! cWorld . lWorld . creatures . ix cid . crPos))
& cWorld . lWorld . creatures . ix cid . crInv . ix invid . itUse . heldAim . aimZoom
.~ (defaultItZoom{_izMax = 0.5, _izMin = 0.5})
_ -> w
setRemoteScope :: Int -> Point2 -> World -> World
setRemoteScope itid pos w = case w ^? cWorld . lWorld . itemLocations . ix itid of
Just (InInv cid' invid) ->
w
& cWorld . lWorld . creatures . ix cid' . crInv . ix invid . itScope
. scopePos
. remotePos
.~ (pos -.- (w ^?! cWorld . lWorld . creatures . ix cid' . crPos))
_ -> w
+9 -3
View File
@@ -361,7 +361,7 @@ useAmmoUpTo amAmount eff item cr =
useAmmoAmount :: Int -> ChainEffect
useAmmoAmount amAmount eff item cr =
eff item cr
. (cWorld . lWorld . creatures . ix (_crID cr) . crInv %~ useAmmoAmount' itref amAmount) -- . _InternalSource . iaLoaded -~ amAmount)
. (cWorld . lWorld . creatures . ix (_crID cr) . crInv %~ useAmmoAmount' itref amAmount)
where
itref = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change
@@ -371,6 +371,12 @@ useAmmoAmount' itref x inv = case inv ^? ix itref . itUse . heldConsumption . la
inv & ix itref . itUse . heldConsumption . laSource . _InternalSource . iaLoaded -~ x
Just AboveSource ->
inv & ix (itref - 1) . itUse . equipEffect . eeUse . euseAmmoAmount -~ x
Just BelowSource ->
inv & ix (itref + 1) . itUse . equipEffect . eeUse . euseAmmoAmount -~ x
Just EitherSource -> case inv ^? ix (itref - 1) . itUse . equipEffect . eeUse . euseAmmoAmount of
Just amamount | amamount > 0 ->
inv & ix (itref - 1) . itUse . equipEffect . eeUse . euseAmmoAmount -~ x
_ -> inv & ix (itref + 1) . itUse . equipEffect . eeUse . euseAmmoAmount -~ x
_ -> inv
-- . crInv . ix itRef . itUse . heldConsumption . laSource
@@ -615,8 +621,8 @@ withTorqueAfter feff item cr w
(rot, g) = randomR (- torque, torque) $ _randGen w
torque = fromMaybe 0 $ item ^? itParams . torqueAfter
--rotateScope = cWorld . lWorld . creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0))
rotateScope = pointerYourItem . itScope . scopePos %~ rotateV rot
rotateScope = id
-- rotateScope = pointerYourItem . itScope . scopePos %~ rotateV rot
sideEffectOnFrame ::
Int ->
+1 -1
View File
@@ -83,7 +83,7 @@ retireRemoteProj :: Int -> Int -> World -> World
retireRemoteProj itid pjid w =
w
& pointerToItemLocation (w ^?! cWorld . lWorld . itemLocations . ix itid)
%~ ( (itScope . scopePos .~ V2 0 0)
%~ ( (itScope . remotePos .~ V2 0 0)
. (itUse . heldUse .~ HeldFireRemoteShell)
)
& cWorld . lWorld . props %~ IM.delete pjid
+20 -21
View File
@@ -93,23 +93,21 @@ moveZoomCamera cfig theinput cr campos =
cr ^? crInv . ix i
newvf = cpos +.+ fromMaybe (V2 0 0) vfoffset
vfoffset = do
iscam <- mitm ^? _Just . itScope . scopeIsCamera
guard iscam
guard (SDL.ButtonRight `M.member` _mouseButtons theinput)
mitm ^? _Just . itScope . scopePos
mitm ^? _Just . itScope . remotePos
mscopeoffset = do
guard (SDL.ButtonRight `M.member` _mouseButtons theinput)
mitm ^? _Just . itScope . scopePos
mitm ^? _Just . itScope . remotePos
newcen = cpos +.+ fromMaybe (V2 0 0) mscopeoffset +.+ offset
offset =
rotateV (campos ^. camRot) $
((newzoom - newDefaultZoom) / (newDefaultZoom * newzoom)) *.* _mousePos theinput
newzoom = case mitm ^? _Just . itScope of
Just zs@ZoomScope{} -> _scopeZoom zs
-- Just zs@ZoomScope{} -> _scopeZoom zs
_ -> newDefaultZoom * newItemZoom
idealDefaultZoom = clipZoom wallZoom
newDefaultZoom = case mitm ^? _Just . itScope of
Just zs@ZoomScope{} -> _scopeZoom zs
-- Just zs@ZoomScope{} -> _scopeZoom zs
_ -> changeZoom (campos ^. camDefaultZoom) idealDefaultZoom
idealItemZoom = fromMaybe 1 $ do
guard $ crIsAiming cr
@@ -140,13 +138,12 @@ updateScopeZoom' i w
w & wppointer %~ doScopeZoom (w ^. input . smoothScrollAmount) mp
| otherwise = w & wppointer %~ resetscope
where
wppointer = cWorld . lWorld . creatures . ix 0 . crInv . ix i . itScope
--resetscope (ZoomScope _ _ defz bl) = ZoomScope (V2 0 0) defz defz bl
resetscope (ZoomScope _ _ defz) = ZoomScope (V2 0 0) defz defz
wppointer = cWorld . lWorld . creatures . ix 0 . crInv . ix (i - 1) . itUse . attachParams . scrollAttachParams
resetscope (ZoomScrollParams _ _ defz) = ZoomScrollParams (V2 0 0) defz defz
resetscope otherAtt = otherAtt
mp = rotateV (w ^. wCam . camRot) $ _mousePos (_input w)
doScopeZoom :: Int -> Point2 -> Scope -> Scope
doScopeZoom :: Int -> Point2 -> ScrollAttachParams -> ScrollAttachParams
doScopeZoom scrollamount mp sc = case scrollamount of
x
| x > 10 -> (zoomInLongGun mp . zoomInLongGun mp . zoomInLongGun mp) sc
@@ -160,21 +157,21 @@ doScopeZoom scrollamount mp sc = case scrollamount of
zoomSpeed :: Float
zoomSpeed = 39 / 40
zoomInLongGun :: Point2 -> Scope -> Scope
zoomInLongGun :: Point2 -> ScrollAttachParams -> ScrollAttachParams
zoomInLongGun mousep sc = fromMaybe sc $ do
curzoom <- sc ^? scopeZoom
curzoom <- sc ^? opticZoom
guard $ curzoom < 8
return $
sc & scopePos .+.+~ (1 - zoomSpeed) * zoomSpeed / curzoom *.* mousep
& scopeZoom %~ (/ zoomSpeed)
sc & opticPos .+.+~ (1 - zoomSpeed) * zoomSpeed / curzoom *.* mousep
& opticZoom %~ (/ zoomSpeed)
zoomOutLongGun :: Scope -> Scope
zoomOutLongGun :: ScrollAttachParams -> ScrollAttachParams
zoomOutLongGun sc = fromMaybe sc $ do
curzoom <- sc ^? scopeZoom
curzoom <- sc ^? opticZoom
guard $ curzoom > 0.5
return $
sc & scopePos %~ (\p -> p +.+ (zoomSpeed - 1) / curzoom *.* p)
& scopeZoom *~ zoomSpeed
sc & opticPos %~ (\p -> p +.+ (zoomSpeed - 1) / curzoom *.* p)
& opticZoom *~ zoomSpeed
ifConfigWallRotate :: Configuration -> World -> World
ifConfigWallRotate cfig w
@@ -213,9 +210,11 @@ rotateCameraBy x w =
rotateanyscope = fromMaybe id $ do
i <- w ^? cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . inInventory . ispItem
return $
lWorld . creatures . ix 0 . crInv . ix i
. itScope
. scopePos
lWorld . creatures . ix 0 . crInv . ix (i - 1)
. itUse
. attachParams
. scrollAttachParams
. opticPos
%~ rotateV x
rotateCamera :: Configuration -> World -> World
+8 -4
View File
@@ -26,10 +26,14 @@ updateWheelEvent yi w = case w ^. hud . hudElement of
-- functions that modify the inventory should be centralised so that
-- this lock can be sensibly applied, perhaps
| w ^?! cWorld . lWorld . creatures . ix 0 . crInvLock -> w
| rbDown -> case (yourItem w ^? _Just . itUse . heldScroll, _rbOptions w) of
(_, EquipOptions{}) -> w & rbOptions . opSel %~ scrollRBOption yi rbscrollmax
(Nothing, _) -> closeObjScrollDir y w
(Just f, _) -> doHeldScroll f y (you w) w
-- | rbDown -> case (yourItem w ^? _Just . itUse . heldScroll, _rbOptions w) of
-- (_, EquipOptions{}) -> w & rbOptions . opSel %~ scrollRBOption yi rbscrollmax
-- (Nothing, _) -> closeObjScrollDir y w
-- (Just f, _) -> doHeldScroll f y (you w) w
| rbDown -> case (yourScrollAttachment w, _rbOptions w) of
(_,EquipOptions{}) -> w & rbOptions . opSel %~ scrollRBOption yi rbscrollmax
(Nothing, _) -> w -- closeObjScrollDir y w
(Just (invid,hs), _) -> doHeldScroll invid hs y w
| lbDown -> w & wCam . camZoom +~ y
| invKeyDown -> changeSwapSel yi w
| otherwise -> stopSoundFrom (CrReloadSound 0) $ scrollAugInvSel yi w