Rethink selection lists as intmaps
This commit is contained in:
+72
-4
@@ -6,8 +6,14 @@ module Dodge.Combine (
|
||||
combineListInfo,
|
||||
toggleCombineInv,
|
||||
enterCombineInv,
|
||||
combineListSelection,
|
||||
picsToSelectable,
|
||||
) where
|
||||
|
||||
import Dodge.Data.Combine
|
||||
import Dodge.Item.Display
|
||||
import Color
|
||||
import Dodge.Data.SelectionList
|
||||
import qualified Data.IntSet as IS
|
||||
import Control.Lens
|
||||
import Control.Monad
|
||||
@@ -44,6 +50,19 @@ combineItemListYouX = map (first $ concatMap g) . lookupItems . yourInv
|
||||
where
|
||||
g (amount, i) = replicate (_getItAmount amount) i
|
||||
|
||||
combineList :: World -> [SelectionItem CombinableItem]
|
||||
combineList = map f . combineListInfo
|
||||
where
|
||||
f (is,(strs,itm)) = SelectionItem
|
||||
{ _siPictures = itemDisplay itm
|
||||
, _siHeight = length (itemDisplay itm)
|
||||
, _siIsSelectable = True
|
||||
, _siWidth = maximum (map length (itemDisplay itm))
|
||||
, _siColor = _itInvColor itm
|
||||
, _siOffX = 0
|
||||
, _siPayload = CombinableItem is itm strs
|
||||
}
|
||||
|
||||
combineListInfo :: World -> [([Int], ([String], Item))]
|
||||
combineListInfo w = filter f . map (cmm inv) $ combineItemListYouX w
|
||||
where
|
||||
@@ -93,10 +112,7 @@ toggleCombineInv w = case w ^. hud . hudElement of
|
||||
|
||||
enterCombineInv :: World -> World
|
||||
enterCombineInv w = w & hud . hudElement . subInventory .~ CombineInventory
|
||||
{ _subInvSel = mi
|
||||
, _subInvRegex = ""
|
||||
, _subInvRegexInput = False
|
||||
}
|
||||
(combineListSelection w mi "" False)
|
||||
where
|
||||
mi = 0 <$ listToMaybe (combineItemListYou w)
|
||||
|
||||
@@ -105,3 +121,55 @@ combineSizes = map (itSlotsTaken . snd) . combineItemListYou
|
||||
|
||||
combinePoss :: World -> [Int]
|
||||
combinePoss = scanl' (+) 0 . combineSizes
|
||||
|
||||
combineListSelection :: World -> Maybe Int -> String -> Bool -> SelectionIntMap CombinableItem
|
||||
combineListSelection w mi regex x = SelectionIntMap
|
||||
{ _smItems = combineList w
|
||||
, _smSelPos = mi
|
||||
, _smLength = length (combineList w)
|
||||
, _smRegex = regex
|
||||
, _smRegexInput = x
|
||||
, _smShownItems = IM.fromAscList $ zip [0..] (combineList w)
|
||||
}
|
||||
|
||||
combineListSelectionItems :: World -> [SelectionItem ()]
|
||||
combineListSelectionItems w = case combineListSelectionItems' w of
|
||||
[] -> [SelectionItem [thetext] 1 False (length thetext) white 0 ()]
|
||||
xs -> xs
|
||||
where
|
||||
thetext = "NO POSSIBLE COMBINATIONS"
|
||||
|
||||
combineListSelectionItems' :: World -> [SelectionItem ()]
|
||||
combineListSelectionItems' = map (picsToSelectable 15 . itemText . snd) . combineItemListYou
|
||||
|
||||
combineToSelectionItem :: Int -> [String] -> SelectionItem ()
|
||||
combineToSelectionItem wdth pics =
|
||||
SelectionItem
|
||||
{ _siPictures = pics
|
||||
, _siHeight = length pics
|
||||
, _siIsSelectable = True
|
||||
, _siWidth = wdth
|
||||
, _siColor = white
|
||||
, _siOffX = 0
|
||||
, _siPayload = ()
|
||||
}
|
||||
|
||||
picsToSelectable :: Int -> [String] -> SelectionItem ()
|
||||
picsToSelectable wdth pics =
|
||||
SelectionItem
|
||||
{ _siPictures = pics
|
||||
, _siHeight = length pics
|
||||
, _siIsSelectable = True
|
||||
, _siWidth = wdth
|
||||
, _siColor = white
|
||||
, _siOffX = 0
|
||||
, _siPayload = ()
|
||||
}
|
||||
|
||||
itemText :: Item -> [String]
|
||||
{-# INLINE itemText #-}
|
||||
itemText it = f $ case _itCurseStatus it of
|
||||
UndroppableIdentified -> itemDisplay it
|
||||
_ -> itemDisplay it
|
||||
where
|
||||
f = take (itSlotsTaken it) . (++ replicate 10 "*")
|
||||
|
||||
Reference in New Issue
Block a user