Commit before attempting to move some data into a "local" world type

This commit is contained in:
2021-11-28 01:32:42 +00:00
parent 3e64e33232
commit 24480bbe52
10 changed files with 47 additions and 21 deletions
+6 -1
View File
@@ -6,6 +6,7 @@ module Dodge.Creature.Action
, stripNoItems , stripNoItems
, setMinInvSize , setMinInvSize
, dropUnselected , dropUnselected
, dropExcept
, startReloadingWeapon , startReloadingWeapon
, blinkAction , blinkAction
, sizeSelf , sizeSelf
@@ -215,13 +216,17 @@ organiseInvKeys cid w = w & creatures . ix cid %~
where where
cr = _creatures w IM.! cid cr = _creatures w IM.! cid
pairs = IM.toList (_crInv cr) 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 newInv = IM.fromAscList $ zip [0..] $ map snd pairs
dropUnselected :: Creature -> World -> World dropUnselected :: Creature -> World -> World
dropUnselected cr w = foldr (dropItem cr) w . IM.keys dropUnselected cr w = foldr (dropItem cr) w . IM.keys
$ _crInvSel cr `IM.delete` _crInv cr $ _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 :: Creature -> Int -> World -> World
dropItem cr invid = rmInvItem cid invid . copyInvItemToFloor cr invid . mayberemoveequip dropItem cr invid = rmInvItem cid invid . copyInvItemToFloor cr invid . mayberemoveequip
where where
+19 -8
View File
@@ -8,7 +8,7 @@ import Dodge.Inventory
import qualified Data.IntMap.Strict as IM import qualified Data.IntMap.Strict as IM
import Control.Lens import Control.Lens
import Data.Maybe --import Data.Maybe
useItem :: Int -> World -> World useItem :: Int -> World -> World
useItem cid w = itemEffect cr it w 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 Consumable{_cnEffect=eff } w = maybe w (rmSelectedInvItem (_crID cr)) (eff (_crID cr) w)
itemEffect cr it w = case it ^? itUse of itemEffect cr it w = case it ^? itUse of
Just RightUse {_rUse = eff,_useMods = usemods} -> foldr ($) eff usemods it cr w 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 _ -> 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 --this is ugly
useLeftItem :: Int -> World -> World useLeftItem :: Int -> World -> World
useLeftItem cid w = case _crInv cr IM.! crinvsel ^? itUse . lUse of 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 Nothing -> case _crLeftInvSel cr of
Just invid -> case _itUse $ _crInv cr IM.! invid of Just invid -> case _itUse $ _crInv cr IM.! invid of
LeftUse {_lUse = f} -> f cr invid w LeftUse {_lUse = f} -> f cr invid w
_ -> w & creatures . ix cid . crLeftInvSel .~ Nothing _ -> w & creatures . ix cid . crLeftInvSel .~ Nothing
Nothing -> case luse of Nothing -> w
Nothing -> w -- Nothing -> case luse of
Just (invid, f) -> f cr invid w & creatures . ix cid . crLeftInvSel ?~ invid -- Nothing -> w
-- Just (invid, f) -> f cr invid w & creatures . ix cid . crLeftInvSel ?~ invid
where where
crinvsel = _crInvSel cr crinvsel = _crInvSel cr
cr = _creatures w IM.! cid cr = _creatures w IM.! cid
luses = IM.mapMaybe (^? itUse . lUse) (_crInv cr) -- luses = IM.mapMaybe (^? itUse . lUse) (_crInv cr)
luse = listToMaybe $ IM.toList luses -- 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
+1 -3
View File
@@ -3,6 +3,7 @@ module Dodge.Creature.State
, doDamage , doDamage
) where ) where
import Dodge.Data import Dodge.Data
import Dodge.Hammer
import Dodge.Base import Dodge.Base
import Dodge.Creature.State.WalkCycle import Dodge.Creature.State.WalkCycle
--import Dodge.Creature.Test --import Dodge.Creature.Test
@@ -129,9 +130,6 @@ invItemUpdate = itUse %~ useupdate
useupdate = (useHammer . hammerPosition %~ moveHammerUp) useupdate = (useHammer . hammerPosition %~ moveHammerUp)
. (useDelay . warmTime %~ decreaseToZero) . (useDelay . warmTime %~ decreaseToZero)
. (useDelay . rateTime %~ decreaseToZero) . (useDelay . rateTime %~ decreaseToZero)
moveHammerUp HammerDown = HammerReleased
moveHammerUp HammerReleased = HammerUp
moveHammerUp HammerUp = HammerUp
invSideEff :: Creature -> World -> World invSideEff :: Creature -> World -> World
invSideEff cr w = weaponReloadSounds cr $ IM.foldrWithKey f w (_crInv cr) invSideEff cr w = weaponReloadSounds cr $ IM.foldrWithKey f w (_crInv cr)
+1
View File
@@ -117,6 +117,7 @@ data World = World
, _rewindWorlds :: [World] , _rewindWorlds :: [World]
, _rewinding :: Bool , _rewinding :: Bool
, _frameClock :: Int , _frameClock :: Int
, _lSelHammerPosition :: HammerPosition
} }
data SaveSlot = QuicksaveSlot | LevelStartSlot data SaveSlot = QuicksaveSlot | LevelStartSlot
+1
View File
@@ -85,6 +85,7 @@ defaultWorld = World
, _worldBounds = defaultBounds , _worldBounds = defaultBounds
, _rewindWorlds = [] , _rewindWorlds = []
, _rewinding = False , _rewinding = False
, _lSelHammerPosition = HammerUp
} }
youLight :: TempLightSource youLight :: TempLightSource
youLight = youLight =
+6 -1
View File
@@ -1,3 +1,8 @@
module Dodge.Hammer where module Dodge.Hammer where
--import Dodge.Item.Data import Dodge.Item.Data
moveHammerUp :: HammerPosition -> HammerPosition
moveHammerUp HammerDown = HammerReleased
moveHammerUp HammerReleased = HammerUp
moveHammerUp HammerUp = HammerUp
+3
View File
@@ -47,6 +47,7 @@ poisonSprayer = defaultAutoGun
] ]
& useAim . aimSpeed .~ 0.2 & useAim . aimSpeed .~ 0.2
& useAim . aimRange .~ 0 & useAim . aimRange .~ 0
& useAim . aimStance .~ TwoHandTwist
, _wpRange = 8 , _wpRange = 8
, _itFloorPict = flamerPic , _itFloorPict = flamerPic
, _itZoom = defaultItZoom , _itZoom = defaultItZoom
@@ -64,12 +65,14 @@ flamer = defaultAutoGun
} }
, _itUse = ruseInstant (\_ -> randWalkAngle 0.2 0.01 aFlame) NoHammer , _itUse = ruseInstant (\_ -> randWalkAngle 0.2 0.01 aFlame) NoHammer
[ ammoCheckI [ ammoCheckI
, useAmmo 1
, withSidePushI 5 , withSidePushI 5
--, withTempLight 1 100 (V3 1 0 0) --, withTempLight 1 100 (V3 1 0 0)
, withSidePushAfterI 20 , withSidePushAfterI 20
] ]
& useAim . aimSpeed .~ 0.5 & useAim . aimSpeed .~ 0.5
& useAim . aimZoom .~ defaultItZoom {_itZoomMax = 5, _itZoomMin = 1.5} & useAim . aimZoom .~ defaultItZoom {_itZoomMax = 5, _itZoomMin = 1.5}
& useAim . aimStance .~ TwoHandTwist
, _wpSpread = 0 , _wpSpread = 0
, _wpRange = 8 , _wpRange = 8
, _itFloorPict = flamerPic , _itFloorPict = flamerPic
+6 -5
View File
@@ -60,7 +60,7 @@ shrinkGun = defaultGun
, _wpLoadedAmmo = 100 , _wpLoadedAmmo = 100
, _wpReloadTime = 20 , _wpReloadTime = 20
} }
, _itUse = defaultlUse {_lUse = hammerCheckL $ \cr invid -> useShrinkGun (_crInv cr IM.! invid) cr} , _itUse = defaultlUse {_lUse = hammerCheckL useShrinkGun}
& useHammer .~ upHammer & useHammer .~ upHammer
, _wpSpread = 0.05 , _wpSpread = 0.05
, _wpRange = 20 , _wpRange = 20
@@ -73,13 +73,14 @@ shrinkGunPic _ = noPic $ colorSH violet $ upperPrismPoly 5 $ square 5
-- be careful changing this around; potential problems include updating the -- be careful changing this around; potential problems include updating the
-- creature but using the old crInvSel value -- creature but using the old crInvSel value
useShrinkGun :: Item -> Creature -> World -> World useShrinkGun :: Creature -> Int -> World -> World
useShrinkGun it cr w = if _itBool $ _itAttachment it useShrinkGun cr invid w = if _itBool $ _itAttachment it
then tryResize 0.5 $ stripNoItems cr . f False UndroppableIdentified . dropUnselected cr then tryResize 0.5 $ stripNoItems cr . f False UndroppableIdentified . dropExcept cr invid
else tryResize 1 $ f True Uncursed . setMinInvSize defaultInvSize cr else tryResize 1 $ f True Uncursed . setMinInvSize defaultInvSize cr
where where
it = _crInv cr IM.! invid
tryResize x g = maybe w g $ sizeSelf x cr w 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) ) ( (itAttachment . itBool .~ isInUse) . (itCurseStatus .~ cstatus) )
blinkGun :: Item blinkGun :: Item
+2
View File
@@ -4,6 +4,7 @@ Description : Simulation update
-} -}
module Dodge.Update (update) where module Dodge.Update (update) where
import Dodge.Data import Dodge.Data
import Dodge.Hammer
import Dodge.Block import Dodge.Block
import Dodge.Distortion import Dodge.Distortion
import Dodge.SoundLogic import Dodge.SoundLogic
@@ -65,6 +66,7 @@ functionalUpdate w = case _menuLayers w of
. updateCreatureGroups . updateCreatureGroups
. updateBlocks . updateBlocks
. updateSeenWalls . updateSeenWalls
. (lSelHammerPosition %~ moveHammerUp)
$ updateCloseObjects w $ updateCloseObjects w
where where
--updatedLightSources = mapMaybe (\b -> _tlsUpdate b w b) $ _tempLightSources w --updatedLightSources = mapMaybe (\b -> _tlsUpdate b w b) $ _tempLightSources w
+2 -3
View File
@@ -18,12 +18,11 @@ updateUsingInput w = if _carteDisplay w
updatePressedButtons :: S.Set MouseButton -> World -> World updatePressedButtons :: S.Set MouseButton -> World -> World
updatePressedButtons pkeys w updatePressedButtons pkeys w
| lbPressed && rbPressed | lbPressed && rbPressed = useItem (_yourID w) w
= useItem (_yourID w) w
| lbPressed = useLeftItem (_yourID w) w | lbPressed = useLeftItem (_yourID w) w
| lbPressed = w | lbPressed = w
| mbPressed = w & clickMousePos .~ _mousePos w | mbPressed = w & clickMousePos .~ _mousePos w
& cameraRot -~ rotation & cameraRot -~ rotation
| otherwise = w | otherwise = w
where where
lbPressed = ButtonLeft `S.member` pkeys lbPressed = ButtonLeft `S.member` pkeys