Add roots and parents to adjacency function from Double Trees
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
module Dodge.Item.Grammar
|
||||
-- (invTree
|
||||
-- , indentInv
|
||||
-- )
|
||||
(invTrees
|
||||
, invIndentIM
|
||||
, invAdj
|
||||
)
|
||||
where
|
||||
import Control.Applicative
|
||||
import Data.Maybe
|
||||
@@ -22,12 +23,6 @@ type CIL = (ComposedItem,[(ComposeLinkType,ComposedItem)], [(ComposeLinkType,Com
|
||||
cisToItem :: ComposedItemStructure -> Item
|
||||
cisToItem (x,_,_,_) = x
|
||||
|
||||
singleDT :: a -> DoubleTree a
|
||||
singleDT x = DT x [] []
|
||||
|
||||
singleLDT :: a -> LabelDoubleTree b a
|
||||
singleLDT x = LDT x [] []
|
||||
|
||||
baseComposedItem :: ItemBaseType -> Item -> CIL
|
||||
baseComposedItem ibt itm = case ibt of
|
||||
HELD hit -> heldComposedItem itm hit
|
||||
@@ -56,9 +51,6 @@ baseCIS :: Item -> ComposedItemStructure
|
||||
baseCIS itm = let (a,b,c) = baseComposedItem (itm ^. itType . iyBase) itm
|
||||
in (itm, a, b, c)
|
||||
|
||||
type LDTTest a b = LabelDoubleTree b a -> LabelDoubleTree b a -> Maybe b
|
||||
type LDTCombine a b = LabelDoubleTree b a -> LabelDoubleTree b a -> b -> LabelDoubleTree b a
|
||||
|
||||
type LDTComb a b = LabelDoubleTree b a -> LabelDoubleTree b a -> Maybe (LabelDoubleTree b a)
|
||||
|
||||
-- the following imposes a strict ordering on the possible attachments
|
||||
@@ -100,8 +92,8 @@ invLDT :: IM.IntMap Item -> [LabelDoubleTree ComposeLinkType ComposedItemStructu
|
||||
invLDT = joinItemsInList (leftRightCombine leftIsParentCombine rightIsParentCombine) . IM.elems .
|
||||
fmap (singleLDT . baseCIS)
|
||||
|
||||
invAdj :: IM.IntMap Item -> IM.IntMap ([Int],[Int])
|
||||
invAdj = IM.unions . fmap (dtToUpDownAdj getid . ldtToDT) . invLDT
|
||||
invAdj :: IM.IntMap Item -> IM.IntMap (Maybe (Int,Int),[Int],[Int])
|
||||
invAdj = IM.unions . fmap (dtToLRAdj getid . ldtToDT) . invLDT
|
||||
where
|
||||
getid (itm, _,_,_) = fromMaybe (error "invAdj attempt to find item not in inventory") $
|
||||
itm ^? itLocation . ipInvID
|
||||
@@ -109,10 +101,7 @@ invAdj = IM.unions . fmap (dtToUpDownAdj getid . ldtToDT) . invLDT
|
||||
invIndentIM :: IM.IntMap Item -> IM.IntMap (Item,Int, LabelDoubleTreeNodeType ComposeLinkType )
|
||||
invIndentIM = IM.fromAscList . zip [0..] . reverse . map (over _1 cisToItem) . concatMap ldtToIndentList . invLDT
|
||||
|
||||
--invTrees :: IM.IntMap Item -> [(LabelDoubleTree ComposeLinkType Item)]
|
||||
invTrees :: IM.IntMap Item -> IM.IntMap (LabelDoubleTree ComposeLinkType Item)
|
||||
--invTrees = map (ldtToIM getindex) . map (fmap cisToItem) . invLDT
|
||||
--invTrees = map (ldtToIM getindex) . map (fmap cisToItem) . invLDT
|
||||
invTrees = IM.unions . map (ldtToIM getindex) . map (fmap cisToItem) . invLDT
|
||||
where
|
||||
getindex :: Item -> Int
|
||||
|
||||
Reference in New Issue
Block a user