From e75cbdf6cb1c3fd2f04d65b3a9fd26774dd35eb9 Mon Sep 17 00:00:00 2001 From: justin Date: Mon, 29 Nov 2021 23:05:51 +0000 Subject: [PATCH] Work on tweak datatypes --- src/Dodge/Data.hs | 18 ++++----------- src/Dodge/Event.hs | 20 ++++++++-------- src/Dodge/Item/Weapon/BatteryGuns.hs | 1 + src/Dodge/Item/Weapon/Launcher.hs | 34 ++++++++++++---------------- src/Dodge/Render/HUD.hs | 4 ++-- 5 files changed, 32 insertions(+), 45 deletions(-) diff --git a/src/Dodge/Data.hs b/src/Dodge/Data.hs index 9e80acb00..809858709 100644 --- a/src/Dodge/Data.hs +++ b/src/Dodge/Data.hs @@ -516,34 +516,26 @@ data AmmoType { _amString :: String } | GenericAmmo data ItemParams - = UtilityItem - | NoParams + = NoParams | ShellLauncher - { _tweakParams :: [TweakParam] + { _tweakParams :: IM.IntMap TweakParam , _tweakSel :: Int , _shellSpinDrag :: Int , _shellSpinAmount :: Int , _shellThrustDelay :: Int } + | Refracting {_phaseVel :: Float} | MultiBarrel { _barrelSpread :: BarrelSpread , _barrelNum :: Int } - | SingleBarrel - {_inaccuracy :: Float} + | SingleBarrel {_inaccuracy :: Float} | AngleWalk { _maxWalkAngle :: Float , _currentWalkAngle :: Float , _walkSpeed :: Float } -data TweakParam - = PjExtraUpdate - { _pjMoveParam :: Int -> Item -> Creature -> Prop -> World -> World - , _curTweak :: Int - , _pjMaxParam :: Int - , _pjDisplayParam :: Int -> String - } - | TweakItem +data TweakParam = TweakParam { _doTweak :: Int -> Item -> Item , _curTweak :: Int , _maxTweak :: Int diff --git a/src/Dodge/Event.hs b/src/Dodge/Event.hs index 2f63e96cb..1e9fb7fcd 100644 --- a/src/Dodge/Event.hs +++ b/src/Dodge/Event.hs @@ -112,10 +112,10 @@ wheelEvent y w = case (_carteDisplay w, _inventoryMode w) of | invKeyDown -> swapInvDir yi $ stopSoundFrom (CrReloadSound 0) $ dirInvPos yi w | otherwise -> stopSoundFrom (CrReloadSound 0) $ dirInvPos yi w (_, TweakInventory) - | invKeyDown && rbDown -> w & moveYourAmmoSel yi + | invKeyDown && rbDown -> w & moveTweakSel yi | invKeyDown -> stopSoundFrom (CrReloadSound 0) $ dirInvPos yi w | rbDown -> w & changeTweakParam yi - | otherwise -> w & moveYourAmmoSel yi + | otherwise -> w & moveTweakSel yi (_, _) -> w where yi = round $ signum y @@ -124,18 +124,18 @@ wheelEvent y w = case (_carteDisplay w, _inventoryMode w) of lbDown = ButtonLeft `S.member` _mouseButtons w invKeyDown = ScancodeCapsLock `S.member` _keys w -moveYourAmmoSel :: Int -> World -> World -moveYourAmmoSel i w = case yourItem w ^? itParams . tweakParams of +moveTweakSel :: Int -> World -> World +moveTweakSel i w = case yourItem w ^? itParams . tweakParams of Just l -> w & creatures . ix (_yourID w) . crInv . ix (_crInvSel (you w)) . itParams . tweakSel %~ (`mod` length l) . subtract i _ -> w changeTweakParam :: Int -> World -> World -changeTweakParam i w = - case yourItem w ^? itParams . tweakParams . ix paramid . pjMaxParam of - Just n -> w & creatures . ix (_yourID w) . crInv . ix (_crInvSel (you w)) - . itParams . tweakParams . ix paramid . curTweak %~ (`mod` n) . (+ i) - _ -> w +changeTweakParam i w = w + & creatures . ix (_yourID w) . crInv . ix (_crInvSel (you w)) %~ + ( (itParams . tweakParams . ix paramid . curTweak .~ x) + . _doTweak params x) where it = yourItem w - theparam = it ^? itParams . tweakParams . ix paramid + params = _tweakParams (_itParams it) IM.! paramid + x = (_curTweak params + i) `mod` _maxTweak params paramid = _tweakSel $ _itParams $ yourItem w diff --git a/src/Dodge/Item/Weapon/BatteryGuns.hs b/src/Dodge/Item/Weapon/BatteryGuns.hs index 2697befdb..bafdefccf 100644 --- a/src/Dodge/Item/Weapon/BatteryGuns.hs +++ b/src/Dodge/Item/Weapon/BatteryGuns.hs @@ -83,6 +83,7 @@ lasGun = defaultAutoGun , _itAttachment = ItCharMode $ Seq.fromList "/VZ" , _itScroll = scrollCharMode , _itInvDisplay = basicWeaponDisplay + , _itParams = Refracting {_phaseVel = 1} } lasGunPic :: Item -> SPic lasGunPic it = diff --git a/src/Dodge/Item/Weapon/Launcher.hs b/src/Dodge/Item/Weapon/Launcher.hs index 6a955fb82..482d341ec 100644 --- a/src/Dodge/Item/Weapon/Launcher.hs +++ b/src/Dodge/Item/Weapon/Launcher.hs @@ -82,34 +82,34 @@ launcherPic _ = , mempty ) -basicAmPjMoves :: [TweakParam] -basicAmPjMoves = +basicAmPjMoves :: IM.IntMap TweakParam +basicAmPjMoves = IM.fromList . zip [0..] $ [spinDrag ,spinStart ,thrustParam ] spinDrag :: TweakParam -spinDrag = PjExtraUpdate - { _pjMoveParam = \i _ _ -> reduceSpinBy (1 - fromIntegral i*2 / 200) +spinDrag = TweakParam + { _doTweak = \i -> itParams . shellSpinDrag .~ i , _curTweak = 1 - , _pjDisplayParam = pjPadText "SPIN SLOWDOWN" . show - , _pjMaxParam = 5 + , _showTweak = pjPadText "SPIN SLOWDOWN" . show + , _maxTweak = 5 } pjPadText :: String -> String -> String pjPadText s = (rightPad 12 ' ' s ++ ) . (' ':) spinStart :: TweakParam -spinStart = PjExtraUpdate - { _pjMoveParam = \i _ cr -> pjEffAtTime 35 $ trySpinByCID (_crID cr) i +spinStart = TweakParam + { _doTweak = \i -> itParams . shellSpinAmount .~ i , _curTweak = 2 - , _pjDisplayParam = pjPadText "SPIN AMOUNT" . show - , _pjMaxParam = 5 + , _showTweak = pjPadText "SPIN AMOUNT" . show + , _maxTweak = 5 } thrustParam :: TweakParam -thrustParam = PjExtraUpdate - { _pjMoveParam = \i _ _ -> pjThrust i +thrustParam = TweakParam + { _doTweak = \i -> itParams . shellThrustDelay .~ i , _curTweak = 1 - , _pjDisplayParam = pjPadText "THRUST DELAY" . show - , _pjMaxParam = 5 + , _showTweak = pjPadText "THRUST DELAY" . show + , _maxTweak = 5 } pjThrust :: Int -> Prop -> World -> World @@ -151,12 +151,6 @@ aRocketWithItemParams it cr w = over props (IM.insert i theShell) w spindrag = _shellSpinDrag params spinamount = _shellSpinAmount params thrustdelay = _shellThrustDelay params - ammoMvs pj w' = - foldr (\pjP -> _pjMoveParam pjP (_curTweak pjP) it cr pj) w' - (filter ispjupdate $ _tweakParams $ _itParams it) - ispjupdate PjExtraUpdate {} = True - ispjupdate _ = False --- I feel like this might leak... theShell = defaultShell { _pjPos = pos , _pjStartPos = pos diff --git a/src/Dodge/Render/HUD.hs b/src/Dodge/Render/HUD.hs index ef1dcf10b..63b1c578c 100644 --- a/src/Dodge/Render/HUD.hs +++ b/src/Dodge/Render/HUD.hs @@ -76,7 +76,7 @@ topInvCursor col iPos cfig w ammoTweakStrings :: Item -> [String] ammoTweakStrings it = case it ^? itParams . tweakParams of - Just l -> map pjTweakString l + Just l -> map pjTweakString $ IM.elems l _ -> ["NOT TWEAKABLE"] mCurs :: Item -> Configuration -> World -> Picture @@ -94,7 +94,7 @@ mCurs it cfig w = case it ^? itParams . tweakSel of y = 155 pjTweakString :: TweakParam -> String -pjTweakString pj = _pjDisplayParam pj $ _curTweak pj +pjTweakString pj = _showTweak pj $ _curTweak pj displayMidList :: Configuration -> [String] -> String -> Picture displayMidList cfig strs s = invHead cfig s