Commit before attempting to move some data into a "local" world type
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -117,6 +117,7 @@ data World = World
|
||||
, _rewindWorlds :: [World]
|
||||
, _rewinding :: Bool
|
||||
, _frameClock :: Int
|
||||
, _lSelHammerPosition :: HammerPosition
|
||||
}
|
||||
|
||||
data SaveSlot = QuicksaveSlot | LevelStartSlot
|
||||
|
||||
@@ -85,6 +85,7 @@ defaultWorld = World
|
||||
, _worldBounds = defaultBounds
|
||||
, _rewindWorlds = []
|
||||
, _rewinding = False
|
||||
, _lSelHammerPosition = HammerUp
|
||||
}
|
||||
youLight :: TempLightSource
|
||||
youLight =
|
||||
|
||||
+6
-1
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user