Cleanup, prepare ground to allow for drawing attached items
This commit is contained in:
+19
-25
@@ -6,6 +6,8 @@ module Dodge.Item.Grammar (
|
||||
invRootMap,
|
||||
) where
|
||||
|
||||
import qualified Linear.Quaternion as Q
|
||||
import Geometry.Data
|
||||
import Control.Applicative
|
||||
--import TreeHelp
|
||||
|
||||
@@ -18,21 +20,22 @@ import Dodge.Data.Item
|
||||
import Dodge.DoubleTree
|
||||
import ListHelp
|
||||
|
||||
useBreakListsLinkTest :: [(ItemStructuralFunction,ComposeLinkType)]
|
||||
-> [(ItemStructuralFunction,ComposeLinkType)]
|
||||
-> LinkTest
|
||||
useBreakListsLinkTest llist rlist = LinkTest ltest rtest
|
||||
|
||||
useBreakListsLinkTest :: [(ItemStructuralFunction,a)]
|
||||
-> [(ItemStructuralFunction,a)]
|
||||
-> LinkTest a
|
||||
useBreakListsLinkTest llist rlist = LTest ltest rtest
|
||||
where
|
||||
ltest (_,sf,_) = do
|
||||
let xs = dropWhile ((/= sf) . fst) llist
|
||||
(_,linktype) <- safeHead xs
|
||||
return $ LinkUpdate linktype (set _3 (useBreakListsLinkTest (tail xs) rlist)) id
|
||||
return $ LUpdate linktype (set _3 (useBreakListsLinkTest (tail xs) rlist)) id
|
||||
rtest (_,sf,_) = do
|
||||
let xs = dropWhile ((/= sf) . fst) rlist
|
||||
(_,linktype) <- safeHead xs
|
||||
return $ LinkUpdate linktype (set _3 (useBreakListsLinkTest llist (tail xs))) id
|
||||
return $ LUpdate linktype (set _3 (useBreakListsLinkTest llist (tail xs))) id
|
||||
|
||||
basePartiallyComposedItem :: Item -> PartiallyComposedItem
|
||||
basePartiallyComposedItem :: Item -> PartiallyComposedItem ComposeLinkType
|
||||
basePartiallyComposedItem itm = case itm ^. itType of
|
||||
HELD _ -> (itm, WeaponPlatformSF, useBreakListsLinkTest
|
||||
(map (\(i,a) -> (AmmoMagSF a,AmmoInLink i a)) (IM.toList $ itm ^. itUse . heldAmmoTypes))
|
||||
@@ -40,24 +43,24 @@ basePartiallyComposedItem itm = case itm ^. itType of
|
||||
)
|
||||
AMMOMAG _ -> ammoComposedItem itm
|
||||
TARGETING {} -> (itm,WeaponTargetingSF, useBreakListsLinkTest [(AugmentedHUDSF,AugmentedHUDLink)] [])
|
||||
ATTACH ZOOMSCOPE -> (itm,WeaponScopeSF, LinkTest (const Nothing) (const Nothing))
|
||||
ATTACH HOMINGMODULE -> (itm,AmmoTargetingSF ProjectileAmmo, LinkTest (const Nothing) (const Nothing))
|
||||
ATTACH ZOOMSCOPE -> (itm,WeaponScopeSF, LTest (const Nothing) (const Nothing))
|
||||
ATTACH HOMINGMODULE -> (itm,AmmoTargetingSF ProjectileAmmo, LTest (const Nothing) (const Nothing))
|
||||
ATTACH AUGMENTEDHUD -> nolinks AugmentedHUDSF
|
||||
BULLETMOD BulletModTrajectory {} -> nolinks $ AmmoTargetingSF BulletAmmo
|
||||
BULLETMOD BulletModPayload {} -> nolinks $ AmmoPayloadSF BulletAmmo
|
||||
BULLETMOD BulletModEffect {} -> nolinks $ AmmoEffectSF BulletAmmo
|
||||
ATTACH REMOTESCREEN -> nolinks RemoteScreenSF
|
||||
ATTACH BULLETSYNTHESIZER -> (itm,AmmoModifierSF BulletAmmo, LinkTest (const Nothing) (const Nothing))
|
||||
ATTACH BULLETSYNTHESIZER -> (itm,AmmoModifierSF BulletAmmo, LTest (const Nothing) (const Nothing))
|
||||
LEFT {} -> isolate
|
||||
EQUIP {} -> isolate
|
||||
CONSUMABLE {} -> isolate
|
||||
CRAFT {} -> isolate
|
||||
-- _ ->
|
||||
where
|
||||
nolinks x = (itm,x, LinkTest (const Nothing) (const Nothing))
|
||||
isolate = (itm,UncomposableIsolateSF, LinkTest (const Nothing) (const Nothing))
|
||||
nolinks x = (itm,x, LTest (const Nothing) (const Nothing))
|
||||
isolate = (itm,UncomposableIsolateSF, LTest (const Nothing) (const Nothing))
|
||||
|
||||
ammoComposedItem :: Item -> PartiallyComposedItem
|
||||
ammoComposedItem :: Item -> PartiallyComposedItem ComposeLinkType
|
||||
ammoComposedItem itm = fromMaybe (error "in ammoComposedItem, wrong item") $ do
|
||||
atype <- itm ^? itUse . amagType
|
||||
return (itm
|
||||
@@ -74,13 +77,13 @@ ammoComposedItem itm = fromMaybe (error "in ammoComposedItem, wrong item") $ do
|
||||
|
||||
type LDTComb a b = LabelDoubleTree b a -> LabelDoubleTree b a -> Maybe (LabelDoubleTree b a)
|
||||
|
||||
leftIsParentCombine :: LDTComb PartiallyComposedItem ComposeLinkType
|
||||
leftIsParentCombine :: LDTComb (PartiallyComposedItem a) a
|
||||
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 ComposeLinkType
|
||||
rightIsParentCombine :: LDTComb (PartiallyComposedItem a) a
|
||||
rightIsParentCombine ltree rtree = do
|
||||
lu <- (rtree ^. ldtValue . _3 . tryLeftLink) (ltree ^. ldtValue)
|
||||
return $ rtree & ldtValue %~ (lu ^. luParentUpdate)
|
||||
@@ -111,20 +114,11 @@ joinItemsInList f xs = snd $ h (xs, [])
|
||||
Nothing -> h (ys, y : z : zs)
|
||||
Just w -> h (w : ys, zs)
|
||||
|
||||
invLDT :: IM.IntMap Item -> [LabelDoubleTree ComposeLinkType PartiallyComposedItem]
|
||||
invLDT :: IM.IntMap Item -> [LabelDoubleTree ComposeLinkType (PartiallyComposedItem ComposeLinkType)]
|
||||
invLDT =
|
||||
joinItemsInList (leftRightCombine leftIsParentCombine rightIsParentCombine) . IM.elems
|
||||
. fmap (singleLDT . basePartiallyComposedItem)
|
||||
|
||||
-- this has provoked an error: hopefully it will crop up at some point and get
|
||||
-- debugged with suitable info
|
||||
--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 item " ++ show (_itID itm) ++ " location:" ++ show (itm ^? itLocation . ilInvID)) )
|
||||
-- $ itm ^? itLocation . ilInvID
|
||||
|
||||
-- this assumes the creature inventory is well formed, specifically the
|
||||
-- location ids
|
||||
-- consider explicitly reseting the inventory ids (but this probably really
|
||||
|
||||
Reference in New Issue
Block a user