Complete PartiallyComposedItem -> ComposedItem

This commit is contained in:
2024-11-29 10:43:08 +00:00
parent 7148051b31
commit 1b99b73f44
10 changed files with 38 additions and 48 deletions
+2 -2
View File
@@ -13,7 +13,7 @@ import Dodge.Data.Creature
import LensHelp
import Padding
itemDisplay :: Creature -> PartiallyComposedItem -> [String]
itemDisplay :: Creature -> ComposedItem -> [String]
itemDisplay cr ci =
zipWithDefaults id (leftPad 15 ' ') itemDisplayPad (basicItemDisplay itm) (itemNumberDisplay cr ci)
where
@@ -93,7 +93,7 @@ showAutoRechargeProgress lc = case lc of
-- where
-- ic = (itm ^?! itUse . heldConsumption . laSource)
itemNumberDisplay :: Creature -> PartiallyComposedItem -> [String]
itemNumberDisplay :: Creature -> ComposedItem -> [String]
itemNumberDisplay cr ci = case (ci ^. _2, itm ^?! itUse) of
(WeaponTargetingSF,_)
-> [maybe "" (const "!TARG!") (itm ^? itTargeting . itTgPos . _Just)]
+1 -1
View File
@@ -14,7 +14,7 @@ import Dodge.Item.Draw.SPic
import Dodge.Item.HeldOffset
import ShapePicture
itemEquipPict :: Creature -> LabelDoubleTree ItemLink PartiallyComposedItem -> SPic
itemEquipPict :: Creature -> LabelDoubleTree ItemLink ComposedItem -> SPic
itemEquipPict cr itmtree = case itm ^. itUse of
UseHeld{} | itm ^? itLocation . ilIsRoot == Just True
&& itm ^? itLocation . ilInvID == cr ^? crManipulation . manObject . imRootSelectedItem
+2 -2
View File
@@ -19,12 +19,12 @@ import Picture
import Shape
import ShapePicture
itemTreeSPic :: LabelDoubleTree ItemLink PartiallyComposedItem -> SPic
itemTreeSPic :: LabelDoubleTree ItemLink ComposedItem -> SPic
itemTreeSPic (LDT (itm,_,_) l r) =
itemSPic itm
<> foldMap (itemRotTreeSPic itm) (l <> r)
itemRotTreeSPic :: Item -> (ItemLink, LabelDoubleTree ItemLink PartiallyComposedItem)
itemRotTreeSPic :: Item -> (ItemLink, LabelDoubleTree ItemLink ComposedItem)
-> SPic
itemRotTreeSPic par (il, t) = translateSP p . overPosSP (Q.rotate q) $ itemTreeSPic t
where
+18 -18
View File
@@ -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))
+1 -1
View File
@@ -8,7 +8,7 @@ import Color
import Control.Lens
import Dodge.Data.ComposedItem
itemInvColor :: PartiallyComposedItem -> Color
itemInvColor :: ComposedItem -> Color
itemInvColor ci = case ci ^. _2 of
WeaponPlatformSF -> white
EquipmentPlatformSF -> yellow