Cleanup inventory management, tweak dragging start

This commit is contained in:
2026-05-15 10:35:17 +01:00
parent 17f8707f62
commit e56a953c9b
23 changed files with 70 additions and 180 deletions
+1 -21
View File
@@ -159,22 +159,6 @@ performTurnToA cr p
dirv = p -.- cpos
jit = _mvTurnJit $ crMvType cr
--setMinInvSize :: Int -> Creature -> World -> World
--setMinInvSize n cr = cWorld . lWorld . creatures . ix (_crID cr) . crInvCapacity .~ n
--organiseInvKeys :: Int -> World -> World
--organiseInvKeys cid w =
-- w & cWorld . lWorld . creatures . ix cid
-- %~ ( (crInvSel . iselPos .~ newSelKey)
-- . (crInv .~ newInv)
-- . (crInvSel . iselAction .~ NoInvSelAction)
-- )
-- where
-- cr = w ^?! cWorld . lWorld . creatures . ix cid -- _creatures (_cWorld w) IM.! cid
-- pairs = IM.toList (_crInv cr)
-- newSelKey = fromMaybe 0 $ findIndex ((== crSel cr) . fst) pairs
-- newInv = IM.fromAscList $ zip [0 ..] $ map snd pairs
-- why not a cid (Int)?
dropItem :: Creature -> Int -> World -> World
dropItem cr invid w =
@@ -207,11 +191,7 @@ dropItem cr invid w =
-- | Get your creature to drop the item under the cursor.
youDropItem :: World -> World
youDropItem w = fromMaybe w $ do
curpos <-
mi
--revise2 w ^? hud . manObject . imSelectedItem . unNInt
--revise1 cr ^? crManipulation . manObject . imSelectedItem . unNInt
<|> fmap fst (IM.lookupMax (cr ^. crInv . unNIntMap))
curpos <- mi <|> fmap fst (IM.lookupMax (cr ^. crInv . unNIntMap))
guard $ not $ w ^. cWorld . lWorld . lInvLock
return $ case cr ^. crStance . posture of
Aiming{} -> throwItem w
-2
View File
@@ -67,7 +67,6 @@ rightHandPQ w cr
| twists w cr = (V3 0 5 20, Q.qz (-1)) `Q.comp` (V3 4 (-10) 0, Q.qz 1)
| twoFlat w cr = (V3 8 (-8) 12, Q.qid)
| Just TwoHandTwist <- w ^? hud . manObject . hiAimStance
--revise1 | Just TwoHandTwist <- cr ^? crManipulation . manObject . imAimStance
= (V3 6 (-6) 10, Q.qid)
| Just TwoHandFlat <- w ^? hud . manObject . hiAimStance
= (V3 (8 - twoHandOffY cr) (-8) 12, Q.qid)
@@ -121,7 +120,6 @@ leftHandPQ w cr
| twists w cr = (V3 0 5 20, Q.qz (-1)) `Q.comp` (V3 12 4 0, Q.qz 0.4)
| twoFlat w cr = (V3 8 8 12, Q.qid)
| Just TwoHandTwist <- w ^? hud . manObject . hiAimStance
--revise1 | Just TwoHandTwist <- cr ^? crManipulation . manObject . imAimStance
= (V3 (10 + twoHandOffY cr) 6 20, Q.qid)
| Just TwoHandFlat <- w ^? hud . manObject . hiAimStance
= (V3 (8 + twoHandOffY cr) 6 12, Q.qid)
-1
View File
@@ -74,7 +74,6 @@ strFromHeldItem :: World -> Creature -> Int
strFromHeldItem w cr = fromMaybe 0 $ do
Aiming {} <- cr ^? crStance . posture
is <- w^?hud . manObject . hiAttachedItems
--revise1 is <- cr ^? crManipulation . manObject . imAttachedItems
let js = IM.elems $ IM.restrictKeys (cr ^. crInv . unNIntMap) is
return . negate . sum . fmap itemWeight $ IM.restrictKeys (w ^.cWorld.lWorld. items) $ IS.fromList js
-1
View File
@@ -87,7 +87,6 @@ crAwayFromPost cr = case _apGoal $ _crActionPlan cr of
crInAimStance :: AimStance -> World -> Creature -> Bool
crInAimStance as w cr = cr ^? crStance . posture == Just Aiming
&& w ^? hud . manObject . hiAimStance == Just as
--revise1 && cr ^? crManipulation . manObject . imAimStance == Just as
oneH :: World -> Creature -> Bool
oneH = crInAimStance OneHand
+4 -12
View File
@@ -39,8 +39,6 @@ handleHotkeys w
| ispressed SDL.ScancodeLShift || ispressed SDL.ScancodeRShift
, (hk : _) <- mapMaybe scancodeToHotkey . M.keys $ pkeys
, Just (Sel 0 invid) <- w ^. hud .diSelection
--revise2 , Just invid <- w ^? hud . manObject . imSelectedItem
--revise1 , Just invid <- lw ^? creatures . ix 0 . crManipulation . manObject . imSelectedItem
, Just itid <- lw ^? creatures . ix 0 . crInv . ix (NInt invid) =
w & cWorld . lWorld %~ assignHotkey (NInt itid) hk
| ispressed SDL.ScancodeLCtrl || ispressed SDL.ScancodeRCtrl
@@ -118,18 +116,15 @@ wasdWithAiming w cr
wasdAim :: Input -> World -> Creature -> Creature
wasdAim inp w cr
| SDL.ButtonRight `M.member` _mouseButtons inp
, AtEase <- cr ^. crStance . posture =
setposture Aiming (-twoHandTwistAmount)
, AtEase <- cr ^. crStance . posture = setposture Aiming (-twistAmount)
| SDL.ButtonRight `M.member` _mouseButtons inp = aimTurn w mousedir cr
| Aiming{} <- cr ^. crStance . posture = setposture AtEase twoHandTwistAmount
-- | otherwise = creatureTurnTowardDir (_crMvAim cr) 0.2 cr
| Aiming{} <- cr ^. crStance . posture = setposture AtEase twistAmount
| otherwise = creatureTurnTowardDir (_crMvDir cr) 0.2 cr
where
setposture x r =
cr
& crStance . posture .~ x
& doAimTwist (w ^? hud . manObject . hiAimStance) r
--revise1 & doAimTwist (cr ^? crManipulation . manObject . imAimStance) r
mousedir = argV $ w ^. cWorld . lWorld . lAimPos - (cr ^. crPos . _xy)
doAimTwist :: Maybe AimStance -> Float -> Creature -> Creature
@@ -137,8 +132,8 @@ doAimTwist as x
| as == Just TwoHandTwist = crDir +~ x
| otherwise = id
twoHandTwistAmount :: Float
twoHandTwistAmount = 1.6 * pi
twistAmount :: Float
twistAmount = 1.6 * pi
wasdMovement :: World -> Input -> Camera -> Float -> Creature -> Creature
wasdMovement w inp cam speed = theMovement -- . setMvAim
@@ -157,7 +152,6 @@ aimTurn lw a cr = creatureTurnTowardDir a (x * 0.2) cr
where
x = fromMaybe 1 $ do
itRef <- lw ^? hud . manObject . hiRootSelectedItem
--revise1 itRef <- cr ^? crManipulation . manObject . imRootSelectedItem
fmap itemBulkiness $ cr ^? crInv . ix itRef >>= \k -> lw ^?cWorld.lWorld. items . ix k . itType
itemBulkiness :: ItemType -> Float
@@ -214,7 +208,5 @@ tryClickUse pkeys w = fromMaybe w $ do
rtime <- pkeys ^? ix SDL.ButtonRight
guard $ ltime <= rtime
case w ^.hud.diSelection of
--revise2 case w ^?hud. manObject . imSelectedItem . unNInt of
--revise1 case w ^? cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . imSelectedItem . unNInt of
Just (Sel 0 invid) -> useItem invid ltime w
_ -> interactWithCloseObj <$> getSelectedCloseObj w ?? w