Hack together correct positioning of grenades from attached items

This commit is contained in:
2025-06-28 22:32:12 +01:00
parent 6af2a8cc36
commit d88aed10c7
12 changed files with 225 additions and 178 deletions
+37 -3
View File
@@ -1,12 +1,16 @@
module Dodge.Item.Grammar (
invLDT,
invLDT',
invAdj,
invRootMap,
invRootTrees,
invRootTrees',
baseCI,
allInvLocs,
allInvLocs',
) where
import Dodge.Item.Orientation
import Dodge.ItemUseCondition
import Dodge.Data.UseCondition
import Dodge.Item.MagAmmoType
@@ -218,6 +222,9 @@ invLDT =
joinItemsInList tryAttachItems . IM.elems
. fmap (singleLDT . baseCI)
invLDT' :: IM.IntMap Item -> [LDTree ItemLink OItem]
invLDT' = fmap propagateOrientation . invLDT
-- this assumes the creature inventory is well formed, specifically the
-- location ids
-- consider explicitly reseting the inventory ids (but this probably really
@@ -243,15 +250,42 @@ invAdj = IM.unions . map g . invLDT
$ itm ^? itLocation . ilInvID
-- returns an intmap with trees for (only!) root items, indexed by inventory position
invRootTrees :: IM.IntMap Item -> IM.IntMap (LDTree ItemLink CItem)
invRootTrees = IM.fromDistinctAscList . reverse . map getid . invLDT
invRootTrees :: IM.IntMap Item -> IM.IntMap (LDTree ItemLink OItem)
invRootTrees = fmap propagateOrientation . IM.fromDistinctAscList . reverse . map getid . invLDT
where
getid :: LDTree ItemLink CItem -> (Int, LDTree ItemLink CItem)
getid t = (t ^?! ldtValue . _1 . itLocation . ilInvID, t)
invRootTrees' :: IM.IntMap Item -> IM.IntMap (LDTree ItemLink CItem)
invRootTrees' = IM.fromDistinctAscList . reverse . map getid . invLDT
where
getid :: LDTree ItemLink CItem -> (Int, LDTree ItemLink CItem)
getid t = (t ^?! ldtValue . _1 . itLocation . ilInvID, t)
-- returns an intmap with indents and locations for all items
allInvLocs :: IM.IntMap Item -> IM.IntMap (Int, LocationLDT ItemLink CItem)
allInvLocs :: IM.IntMap Item -> IM.IntMap (Int, LocationLDT ItemLink OItem)
allInvLocs inv = foldMap (f . LocLDT TopLDT) (IM.elems (invRootTrees inv)) mempty
where
f t = cldtPropagateFold h h g 0 t id
h x _ _ _ = x + 1
g ::
Int ->
LocationLDT ItemLink OItem ->
( IM.IntMap (Int, LocationLDT ItemLink OItem) ->
IM.IntMap (Int, LocationLDT ItemLink OItem)
) ->
IM.IntMap (Int, LocationLDT ItemLink OItem) ->
IM.IntMap (Int, LocationLDT ItemLink OItem)
g x ldt =
(.)
( IM.insert
(ldt ^?! locLDT . ldtValue . _1 . itLocation . ilInvID)
(x, ldt)
)
-- returns an intmap with indents and locations for all items
allInvLocs' :: IM.IntMap Item -> IM.IntMap (Int, LocationLDT ItemLink CItem)
allInvLocs' inv = foldMap (f . LocLDT TopLDT) (IM.elems (invRootTrees' inv)) mempty
where
f t = cldtPropagateFold h h g 0 t id
h x _ _ _ = x + 1