From 24480bbe52e2e1e39ff772c9faa84d02ee36d26a Mon Sep 17 00:00:00 2001 From: justin Date: Sun, 28 Nov 2021 01:32:42 +0000 Subject: [PATCH] Commit before attempting to move some data into a "local" world type --- src/Dodge/Creature/Action.hs | 7 ++++++- src/Dodge/Creature/Impulse/UseItem.hs | 27 +++++++++++++++++++-------- src/Dodge/Creature/State.hs | 4 +--- src/Dodge/Data.hs | 1 + src/Dodge/Default/World.hs | 1 + src/Dodge/Hammer.hs | 7 ++++++- src/Dodge/Item/Weapon/SprayGuns.hs | 3 +++ src/Dodge/Item/Weapon/Utility.hs | 11 ++++++----- src/Dodge/Update.hs | 2 ++ src/Dodge/Update/UsingInput.hs | 5 ++--- 10 files changed, 47 insertions(+), 21 deletions(-) diff --git a/src/Dodge/Creature/Action.hs b/src/Dodge/Creature/Action.hs index 6e8c26ff5..48628bafd 100644 --- a/src/Dodge/Creature/Action.hs +++ b/src/Dodge/Creature/Action.hs @@ -6,6 +6,7 @@ module Dodge.Creature.Action , stripNoItems , setMinInvSize , dropUnselected + , dropExcept , startReloadingWeapon , blinkAction , sizeSelf @@ -215,13 +216,17 @@ organiseInvKeys cid w = w & creatures . ix cid %~ where cr = _creatures w IM.! cid pairs = IM.toList (_crInv cr) - newSelKey = fromJust $ findIndex ( (== _crInvSel cr) . fst) pairs + newSelKey = fromMaybe 0 $ findIndex ( (== _crInvSel cr) . fst) pairs newInv = IM.fromAscList $ zip [0..] $ map snd pairs dropUnselected :: Creature -> World -> World dropUnselected cr w = foldr (dropItem cr) w . IM.keys $ _crInvSel cr `IM.delete` _crInv cr +dropExcept :: Creature -> Int -> World -> World +dropExcept cr invid w = foldr (dropItem cr) w . IM.keys + $ invid `IM.delete` _crInv cr + dropItem :: Creature -> Int -> World -> World dropItem cr invid = rmInvItem cid invid . copyInvItemToFloor cr invid . mayberemoveequip where diff --git a/src/Dodge/Creature/Impulse/UseItem.hs b/src/Dodge/Creature/Impulse/UseItem.hs index 6205affc1..b7cebe3f9 100644 --- a/src/Dodge/Creature/Impulse/UseItem.hs +++ b/src/Dodge/Creature/Impulse/UseItem.hs @@ -8,7 +8,7 @@ import Dodge.Inventory import qualified Data.IntMap.Strict as IM import Control.Lens -import Data.Maybe +--import Data.Maybe useItem :: Int -> World -> World useItem cid w = itemEffect cr it w @@ -25,22 +25,33 @@ itemEffect :: Creature -> Item -> World -> World itemEffect cr Consumable{_cnEffect=eff } w = maybe w (rmSelectedInvItem (_crID cr)) (eff (_crID cr) w) itemEffect cr it w = case it ^? itUse of Just RightUse {_rUse = eff,_useMods = usemods} -> foldr ($) eff usemods it cr w - Just LeftUse {} -> w & creatures . ix (_crID cr) . crLeftInvSel ?~ _crInvSel cr + Just LeftUse {} -> w + & lSelHammerPosition .~ HammerDown + & docycle _ -> w + where + docycle | _lSelHammerPosition w == HammerUp = creatures . ix (_crID cr) . crLeftInvSel %~ cyclelsel + | otherwise = id + cyclelsel mi = case mi of + Just i | i == _crInvSel cr -> Nothing + _ -> Just $ _crInvSel cr --this is ugly useLeftItem :: Int -> World -> World useLeftItem cid w = case _crInv cr IM.! crinvsel ^? itUse . lUse of - Just f -> f cr crinvsel w & creatures . ix cid . crLeftInvSel ?~ crinvsel + Just f -> f cr crinvsel (w & creatures . ix cid . crLeftInvSel ?~ crinvsel) Nothing -> case _crLeftInvSel cr of Just invid -> case _itUse $ _crInv cr IM.! invid of LeftUse {_lUse = f} -> f cr invid w _ -> w & creatures . ix cid . crLeftInvSel .~ Nothing - Nothing -> case luse of - Nothing -> w - Just (invid, f) -> f cr invid w & creatures . ix cid . crLeftInvSel ?~ invid + Nothing -> w +-- Nothing -> case luse of +-- Nothing -> w +-- Just (invid, f) -> f cr invid w & creatures . ix cid . crLeftInvSel ?~ invid where crinvsel = _crInvSel cr cr = _creatures w IM.! cid - luses = IM.mapMaybe (^? itUse . lUse) (_crInv cr) - luse = listToMaybe $ IM.toList luses +-- luses = IM.mapMaybe (^? itUse . lUse) (_crInv cr) +-- luse = listToMaybe $ IM.toList luses +--the old code automatically selected the first unused item in the list: not +--sure if I want this behaviour, can probably set it as an option later diff --git a/src/Dodge/Creature/State.hs b/src/Dodge/Creature/State.hs index 33d093c8d..cf3225197 100644 --- a/src/Dodge/Creature/State.hs +++ b/src/Dodge/Creature/State.hs @@ -3,6 +3,7 @@ module Dodge.Creature.State , doDamage ) where import Dodge.Data +import Dodge.Hammer import Dodge.Base import Dodge.Creature.State.WalkCycle --import Dodge.Creature.Test @@ -129,9 +130,6 @@ invItemUpdate = itUse %~ useupdate useupdate = (useHammer . hammerPosition %~ moveHammerUp) . (useDelay . warmTime %~ decreaseToZero) . (useDelay . rateTime %~ decreaseToZero) - moveHammerUp HammerDown = HammerReleased - moveHammerUp HammerReleased = HammerUp - moveHammerUp HammerUp = HammerUp invSideEff :: Creature -> World -> World invSideEff cr w = weaponReloadSounds cr $ IM.foldrWithKey f w (_crInv cr) diff --git a/src/Dodge/Data.hs b/src/Dodge/Data.hs index 999b55125..b06f1f05b 100644 --- a/src/Dodge/Data.hs +++ b/src/Dodge/Data.hs @@ -117,6 +117,7 @@ data World = World , _rewindWorlds :: [World] , _rewinding :: Bool , _frameClock :: Int + , _lSelHammerPosition :: HammerPosition } data SaveSlot = QuicksaveSlot | LevelStartSlot diff --git a/src/Dodge/Default/World.hs b/src/Dodge/Default/World.hs index 86228d7e7..1f851468e 100644 --- a/src/Dodge/Default/World.hs +++ b/src/Dodge/Default/World.hs @@ -85,6 +85,7 @@ defaultWorld = World , _worldBounds = defaultBounds , _rewindWorlds = [] , _rewinding = False + , _lSelHammerPosition = HammerUp } youLight :: TempLightSource youLight = diff --git a/src/Dodge/Hammer.hs b/src/Dodge/Hammer.hs index c48f950ba..ef83f948f 100644 --- a/src/Dodge/Hammer.hs +++ b/src/Dodge/Hammer.hs @@ -1,3 +1,8 @@ module Dodge.Hammer where ---import Dodge.Item.Data +import Dodge.Item.Data + +moveHammerUp :: HammerPosition -> HammerPosition +moveHammerUp HammerDown = HammerReleased +moveHammerUp HammerReleased = HammerUp +moveHammerUp HammerUp = HammerUp diff --git a/src/Dodge/Item/Weapon/SprayGuns.hs b/src/Dodge/Item/Weapon/SprayGuns.hs index 66fe5fe88..add92322e 100644 --- a/src/Dodge/Item/Weapon/SprayGuns.hs +++ b/src/Dodge/Item/Weapon/SprayGuns.hs @@ -47,6 +47,7 @@ poisonSprayer = defaultAutoGun ] & useAim . aimSpeed .~ 0.2 & useAim . aimRange .~ 0 + & useAim . aimStance .~ TwoHandTwist , _wpRange = 8 , _itFloorPict = flamerPic , _itZoom = defaultItZoom @@ -64,12 +65,14 @@ flamer = defaultAutoGun } , _itUse = ruseInstant (\_ -> randWalkAngle 0.2 0.01 aFlame) NoHammer [ ammoCheckI + , useAmmo 1 , withSidePushI 5 --, withTempLight 1 100 (V3 1 0 0) , withSidePushAfterI 20 ] & useAim . aimSpeed .~ 0.5 & useAim . aimZoom .~ defaultItZoom {_itZoomMax = 5, _itZoomMin = 1.5} + & useAim . aimStance .~ TwoHandTwist , _wpSpread = 0 , _wpRange = 8 , _itFloorPict = flamerPic diff --git a/src/Dodge/Item/Weapon/Utility.hs b/src/Dodge/Item/Weapon/Utility.hs index 323a00fbc..1828b78a3 100644 --- a/src/Dodge/Item/Weapon/Utility.hs +++ b/src/Dodge/Item/Weapon/Utility.hs @@ -60,7 +60,7 @@ shrinkGun = defaultGun , _wpLoadedAmmo = 100 , _wpReloadTime = 20 } - , _itUse = defaultlUse {_lUse = hammerCheckL $ \cr invid -> useShrinkGun (_crInv cr IM.! invid) cr} + , _itUse = defaultlUse {_lUse = hammerCheckL useShrinkGun} & useHammer .~ upHammer , _wpSpread = 0.05 , _wpRange = 20 @@ -73,13 +73,14 @@ shrinkGunPic _ = noPic $ colorSH violet $ upperPrismPoly 5 $ square 5 -- be careful changing this around; potential problems include updating the -- creature but using the old crInvSel value -useShrinkGun :: Item -> Creature -> World -> World -useShrinkGun it cr w = if _itBool $ _itAttachment it - then tryResize 0.5 $ stripNoItems cr . f False UndroppableIdentified . dropUnselected cr +useShrinkGun :: Creature -> Int -> World -> World +useShrinkGun cr invid w = if _itBool $ _itAttachment it + then tryResize 0.5 $ stripNoItems cr . f False UndroppableIdentified . dropExcept cr invid else tryResize 1 $ f True Uncursed . setMinInvSize defaultInvSize cr where + it = _crInv cr IM.! invid tryResize x g = maybe w g $ sizeSelf x cr w - f isInUse cstatus = creatures . ix (_crID cr) . crInv . ix (_crInvSel cr) %~ + f isInUse cstatus = creatures . ix (_crID cr) . crInv . ix invid %~ ( (itAttachment . itBool .~ isInUse) . (itCurseStatus .~ cstatus) ) blinkGun :: Item diff --git a/src/Dodge/Update.hs b/src/Dodge/Update.hs index ed8a2a7f4..8399ce5e5 100644 --- a/src/Dodge/Update.hs +++ b/src/Dodge/Update.hs @@ -4,6 +4,7 @@ Description : Simulation update -} module Dodge.Update (update) where import Dodge.Data +import Dodge.Hammer import Dodge.Block import Dodge.Distortion import Dodge.SoundLogic @@ -65,6 +66,7 @@ functionalUpdate w = case _menuLayers w of . updateCreatureGroups . updateBlocks . updateSeenWalls + . (lSelHammerPosition %~ moveHammerUp) $ updateCloseObjects w where --updatedLightSources = mapMaybe (\b -> _tlsUpdate b w b) $ _tempLightSources w diff --git a/src/Dodge/Update/UsingInput.hs b/src/Dodge/Update/UsingInput.hs index c4efa5863..1391bf7f7 100644 --- a/src/Dodge/Update/UsingInput.hs +++ b/src/Dodge/Update/UsingInput.hs @@ -18,12 +18,11 @@ updateUsingInput w = if _carteDisplay w updatePressedButtons :: S.Set MouseButton -> World -> World updatePressedButtons pkeys w - | lbPressed && rbPressed - = useItem (_yourID w) w + | lbPressed && rbPressed = useItem (_yourID w) w | lbPressed = useLeftItem (_yourID w) w | lbPressed = w | mbPressed = w & clickMousePos .~ _mousePos w - & cameraRot -~ rotation + & cameraRot -~ rotation | otherwise = w where lbPressed = ButtonLeft `S.member` pkeys