From 970858e1296fb47077221ed3d4b1f914586c841a Mon Sep 17 00:00:00 2001 From: justin Date: Wed, 8 Jun 2022 22:14:50 +0100 Subject: [PATCH] Cleanup --- src/Dodge/Combine.hs | 1 + src/Dodge/Creature/State.hs | 12 ++++++----- src/Dodge/Data.hs | 33 ++++++++++++++----------------- src/Dodge/Inventory.hs | 2 +- src/Dodge/Item/Equipment.hs | 16 +++++++-------- src/Dodge/Item/Weapon/Booster.hs | 6 +++--- src/Dodge/Item/Weapon/Grenade.hs | 6 +++--- src/Dodge/Item/Weapon/Launcher.hs | 2 +- src/Dodge/Render/HUD.hs | 3 ++- 9 files changed, 41 insertions(+), 40 deletions(-) diff --git a/src/Dodge/Combine.hs b/src/Dodge/Combine.hs index 55c6399fc..5b1ef7f76 100644 --- a/src/Dodge/Combine.hs +++ b/src/Dodge/Combine.hs @@ -86,6 +86,7 @@ combineTwoModuleMaps = mergeA g _ md EMPTYMODULE = ([],md) g _ md2 md1 = ([rm "REPLACES" md1 ++ rm " WITH" md2],md2) rm str md = str ++ " "++fullModuleName md +-- g above could be a monoid of some description... fullModuleName :: ItemModuleType -> String fullModuleName = fromMaybe "EMPTYMODULE" . moduleName diff --git a/src/Dodge/Creature/State.hs b/src/Dodge/Creature/State.hs index 6f9113545..688b5d459 100644 --- a/src/Dodge/Creature/State.hs +++ b/src/Dodge/Creature/State.hs @@ -211,12 +211,14 @@ equipmentEffects :: Creature -> World -> World equipmentEffects cr = flip (foldr $ useEquipment cr) (IM.keys $ _crInvEquipped cr) -- a loop going over all inventory items 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) where - f i it w' = doItemTargeting i cr w' & case it ^? itEffect . itInvEffect of - Nothing -> id - Just g -> g it cr + f i it w' = doItemTargeting i cr w' & maybe id (\g -> g it cr) (it ^? itEffect . ieInv) +-- Nothing -> id +-- Just g -> g it cr +-- f i it w' = doItemTargeting i cr w' & case it ^? itEffect . ieInv of +-- Nothing -> id +-- Just g -> g it cr itemUpdate :: Creature -> Int -> Item -> Item itemUpdate cr i diff --git a/src/Dodge/Data.hs b/src/Dodge/Data.hs index 3e924cb6f..839ddff92 100644 --- a/src/Dodge/Data.hs +++ b/src/Dodge/Data.hs @@ -436,8 +436,8 @@ data PressPlate = PressPlate } data FloorItem = FlIt { _flIt :: Item , _flItPos :: Point2 , _flItRot :: Float, _flItID :: Int} data ItemPos - = InInv { _itCrId :: Int , _itInvId :: Int } - | OnFloor { _itFlID :: Int } + = InInv { _ipCrId :: Int , _ipInvId :: Int } + | OnFloor { _ipFlID :: Int } data ItemUse = RightUse { _rUse :: Item -> Creature -> World -> World @@ -549,30 +549,27 @@ data ReloadType -- I believe this is called every frame, not sure when though data ItEffect = NoItEffect --- | ItSimpleInvEffect --- {_itInvEffect :: Item -> Creature -> World -> World --- } | ItInvEffect - {_itInvEffect :: Item -> Creature -> World -> World - ,_itEffectCounter :: Int + {_ieInv :: Item -> Creature -> World -> World + ,_ieCounter :: Int } | ItRewindEffect - {_itInvEffect :: Item -> Creature -> World -> World - ,_itStoredWorlds :: [World] + {_ieInv :: Item -> Creature -> World -> World + ,_ieStoredWorlds :: [World] } | ItEffect - {_itInvEffect :: Item -> Creature -> World -> World - ,_itFloorEffect :: Int -> World -> World - ,_itEffectCounter :: Int + {_ieInv :: Item -> Creature -> World -> World + ,_ieFloor :: Int -> World -> World + ,_ieCounter :: Int } | ItInvEffectID - {_itInvEffect :: Item -> Creature -> World -> World - ,_itEffectID :: Maybe Int - } + {_ieInv :: Item -> Creature -> World -> World + ,_ieMID :: Maybe Int + } -- the duplication of ieMID may cause errors... | ItInvEffectDrop - { _itInvEffect :: Item -> Creature -> World -> World - , _itEffectDrop :: Item -> Creature -> World -> World - , _itEffectMID :: Maybe Int + { _ieInv :: Item -> Creature -> World -> World + , _ieDrop :: Item -> Creature -> World -> World + , _ieMID :: Maybe Int } data IntID a = IntID Int a diff --git a/src/Dodge/Inventory.hs b/src/Dodge/Inventory.hs index ff60beee0..73840a809 100644 --- a/src/Dodge/Inventory.hs +++ b/src/Dodge/Inventory.hs @@ -70,7 +70,7 @@ rmInvItem cid invid w = case w ^? creatures . ix cid . crInv . ix invid . itCons rmf <- itm ^? itUse . eqEq . eqOnRemove return $ rmf itm cr doanyitemeffect = fromMaybe id $ do - rmf <- itm ^? itEffect . itEffectDrop + rmf <- itm ^? itEffect . ieDrop return $ rmf itm cr removeAnySlotEquipment = case w ^? creatures . ix cid . crInvEquipped . ix invid of Just epos -> creatures . ix cid . crEquipment . at epos .~ Nothing diff --git a/src/Dodge/Item/Equipment.hs b/src/Dodge/Item/Equipment.hs index d6b7b8654..7b49f3bbd 100644 --- a/src/Dodge/Item/Equipment.hs +++ b/src/Dodge/Item/Equipment.hs @@ -136,8 +136,8 @@ flatShieldEquipSPic _ = ) effectOnEquip :: (Creature -> Item -> World -> World) -> ItEffect effectOnEquip f = ItInvEffectID - { _itInvEffect = g f - , _itEffectID = Nothing + { _ieInv = g f + , _ieMID = Nothing } where g f' itm cr w @@ -167,9 +167,9 @@ shieldWallDamage dm _ crid w = case _dmType dm of _ -> w createShieldWall :: Creature -> Int -> World -> World -createShieldWall cr invid w = case _itEffectID $ _itEffect it of +createShieldWall cr invid w = case _ieMID $ _itEffect it of Nothing -> let (wlid,w') = createWall ((shieldWall crid) {_wlLine = wlline,_wlID = wlid}) w - in w' & creatures . ix crid . crInv . ix invid . itEffect . itEffectID ?~ wlid + in w' & creatures . ix crid . crInv . ix invid . itEffect . ieMID ?~ wlid Just wid -> moveWallID wid wlline w where crid = _crID cr @@ -183,10 +183,10 @@ createShieldWall cr invid w = case _itEffectID $ _itEffect it of therot | crIsAiming cr = vNormal | otherwise = rotateV (twoFlatHRot cr) . vNormal removeShieldWall :: Creature -> Int -> World -> World -removeShieldWall cr invid w = case _itEffectID $ _itEffect it of +removeShieldWall cr invid w = case _ieMID $ _itEffect it of Nothing -> w Just wid -> w & deleteWallID wid - & creatures . ix crid . crInv . ix invid . itEffect . itEffectID .~ Nothing + & creatures . ix crid . crInv . ix invid . itEffect . ieMID .~ Nothing where crid = _crID cr it = _crInv (_creatures w IM.! crid) IM.! invid @@ -196,8 +196,8 @@ effectOnOffHeld -> (Creature -> Int -> World -> World) -- ^ effect when not held -> ItEffect effectOnOffHeld f f' = ItInvEffectID - { _itInvEffect = g - , _itEffectID = Nothing + { _ieInv = g + , _ieMID = Nothing } where g itm cr w diff --git a/src/Dodge/Item/Weapon/Booster.hs b/src/Dodge/Item/Weapon/Booster.hs index 2f4647486..3cb4b5f4c 100644 --- a/src/Dodge/Item/Weapon/Booster.hs +++ b/src/Dodge/Item/Weapon/Booster.hs @@ -49,7 +49,7 @@ boostSelfL x itm cr w = case boostPoint x cr w of (crPos .~ p) . (crInv . ix invid %~ ammoEff - . (itEffect . itEffectCounter .~ 1) + . (itEffect . ieCounter .~ 1) . (itAttachment .~ ItInt pid) ) @@ -124,8 +124,8 @@ resetAttachmentID :: ItEffect resetAttachmentID = ItInvEffect f 0 where f itm cr w - | _itEffectCounter iteff < 0 = w & pointToIt . itAttachment .~ NoItAttachment - | otherwise = w & pointToIt . itEffect . itEffectCounter -~ 1 + | _ieCounter iteff < 0 = w & pointToIt . itAttachment .~ NoItAttachment + | otherwise = w & pointToIt . itEffect . ieCounter -~ 1 where iteff = _itEffect itm invid = fromJust $ _itInvPos itm diff --git a/src/Dodge/Item/Weapon/Grenade.hs b/src/Dodge/Item/Weapon/Grenade.hs index a67ad78c9..6f3b0b31f 100644 --- a/src/Dodge/Item/Weapon/Grenade.hs +++ b/src/Dodge/Item/Weapon/Grenade.hs @@ -117,16 +117,16 @@ throwGrenade thePayload cr w = setWp $ removePict $ over props addG w fuseTime = _itFuseTime $ _itAttachment $ _crInv cr IM.! j throwArmReset :: Int -> ItEffect -throwArmReset x = ItInvEffect {_itInvEffect = f ,_itEffectCounter = x } +throwArmReset x = ItInvEffect {_ieInv = f ,_ieCounter = x } where f itm cr = creatures . ix (_crID cr) . crInv %~ IM.adjust counterDown i where i = fromJust $ _itInvPos itm counterDown it - | _itEffectCounter (_itEffect it) == 0 = it + | _ieCounter (_itEffect it) == 0 = it & itUse . useHammer . hammerPosition .~ HammerUp & itEquipPict .~ pictureWeaponAim (\_ -> grenadePic 50) - | otherwise = it & itEffect . itEffectCounter -~ 1 + | otherwise = it & itEffect . ieCounter -~ 1 --flameGrenade :: Item --flameGrenade = grenade { diff --git a/src/Dodge/Item/Weapon/Launcher.hs b/src/Dodge/Item/Weapon/Launcher.hs index bec425d5a..7615f6eb3 100644 --- a/src/Dodge/Item/Weapon/Launcher.hs +++ b/src/Dodge/Item/Weapon/Launcher.hs @@ -324,7 +324,7 @@ moveRemoteShell cid itid pj w newPos = oldPos +.+ vel newdir | SDL.ButtonRight `S.member` _mouseButtons w - && w ^? creatures . ix cid . crInvSel == w ^? itemPositions . ix itid . itInvId + && w ^? creatures . ix cid . crInvSel == w ^? itemPositions . ix itid . ipInvId = _cameraRot w + argV (_mousePos w) | otherwise = _pjDir pj accel = rotateV newdir (V2 2 0) diff --git a/src/Dodge/Render/HUD.hs b/src/Dodge/Render/HUD.hs index 7a401c6a8..480e89618 100644 --- a/src/Dodge/Render/HUD.hs +++ b/src/Dodge/Render/HUD.hs @@ -116,7 +116,8 @@ subInventoryDisplay subinv cfig w = case subinv of where closeobjectcursor = case selectedCloseObject w of Nothing -> mempty - Just (i,co) -> listCursorNS clObjFloatIn 0 cfig (selNumPos i w) (closeObjectCol co) topInvW (invSelSize i w) + Just (i,co) -> listCursorNS + clObjFloatIn 0 cfig (selNumPos i w) (closeObjectCol co) topInvW (invSelSize i w) itcol = fromMaybe (greyN 0.5) (it ^? _Just . itInvColor) cr = you w it = yourItem w