Remove duplicated selection/manipulation positions

Needs more testing to make sure it all works properly
This commit is contained in:
2026-05-14 20:40:46 +01:00
parent 06b984c2e5
commit c70097f1e1
15 changed files with 318 additions and 323 deletions
+2 -2
View File
@@ -27,14 +27,14 @@ yourSelectedItem w = do
yourRootItem :: World -> Maybe Item
yourRootItem w = do
i <- w ^? hud . manObject . imRootSelectedItem
i <- w ^? hud . manObject . hiRootSelectedItem
--revise1 i <- you w ^? crManipulation . manObject . imRootSelectedItem
j <- _crInv (you w) ^? ix i
w ^? cWorld . lWorld . items . ix j
yourRootItemDT :: World -> Maybe (DTree OItem)
yourRootItemDT w = do
i <- w^?hud. manObject . imRootSelectedItem . unNInt
i <- w^?hud. manObject . hiRootSelectedItem . unNInt
invIMDT ((\k -> w ^?! cWorld . lWorld . items . ix k) <$> you w ^. crInv) ^? ix i
yourInv :: World -> NewIntMap InvInt Item
+4 -4
View File
@@ -66,10 +66,10 @@ rightHandPQ w cr
| oneH w cr = (V3 11 (-3) 20, Q.qid)
| 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 . imAimStance
| Just TwoHandTwist <- w ^? hud . manObject . hiAimStance
--revise1 | Just TwoHandTwist <- cr ^? crManipulation . manObject . imAimStance
= (V3 6 (-6) 10, Q.qid)
| Just TwoHandFlat <- w ^? hud . manObject . imAimStance
| Just TwoHandFlat <- w ^? hud . manObject . hiAimStance
= (V3 (8 - twoHandOffY cr) (-8) 12, Q.qid)
| Just p <- crRightHandWall cr = (20 & _xy .~ p, Q.qid)
| otherwise = (handWalkingPos LeftForward (-8) cr, Q.qid)
@@ -120,10 +120,10 @@ leftHandPQ :: World -> Creature -> Point3Q
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 . imAimStance
| 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 . imAimStance
| Just TwoHandFlat <- w ^? hud . manObject . hiAimStance
= (V3 (8 + twoHandOffY cr) 6 12, Q.qid)
| Just p <- crLeftHandWall cr = (20 & _xy .~ p, Q.qid)
| oneH w cr = (V3 0 8 10, Q.qz 0.4)
+1 -1
View File
@@ -73,7 +73,7 @@ crCurrentEquipment lw = fmap f . _crEquipment
strFromHeldItem :: World -> Creature -> Int
strFromHeldItem w cr = fromMaybe 0 $ do
Aiming {} <- cr ^? crStance . posture
is <- w^?hud . manObject . imAttachedItems
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 -1
View File
@@ -86,7 +86,7 @@ crAwayFromPost cr = case _apGoal $ _crActionPlan cr of
crInAimStance :: AimStance -> World -> Creature -> Bool
crInAimStance as w cr = cr ^? crStance . posture == Just Aiming
&& w ^? hud . manObject . imAimStance == Just as
&& w ^? hud . manObject . hiAimStance == Just as
--revise1 && cr ^? crManipulation . manObject . imAimStance == Just as
oneH :: World -> Creature -> Bool
+2 -2
View File
@@ -128,7 +128,7 @@ wasdAim inp w cr
setposture x r =
cr
& crStance . posture .~ x
& doAimTwist (w ^? hud . manObject . imAimStance) r
& doAimTwist (w ^? hud . manObject . hiAimStance) r
--revise1 & doAimTwist (cr ^? crManipulation . manObject . imAimStance) r
mousedir = argV $ w ^. cWorld . lWorld . lAimPos - (cr ^. crPos . _xy)
@@ -156,7 +156,7 @@ aimTurn :: World -> Float -> Creature -> Creature
aimTurn lw a cr = creatureTurnTowardDir a (x * 0.2) cr
where
x = fromMaybe 1 $ do
itRef <- lw ^? hud . manObject . imRootSelectedItem
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
@@ -18,18 +18,24 @@ import Data.Aeson.TH
-- deriving (Eq, Ord, Show, Read) --Generic, Flat)
data ManipulatedObject
= SortInventory
| SelectedItem
{ _imRootSelectedItem :: NewInt InvInt
, _imAimStance :: AimStance
, _imAttachedItems :: IS.IntSet -- this should probably be NewIntSet InvInt also
= HeldItem
{ _hiRootSelectedItem :: NewInt InvInt
, _hiAimStance :: AimStance
, _hiAttachedItems :: IS.IntSet -- this should probably be NewIntSet InvInt also
}
| SelNothing
| SortCloseItem
| SelCloseItem {_ispCloseItem :: Int}
| SortCloseButton
| SelCloseButton {_ispCloseButton :: Int}
deriving (Eq, Ord, Show, Read) --Generic, Flat)
| HandsFree
-- = SortInventory
-- | SelectedItem
-- { _imRootSelectedItem :: NewInt InvInt
-- , _imAimStance :: AimStance
-- , _imAttachedItems :: IS.IntSet -- this should probably be NewIntSet InvInt also
-- }
-- | SelNothing
-- | SortCloseItem
-- | SelCloseItem {_ispCloseItem :: Int}
-- | SortCloseButton
-- | SelCloseButton {_ispCloseButton :: Int}
-- deriving (Eq, Ord, Show, Read) --Generic, Flat)
makeLenses ''ManipulatedObject
--makeLenses ''Manipulation
+1 -1
View File
@@ -320,7 +320,7 @@ drawCreatureRad cr = setLayer DebugLayer
showMuzzlePositions :: Universe -> Picture
showMuzzlePositions u = fold $ do
cr <- u ^? uvWorld . cWorld . lWorld . creatures . ix 0
invid <- u ^?uvWorld.hud . manObject . imRootSelectedItem . unNInt
invid <- u ^?uvWorld.hud . manObject . hiRootSelectedItem . unNInt
--revise1 invid <- cr ^? crManipulation . manObject . imRootSelectedItem . unNInt
loc <- invIndents ((\k -> u ^?! uvWorld . cWorld . lWorld . items . ix k) <$> _crInv cr)
^? ix invid . _2
+1 -1
View File
@@ -182,5 +182,5 @@ defaultHUD =
, _diCloseFilter = mempty
, _closeItems = mempty
, _closeButtons = mempty
, _manObject = SelNothing
, _manObject = HandsFree
}
+8 -5
View File
@@ -252,13 +252,14 @@ multiSelScroll' f w = fromMaybe w $ do
& hud . diSelection . _Just . slInt .~ k
changeSwapOther ::
((Int -> Identity Int) -> ManipulatedObject -> Identity ManipulatedObject) ->
--revise3 ((Int -> Identity Int) -> ManipulatedObject -> Identity ManipulatedObject) ->
Int ->
(Int -> IM.IntMap (SelectionItem ()) -> Maybe Int) ->
Int ->
World ->
World
changeSwapOther manlens n f i w = fromMaybe w $ do
--revise3 changeSwapOther manlens n f i w = fromMaybe w $ do
changeSwapOther n f i w = fromMaybe w $ do
ss <- w ^? hud . diSections . ix n . ssItems
k <- f i ss
let doswap j
@@ -268,7 +269,7 @@ changeSwapOther manlens n f i w = fromMaybe w $ do
return $
w
& swapAnyExtraSelection 3 i k
&hud. manObject . manlens %~ doswap
-- &hud. manObject . manlens %~ doswap
--revise1 & cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . manlens %~ doswap
& hud . closeItems %~ swapIndices i k
& hud . diSelection . _Just . slInt %~ doswap
@@ -281,8 +282,10 @@ swapItemWith ::
World
swapItemWith f (j, i) = case j of
0 -> swapInvItems f i
3 -> changeSwapOther ispCloseItem 3 f i
5 -> changeSwapOther ispCloseButton 5 f i
3 -> changeSwapOther 3 f i
5 -> changeSwapOther 5 f i
--revise3 3 -> changeSwapOther ispCloseItem 3 f i
--revise3 5 -> changeSwapOther ispCloseButton 5 f i
_ -> id
changeSwapWith :: (Int -> IM.IntMap (SelectionItem ()) -> Maybe Int) -> World -> World
+25 -28
View File
@@ -44,7 +44,7 @@ updateRootItemID m cr w = fromMaybe w $ do
Sel 0 i <- w^?hud.diSelection._Just
--revise2 i <- w^?hud . manObject . imSelectedItem . unNInt
let j = getRootItemInvID m i cr
return $ w & hud . manObject . imRootSelectedItem .~ NInt j
return $ w & hud . manObject . hiRootSelectedItem .~ NInt j
-- the following assumes that the crManipulation is correct
crUpdateItemLocations :: Int -> World -> World
@@ -76,10 +76,10 @@ crUpdateInvidLocations mo crid lw invid itm =
InInv
{ _ilCrID = crid
, _ilInvID = NInt invid
, _ilIsRoot = Just (NInt invid) == mo ^? imRootSelectedItem
, _ilIsRoot = Just (NInt invid) == mo ^? hiRootSelectedItem
, _ilIsSelected = Just (NInt invid) == lw ^? hud.diSelection._Just.slInt.to NInt -- this may match with the wrong sections, not sure if this is possible
--revise1 , _ilIsSelected = Just (NInt i2vid) == mo ^? imSelectedItem
, _ilIsAttached = invid `IS.member` (mo ^. imAttachedItems)
, _ilIsAttached = invid `IS.member` (mo ^. hiAttachedItems)
, _ilEquipSite = lw ^? cWorld .lWorld. items . ix itid . itLocation . ilEquipSite . _Just
--revise1 , _ilEquipSite = lw ^? items . ix itid . itLocation . ilEquipSite . _Just
}
@@ -91,29 +91,26 @@ setInvPosFromSS :: World -> World
setInvPosFromSS w = w &hud . manObject .~ thesel
--revise1 & cWorld . lWorld . creatures . ix 0 . crManipulation . manObject .~ thesel
where
thesel = fromMaybe SelNothing $ do
thesel = fromMaybe HandsFree $ do
--Sel i j _ <- w ^? hud . diSelection . _Just
Sel i j <- w ^? hud . diSelection . _Just
case i of
(-1) -> Just SortInventory
0 -> do
(rootid, aset) <-
tryGetRootAttachedFromInvID
(NInt j)
( fmap (\k -> w ^?! cWorld . lWorld . items . ix k) $
you w ^. crInv
)
dt <- invIMDT ((\k -> w ^?! cWorld . lWorld . items . ix k) <$> you w ^. crInv) ^? ix rootid
-- there is redundancy above
return
SelectedItem
{ _imRootSelectedItem = NInt rootid
, _imAimStance = itemAimStance ((\(x,y,_) -> (x,y)) <$> dt)
, _imAttachedItems = aset
}
1 -> Just SelNothing
2 -> Just SortCloseItem
3 -> Just $ SelCloseItem j
4 -> Just SortCloseButton
5 -> Just $ SelCloseButton j
_ -> error "selection out of bounds"
Sel 0 j <- w ^? hud . diSelection . _Just
(rootid, aset) <-
tryGetRootAttachedFromInvID
(NInt j)
( fmap (\k -> w ^?! cWorld . lWorld . items . ix k) $
you w ^. crInv
)
dt <- invIMDT ((\k -> w ^?! cWorld . lWorld . items . ix k) <$> you w ^. crInv) ^? ix rootid
-- there is redundancy above
return
HeldItem
{ _hiRootSelectedItem = NInt rootid
, _hiAimStance = itemAimStance ((\(x,y,_) -> (x,y)) <$> dt)
, _hiAttachedItems = aset
}
-- 1 -> Just SelNothing
-- 2 -> Just SortCloseItem
-- 3 -> Just $ SelCloseItem j
-- 4 -> Just SortCloseButton
-- 5 -> Just $ SelCloseButton j
-- _ -> error "selection out of bounds"
+1 -1
View File
@@ -20,7 +20,7 @@ itemEquipPict w cr itmtree
| Just esite <- itm ^? itLocation . ilEquipSite . _Just
, Just attachpos <- equipAttachPos <$> itm ^? itType . ibtEquip =
equipPosition esite w cr attachpos (itemSPic itm)
| itm ^? itLocation . ilInvID == w ^? hud . manObject . imRootSelectedItem =
| itm ^? itLocation . ilInvID == w ^? hud . manObject . hiRootSelectedItem =
--revise1 | itm ^? itLocation . ilInvID == cr ^? crManipulation . manObject . imRootSelectedItem =
overPosSP (Q.apply $ handHandleOrient w loc cr) (itemTreeSPic itmtree)
| otherwise = mempty
+1 -1
View File
@@ -34,7 +34,7 @@ pointerYourSelectedItem f w = fromMaybe (pure w) $ do
pointerYourRootItem :: Applicative a => (Item -> a Item) -> World -> a World
pointerYourRootItem f w = fromMaybe (pure w) $ do
itinvid <- w ^? hud. manObject . imRootSelectedItem
itinvid <- w ^? hud. manObject . hiRootSelectedItem
--revise1 itinvid <- w ^? cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . imRootSelectedItem
itid <- w ^? cWorld . lWorld . creatures . ix 0 . crInv . ix itinvid
Just $ (cWorld . lWorld . items . ix itid) f w
+8 -7
View File
@@ -127,19 +127,20 @@ topTestPart u =
]
showManObj :: ManipulatedObject -> String
showManObj SortInventory = "SortInventory"
showManObj (SelectedItem y as z) =
--showManObj SortInventory = "SortInventory"
showManObj (HeldItem y as z) =
" Root: "
++ show y
++ " Attached: "
++ show z
++ " AimStance: "
++ show as
showManObj SelNothing = "SelNothing"
showManObj SortCloseItem = "SortCloseItem"
showManObj (SelCloseItem x) = "CloseItem " ++ show x
showManObj SortCloseButton = "SortCloseButton"
showManObj (SelCloseButton x) = "CloseButton " ++ show x
showManObj HandsFree = "HandsFree"
--showManObj SelNothing = "SelNothing"
--showManObj SortCloseItem = "SortCloseItem"
--showManObj (SelCloseItem x) = "CloseItem " ++ show x
--showManObj SortCloseButton = "SortCloseButton"
--showManObj (SelCloseButton x) = "CloseButton " ++ show x
showTimeFlow :: TimeFlowStatus -> String
showTimeFlow tfs = case tfs of
+1 -1
View File
@@ -350,7 +350,7 @@ pushYouOutFromWalls u
-- rotate creature as well? behaviour on ledges?
muzzleWallCheck :: World -> Creature -> Creature
muzzleWallCheck w cr = fromMaybe cr $ do
invid <- w ^? hud . manObject . imRootSelectedItem . unNInt
invid <- w ^? hud . manObject . hiRootSelectedItem . unNInt
--revise1 invid <- cr ^? crManipulation . manObject . imRootSelectedItem . unNInt
loc <-
invIndents ((\k -> w ^?! cWorld . lWorld . items . ix k) <$> _crInv cr)
+245 -257
View File
File diff suppressed because it is too large Load Diff