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
-1
View File
@@ -9,7 +9,6 @@ module Dodge.Creature.Picture (
deadFeet, deadFeet,
) where ) where
import Dodge.Data.ComposedItem
import Control.Lens import Control.Lens
import Dodge.Creature.HandPos (translateToLeftHand, translateToRightHand) import Dodge.Creature.HandPos (translateToLeftHand, translateToRightHand)
import Dodge.Creature.Test import Dodge.Creature.Test
+8 -8
View File
@@ -174,7 +174,7 @@ invRootItemEffs cr =
(reduceLocLDT (Endo . invItemLocUpdate) . LocLDT TopLDT) (reduceLocLDT (Endo . invItemLocUpdate) . LocLDT TopLDT)
(invLDT (_crInv cr)) (invLDT (_crInv cr))
invItemLocUpdate :: LocationLDT ItemLink PartiallyComposedItem -> World -> World invItemLocUpdate :: LocationLDT ItemLink ComposedItem -> World -> World
invItemLocUpdate loc w = case itm ^. itType of invItemLocUpdate loc w = case itm ^. itType of
ATTACH BULLETSYNTH -> fromMaybe w $ do ATTACH BULLETSYNTH -> fromMaybe w $ do
i <- itm ^? itLocation . ilInvID i <- itm ^? itLocation . ilInvID
@@ -237,7 +237,7 @@ updateHeldRootItem cr = fromMaybe id $ do
itmtree <- invRootTrees (_crInv cr) ^? ix invid itmtree <- invRootTrees (_crInv cr) ^? ix invid
return $ updateAttachedItems itmtree cr return $ updateAttachedItems itmtree cr
updateAttachedItems :: LabelDoubleTree ItemLink PartiallyComposedItem -> Creature -> World -> World updateAttachedItems :: LabelDoubleTree ItemLink ComposedItem -> Creature -> World -> World
updateAttachedItems itmtree cr = updateAttachedItems itmtree cr =
cldtPropagateFold cldtPropagateFold
chainLinkOrientation chainLinkOrientation
@@ -249,9 +249,9 @@ updateAttachedItems itmtree cr =
-- need to check rotation -- need to check rotation
chainLinkOrientation :: chainLinkOrientation ::
(Point3, Q.Quaternion Float) -> (Point3, Q.Quaternion Float) ->
PartiallyComposedItem -> ComposedItem ->
ItemLink -> ItemLink ->
PartiallyComposedItem -> ComposedItem ->
(Point3, Q.Quaternion Float) (Point3, Q.Quaternion Float)
chainLinkOrientation mo (par, _, _) (ILink lt f) (child, _, _) = chainLinkOrientation mo (par, _, _) (ILink lt f) (child, _, _) =
(p + Q.rotate q p1, q * q1) (p + Q.rotate q p1, q * q1)
@@ -262,7 +262,7 @@ chainLinkOrientation mo (par, _, _) (ILink lt f) (child, _, _) =
updateItemWithOrientation :: updateItemWithOrientation ::
Creature -> Creature ->
(Point3, Q.Quaternion Float) -> (Point3, Q.Quaternion Float) ->
LocationLDT ItemLink PartiallyComposedItem -> LocationLDT ItemLink ComposedItem ->
World -> World ->
World World
updateItemWithOrientation cr m loc@(LocLDT _ itmtree) = updateItemWithOrientation cr m loc@(LocLDT _ itmtree) =
@@ -276,14 +276,14 @@ updateItemWithOrientation cr m loc@(LocLDT _ itmtree) =
ci = itmtree ^. ldtValue ci = itmtree ^. ldtValue
itm = ci ^. _1 itm = ci ^. _1
drawAugmentedHUD :: LocationLDT ItemLink PartiallyComposedItem -> World -> World drawAugmentedHUD :: LocationLDT ItemLink ComposedItem -> World -> World
drawAugmentedHUD (LocLDT con _) w = fromMaybe w $ do drawAugmentedHUD (LocLDT con _) w = fromMaybe w $ do
itm <- con ^? cldtParent . _1 itm <- con ^? cldtParent . _1
return $ w & cWorld . lWorld . flares <>~ drawTargeting itm w return $ w & cWorld . lWorld . flares <>~ drawTargeting itm w
shineTargetLaser :: shineTargetLaser ::
Creature -> Creature ->
LabelDoubleTree ItemLink PartiallyComposedItem -> LabelDoubleTree ItemLink ComposedItem ->
(Point3, Q.Quaternion Float) -> (Point3, Q.Quaternion Float) ->
World -> World ->
World World
@@ -325,7 +325,7 @@ shineTargetLaser cr itmtree (p, q) w = fromMaybe (w & pointittarg . itTgPos .~ N
shineTorch :: shineTorch ::
Creature -> Creature ->
LabelDoubleTree ItemLink PartiallyComposedItem -> LabelDoubleTree ItemLink ComposedItem ->
(Point3, Q.Quaternion Float) -> (Point3, Q.Quaternion Float) ->
World -> World ->
World World
+5 -13
View File
@@ -8,7 +8,6 @@ module Dodge.Data.ComposedItem where
import Control.Lens import Control.Lens
import Data.Aeson import Data.Aeson
import Data.Aeson.TH import Data.Aeson.TH
-- it would be nice not to have to import the following...
import Dodge.Data.Item import Dodge.Data.Item
import Geometry.Data import Geometry.Data
import Linear.Quaternion (Quaternion (..)) import Linear.Quaternion (Quaternion (..))
@@ -42,12 +41,7 @@ data ItemStructuralFunction
| FunctionChangeSF | FunctionChangeSF
deriving (Eq, Ord, Show, Read) deriving (Eq, Ord, Show, Read)
type PartiallyComposedItem = (Item, ItemStructuralFunction, LinkTest) type ComposedItem = (Item, ItemStructuralFunction, LinkTest)
--data ComposedItem = CItem
-- { _cItem :: Item
-- , _cItemFunction :: ItemStructuralFunction
-- }
data ItemLink = ILink data ItemLink = ILink
{ _iatType :: ComposeLinkType { _iatType :: ComposeLinkType
@@ -55,20 +49,18 @@ data ItemLink = ILink
} }
data LinkTest = LTest data LinkTest = LTest
{ _tryLeftLink :: PartiallyComposedItem -> Maybe LinkUpdate { _tryLeftLink :: ComposedItem -> Maybe LinkUpdate
, _tryRightLink :: PartiallyComposedItem -> Maybe LinkUpdate , _tryRightLink :: ComposedItem -> Maybe LinkUpdate
} }
data LinkUpdate = LUpdate data LinkUpdate = LUpdate
{ _luLinkType :: ItemLink { _luLinkType :: ItemLink
, _luParentUpdate :: PartiallyComposedItem -> PartiallyComposedItem , _luParentUpdate :: ComposedItem -> ComposedItem
, _luChildUpdate :: PartiallyComposedItem -> PartiallyComposedItem , _luChildUpdate :: ComposedItem -> ComposedItem
} }
--makeLenses ''ComposedItem
makeLenses ''ItemLink makeLenses ''ItemLink
makeLenses ''LinkTest makeLenses ''LinkTest
makeLenses ''LinkUpdate makeLenses ''LinkUpdate
deriveJSON defaultOptions ''ItemStructuralFunction deriveJSON defaultOptions ''ItemStructuralFunction
--deriveJSON defaultOptions ''ComposedItem
deriveJSON defaultOptions ''ComposeLinkType deriveJSON defaultOptions ''ComposeLinkType
+1 -1
View File
@@ -19,7 +19,7 @@ import NewInt
import Padding import Padding
import Picture.Base import Picture.Base
invSelectionItem :: Int -> Creature -> Int -> PartiallyComposedItem -> SelectionItem () invSelectionItem :: Int -> Creature -> Int -> ComposedItem -> SelectionItem ()
invSelectionItem indent cr i ci = invSelectionItem indent cr i ci =
SelectionItem SelectionItem
{ _siPictures = pics & ix 0 %~ (++ anyequippos ++ anyhotkey) { _siPictures = pics & ix 0 %~ (++ anyequippos ++ anyhotkey)
+2 -2
View File
@@ -13,7 +13,7 @@ import Dodge.Data.Creature
import LensHelp import LensHelp
import Padding import Padding
itemDisplay :: Creature -> PartiallyComposedItem -> [String] itemDisplay :: Creature -> ComposedItem -> [String]
itemDisplay cr ci = itemDisplay cr ci =
zipWithDefaults id (leftPad 15 ' ') itemDisplayPad (basicItemDisplay itm) (itemNumberDisplay cr ci) zipWithDefaults id (leftPad 15 ' ') itemDisplayPad (basicItemDisplay itm) (itemNumberDisplay cr ci)
where where
@@ -93,7 +93,7 @@ showAutoRechargeProgress lc = case lc of
-- where -- where
-- ic = (itm ^?! itUse . heldConsumption . laSource) -- ic = (itm ^?! itUse . heldConsumption . laSource)
itemNumberDisplay :: Creature -> PartiallyComposedItem -> [String] itemNumberDisplay :: Creature -> ComposedItem -> [String]
itemNumberDisplay cr ci = case (ci ^. _2, itm ^?! itUse) of itemNumberDisplay cr ci = case (ci ^. _2, itm ^?! itUse) of
(WeaponTargetingSF,_) (WeaponTargetingSF,_)
-> [maybe "" (const "!TARG!") (itm ^? itTargeting . itTgPos . _Just)] -> [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 Dodge.Item.HeldOffset
import ShapePicture import ShapePicture
itemEquipPict :: Creature -> LabelDoubleTree ItemLink PartiallyComposedItem -> SPic itemEquipPict :: Creature -> LabelDoubleTree ItemLink ComposedItem -> SPic
itemEquipPict cr itmtree = case itm ^. itUse of itemEquipPict cr itmtree = case itm ^. itUse of
UseHeld{} | itm ^? itLocation . ilIsRoot == Just True UseHeld{} | itm ^? itLocation . ilIsRoot == Just True
&& itm ^? itLocation . ilInvID == cr ^? crManipulation . manObject . imRootSelectedItem && itm ^? itLocation . ilInvID == cr ^? crManipulation . manObject . imRootSelectedItem
+2 -2
View File
@@ -19,12 +19,12 @@ import Picture
import Shape import Shape
import ShapePicture import ShapePicture
itemTreeSPic :: LabelDoubleTree ItemLink PartiallyComposedItem -> SPic itemTreeSPic :: LabelDoubleTree ItemLink ComposedItem -> SPic
itemTreeSPic (LDT (itm,_,_) l r) = itemTreeSPic (LDT (itm,_,_) l r) =
itemSPic itm itemSPic itm
<> foldMap (itemRotTreeSPic itm) (l <> r) <> foldMap (itemRotTreeSPic itm) (l <> r)
itemRotTreeSPic :: Item -> (ItemLink, LabelDoubleTree ItemLink PartiallyComposedItem) itemRotTreeSPic :: Item -> (ItemLink, LabelDoubleTree ItemLink ComposedItem)
-> SPic -> SPic
itemRotTreeSPic par (il, t) = translateSP p . overPosSP (Q.rotate q) $ itemTreeSPic t itemRotTreeSPic par (il, t) = translateSP p . overPosSP (Q.rotate q) $ itemTreeSPic t
where where
+18 -18
View File
@@ -21,9 +21,9 @@ import LensHelp
import ListHelp import ListHelp
tryAttachItems :: tryAttachItems ::
LabelDoubleTree ItemLink PartiallyComposedItem -> LabelDoubleTree ItemLink ComposedItem ->
LabelDoubleTree ItemLink PartiallyComposedItem -> LabelDoubleTree ItemLink ComposedItem ->
Maybe (LabelDoubleTree ItemLink PartiallyComposedItem) Maybe (LabelDoubleTree ItemLink ComposedItem)
tryAttachItems = leftRightCombine leftIsParentCombine rightIsParentCombine tryAttachItems = leftRightCombine leftIsParentCombine rightIsParentCombine
useBreakL :: useBreakL ::
@@ -100,7 +100,7 @@ itemToFunction itm = case itm ^. itType of
EQUIP{} -> EquipmentPlatformSF EQUIP{} -> EquipmentPlatformSF
_ -> UncomposableIsolateSF _ -> UncomposableIsolateSF
basePCI :: Item -> PartiallyComposedItem basePCI :: Item -> ComposedItem
basePCI itm = case _itType itm of basePCI itm = case _itType itm of
_ -> (itm, itemToFunction itm, itemBaseConnections itm) _ -> (itm, itemToFunction itm, itemBaseConnections itm)
@@ -112,13 +112,13 @@ itemBaseConnections itm = case _itType itm of
laserLinkTest :: Item -> LinkTest laserLinkTest :: Item -> LinkTest
laserLinkTest itm = LTest (llleft itm) (llright itm) laserLinkTest itm = LTest (llleft itm) (llright itm)
llleft :: Item -> PartiallyComposedItem -> Maybe LinkUpdate llleft :: Item -> ComposedItem -> Maybe LinkUpdate
llleft itm = llleft itm =
_tryLeftLink _tryLeftLink
. uncurry useBreakL . uncurry useBreakL
$ itemToBreakLists itm WeaponTargetingSF $ itemToBreakLists itm WeaponTargetingSF
llright :: Item -> PartiallyComposedItem -> Maybe LinkUpdate llright :: Item -> ComposedItem -> Maybe LinkUpdate
llright itm pci = case pci ^. _1 . itType of llright itm pci = case pci ^. _1 . itType of
CRAFT TRANSFORMER -> Just (toLasgunUpdate itm) CRAFT TRANSFORMER -> Just (toLasgunUpdate itm)
_ -> _tryRightLink (uncurry useBreakL $ itemToBreakLists itm WeaponTargetingSF) pci _ -> _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) 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 leftIsParentCombine ltree rtree = do
lu <- (ltree ^. ldtValue . _3 . tryRightLink) (rtree ^. ldtValue) lu <- (ltree ^. ldtValue . _3 . tryRightLink) (rtree ^. ldtValue)
return $ return $
ltree & ldtValue %~ (lu ^. luParentUpdate) ltree & ldtValue %~ (lu ^. luParentUpdate)
& ldtRight %~ (++ [(lu ^. luLinkType, rtree & ldtValue %~ (lu ^. luChildUpdate))]) & ldtRight %~ (++ [(lu ^. luLinkType, rtree & ldtValue %~ (lu ^. luChildUpdate))])
rightIsParentCombine :: LDTComb PartiallyComposedItem ItemLink rightIsParentCombine :: LDTComb ComposedItem ItemLink
rightIsParentCombine ltree rtree = do rightIsParentCombine ltree rtree = do
lu <- (rtree ^. ldtValue . _3 . tryLeftLink) (ltree ^. ldtValue) lu <- (rtree ^. ldtValue . _3 . tryLeftLink) (ltree ^. ldtValue)
return $ return $
@@ -176,7 +176,7 @@ joinItemsInList f xs = snd $ h (xs, [])
Just w -> h (w : ys, zs) Just w -> h (w : ys, zs)
-- this puts the first elements in the intmap at the end of the list -- 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 = invLDT =
joinItemsInList tryAttachItems . IM.elems joinItemsInList tryAttachItems . IM.elems
. fmap (singleLDT . basePCI) . fmap (singleLDT . basePCI)
@@ -215,23 +215,23 @@ invTrees' = IM.unions . map (ldtToIM getindex . fmap (^. _1)) . map (fmap (\(x,
i ^? itLocation . ilInvID i ^? itLocation . ilInvID
-- returns an intmap with trees for (only!) root items, indexed by inventory position -- 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 invRootTrees = IM.fromDistinctAscList . reverse . map (getid) . invLDT
where where
getid :: LabelDoubleTree ItemLink PartiallyComposedItem getid :: LabelDoubleTree ItemLink ComposedItem
-> (Int, LabelDoubleTree ItemLink PartiallyComposedItem) -> (Int, LabelDoubleTree ItemLink ComposedItem)
getid t = (t ^?! ldtValue . _1 . itLocation . ilInvID, t) getid t = (t ^?! ldtValue . _1 . itLocation . ilInvID, t)
-- returns an intmap with indents and locations for all items -- 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 allInvLocs inv = foldMap (f . LocLDT TopLDT) (IM.elems (invRootTrees inv)) mempty
where where
f t = cldtPropagateFold h h g 0 t id f t = cldtPropagateFold h h g 0 t id
h x _ _ _ = x + 1 h x _ _ _ = x + 1
g :: Int -> LocationLDT ItemLink PartiallyComposedItem g :: Int -> LocationLDT ItemLink ComposedItem
-> (IM.IntMap (Int, LocationLDT ItemLink PartiallyComposedItem) -> (IM.IntMap (Int, LocationLDT ItemLink ComposedItem)
-> IM.IntMap (Int, LocationLDT ItemLink PartiallyComposedItem)) -> IM.IntMap (Int, LocationLDT ItemLink ComposedItem))
-> IM.IntMap (Int, LocationLDT ItemLink PartiallyComposedItem) -> IM.IntMap (Int, LocationLDT ItemLink ComposedItem)
-> IM.IntMap (Int, LocationLDT ItemLink PartiallyComposedItem) -> IM.IntMap (Int, LocationLDT ItemLink ComposedItem)
g x ldt = (.) (IM.insert (ldt ^?! locLDT . ldtValue . _1 . itLocation . ilInvID) g x ldt = (.) (IM.insert (ldt ^?! locLDT . ldtValue . _1 . itLocation . ilInvID)
(x, ldt)) (x, ldt))
+1 -1
View File
@@ -8,7 +8,7 @@ import Color
import Control.Lens import Control.Lens
import Dodge.Data.ComposedItem import Dodge.Data.ComposedItem
itemInvColor :: PartiallyComposedItem -> Color itemInvColor :: ComposedItem -> Color
itemInvColor ci = case ci ^. _2 of itemInvColor ci = case ci ^. _2 of
WeaponPlatformSF -> white WeaponPlatformSF -> white
EquipmentPlatformSF -> yellow EquipmentPlatformSF -> yellow
-1
View File
@@ -19,7 +19,6 @@ import Dodge.Creature.Info
import Dodge.Creature.Test import Dodge.Creature.Test
import Dodge.Data.CardinalPoint import Dodge.Data.CardinalPoint
import Dodge.Data.Combine import Dodge.Data.Combine
import Dodge.Data.ComposedItem
import Dodge.Data.Config import Dodge.Data.Config
import Dodge.Data.DoubleTree import Dodge.Data.DoubleTree
import Dodge.Data.SelectionList import Dodge.Data.SelectionList