Extend inv item location information to include "attached" items
This commit is contained in:
@@ -2,6 +2,7 @@ module Dodge.Item.Grammar
|
||||
(invTrees
|
||||
, invIndentIM
|
||||
, invAdj'
|
||||
, invRootMap
|
||||
)
|
||||
where
|
||||
import Control.Applicative
|
||||
@@ -101,6 +102,16 @@ invLDT = joinItemsInList (leftRightCombine leftIsParentCombine rightIsParentComb
|
||||
-- (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
|
||||
-- should be done upstream anyway in the actually creature inventory)
|
||||
invRootMap :: IM.IntMap Item -> IM.IntMap (Maybe Int, DoubleTree ComposedItemStructure)
|
||||
invRootMap = foldMap (dtToIntMapWithRoot (^?! _1 . itLocation . ilInvID) . ldtToDT) . invLDT
|
||||
--invRootMap = foldMap (dtToRootIntMap g . ldtToDT) . invLDT
|
||||
-- where
|
||||
-- g = _
|
||||
|
||||
-- this assumes the creature inventory is well formed, specifically the
|
||||
-- location ids
|
||||
-- consider explicitly reseting the inventory ids (but this probably really
|
||||
|
||||
@@ -9,7 +9,7 @@ import Dodge.Data.Item
|
||||
flatShield :: Item
|
||||
flatShield =
|
||||
defaultHeldItem
|
||||
& itEffect . ieInv .~ EffectIfHeld CreateShieldWall RemoveShieldWall
|
||||
& itEffect . ieInv .~ EffectRootNotroot CreateShieldWall RemoveShieldWall
|
||||
& itUse . heldAim . aimWeight .~ 5
|
||||
& itUse . heldAim . aimTurnSpeed .~ 0.5
|
||||
& itUse . heldAim . aimStance .~ TwoHandFlat
|
||||
@@ -26,7 +26,7 @@ latchkey _ = defaultHeldItem
|
||||
torch :: Item
|
||||
torch =
|
||||
defaultHeldItem
|
||||
& itEffect . ieInv .~ EffectWhileHeld CreateHeldLight
|
||||
& itEffect . ieInv .~ EffectWhileRoot CreateHeldLight
|
||||
& itType . iyBase .~ HELD TORCH
|
||||
-- & itUse . heldAim . aimHandlePos .~ 5
|
||||
& itUse . heldAim . aimMuzzles . ix 0 . mzPos . _x .~ 10
|
||||
|
||||
@@ -35,12 +35,13 @@ pointerToItemLocation _ = const pure
|
||||
pointerYourSelectedItem :: Applicative a => (Item -> a Item) -> World -> a World
|
||||
pointerYourSelectedItem f w = fromMaybe (pure w) $ do
|
||||
itinvid <- w ^? cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . inInventory . imSelectedItem
|
||||
Just $ pointerToItemLocation (InInv 0 itinvid True True) f w
|
||||
Just $ pointerToItemLocation (InInv 0 itinvid True True True) f w
|
||||
-- note the ilIsRoot/Selected/Attached booleans are irrelevant
|
||||
|
||||
pointerYourRootItem :: Applicative a => (Item -> a Item) -> World -> a World
|
||||
pointerYourRootItem f w = fromMaybe (pure w) $ do
|
||||
itinvid <- w ^? cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . inInventory . imRootItem
|
||||
Just $ pointerToItemLocation (InInv 0 itinvid True True) f w
|
||||
Just $ pointerToItemLocation (InInv 0 itinvid True True True) f w
|
||||
|
||||
pointerToItem ::
|
||||
Applicative f =>
|
||||
|
||||
@@ -37,13 +37,20 @@ initCrItemLocations w cr = (w', cr & crInv .~ newinv)
|
||||
where
|
||||
(w',newinv) = imapAccumR (initCrItemLocation cr) w (_crInv cr)
|
||||
|
||||
-- does not worry about creature manipulation for now
|
||||
initCrItemLocation :: Creature -> Int -> LWorld -> Item -> (LWorld,Item)
|
||||
initCrItemLocation cr invid w it = (w & itemLocations . at locid ?~ loc
|
||||
,it & itID .~ locid
|
||||
& itLocation .~ loc)
|
||||
where
|
||||
locid = IM.newKey ( w ^. itemLocations)
|
||||
loc = InInv (_crID cr) invid False False
|
||||
loc = InInv
|
||||
{ _ilCrID = _crID cr
|
||||
, _ilInvID = invid
|
||||
, _ilIsRoot = False
|
||||
, _ilIsSelected = False
|
||||
, _ilIsAttached = False
|
||||
}
|
||||
|
||||
|
||||
initFlItemLocation :: LWorld -> FloorItem -> (LWorld, FloorItem)
|
||||
|
||||
@@ -8,7 +8,7 @@ import Geometry
|
||||
|
||||
setRemoteScope :: Int -> Point2 -> World -> World
|
||||
setRemoteScope itid pos w = case w ^? cWorld . lWorld . itemLocations . ix itid of
|
||||
Just (InInv cid' invid _ _) ->
|
||||
Just (InInv cid' invid _ _ _) ->
|
||||
w
|
||||
& cWorld . lWorld . creatures . ix cid' . crInv . ix invid . itScope
|
||||
. remotePos
|
||||
|
||||
Reference in New Issue
Block a user