Add files, move towards joining items in inventory
This commit is contained in:
+42
-38
@@ -4,64 +4,67 @@ module Dodge.Combine (
|
||||
combineList',
|
||||
) where
|
||||
|
||||
import Dodge.Item.SlotsTaken
|
||||
import Dodge.Data.Universe
|
||||
import Dodge.Data.Combine
|
||||
import Dodge.Item.Display
|
||||
import Dodge.Item.InventoryColor
|
||||
import Color
|
||||
--import Dodge.Data.SelectionList
|
||||
import qualified Data.IntSet as IS
|
||||
|
||||
import Control.Lens
|
||||
import Control.Monad
|
||||
import Data.Bifunctor
|
||||
import qualified Data.IntSet as IS
|
||||
import Data.List (sortOn)
|
||||
import Data.Map.Merge.Strict
|
||||
import qualified Data.Map.Strict as M
|
||||
import Data.Maybe
|
||||
import Dodge.Base.You
|
||||
import Dodge.Combine.Trie
|
||||
import Dodge.Data.Combine
|
||||
import Dodge.Data.Universe
|
||||
import Dodge.Item.Display
|
||||
import Dodge.Item.InventoryColor
|
||||
import Dodge.Item.SlotsTaken
|
||||
--import Dodge.Data.World
|
||||
import Dodge.Item.Amount
|
||||
--import Dodge.Item.Amount
|
||||
import Dodge.Module
|
||||
import qualified IntMapHelp as IM
|
||||
import SimpleTrie
|
||||
|
||||
invertInventory :: IM.IntMap Item -> [(ItemBaseType, ItAmount, Int)]
|
||||
invertInventory =
|
||||
IM.foldrWithKey
|
||||
(\k it -> ((_iyBase $ _itType it, itStackAmount it, k) :))
|
||||
[]
|
||||
--invertInventory :: IM.IntMap Item -> [(ItemBaseType, ItAmount, Int)]
|
||||
--invertInventory =
|
||||
-- IM.foldrWithKey
|
||||
-- (\k it -> ((_iyBase $ _itType it, itStackAmount it, k) :))
|
||||
-- []
|
||||
|
||||
invertInventoryToMap :: IM.IntMap Item -> M.Map ItemBaseType [Int]
|
||||
invertInventoryToMap =
|
||||
IM.foldrWithKey
|
||||
(\k it -> (M.insertWith (++) (_iyBase $ _itType it) (replicate (fromIntegral $ itStackAmount it) k)))
|
||||
(\k it -> (M.insertWith (++) (_iyBase $ _itType it) [k]))
|
||||
mempty
|
||||
|
||||
splitItAmounts :: [(ItemBaseType, ItAmount, Int)] -> [((ItAmount, ItemBaseType), (ItAmount, Int))]
|
||||
splitItAmounts = concatMap f
|
||||
where
|
||||
f (x, n, y) = [((i, x), (i, y)) | i <- [1 .. n]]
|
||||
--splitItAmounts :: [(ItemBaseType, ItAmount, Int)] -> [((ItAmount, ItemBaseType), (ItAmount, Int))]
|
||||
--splitItAmounts = concatMap f
|
||||
-- where
|
||||
-- f (x, n, y) = [((i, x), (i, y)) | i <- [1 .. n]]
|
||||
|
||||
groupSplitItemAmounts :: M.Map ItemBaseType [Int] -> [((ItAmount, ItemBaseType), [Int])]
|
||||
groupSplitItemAmounts = M.foldrWithKey f []
|
||||
where
|
||||
f ibt is = (++) [((fromIntegral i, ibt), take i is) | i <- [1..length is]]
|
||||
f ibt is = (++) [((fromIntegral i, ibt), take i is) | i <- [1 .. length is]]
|
||||
|
||||
flatSplitItAmounts :: [(ItemBaseType, ItAmount, Int)] -> [((ItAmount, ItemBaseType), [Int])]
|
||||
flatSplitItAmounts = concatMap f
|
||||
where
|
||||
f (x, n, y) = [((i, x), replicate (fromIntegral i) y) | i <- [1 .. n]]
|
||||
--flatSplitItAmounts :: [(ItemBaseType, ItAmount, Int)] -> [((ItAmount, ItemBaseType), [Int])]
|
||||
--flatSplitItAmounts = concatMap f
|
||||
-- where
|
||||
-- f (x, n, y) = [((i, x), replicate (fromIntegral i) y) | i <- [1 .. n]]
|
||||
|
||||
lookupItems :: IM.IntMap Item -> [([(ItAmount, Int)], Item)]
|
||||
lookupItems = flip multiLookupTrieI combinationsTrie . sortOn fst . splitItAmounts . invertInventory
|
||||
--lookupItems :: IM.IntMap Item -> [([(ItAmount, Int)], Item)]
|
||||
--lookupItems = flip multiLookupTrieI combinationsTrie . sortOn fst . splitItAmounts . invertInventory
|
||||
|
||||
flatLookupItems :: IM.IntMap Item -> [([[Int]], Item)]
|
||||
flatLookupItems =
|
||||
flip multiLookupTrieI combinationsTrie . sortOn fst . groupSplitItemAmounts
|
||||
. invertInventoryToMap
|
||||
|
||||
flatLookupItems :: IM.IntMap Item -> [([[Int]],Item)]
|
||||
flatLookupItems = flip multiLookupTrieI combinationsTrie . sortOn fst . groupSplitItemAmounts
|
||||
. invertInventoryToMap
|
||||
--flatLookupItems :: IM.IntMap Item -> [([[Int]],Item)]
|
||||
--flatLookupItems = flip multiLookupTrieI combinationsTrie . sortOn fst . flatSplitItAmounts
|
||||
--flatLookupItems = flip multiLookupTrieI combinationsTrie . sortOn fst . flatSplitItAmounts
|
||||
-- . invertInventory
|
||||
|
||||
combineItemListYouX :: World -> [([Int], Item)]
|
||||
@@ -80,21 +83,22 @@ combineList w = case combineList' w of
|
||||
combineList' :: World -> [SelectionItem CombinableItem]
|
||||
combineList' = map f . combineListInfo
|
||||
where
|
||||
f (is,(strs,itm)) = SelectionItem
|
||||
{ _siPictures = basicItemDisplay itm
|
||||
, _siHeight = itSlotsTaken itm
|
||||
, _siIsSelectable = True
|
||||
, _siColor = itemInvColor itm
|
||||
, _siOffX = 0
|
||||
, _siOffY = 0
|
||||
, _siPayload = CombinableItem is itm strs
|
||||
}
|
||||
f (is, (strs, itm)) =
|
||||
SelectionItem
|
||||
{ _siPictures = basicItemDisplay itm
|
||||
, _siHeight = itSlotsTaken itm
|
||||
, _siIsSelectable = True
|
||||
, _siColor = itemInvColor itm
|
||||
, _siOffX = 0
|
||||
, _siOffY = 0
|
||||
, _siPayload = CombinableItem is itm strs
|
||||
}
|
||||
|
||||
combineListInfo :: World -> [([Int], ([String], Item))]
|
||||
combineListInfo w = filter f . map (cmm inv) $ combineItemListYouX w
|
||||
where
|
||||
inv = yourInv w
|
||||
f (is,(_,itm)) = _itType itm `notElem` fmap _itType (IM.restrictKeys inv (IS.fromList is))
|
||||
f (is, (_, itm)) = _itType itm `notElem` fmap _itType (IM.restrictKeys inv (IS.fromList is))
|
||||
|
||||
cmm :: IM.IntMap Item -> ([Int], Item) -> ([Int], ([String], Item))
|
||||
cmm inv (is, itm) = (is, itm & itType . iyModules %%~ flip combineModuleMaps mms)
|
||||
|
||||
Reference in New Issue
Block a user