Use NewIntMap InvInt for crInv
This commit is contained in:
+12
-11
@@ -9,6 +9,7 @@ module Dodge.Item.Grammar (
|
||||
invIndents,
|
||||
) where
|
||||
|
||||
import NewInt
|
||||
import Dodge.Item.Orientation
|
||||
import Dodge.ItemUseCondition
|
||||
import Dodge.Data.UseCondition
|
||||
@@ -212,22 +213,22 @@ joinItemsInList f = fst . h . ([],)
|
||||
Just w -> h ( zs,w : ys)
|
||||
|
||||
-- this puts the first elements in the intmap at the end of the list
|
||||
invDT :: IM.IntMap Item -> [DTree CItem]
|
||||
invDT :: NewIntMap InvInt Item -> [DTree CItem]
|
||||
invDT =
|
||||
joinItemsInList tryAttachItems . IM.elems
|
||||
joinItemsInList tryAttachItems . IM.elems . _unNIntMap
|
||||
. fmap (singleDT . baseCI)
|
||||
|
||||
invDT' :: IM.IntMap Item -> [DTree OItem]
|
||||
invDT' :: NewIntMap InvInt Item -> [DTree OItem]
|
||||
invDT' = fmap propagateOrientation' . invDT
|
||||
|
||||
-- this assumes the creature inventory is well formed, specifically the
|
||||
-- location ids
|
||||
-- consider explicitly reseting the inventory ids (but this probably really
|
||||
-- should be done upstream anyway in the actually creature inventory)
|
||||
invRootMap :: IM.IntMap Item -> IM.IntMap (Maybe Int, DTree Item)
|
||||
invRootMap :: NewIntMap InvInt Item -> IM.IntMap (Maybe Int, DTree Item)
|
||||
invRootMap =
|
||||
foldMap
|
||||
(dtToIntMapWithRoot (^?! itLocation . ilInvID) . fmap (^. _1) )
|
||||
(dtToIntMapWithRoot (^?! itLocation . ilInvID . unNInt) . fmap (^. _1) )
|
||||
. invDT
|
||||
|
||||
-- this assumes the creature inventory is well formed, specifically the
|
||||
@@ -235,24 +236,24 @@ invRootMap =
|
||||
-- consider explicitly reseting the inventory ids (but this probably really
|
||||
-- should be done upstream anyway in the actually creature inventory)
|
||||
-- The first Int in the maybe is the root, the second the parent
|
||||
invAdj :: IM.IntMap Item -> IM.IntMap (Maybe (Int, Int), [Int], [Int])
|
||||
invAdj :: NewIntMap InvInt Item -> IM.IntMap (Maybe (Int, Int), [Int], [Int])
|
||||
invAdj = IM.unions . map g . invDT
|
||||
where
|
||||
g = dtToLRAdj getid
|
||||
getid (itm, _) =
|
||||
fromMaybe
|
||||
(error ("invAdj item " ++ show (_itID itm) ++ " location: " ++ show (itm ^? itLocation)))
|
||||
$ itm ^? itLocation . ilInvID
|
||||
$ itm ^? itLocation . ilInvID . unNInt
|
||||
|
||||
---- returns an intmap with trees for (only!) root items, indexed by inventory position
|
||||
invIMDT :: IM.IntMap Item -> IM.IntMap (DTree OItem)
|
||||
invIMDT :: NewIntMap InvInt Item -> IM.IntMap (DTree OItem)
|
||||
invIMDT = fmap propagateOrientation' . IM.fromDistinctAscList . reverse . map getid . invDT
|
||||
where
|
||||
getid :: DTree CItem -> (Int, DTree CItem)
|
||||
getid t = (t ^?! dtValue . _1 . itLocation . ilInvID, t)
|
||||
getid t = (t ^?! dtValue . _1 . itLocation . ilInvID . unNInt, t)
|
||||
|
||||
---- returns an intmap with indents and locations for all items
|
||||
invIndents :: IM.IntMap Item -> IM.IntMap (Int, LocationDT OItem)
|
||||
invIndents :: NewIntMap InvInt Item -> IM.IntMap (Int, LocationDT OItem)
|
||||
invIndents inv = foldMap (f . LocDT TopDT) (IM.elems (invIMDT inv)) mempty
|
||||
where
|
||||
f t = cdtPropagateFold h h g 0 t id
|
||||
@@ -268,6 +269,6 @@ invIndents inv = foldMap (f . LocDT TopDT) (IM.elems (invIMDT inv)) mempty
|
||||
g x ldt =
|
||||
(.)
|
||||
( IM.insert
|
||||
(ldt ^?! locDT . dtValue . _1 . itLocation . ilInvID)
|
||||
(ldt ^?! locDT . dtValue . _1 . itLocation . ilInvID . unNInt)
|
||||
(x, ldt)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user