Cleanup
This commit is contained in:
+1
-38
@@ -1,12 +1,8 @@
|
||||
--{-# LANGUAGE TupleSections #-}
|
||||
module Dodge.Combine (
|
||||
combineList,
|
||||
combineList',
|
||||
) where
|
||||
|
||||
import Color
|
||||
--import Dodge.Data.SelectionList
|
||||
|
||||
import Control.Lens
|
||||
import Control.Monad
|
||||
import Data.Bifunctor
|
||||
@@ -28,60 +24,27 @@ 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) :))
|
||||
-- []
|
||||
|
||||
invertInventoryToMap :: IM.IntMap Item -> M.Map ItemBaseType [Int]
|
||||
invertInventoryToMap =
|
||||
IM.foldrWithKey
|
||||
(\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]]
|
||||
|
||||
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]]
|
||||
|
||||
--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
|
||||
|
||||
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
|
||||
-- . invertInventory
|
||||
|
||||
combineItemListYouX :: World -> [([Int], Item)]
|
||||
combineItemListYouX = map (first $ concat) . flatLookupItems . yourInv
|
||||
|
||||
--combineItemListYouX' :: World -> [([Int], Item)]
|
||||
--combineItemListYouX' = map (first $ concatMap g) . lookupItems . yourInv
|
||||
-- where
|
||||
-- g (amount, i) = replicate (_getItAmount amount) i
|
||||
|
||||
combineList :: World -> [SelectionItem CombinableItem]
|
||||
combineList w = case combineList' w of
|
||||
[] -> [SelectionInfo ["No possible combinations"] 1 False white 0]
|
||||
xs -> xs
|
||||
|
||||
combineList' :: World -> [SelectionItem CombinableItem]
|
||||
combineList' = map f . combineListInfo
|
||||
combineList = map f . combineListInfo
|
||||
where
|
||||
f (is, (strs, itm)) =
|
||||
SelectionItem
|
||||
|
||||
@@ -49,7 +49,7 @@ updateCombineSections w cfig sss =
|
||||
where
|
||||
mselpos = sss ^. sssExtra . sssSelPos
|
||||
availablelines = getAvailableListLines secondColumnParams cfig
|
||||
allcombs = IM.fromAscList $ zip [0 ..] $ combineList' w
|
||||
allcombs = IM.fromAscList $ zip [0 ..] $ combineList w
|
||||
filtcombs = fromMaybe allcombs $ do
|
||||
str <- mstr
|
||||
invitms <- w ^? hud . hudElement . diSections . sssSections . ix 0 . ssItems
|
||||
@@ -140,7 +140,7 @@ updateDisplaySections w cfig sss =
|
||||
invDimColor :: Color
|
||||
invDimColor = greyN 0.7
|
||||
|
||||
-- it is annoying that this is necessary
|
||||
-- this appears to be only for filtering
|
||||
updateInventorySectionItems :: World -> World
|
||||
updateInventorySectionItems w =
|
||||
w
|
||||
@@ -214,20 +214,15 @@ updateSection sis mcsel availablelines ss =
|
||||
si <- sis ^? ix csel
|
||||
let xselsize = length $ _siPictures si
|
||||
return $ case sum $ fmap (length . _siPictures) . fst . IM.split csel $ sis of
|
||||
pos
|
||||
| pos == 0 || length allstrings <= availablelines ->
|
||||
pos | pos == 0 || length allstrings <= availablelines ->
|
||||
0
|
||||
pos
|
||||
| pos - 1 < oldoffset ->
|
||||
pos | pos - 1 < oldoffset ->
|
||||
pos - 1
|
||||
pos
|
||||
| maxcsel == csel ->
|
||||
pos | maxcsel == csel ->
|
||||
pos - availablelines + xselsize
|
||||
pos
|
||||
| pos + 1 + xselsize - availablelines > oldoffset ->
|
||||
pos | pos + 1 + xselsize - availablelines > oldoffset ->
|
||||
pos - availablelines + 1 + xselsize
|
||||
_
|
||||
| length allstrings - oldoffset < availablelines ->
|
||||
_ | length allstrings - oldoffset < availablelines ->
|
||||
length allstrings - availablelines
|
||||
_ -> oldoffset
|
||||
tweakfirst (x : xs)
|
||||
@@ -263,7 +258,7 @@ enterCombineInv cfig w =
|
||||
cm'
|
||||
sss
|
||||
where
|
||||
cm' = IM.fromAscList $ zip [0 ..] $ combineList' w
|
||||
cm' = IM.fromAscList $ zip [0 ..] $ combineList w
|
||||
cm
|
||||
| null cm' = IM.singleton 0 $ SelectionInfo ["No possible combinations"] 1 False white 0
|
||||
| otherwise = cm'
|
||||
|
||||
@@ -46,9 +46,7 @@ invSelectionItem cr i (it,indent,_) =
|
||||
anyhotkey = maybe [] ((' ':) .hotkeyToString) (cr ^? crInvHotkeys . ix i)
|
||||
anyequippos = maybe [] (rightPad 8 ' ' . (' ':) . eqPosText) (cr ^? crInvEquipped . ix i)
|
||||
col = itemInvColor it
|
||||
pics = case _itCurseStatus it of
|
||||
UndroppableIdentified -> itemDisplay cr it
|
||||
_ -> itemDisplay cr it
|
||||
pics = itemDisplay cr it
|
||||
|
||||
hotkeyToString :: Hotkey -> String
|
||||
hotkeyToString x = case x of
|
||||
|
||||
@@ -28,7 +28,6 @@ import Geometry
|
||||
import LensHelp
|
||||
import SDL
|
||||
|
||||
-- might not need the full universe here
|
||||
updateUseInputInGame :: Universe -> Universe
|
||||
updateUseInputInGame u = case u ^. uvWorld . hud . hudElement of
|
||||
DisplayCarte -> over uvWorld updatePressedButtonsCarte u
|
||||
|
||||
Reference in New Issue
Block a user