Complete PartiallyComposedItem -> ComposedItem
This commit is contained in:
+18
-18
@@ -21,9 +21,9 @@ import LensHelp
|
||||
import ListHelp
|
||||
|
||||
tryAttachItems ::
|
||||
LabelDoubleTree ItemLink PartiallyComposedItem ->
|
||||
LabelDoubleTree ItemLink PartiallyComposedItem ->
|
||||
Maybe (LabelDoubleTree ItemLink PartiallyComposedItem)
|
||||
LabelDoubleTree ItemLink ComposedItem ->
|
||||
LabelDoubleTree ItemLink ComposedItem ->
|
||||
Maybe (LabelDoubleTree ItemLink ComposedItem)
|
||||
tryAttachItems = leftRightCombine leftIsParentCombine rightIsParentCombine
|
||||
|
||||
useBreakL ::
|
||||
@@ -100,7 +100,7 @@ itemToFunction itm = case itm ^. itType of
|
||||
EQUIP{} -> EquipmentPlatformSF
|
||||
_ -> UncomposableIsolateSF
|
||||
|
||||
basePCI :: Item -> PartiallyComposedItem
|
||||
basePCI :: Item -> ComposedItem
|
||||
basePCI itm = case _itType itm of
|
||||
_ -> (itm, itemToFunction itm, itemBaseConnections itm)
|
||||
|
||||
@@ -112,13 +112,13 @@ itemBaseConnections itm = case _itType itm of
|
||||
laserLinkTest :: Item -> LinkTest
|
||||
laserLinkTest itm = LTest (llleft itm) (llright itm)
|
||||
|
||||
llleft :: Item -> PartiallyComposedItem -> Maybe LinkUpdate
|
||||
llleft :: Item -> ComposedItem -> Maybe LinkUpdate
|
||||
llleft itm =
|
||||
_tryLeftLink
|
||||
. uncurry useBreakL
|
||||
$ itemToBreakLists itm WeaponTargetingSF
|
||||
|
||||
llright :: Item -> PartiallyComposedItem -> Maybe LinkUpdate
|
||||
llright :: Item -> ComposedItem -> Maybe LinkUpdate
|
||||
llright itm pci = case pci ^. _1 . itType of
|
||||
CRAFT TRANSFORMER -> Just (toLasgunUpdate itm)
|
||||
_ -> _tryRightLink (uncurry useBreakL $ itemToBreakLists itm WeaponTargetingSF) pci
|
||||
@@ -136,14 +136,14 @@ toLasgunUpdate itm =
|
||||
|
||||
type LDTComb a b = LabelDoubleTree b a -> LabelDoubleTree b a -> Maybe (LabelDoubleTree b a)
|
||||
|
||||
leftIsParentCombine :: LDTComb PartiallyComposedItem ItemLink
|
||||
leftIsParentCombine :: LDTComb ComposedItem ItemLink
|
||||
leftIsParentCombine ltree rtree = do
|
||||
lu <- (ltree ^. ldtValue . _3 . tryRightLink) (rtree ^. ldtValue)
|
||||
return $
|
||||
ltree & ldtValue %~ (lu ^. luParentUpdate)
|
||||
& ldtRight %~ (++ [(lu ^. luLinkType, rtree & ldtValue %~ (lu ^. luChildUpdate))])
|
||||
|
||||
rightIsParentCombine :: LDTComb PartiallyComposedItem ItemLink
|
||||
rightIsParentCombine :: LDTComb ComposedItem ItemLink
|
||||
rightIsParentCombine ltree rtree = do
|
||||
lu <- (rtree ^. ldtValue . _3 . tryLeftLink) (ltree ^. ldtValue)
|
||||
return $
|
||||
@@ -176,7 +176,7 @@ joinItemsInList f xs = snd $ h (xs, [])
|
||||
Just w -> h (w : ys, zs)
|
||||
|
||||
-- this puts the first elements in the intmap at the end of the list
|
||||
invLDT :: IM.IntMap Item -> [LabelDoubleTree ItemLink PartiallyComposedItem]
|
||||
invLDT :: IM.IntMap Item -> [LabelDoubleTree ItemLink ComposedItem]
|
||||
invLDT =
|
||||
joinItemsInList tryAttachItems . IM.elems
|
||||
. fmap (singleLDT . basePCI)
|
||||
@@ -215,23 +215,23 @@ invTrees' = IM.unions . map (ldtToIM getindex . fmap (^. _1)) . map (fmap (\(x,
|
||||
i ^? itLocation . ilInvID
|
||||
|
||||
-- returns an intmap with trees for (only!) root items, indexed by inventory position
|
||||
invRootTrees :: IM.IntMap Item -> IM.IntMap (LabelDoubleTree ItemLink PartiallyComposedItem)
|
||||
invRootTrees :: IM.IntMap Item -> IM.IntMap (LabelDoubleTree ItemLink ComposedItem)
|
||||
invRootTrees = IM.fromDistinctAscList . reverse . map (getid) . invLDT
|
||||
where
|
||||
getid :: LabelDoubleTree ItemLink PartiallyComposedItem
|
||||
-> (Int, LabelDoubleTree ItemLink PartiallyComposedItem)
|
||||
getid :: LabelDoubleTree ItemLink ComposedItem
|
||||
-> (Int, LabelDoubleTree ItemLink ComposedItem)
|
||||
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 PartiallyComposedItem)
|
||||
allInvLocs :: IM.IntMap Item -> IM.IntMap (Int, LocationLDT ItemLink ComposedItem)
|
||||
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 PartiallyComposedItem
|
||||
-> (IM.IntMap (Int, LocationLDT ItemLink PartiallyComposedItem)
|
||||
-> IM.IntMap (Int, LocationLDT ItemLink PartiallyComposedItem))
|
||||
-> IM.IntMap (Int, LocationLDT ItemLink PartiallyComposedItem)
|
||||
-> IM.IntMap (Int, LocationLDT ItemLink PartiallyComposedItem)
|
||||
g :: Int -> LocationLDT ItemLink ComposedItem
|
||||
-> (IM.IntMap (Int, LocationLDT ItemLink ComposedItem)
|
||||
-> IM.IntMap (Int, LocationLDT ItemLink ComposedItem))
|
||||
-> IM.IntMap (Int, LocationLDT ItemLink ComposedItem)
|
||||
-> IM.IntMap (Int, LocationLDT ItemLink ComposedItem)
|
||||
g x ldt = (.) (IM.insert (ldt ^?! locLDT . ldtValue . _1 . itLocation . ilInvID)
|
||||
(x, ldt))
|
||||
|
||||
Reference in New Issue
Block a user