Continue tree based inventory update

This commit is contained in:
2024-09-10 16:35:44 +01:00
parent 854fc96ac7
commit 26f3610f82
14 changed files with 259 additions and 271 deletions
+1 -40
View File
@@ -1,40 +1 @@
/home/justin/Haskell/loop/src/Dodge/DisplayInventory.hs:25:1-25: warning: [-Wunused-imports]
The import of Dodge.Item.Grammar is redundant
|
25 | import Dodge.Item.Grammar
| ^^^^^^^^^^^^^^^^^^^^^^^^^
/home/justin/Haskell/loop/src/Dodge/Item/Draw/SPic.hs:20:1: warning: [-Wunused-top-binds]
Defined but not used: itemHeldAmmoPic
|
20 | itemHeldAmmoPic itm amit = itemSPic itm <> addAmmoClip itm amit
| ^^^^^^^^^^^^^^^
/home/justin/Haskell/loop/src/Dodge/Item/Draw/SPic.hs:23:1: warning: [-Wunused-top-binds]
Defined but not used: addAmmoClip
|
23 | addAmmoClip itm amit = fromMaybe mempty $ do
| ^^^^^^^^^^^
/home/justin/Haskell/loop/src/Dodge/Item/Draw/SPic.hs:23:17: warning: [-Wunused-matches]
Defined but not used: amit
|
23 | addAmmoClip itm amit = fromMaybe mempty $ do
| ^^^^
/home/justin/Haskell/loop/src/Dodge/Item/Draw/SPic.hs:24:5: warning: [-Wunused-matches]
Defined but not used: hit
|
24 | hit <- itm ^? itType . iyBase . ibtHeld
| ^^^
/home/justin/Haskell/loop/src/Dodge/Inventory/CheckSlots.hs:7:1: warning: [-Wunused-imports]
The import of Control.Lens is redundant
|
7 | import Control.Lens
| ^^^^^^^^^^^^^^^^^^^
/home/justin/Haskell/loop/src/Dodge/Inventory/CheckSlots.hs:8:1: warning: [-Wunused-imports]
The import of Data.Maybe is redundant
|
8 | import Data.Maybe
| ^^^^^^^^^^^^^^^^^
/home/justin/Haskell/loop/src/Dodge/Inventory/CheckSlots.hs:28:14: warning: [-Wunused-matches]
Defined but not used: it
|
28 | findItemSlot it inv = maybe 0 ((+ 1) . fst) $ IM.lookupMax inv
| ^^
All good (614 modules, at 16:33:21)
+2
View File
@@ -238,6 +238,7 @@ inventoryX c = case c of
, rifle
, shellMag
]
'P' -> [burstRifle , tinMag, bulletSynthesizer]
'T' -> testInventory
_ -> []
@@ -269,6 +270,7 @@ stackedInventory :: [Item]
stackedInventory =
[ burstRifle
, tinMag
, bulletSynthesizer
, drumMag
, launcher
, shellMag
+2
View File
@@ -11,6 +11,8 @@ import Data.Aeson.TH
data ComposedItem = WeaponCI
| WeaponScopeCI
| AmmoModifierCI
| BulletAmmoCI
| UncomposableCI
deriving (Eq,Ord,Show,Read)
+1
View File
@@ -97,6 +97,7 @@ data ItemBaseType
data AttachType
= SCROLLATTACH ScrollAttachType
| TARGETATTACH {_ibtAttachTarget :: TargetType}
| BULLETSYNTHESIZER
-- | BULPAYLOADATTACH
-- | BULTRAJECTORYATTACH
deriving (Eq, Ord, Show, Read)
+1
View File
@@ -77,6 +77,7 @@ data HeldParams
data AttachParams
= ScrollAttachParams {_scrollAttachParams :: ScrollAttachParams}
| TargetAttachParams
| NoAttachParams
data AmmoParams = BulletParams {_ampBullet :: Bullet}
| ProjectileParams
+4 -1
View File
@@ -11,6 +11,7 @@ module Dodge.DisplayInventory (
import Control.Monad
import qualified Data.IntMap.Strict as IM
import qualified Data.IntMap.Merge.Strict as MIM
import Data.Maybe
import Dodge.Base.You
import Dodge.Combine
@@ -112,9 +113,11 @@ updateDisplaySections w cfig sss =
coitems' =
IM.fromDistinctAscList . zip [0 ..] $
map closeObjectToSelectionItem (w ^. hud . closeObjects)
invitems' = IM.mapWithKey (invSelectionItem cr) inv
invitems' = MIM.merge MIM.dropMissing MIM.dropMissing (MIM.zipWithMatched $ const addindent) indents $ IM.mapWithKey (invSelectionItem cr) inv
addindent x y = y & siPictures %~ map (x ++)
cr = you w
inv = _crInv (you w)
indents = indentInv inv
--inv = indentInv $ _crInv (you w)
nfreeslots = crNumFreeSlots cr
filtpair i itms filtdescription =
+3 -5
View File
@@ -4,8 +4,6 @@ module Dodge.Inventory.CheckSlots (
crInvSize,
) where
import Control.Lens
import Data.Maybe
import Dodge.Base.You
import Dodge.Data.World
import Dodge.Item.SlotsTaken
@@ -17,15 +15,15 @@ import qualified IntMapHelp as IM
checkInvSlotsYou :: Item -> World -> Maybe Int
checkInvSlotsYou it w
| crNumFreeSlots ycr >= ceiling (_itInvSize it) =
Just $ findItemSlot it (_crInv ycr)
Just $ findItemSlot (_crInv ycr)
| otherwise = Nothing
where
ycr = you w
-- Assumes that the item is singular.
-- Do not want to stack floor items for now
findItemSlot :: Item -> IM.IntMap Item -> Int
findItemSlot it inv = maybe 0 ((+ 1) . fst) $ IM.lookupMax inv
findItemSlot :: IM.IntMap Item -> Int
findItemSlot = maybe 0 ((+ 1) . fst) . IM.lookupMax
--findItemSlot it inv = case it ^? itUse . useAmount of
-- Just _ ->
-- fromMaybe newslot $ IM.findIndex (\it' -> _itType it == _itType it') inv
+1
View File
@@ -39,6 +39,7 @@ itemFromAttachType :: AttachType -> Item
itemFromAttachType at = case at of
SCROLLATTACH ZOOMSCOPE -> zoomScope
TARGETATTACH tt -> targetingScope tt
BULLETSYNTHESIZER -> bulletSynthesizer
itemFromConsumableType :: ConsumableItemType -> Item
+5
View File
@@ -71,3 +71,8 @@ battery =
, _iaLoaded = 100
}
}
bulletSynthesizer :: Item
bulletSynthesizer = defaultHeldItem
& itType . iyBase .~ ATTACH BULLETSYNTHESIZER
& itUse .~ AttachUse NoAttachParams
+1
View File
@@ -88,6 +88,7 @@ showAttachItem :: AttachType -> String
showAttachItem t = case t of
SCROLLATTACH x -> show x
TARGETATTACH x -> show x
BULLETSYNTHESIZER -> "BSYNTH"
showEquipItem :: EquipItemType -> String
showEquipItem eit = case eit of
+7 -7
View File
@@ -14,15 +14,15 @@ import LensHelp
import Picture
import Shape
import ShapePicture
import Data.Maybe
--import Data.Maybe
itemHeldAmmoPic :: Item -> Item -> SPic
itemHeldAmmoPic itm amit = itemSPic itm <> addAmmoClip itm amit
--itemHeldAmmoPic :: Item -> Item -> SPic
--itemHeldAmmoPic itm amit = itemSPic itm <> addAmmoClip itm amit
addAmmoClip :: Item -> Item -> SPic
addAmmoClip itm amit = fromMaybe mempty $ do
hit <- itm ^? itType . iyBase . ibtHeld
return mempty
--addAmmoClip :: Item -> Item -> SPic
--addAmmoClip itm amit = fromMaybe mempty $ do
-- hit <- itm ^? itType . iyBase . ibtHeld
-- return mempty
itemSPic :: Item -> SPic
itemSPic it =
+15 -5
View File
@@ -19,7 +19,9 @@ singleDT x = DT x [] []
baseComposedItem :: ItemBaseType -> PCI
baseComposedItem ibt = case ibt of
HELD BURSTRIFLE -> (WeaponCI, [BulletAmmoCI])
AMMOMAG TINMAG -> (BulletAmmoCI, [])
AMMOMAG TINMAG -> (BulletAmmoCI, [AmmoModifierCI])
AMMOMAG DRUMMAG -> (BulletAmmoCI, [AmmoModifierCI])
ATTACH BULLETSYNTHESIZER -> (AmmoModifierCI, [])
_ -> (UncomposableCI, [])
baseCI :: Item -> PCI'
@@ -34,7 +36,7 @@ joinItems t@(DT (itm,px,cx) ls' rs') s@(DT (_,py,_) _ _)
checkdepth a a'@(DT b ls rs) = fromMaybe (checktop a a') $ do
c <- safeHead ls
d <- checkdepth a c
return $ Just $ DT b (d:ls) rs
return $ Just $ DT b (d:tail ls) rs
checktop a@(DT (_,pa,_) _ _) (DT (itm2,pb,cb) ls rs)
| pa `elem` cb = Just (DT (itm2,pb, delete pa cb) (a:ls) rs)
| otherwise = Nothing
@@ -107,9 +109,17 @@ iDTboth fspace fline flink (DT x l r) = DT (flink x)
flattenDT :: DoubleTree a -> [a]
flattenDT (DT x l r) = concatMap flattenDT l ++ (x : concatMap flattenDT r)
indentInv :: IM.IntMap Item -> [String]
indentInv =
concatMap (flattenDT .indentDoubleTreeWith (' ':) ('|':) ('+':) . fmap (const "")) .
prettyDT :: (a -> String) -> DoubleTree a -> [String]
prettyDT f (DT x l r) = concatMap (map ('/':) . prettyDT f) r
++ (f x : concatMap (map ('\\':) . prettyDT f) l)
invTree :: IM.IntMap Item -> [String]
invTree = concatMap (prettyDT (\(itm,_,_) -> show (_itType itm))) .
joinItemsInList joinItems . IM.elems . fmap (singleDT . baseCI)
indentInv :: IM.IntMap Item -> IM.IntMap String
indentInv = IM.fromList . zip [0..] .
reverse . concatMap (flattenDT .indentDoubleTreeWith (' ':) ('|':) ('+':) . fmap (const "")) .
joinItemsInList joinItems . IM.elems . fmap (singleDT . baseCI)
--indentInv :: IM.IntMap Item -> [String]
+2 -4
View File
@@ -1,6 +1,7 @@
{-# OPTIONS_GHC -Wno-unused-imports #-}
module Dodge.TestString where
import Dodge.Item.Grammar
import Dodge.Item.Display
import AesonHelp
import Dodge.SmoothScroll
@@ -19,10 +20,7 @@ import Dodge.Data.Universe
--import qualified Data.Map.Strict as M
import qualified IntMapHelp as IM
testStringInit :: Universe -> [String]
testStringInit u = [fromMaybe "" $ do
proj <- u ^? uvWorld . cWorld . lWorld . projectiles
return $ show $ IM.size proj
]
testStringInit u = maybe [] invTree (u ^? uvWorld . cWorld . lWorld . creatures . ix 0 . crInv)
-- [fromMaybe "" $ do
-- cr <- u ^? uvWorld . cWorld . lWorld . creatures . ix 0
-- i <- cr ^? crManipulation . manObject . inInventory . ispItem
+214 -209
View File
File diff suppressed because it is too large Load Diff