Add files, move towards joining items in inventory

This commit is contained in:
2024-09-09 23:13:00 +01:00
parent db4a6a10de
commit 52d0008441
12 changed files with 230 additions and 270 deletions
-8
View File
@@ -1,8 +0,0 @@
module Dodge.Item.Amount where
import Control.Lens
import Data.Maybe
import Dodge.Data.Item
itStackAmount :: Item -> ItAmount
itStackAmount it = 1 -- fromMaybe 1 $ it ^? itUse . useAmount
+52
View File
@@ -0,0 +1,52 @@
module Dodge.Item.Grammar
where
import Data.Maybe
import ListHelp
import Dodge.Data.Item
import Dodge.Data.DoubleTree
import Dodge.Data.ComposedItem
import TreeHelp
type PCI = (ComposedItem, [ComposedItem])
baseComposedItem :: ItemBaseType -> PCI
baseComposedItem ibt = case ibt of
HELD BURSTRIFLE -> (WeaponCI, [BulletAmmoCI])
AMMOMAG TINMAG -> (BulletAmmoCI, [])
_ -> (UncomposableCI, [])
joinItems :: DoubleTree PCI -> DoubleTree PCI -> Maybe (DoubleTree PCI)
joinItems t@(DT (px,cx) ls' rs') s@(DT (py,_) _ _)
| py `elem` cx = Just (DT (px, delete py cx) ls' (rs' ++ [s]))
| otherwise = checkdepth t s
where
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
checktop a@(DT (pa,_) _ _) (DT (pb,cb) ls rs)
| pa `elem` cb = Just (DT (pb, delete pa cb) (a:ls) rs)
| otherwise = Nothing
joinItems' :: Tree PCI -> Tree PCI -> Maybe (Tree PCI)
joinItems' t@(Node (px,cx) xs) s@(Node (py,_) _)
-- | fst y `elem` cx = Just (Node (px, delete y cx) (xs ++ [s]))
| py `elem` cx = Just (Node (px, delete py cx) (xs ++ [s]))
| otherwise = checkdepth t s
where
checkdepth a a'@(Node b cs) = fromMaybe (checktop a a') $ do
c <- safeHead cs
d <- checkdepth a c
return $ Just $ Node b (d:cs)
checktop a@(Node (pa,_) _) (Node (pb,cb) bs)
| pa `elem` cb = Just (Node (pb, delete pa cb) (a:bs))
| otherwise = Nothing
joinItemsInList :: (a -> a -> Maybe a) -> [a] -> [a]
joinItemsInList f xs = snd $ h (xs,[])
where
h ([],zs) = ([],zs)
h ((y:ys), []) = h (ys, [y])
h ((y:ys),(z:zs)) = case f y z of
Nothing -> h (ys, (y:z:zs))
Just w -> h ((w:ys),zs)
+1 -1
View File
@@ -2,7 +2,7 @@ module Dodge.Item.SlotsTaken (
itSlotsTaken,
) where
import Control.Lens
--import Control.Lens
import Dodge.Data.Item
import Dodge.Module