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 :: World -> Maybe Item
yourRootItem w = do yourRootItem w = do
i <- w ^? hud . manObject . imRootSelectedItem i <- w ^? hud . manObject . hiRootSelectedItem
--revise1 i <- you w ^? crManipulation . manObject . imRootSelectedItem --revise1 i <- you w ^? crManipulation . manObject . imRootSelectedItem
j <- _crInv (you w) ^? ix i j <- _crInv (you w) ^? ix i
w ^? cWorld . lWorld . items . ix j w ^? cWorld . lWorld . items . ix j
yourRootItemDT :: World -> Maybe (DTree OItem) yourRootItemDT :: World -> Maybe (DTree OItem)
yourRootItemDT w = do 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 invIMDT ((\k -> w ^?! cWorld . lWorld . items . ix k) <$> you w ^. crInv) ^? ix i
yourInv :: World -> NewIntMap InvInt Item 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) | 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) | 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) | 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 --revise1 | Just TwoHandTwist <- cr ^? crManipulation . manObject . imAimStance
= (V3 6 (-6) 10, Q.qid) = (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) = (V3 (8 - twoHandOffY cr) (-8) 12, Q.qid)
| Just p <- crRightHandWall cr = (20 & _xy .~ p, Q.qid) | Just p <- crRightHandWall cr = (20 & _xy .~ p, Q.qid)
| otherwise = (handWalkingPos LeftForward (-8) cr, Q.qid) | otherwise = (handWalkingPos LeftForward (-8) cr, Q.qid)
@@ -120,10 +120,10 @@ leftHandPQ :: World -> Creature -> Point3Q
leftHandPQ w cr leftHandPQ w cr
| twists w cr = (V3 0 5 20, Q.qz (-1)) `Q.comp` (V3 12 4 0, Q.qz 0.4) | 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) | 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 --revise1 | Just TwoHandTwist <- cr ^? crManipulation . manObject . imAimStance
= (V3 (10 + twoHandOffY cr) 6 20, Q.qid) = (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) = (V3 (8 + twoHandOffY cr) 6 12, Q.qid)
| Just p <- crLeftHandWall cr = (20 & _xy .~ p, Q.qid) | Just p <- crLeftHandWall cr = (20 & _xy .~ p, Q.qid)
| oneH w cr = (V3 0 8 10, Q.qz 0.4) | 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 :: World -> Creature -> Int
strFromHeldItem w cr = fromMaybe 0 $ do strFromHeldItem w cr = fromMaybe 0 $ do
Aiming {} <- cr ^? crStance . posture Aiming {} <- cr ^? crStance . posture
is <- w^?hud . manObject . imAttachedItems is <- w^?hud . manObject . hiAttachedItems
--revise1 is <- cr ^? crManipulation . manObject . imAttachedItems --revise1 is <- cr ^? crManipulation . manObject . imAttachedItems
let js = IM.elems $ IM.restrictKeys (cr ^. crInv . unNIntMap) is let js = IM.elems $ IM.restrictKeys (cr ^. crInv . unNIntMap) is
return . negate . sum . fmap itemWeight $ IM.restrictKeys (w ^.cWorld.lWorld. items) $ IS.fromList js 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 :: AimStance -> World -> Creature -> Bool
crInAimStance as w cr = cr ^? crStance . posture == Just Aiming 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 --revise1 && cr ^? crManipulation . manObject . imAimStance == Just as
oneH :: World -> Creature -> Bool oneH :: World -> Creature -> Bool
+2 -2
View File
@@ -128,7 +128,7 @@ wasdAim inp w cr
setposture x r = setposture x r =
cr cr
& crStance . posture .~ x & crStance . posture .~ x
& doAimTwist (w ^? hud . manObject . imAimStance) r & doAimTwist (w ^? hud . manObject . hiAimStance) r
--revise1 & doAimTwist (cr ^? crManipulation . manObject . imAimStance) r --revise1 & doAimTwist (cr ^? crManipulation . manObject . imAimStance) r
mousedir = argV $ w ^. cWorld . lWorld . lAimPos - (cr ^. crPos . _xy) 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 aimTurn lw a cr = creatureTurnTowardDir a (x * 0.2) cr
where where
x = fromMaybe 1 $ do x = fromMaybe 1 $ do
itRef <- lw ^? hud . manObject . imRootSelectedItem itRef <- lw ^? hud . manObject . hiRootSelectedItem
--revise1 itRef <- cr ^? crManipulation . manObject . imRootSelectedItem --revise1 itRef <- cr ^? crManipulation . manObject . imRootSelectedItem
fmap itemBulkiness $ cr ^? crInv . ix itRef >>= \k -> lw ^?cWorld.lWorld. items . ix k . itType 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) -- deriving (Eq, Ord, Show, Read) --Generic, Flat)
data ManipulatedObject data ManipulatedObject
= SortInventory = HeldItem
| SelectedItem { _hiRootSelectedItem :: NewInt InvInt
{ _imRootSelectedItem :: NewInt InvInt , _hiAimStance :: AimStance
, _imAimStance :: AimStance , _hiAttachedItems :: IS.IntSet -- this should probably be NewIntSet InvInt also
, _imAttachedItems :: IS.IntSet -- this should probably be NewIntSet InvInt also
} }
| SelNothing | HandsFree
| SortCloseItem -- = SortInventory
| SelCloseItem {_ispCloseItem :: Int} -- | SelectedItem
| SortCloseButton -- { _imRootSelectedItem :: NewInt InvInt
| SelCloseButton {_ispCloseButton :: Int} -- , _imAimStance :: AimStance
deriving (Eq, Ord, Show, Read) --Generic, Flat) -- , _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 ''ManipulatedObject
--makeLenses ''Manipulation --makeLenses ''Manipulation
+1 -1
View File
@@ -320,7 +320,7 @@ drawCreatureRad cr = setLayer DebugLayer
showMuzzlePositions :: Universe -> Picture showMuzzlePositions :: Universe -> Picture
showMuzzlePositions u = fold $ do showMuzzlePositions u = fold $ do
cr <- u ^? uvWorld . cWorld . lWorld . creatures . ix 0 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 --revise1 invid <- cr ^? crManipulation . manObject . imRootSelectedItem . unNInt
loc <- invIndents ((\k -> u ^?! uvWorld . cWorld . lWorld . items . ix k) <$> _crInv cr) loc <- invIndents ((\k -> u ^?! uvWorld . cWorld . lWorld . items . ix k) <$> _crInv cr)
^? ix invid . _2 ^? ix invid . _2
+1 -1
View File
@@ -182,5 +182,5 @@ defaultHUD =
, _diCloseFilter = mempty , _diCloseFilter = mempty
, _closeItems = mempty , _closeItems = mempty
, _closeButtons = 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 & hud . diSelection . _Just . slInt .~ k
changeSwapOther :: changeSwapOther ::
((Int -> Identity Int) -> ManipulatedObject -> Identity ManipulatedObject) -> --revise3 ((Int -> Identity Int) -> ManipulatedObject -> Identity ManipulatedObject) ->
Int -> Int ->
(Int -> IM.IntMap (SelectionItem ()) -> Maybe Int) -> (Int -> IM.IntMap (SelectionItem ()) -> Maybe Int) ->
Int -> Int ->
World -> World ->
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 ss <- w ^? hud . diSections . ix n . ssItems
k <- f i ss k <- f i ss
let doswap j let doswap j
@@ -268,7 +269,7 @@ changeSwapOther manlens n f i w = fromMaybe w $ do
return $ return $
w w
& swapAnyExtraSelection 3 i k & swapAnyExtraSelection 3 i k
&hud. manObject . manlens %~ doswap -- &hud. manObject . manlens %~ doswap
--revise1 & cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . manlens %~ doswap --revise1 & cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . manlens %~ doswap
& hud . closeItems %~ swapIndices i k & hud . closeItems %~ swapIndices i k
& hud . diSelection . _Just . slInt %~ doswap & hud . diSelection . _Just . slInt %~ doswap
@@ -281,8 +282,10 @@ swapItemWith ::
World World
swapItemWith f (j, i) = case j of swapItemWith f (j, i) = case j of
0 -> swapInvItems f i 0 -> swapInvItems f i
3 -> changeSwapOther ispCloseItem 3 f i 3 -> changeSwapOther 3 f i
5 -> changeSwapOther ispCloseButton 5 f i 5 -> changeSwapOther 5 f i
--revise3 3 -> changeSwapOther ispCloseItem 3 f i
--revise3 5 -> changeSwapOther ispCloseButton 5 f i
_ -> id _ -> id
changeSwapWith :: (Int -> IM.IntMap (SelectionItem ()) -> Maybe Int) -> World -> World 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 Sel 0 i <- w^?hud.diSelection._Just
--revise2 i <- w^?hud . manObject . imSelectedItem . unNInt --revise2 i <- w^?hud . manObject . imSelectedItem . unNInt
let j = getRootItemInvID m i cr 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 -- the following assumes that the crManipulation is correct
crUpdateItemLocations :: Int -> World -> World crUpdateItemLocations :: Int -> World -> World
@@ -76,10 +76,10 @@ crUpdateInvidLocations mo crid lw invid itm =
InInv InInv
{ _ilCrID = crid { _ilCrID = crid
, _ilInvID = NInt invid , _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 , _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 --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 , _ilEquipSite = lw ^? cWorld .lWorld. items . ix itid . itLocation . ilEquipSite . _Just
--revise1 , _ilEquipSite = lw ^? 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 setInvPosFromSS w = w &hud . manObject .~ thesel
--revise1 & cWorld . lWorld . creatures . ix 0 . crManipulation . manObject .~ thesel --revise1 & cWorld . lWorld . creatures . ix 0 . crManipulation . manObject .~ thesel
where where
thesel = fromMaybe SelNothing $ do thesel = fromMaybe HandsFree $ do
--Sel i j _ <- w ^? hud . diSelection . _Just --Sel i j _ <- w ^? hud . diSelection . _Just
Sel i j <- w ^? hud . diSelection . _Just Sel 0 j <- w ^? hud . diSelection . _Just
case i of (rootid, aset) <-
(-1) -> Just SortInventory tryGetRootAttachedFromInvID
0 -> do (NInt j)
(rootid, aset) <- ( fmap (\k -> w ^?! cWorld . lWorld . items . ix k) $
tryGetRootAttachedFromInvID you w ^. crInv
(NInt j) )
( fmap (\k -> w ^?! cWorld . lWorld . items . ix k) $ dt <- invIMDT ((\k -> w ^?! cWorld . lWorld . items . ix k) <$> you w ^. crInv) ^? ix rootid
you w ^. crInv -- there is redundancy above
) return
dt <- invIMDT ((\k -> w ^?! cWorld . lWorld . items . ix k) <$> you w ^. crInv) ^? ix rootid HeldItem
-- there is redundancy above { _hiRootSelectedItem = NInt rootid
return , _hiAimStance = itemAimStance ((\(x,y,_) -> (x,y)) <$> dt)
SelectedItem , _hiAttachedItems = aset
{ _imRootSelectedItem = NInt rootid }
, _imAimStance = itemAimStance ((\(x,y,_) -> (x,y)) <$> dt) -- 1 -> Just SelNothing
, _imAttachedItems = aset -- 2 -> Just SortCloseItem
} -- 3 -> Just $ SelCloseItem j
1 -> Just SelNothing -- 4 -> Just SortCloseButton
2 -> Just SortCloseItem -- 5 -> Just $ SelCloseButton j
3 -> Just $ SelCloseItem j -- _ -> error "selection out of bounds"
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 esite <- itm ^? itLocation . ilEquipSite . _Just
, Just attachpos <- equipAttachPos <$> itm ^? itType . ibtEquip = , Just attachpos <- equipAttachPos <$> itm ^? itType . ibtEquip =
equipPosition esite w cr attachpos (itemSPic itm) 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 = --revise1 | itm ^? itLocation . ilInvID == cr ^? crManipulation . manObject . imRootSelectedItem =
overPosSP (Q.apply $ handHandleOrient w loc cr) (itemTreeSPic itmtree) overPosSP (Q.apply $ handHandleOrient w loc cr) (itemTreeSPic itmtree)
| otherwise = mempty | 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 :: Applicative a => (Item -> a Item) -> World -> a World
pointerYourRootItem f w = fromMaybe (pure w) $ do 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 --revise1 itinvid <- w ^? cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . imRootSelectedItem
itid <- w ^? cWorld . lWorld . creatures . ix 0 . crInv . ix itinvid itid <- w ^? cWorld . lWorld . creatures . ix 0 . crInv . ix itinvid
Just $ (cWorld . lWorld . items . ix itid) f w Just $ (cWorld . lWorld . items . ix itid) f w
+8 -7
View File
@@ -127,19 +127,20 @@ topTestPart u =
] ]
showManObj :: ManipulatedObject -> String showManObj :: ManipulatedObject -> String
showManObj SortInventory = "SortInventory" --showManObj SortInventory = "SortInventory"
showManObj (SelectedItem y as z) = showManObj (HeldItem y as z) =
" Root: " " Root: "
++ show y ++ show y
++ " Attached: " ++ " Attached: "
++ show z ++ show z
++ " AimStance: " ++ " AimStance: "
++ show as ++ show as
showManObj SelNothing = "SelNothing" showManObj HandsFree = "HandsFree"
showManObj SortCloseItem = "SortCloseItem" --showManObj SelNothing = "SelNothing"
showManObj (SelCloseItem x) = "CloseItem " ++ show x --showManObj SortCloseItem = "SortCloseItem"
showManObj SortCloseButton = "SortCloseButton" --showManObj (SelCloseItem x) = "CloseItem " ++ show x
showManObj (SelCloseButton x) = "CloseButton " ++ show x --showManObj SortCloseButton = "SortCloseButton"
--showManObj (SelCloseButton x) = "CloseButton " ++ show x
showTimeFlow :: TimeFlowStatus -> String showTimeFlow :: TimeFlowStatus -> String
showTimeFlow tfs = case tfs of showTimeFlow tfs = case tfs of
+1 -1
View File
@@ -350,7 +350,7 @@ pushYouOutFromWalls u
-- rotate creature as well? behaviour on ledges? -- rotate creature as well? behaviour on ledges?
muzzleWallCheck :: World -> Creature -> Creature muzzleWallCheck :: World -> Creature -> Creature
muzzleWallCheck w cr = fromMaybe cr $ do 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 --revise1 invid <- cr ^? crManipulation . manObject . imRootSelectedItem . unNInt
loc <- loc <-
invIndents ((\k -> w ^?! cWorld . lWorld . items . ix k) <$> _crInv cr) invIndents ((\k -> w ^?! cWorld . lWorld . items . ix k) <$> _crInv cr)
+245 -257
View File
File diff suppressed because it is too large Load Diff