diff --git a/ghcidOutput b/ghcidOutput index 2c1bd9dca..3ec47f821 100644 --- a/ghcidOutput +++ b/ghcidOutput @@ -1,3 +1,8 @@ +/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’ | diff --git a/src/Dodge/Data/DoubleTree.hs b/src/Dodge/Data/DoubleTree.hs index 589366aa1..c6d4e0c48 100644 --- a/src/Dodge/Data/DoubleTree.hs +++ b/src/Dodge/Data/DoubleTree.hs @@ -13,5 +13,8 @@ import Data.Aeson.TH data DoubleTree a = DT {_dtValue :: a,_dtLeft :: [DoubleTree a],_dtRight :: [DoubleTree a]} deriving (Eq,Ord,Show,Read) +instance Functor DoubleTree where + fmap f (DT x l r) = DT (f x) (fmap (fmap f) l) (fmap (fmap f) r) + makeLenses ''DoubleTree deriveJSON defaultOptions ''DoubleTree diff --git a/src/Dodge/DisplayInventory.hs b/src/Dodge/DisplayInventory.hs index 80809b22c..452373ab9 100644 --- a/src/Dodge/DisplayInventory.hs +++ b/src/Dodge/DisplayInventory.hs @@ -22,6 +22,7 @@ import Dodge.Inventory.CheckSlots import Dodge.Inventory.SelectionList import Dodge.ListDisplayParams import Dodge.SelectionList +import Dodge.Item.Grammar import LensHelp import ListHelp import Picture.Base @@ -114,6 +115,7 @@ updateDisplaySections w cfig sss = invitems' = IM.mapWithKey (invSelectionItem cr) inv cr = you w inv = _crInv (you w) + --inv = indentInv $ _crInv (you w) nfreeslots = crNumFreeSlots cr filtpair i itms filtdescription = ( (i, filtsis) diff --git a/src/Dodge/Item/Grammar.hs b/src/Dodge/Item/Grammar.hs index 694dd781c..7db3befc7 100644 --- a/src/Dodge/Item/Grammar.hs +++ b/src/Dodge/Item/Grammar.hs @@ -6,17 +6,41 @@ import Dodge.Data.Item import Dodge.Data.DoubleTree import Dodge.Data.ComposedItem import TreeHelp +import qualified Data.IntMap.Strict as IM +import Control.Lens type PCI = (ComposedItem, [ComposedItem]) +type PCI' = (Item,ComposedItem, [ComposedItem]) + +singleDT :: a -> DoubleTree a +singleDT x = DT x [] [] + 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,_) _ _) +baseCI :: Item -> PCI' +baseCI itm = let (a,b) = baseComposedItem (itm ^. itType . iyBase) + in (itm, a, b) + +joinItems :: DoubleTree PCI' -> DoubleTree PCI' -> Maybe (DoubleTree PCI') +joinItems t@(DT (itm,px,cx) ls' rs') s@(DT (_,py,_) _ _) + | py `elem` cx = Just (DT (itm,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 (itm2,pb,cb) ls rs) + | pa `elem` cb = Just (DT (itm2,pb, delete pa cb) (a:ls) rs) + | otherwise = Nothing + +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 @@ -28,8 +52,8 @@ joinItems t@(DT (px,cx) ls' rs') s@(DT (py,_) _ _) | 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,_) _) +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 @@ -50,3 +74,45 @@ joinItemsInList f xs = snd $ h (xs,[]) h ((y:ys),(z:zs)) = case f y z of Nothing -> h (ys, (y:z:zs)) Just w -> h ((w:ys),zs) + +headMap :: (a -> a) -> (a -> a) -> [a] -> [a] +headMap f g (x:xs) = f x : map g xs +headMap _ _ [] = [] + +lastMap :: (a -> a) -> (a -> a) -> [a] -> [a] +lastMap _ _ [] = [] +lastMap f _ (x:[]) = [f x] +lastMap f g (x:xs) = g x : lastMap f g xs + +indentDoubleTreeWith :: (a -> a) -> (a -> a) -> (a -> a) -> DoubleTree a -> DoubleTree a +indentDoubleTreeWith f g h (DT x l r) = DT x + (headMap (iDTL f g h) (iDTboth f g h) l) + (lastMap (iDTR f g h) (iDTboth f g h) r) + +iDTL :: (a -> a) -> (a -> a) -> (a -> a) -> DoubleTree a -> DoubleTree a +iDTL fspace fline flink (DT x l r) = DT (flink x) + (map (fmap fspace . indentDoubleTreeWith fspace fline flink) l) + (map (fmap fline . indentDoubleTreeWith fspace fline flink) r) + +iDTR :: (a -> a) -> (a -> a) -> (a -> a) -> DoubleTree a -> DoubleTree a +iDTR fspace fline flink (DT x l r) = DT (flink x) + (map (fmap fline . indentDoubleTreeWith fspace fline flink) l) + (map (fmap fspace . indentDoubleTreeWith fspace fline flink) r) + +iDTboth :: (a -> a) -> (a -> a) -> (a -> a) -> DoubleTree a -> DoubleTree a +iDTboth fspace fline flink (DT x l r) = DT (flink x) + (map (fmap fline . indentDoubleTreeWith fspace fline flink) l) + (map (fmap fline . indentDoubleTreeWith fspace fline flink) r) + +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 "")) . + joinItemsInList joinItems . IM.elems . fmap (singleDT . baseCI) + +--indentInv :: IM.IntMap Item -> [String] +--indentInv = concat . fmap (flattenDT . indentDoubleTreeWith (' ':) ('|':) ('+':) . fmap const "") +-- . joinItemsInList joinItems +-- . IM.toList . fmap (singleDT . baseComposedItem) diff --git a/tags b/tags index 9cf3b0d50..ff0245ab2 100644 --- a/tags +++ b/tags @@ -1837,7 +1837,8 @@ P2Ac src/Dodge/Data/CreatureEffect.hs 53;" t P2Imp src/Dodge/Data/CreatureEffect.hs 28;" t P2ImpNo src/Dodge/Data/CreatureEffect.hs 28;" C P2NoAction src/Dodge/Data/CreatureEffect.hs 53;" C -PCI src/Dodge/Item/Grammar.hs 10;" t +PCI src/Dodge/Item/Grammar.hs 12;" t +PCI' src/Dodge/Item/Grammar.hs 14;" t PENBUL src/Dodge/Combine/Data.hs 204;" C PENMODULE src/Dodge/Combine/Data.hs 70;" C PIERCING src/Dodge/Data/Damage/Type.hs 12;" C @@ -3297,6 +3298,7 @@ _drTrigger src/Dodge/Data/Door.hs 38;" f _drWallIDs src/Dodge/Data/Door.hs 36;" f _dtLeft src/Dodge/Data/DoubleTree.hs 13;" f _dtRight src/Dodge/Data/DoubleTree.hs 13;" f +_dtValue src/Dodge/Data/DoubleTree.hs 13;" f _ebColor src/Dodge/Data/EnergyBall.hs 17;" f _ebEff src/Dodge/Data/EnergyBall.hs 21;" f _ebPos src/Dodge/Data/EnergyBall.hs 18;" f @@ -4384,7 +4386,7 @@ amr src/Dodge/Item/Weapon/BulletGun/Rod.hs 56;" f anItemFindPulse src/Dodge/Item/Weapon/UseEffect.hs 25;" f analyser src/Dodge/Placement/Instance/Analyser.hs 12;" f analyserByDoor src/Dodge/Room/LasTurret.hs 75;" f -andOrRegex src/Dodge/DisplayInventory.hs 77;" f +andOrRegex src/Dodge/DisplayInventory.hs 78;" f angleBetween src/Geometry.hs 145;" f angleVV src/Geometry/Vector.hs 57;" f angleVV3 src/Geometry/Vector3D.hs 122;" f @@ -4499,8 +4501,9 @@ baseAMRShape src/Dodge/Item/Draw/SPic.hs 445;" f baseBlockPane src/Dodge/Placement/Instance/Wall.hs 86;" f baseBlockPane src/Dodge/Placements/Wall.hs 63;" f baseBlockPane src/Dodge/Room/Placement.hs 93;" f +baseCI src/Dodge/Item/Grammar.hs 25;" f baseCaneShape src/Dodge/Item/Draw/SPic.hs 251;" f -baseComposedItem src/Dodge/Item/Grammar.hs 12;" f +baseComposedItem src/Dodge/Item/Grammar.hs 19;" f baseDebris src/Dodge/Block/Debris.hs 122;" f baseFloorTileSize src/Tile.hs 38;" f baseRifleShape src/Dodge/Item/Draw/SPic.hs 254;" f @@ -5128,7 +5131,7 @@ displayConfig src/Dodge/Menu.hs 196;" f displayControls src/Dodge/Menu.hs 206;" f displayEnergyBallType src/Dodge/Module/Info.hs 19;" f displayFrameTicks src/Dodge/Render/Picture.hs 27;" f -displayFreeSlots src/Dodge/DisplayInventory.hs 154;" f +displayFreeSlots src/Dodge/DisplayInventory.hs 156;" f displayTerminal src/Dodge/Render/HUD.hs 211;" f displayTerminalLineString src/Dodge/Update.hs 325;" f dist src/Geometry/Vector.hs 179;" f @@ -5379,7 +5382,7 @@ encircleCloseP src/Dodge/Creature/Boid.hs 35;" f encircleDistP src/Dodge/Creature/Boid.hs 21;" f encircleP src/Dodge/Creature/Boid.hs 27;" f energyBallCraft src/Dodge/Item/Craftable.hs 18;" f -enterCombineInv src/Dodge/DisplayInventory.hs 264;" f +enterCombineInv src/Dodge/DisplayInventory.hs 266;" f eqConstr src/SameConstr.hs 17;" f eqPosText src/Dodge/Equipment/Text.hs 6;" f equipAimSpeed src/Dodge/Creature/Action/Movement.hs 109;" f @@ -5480,6 +5483,7 @@ flatShieldEquipSPic src/Dodge/Item/Draw/SPic.hs 489;" f flatV2 src/Picture/Data.hs 65;" f flatV3 src/Picture/Data.hs 68;" f flatV4 src/Picture/Data.hs 71;" f +flattenDT src/Dodge/Item/Grammar.hs 107;" f flattenIMIMIM src/Dodge/Base/Zone.hs 246;" f fleeFrom src/Dodge/CreatureEffect.hs 119;" f fleeFromTarget src/Dodge/CreatureEffect.hs 65;" f @@ -5667,6 +5671,7 @@ hatCombinations src/Dodge/Combine/Combinations.hs 33;" f head src/DoubleStack.hs 14;" f headLamp src/Dodge/Item/Equipment.hs 118;" f headLampShape src/Dodge/Item/Draw/SPic.hs 495;" f +headMap src/Dodge/Item/Grammar.hs 78;" f heal src/Dodge/Item/Consumable.hs 17;" f heal25 src/Dodge/Item/Consumable.hs 14;" f healS src/Dodge/SoundLogic/ExternallyGeneratedSounds.hs 354;" f @@ -5704,6 +5709,9 @@ hvBulDams src/Dodge/Particle/Damage.hs 13;" f hvBulHitCr src/Dodge/Particle/Bullet/HitEffect.hs 17;" f hvBulHitWall src/Dodge/Particle/Bullet/HitEffect.hs 54;" f hvBulletAmmo src/Dodge/Item/Weapon/Bullet.hs 31;" f +iDTL src/Dodge/Item/Grammar.hs 92;" f +iDTR src/Dodge/Item/Grammar.hs 97;" f +iDTboth src/Dodge/Item/Grammar.hs 102;" f iShape src/Dodge/Placement/Instance/LightSource.hs 74;" f iShape src/Dodge/Placements/LightSource.hs 32;" f icosahedronPoints src/Polyhedra/Geodesic.hs 11;" f @@ -5723,6 +5731,8 @@ incBallAt src/Dodge/EnergyBall.hs 54;" f incendiaryModule src/Dodge/Item/Craftable.hs 21;" f incidenceToFunction src/Dodge/Graph.hs 26;" f indefiniteExceptions src/StringHelp.hs 29;" f +indentDoubleTreeWith src/Dodge/Item/Grammar.hs 87;" f +indentInv src/Dodge/Item/Grammar.hs 110;" f initCrItemLocation src/Dodge/Item/Location/Initialize.hs 39;" f initCrItemLocations src/Dodge/Item/Location/Initialize.hs 34;" f initCrsItemLocations src/Dodge/Item/Location/Initialize.hs 14;" f @@ -5789,7 +5799,7 @@ intersectSegsSeg src/Geometry/Intersect.hs 232;" f intervalList src/Geometry.hs 315;" f interweave src/Justify.hs 17;" f intsToPos src/Dodge/Room/Modify/Girder.hs 160;" f -invDimColor src/Dodge/DisplayInventory.hs 135;" f +invDimColor src/Dodge/DisplayInventory.hs 137;" f invDimColor src/Dodge/Inventory/Color.hs 4;" f invDisplayParams src/Dodge/ListDisplayParams.hs 29;" f invHead src/Dodge/Render/HUD.hs 276;" f @@ -5876,8 +5886,10 @@ jShape src/Dodge/Placement/Instance/LightSource.hs 86;" f jShape src/Dodge/Placements/LightSource.hs 43;" f jaggedShape src/Dodge/Block/Debris.hs 191;" f jetPack src/Dodge/Item/Equipment.hs 92;" f -joinItems src/Dodge/Item/Grammar.hs 18;" f -joinItemsInList src/Dodge/Item/Grammar.hs 32;" f +joinItems src/Dodge/Item/Grammar.hs 29;" f +joinItems' src/Dodge/Item/Grammar.hs 42;" f +joinItems'' src/Dodge/Item/Grammar.hs 55;" f +joinItemsInList src/Dodge/Item/Grammar.hs 69;" f jps0' src/Dodge/LevelGen/Data.hs 60;" f jps0' src/Dodge/LevelGen/PlacementHelper.hs 60;" f jps0PushPS src/Dodge/LevelGen/Data.hs 63;" f @@ -5927,6 +5939,7 @@ lasTurret src/Dodge/Placement/Instance/Turret.hs 23;" f lasTurret src/Dodge/Placements/Turret.hs 29;" f lasWide src/Dodge/Item/Held/BatteryGuns.hs 97;" f lasWideRate src/Dodge/HeldUse.hs 353;" f +lastMap src/Dodge/Item/Grammar.hs 82;" f latchkey src/Dodge/Item/Held/Utility.hs 23;" f latchkey src/Dodge/Item/PassKey.hs 14;" f launcher src/Dodge/Item/Held/Launcher.hs 10;" f @@ -6353,7 +6366,7 @@ optionScreenUpdate src/Dodge/Update/Input/ScreenLayer.hs 39;" f optionValueOffset src/Dodge/Menu/Option.hs 107;" f optionsOptions src/Dodge/Menu.hs 108;" f optionsToSelections src/Dodge/Menu/Option.hs 59;" f -orRegex src/Dodge/DisplayInventory.hs 80;" f +orRegex src/Dodge/DisplayInventory.hs 81;" f orange src/Color.hs 25;" f orderAround3 src/Geometry/Vector3D.hs 105;" f orderAroundFirst src/Geometry/Polygon.hs 74;" f @@ -6383,7 +6396,7 @@ overlapCircWalls src/Dodge/Base/Collide.hs 137;" f overlapCircWallsClosest src/Dodge/Base/Collide.hs 168;" f overlapSegCrs src/Dodge/Base/Collide.hs 58;" f overlapSegWalls src/Dodge/Base/Collide.hs 119;" f -overlapSelectionItems src/Dodge/DisplayInventory.hs 250;" f +overlapSelectionItems src/Dodge/DisplayInventory.hs 252;" f overrideInternal src/Dodge/Creature/ReaderUpdate.hs 172;" f overrideMeleeCloseTarget src/Dodge/Creature/ReaderUpdate.hs 33;" f overwriteLabel src/Dodge/Tree/Compose.hs 31;" f @@ -6477,7 +6490,7 @@ placeSpotRoomRand src/Dodge/Placement/PlaceSpot.hs 78;" f placeSpotUsingLink src/Dodge/Placement/PlaceSpot.hs 59;" f placeString src/Dodge/Render/MenuScreen.hs 54;" f placeWallPoly src/Dodge/Placement/PlaceSpot.hs 154;" f -plainRegex src/Dodge/DisplayInventory.hs 151;" f +plainRegex src/Dodge/DisplayInventory.hs 153;" f plainShellCollisionCheck src/Dodge/Projectile/Update.hs 45;" f plateCraft src/Dodge/Item/Craftable.hs 47;" f playIfFree src/Sound.hs 136;" f @@ -6762,7 +6775,7 @@ reflectInParam src/Geometry.hs 233;" f reflectLaserAlong src/Dodge/Item/Weapon/LaserPath.hs 13;" f refract src/Dodge/Item/Weapon/LaserPath.hs 40;" f refreshOptionsSelectionList src/Dodge/Menu/Option.hs 34;" f -regexCombs src/Dodge/DisplayInventory.hs 67;" f +regexCombs src/Dodge/DisplayInventory.hs 68;" f regexFocus src/Dodge/InputFocus.hs 46;" f regexIn src/Regex.hs 4;" f regexList src/Regex.hs 7;" f @@ -7161,6 +7174,7 @@ singleBarrel src/Dodge/Item/Held/SingleBarrel.hs 6;" f singleBlock src/Dodge/Placement/Instance/Wall.hs 30;" f singleBlock src/Dodge/Placements/Wall.hs 11;" f singleBlock src/Dodge/Room/Placement.hs 23;" f +singleDT src/Dodge/Item/Grammar.hs 16;" f singleton src/DoubleStack.hs 11;" f singletonTrie src/SimpleTrie.hs 14;" f sizeFBOs src/Framebuffer/Update.hs 22;" f @@ -7443,7 +7457,7 @@ toTopLeft src/Dodge/Render/List.hs 185;" f toV2 src/Geometry/Data.hs 36;" f toV3 src/Geometry/Data.hs 38;" f toV4 src/Geometry/Data.hs 40;" f -toggleCombineInv src/Dodge/DisplayInventory.hs 30;" f +toggleCombineInv src/Dodge/DisplayInventory.hs 31;" f toggleCommand src/Dodge/Terminal.hs 194;" f toggleEquipmentAt src/Dodge/Creature/Impulse/UseItem.hs 59;" f toggleJust src/MaybeHelp.hs 41;" f @@ -7612,14 +7626,14 @@ updateCamera src/Dodge/Update/Camera.hs 32;" f updateCloseObjects src/Dodge/Inventory.hs 166;" f updateCloud src/Dodge/Update.hs 605;" f updateClouds src/Dodge/Update.hs 454;" f -updateCombinePositioning src/Dodge/DisplayInventory.hs 35;" f -updateCombineSections src/Dodge/DisplayInventory.hs 40;" f +updateCombinePositioning src/Dodge/DisplayInventory.hs 36;" f +updateCombineSections src/Dodge/DisplayInventory.hs 41;" f updateCreature src/Dodge/Creature/Update.hs 10;" f updateCreatureGroups src/Dodge/Update.hs 391;" f updateCreatureSoundPositions src/Dodge/Update.hs 371;" f updateDebugMessageOffset src/Dodge/Update.hs 91;" f updateDelayedEvents src/Dodge/Update.hs 668;" f -updateDisplaySections src/Dodge/DisplayInventory.hs 90;" f +updateDisplaySections src/Dodge/DisplayInventory.hs 91;" f updateDistortion src/Dodge/Distortion.hs 5;" f updateDistortions src/Dodge/Update.hs 412;" f updateEnergyBall src/Dodge/EnergyBall.hs 46;" f @@ -7642,8 +7656,8 @@ updateInGameCamera src/Dodge/Update/Camera.hs 71;" f updateInitialPressInGame src/Dodge/Update/Input/InGame.hs 107;" f updateInstantBullets src/Dodge/Update.hs 531;" f updateInv src/Dodge/Creature/State.hs 224;" f -updateInventoryPositioning src/Dodge/DisplayInventory.hs 85;" f -updateInventorySectionItems src/Dodge/DisplayInventory.hs 139;" f +updateInventoryPositioning src/Dodge/DisplayInventory.hs 86;" f +updateInventorySectionItems src/Dodge/DisplayInventory.hs 141;" f updateKeyInGame src/Dodge/Update/Input/InGame.hs 101;" f updateKeysInTerminal src/Dodge/Update/Input/InGame.hs 90;" f updateLampoid src/Dodge/Lampoid.hs 13;" f @@ -7679,8 +7693,8 @@ updateRenderSplit appDodge/Main.hs 105;" f updateScopeZoom src/Dodge/Update/Camera.hs 131;" f updateScopeZoom' src/Dodge/Update/Camera.hs 136;" f updateScrollTestValue src/Dodge/ScrollValue.hs 6;" f -updateSection src/Dodge/DisplayInventory.hs 181;" f -updateSectionsPositioning src/Dodge/DisplayInventory.hs 160;" f +updateSection src/Dodge/DisplayInventory.hs 183;" f +updateSectionsPositioning src/Dodge/DisplayInventory.hs 162;" f updateSeenWalls src/Dodge/Update.hs 562;" f updateShockwave src/Dodge/Shockwave/Update.hs 12;" f updateShockwaves src/Dodge/Update.hs 436;" f