Commit before implementing positional inventory

This commit is contained in:
2023-05-18 09:52:46 +01:00
parent 7df81559d9
commit 2f0bb5115b
12 changed files with 132 additions and 78 deletions
+2 -21
View File
@@ -10,18 +10,15 @@ import Dodge.Hotkey
import Control.Lens
import Control.Monad
import Data.Foldable
import qualified Data.Map.Strict as M
import Data.Maybe
import Dodge.Cuse
import Dodge.Data.World
import Dodge.Euse
import Dodge.HeldUse
import Dodge.Inventory
import Dodge.Item.Location
import Dodge.Luse
import Dodge.Reloading
import qualified IntMapHelp as IM
import qualified SDL
useItemRightClick :: Creature -> World -> World
useItemRightClick cr' w = fromMaybe (f w) $ do
@@ -37,7 +34,6 @@ useItemRightClick cr' w = fromMaybe (f w) $ do
itemEffect :: Creature -> Item -> World -> World
itemEffect cr it w = case it ^. itUse of
HeldUse{_heldUse = eff, _heldMods = usemods} ->
--hammerTest $ tryReload cr it (_input w) $ foldl' (&) (useHeld eff) (useMod usemods) it cr
hammerTest $ foldl' (&) (useHeld eff) (useMod usemods) it cr
LeftUse{} -> doequipmentchange
EquipUse{} -> doequipmentchange
@@ -56,21 +52,6 @@ itemEffect cr it w = case it ^. itUse of
( toggleEquipmentAt itRef cr
)
tryReload :: Creature -> Item -> Input -> (World -> World) -> World -> World
tryReload cr it theinput f
| cid == 0 && itNeedsLoading it && _mouseButtons theinput M.!? SDL.ButtonLeft == Just 0 =
cWorld . lWorld . creatures . ix cid %~ crToggleReloading
| otherwise =
(runIdentity . pointerToItemLocation (_itLocation it) (return . (itUse . heldHammer .~ HammerDown)))
. f
where
cid = _crID cr
itNeedsLoading :: Item -> Bool
itNeedsLoading it = fromMaybe False $ do
internalammo <- it ^? itUse . heldConsumption . laSource . _InternalSource
return $ _iaLoaded internalammo == 0 || not (_iaPrimed internalammo)
toggleEquipmentAt :: Int -> Creature -> World -> World
toggleEquipmentAt invid cr w = case getEquipmentAllocation w of
DoNotMoveEquipment -> w
@@ -120,14 +101,14 @@ useItemLeftClick cr w = fromMaybe w $ do
invid <- cr ^? crManipulation . manObject . inInventory . ispItem
ituse <- cr ^? crInv . ix invid . itUse
case ituse of
HeldUse{} -> return $ hammerTest (cWorld . lWorld . creatures . ix (_crID cr) %~ crToggleReloading)
HeldUse{} -> return $ hammerTest (cWorld . lWorld . creatures . ix (_crID cr) %~ crUpdateLoadSource)
ConsumeUse{} -> return $ useItemRightClick cr w
EquipUse{} -> return $ useItemRightClick cr w
LeftUse{} -> return $ useItemRightClick cr w
_ -> Nothing
where
hammerTest f = case _crHammerPosition cr of
HammerUp -> f w
HammerUp -> f w & setuhamdown
_ -> w & setuhamdown
setuhamdown = cWorld . lWorld . creatures . ix (_crID cr) . crHammerPosition .~ HammerDown