Cleanup
This commit is contained in:
@@ -545,7 +545,7 @@ tryCombine (i, j) w = fromMaybe w $ do
|
||||
. ciSections . ix i . ssItems . ix j . siPayload . _Just
|
||||
p <- w ^? cWorld . lWorld . creatures . ix 0 . crPos
|
||||
return $
|
||||
(createItemYou it (foldr (destroyInvItem 0 . NInt) w (sort is)))
|
||||
createItemYou it (foldr (destroyInvItem 0 . NInt) w (sort is))
|
||||
& soundStart InventorySound p wrench1S Nothing
|
||||
& hud . diSelection . _Just . slSet .~ mempty
|
||||
|
||||
|
||||
+33
-48
@@ -3,22 +3,22 @@ module Dodge.Update.Scroll (
|
||||
updateWheelEvent,
|
||||
) where
|
||||
|
||||
import NewInt
|
||||
import Control.Applicative
|
||||
import qualified Data.ListTrie.Patricia.Map.Enum as PTE
|
||||
import Dodge.Data.Terminal.Status
|
||||
import Dodge.Data.EquipType
|
||||
import Padding
|
||||
import Control.Monad
|
||||
import qualified Data.ListTrie.Patricia.Map.Enum as PTE
|
||||
import qualified Data.Map.Strict as M
|
||||
import Data.Maybe
|
||||
import Dodge.Base
|
||||
import Dodge.Data.EquipType
|
||||
import Dodge.Data.Terminal.Status
|
||||
import Dodge.Data.Universe
|
||||
import Dodge.Inventory
|
||||
import Dodge.SelectionSections
|
||||
import Dodge.Terminal
|
||||
import Geometry
|
||||
import LensHelp
|
||||
import NewInt
|
||||
import Padding
|
||||
import SDL
|
||||
|
||||
-- yi should be nonzero
|
||||
@@ -33,7 +33,7 @@ updateWheelEvent yi w = case w ^. hud . subInventory of
|
||||
-- yi should be nonzero
|
||||
updateBaseWheelEvent :: Int -> World -> World
|
||||
updateBaseWheelEvent yi w
|
||||
-- | Just True <- w ^? cWorld . lWorld . creatures . ix 0 . crInvLock = w
|
||||
-- | Just True <- w ^? cWorld . lWorld . creatures . ix 0 . crInvLock = w
|
||||
| Just True <- w ^? cWorld . lWorld . lInvLock = w
|
||||
| bdown ButtonRight = case _rbState w of
|
||||
EquipOptions{} -> w & rbState . opSel %~ scrollRBOption yi rbscrollmax
|
||||
@@ -56,8 +56,9 @@ selectedItemScroll yi w = do
|
||||
|
||||
itemScroll :: Int -> Item -> World -> World
|
||||
itemScroll yi itm w
|
||||
| Just xs <- itm ^? itUse . uaParams . apProjectiles = w
|
||||
& itmlens . itUse . uaParams . apProjectiles .~ rotateList yi xs
|
||||
| Just xs <- itm ^? itUse . uaParams . apProjectiles =
|
||||
w
|
||||
& itmlens . itUse . uaParams . apProjectiles .~ rotateList yi xs
|
||||
| ATTACH ZOOMSCOPE <- itm ^. itType = updateScopeZoom (itm ^. itID) w
|
||||
| HELD ALTERIFLE <- itm ^. itType
|
||||
, yi /= 0 =
|
||||
@@ -65,8 +66,9 @@ itemScroll yi itm w
|
||||
& itmlens . itParams . alteRifleSwitch
|
||||
%~ ((`mod` 2) . (+ 1))
|
||||
| isJust $ itm ^? itScroll . itsInt = w & itmlens . itScroll . itsInt +~ yi
|
||||
| Just y <- itm ^? itScroll . itsMax = w & itmlens . itScroll . itsRangeInt
|
||||
%~ ((`mod` y) . (+ yi))
|
||||
| Just y <- itm ^? itScroll . itsMax =
|
||||
w & itmlens . itScroll . itsRangeInt
|
||||
%~ ((`mod` y) . (+ yi))
|
||||
| otherwise = w
|
||||
where
|
||||
--itmlens = cWorld . lWorld . creatures . ix 0 . crInv . ix invid
|
||||
@@ -140,77 +142,60 @@ terminalWheelEvent yi tmid w
|
||||
wrapdown s coms = PTE.findPredecessor s coms <|> PTE.findMax coms
|
||||
f tm = fromMaybe tm $ do
|
||||
let coms = getCommands w tm
|
||||
x <- tm ^? tmStatus . tiText
|
||||
x <- tm ^? tmStatus . tiText
|
||||
let s = fromMaybe "" $ x ^? to words . ix 0
|
||||
(s',_) <- dowrap s coms
|
||||
(s', _) <- dowrap s coms
|
||||
return $ tm & tmStatus . tiText .~ s'
|
||||
g tm = fromMaybe tm $ do
|
||||
let coms = getCommands w tm
|
||||
x <- tm ^? tmStatus . tiText
|
||||
let s = fromMaybe "" $ x ^? to words . ix 0
|
||||
y = fromMaybe "" $ x ^? to words . ix 1
|
||||
-- (s',m) <- fmap (s,) (PTE.lookup s coms) <|> dowrap s coms
|
||||
-- (arg,_) <- dowrap y m
|
||||
(s',arg,_) <- if yi > 0 then doubleFindSucc s y coms <|> doubleFindMin coms
|
||||
else doubleFindPred s y coms <|> doubleFindMax coms
|
||||
(s', arg, _) <-
|
||||
if yi > 0
|
||||
then doubleFindSucc s y coms <|> doubleFindMin coms
|
||||
else doubleFindPred s y coms <|> doubleFindMax coms
|
||||
return $ tm & tmStatus . tiText .~ s' ++ " " ++ arg
|
||||
--case tm ^? tmInput . tiSel of
|
||||
-- Nothing -> tm & tmInput . tiSel .~ (0, 0)
|
||||
-- Just (i, _) ->
|
||||
-- let newi = (i - yi) `mod` length (scrollCommandStrings w tm)
|
||||
-- in tm & setInput newi 0
|
||||
-- updatetermsubsel tm = case tm ^? tmInput . tiSel of
|
||||
-- Nothing -> tm & tmInput . tiSel .~ (0, 0)
|
||||
-- Just (i, j) ->
|
||||
-- let newj = (j - yi) `mod` length (getArguments' (scrollCommands tm !! i) tm w)
|
||||
-- in tm & setInput i newj
|
||||
-- setInput i j tm =
|
||||
-- tm
|
||||
-- & tmInput . tiSel .~ (i, j)
|
||||
-- & tmStatus . tiText .~ comstr ++ arg
|
||||
-- where
|
||||
-- comstr = scrollCommandStrings w tm !! i
|
||||
-- tc = scrollCommands tm !! i
|
||||
-- arg = getArguments' tc tm w !! j
|
||||
|
||||
doubleFindMin :: (Enum a,Enum b) => PTE.TrieMap a (PTE.TrieMap b c) -> Maybe ([a],[b],c)
|
||||
doubleFindMin :: (Enum a, Enum b) => PTE.TrieMap a (PTE.TrieMap b c) -> Maybe ([a], [b], c)
|
||||
doubleFindMin m = do
|
||||
(x,n) <- PTE.findMin m
|
||||
(x, n) <- PTE.findMin m
|
||||
case PTE.findMin n of
|
||||
Just (y,z) -> Just (x,y,z)
|
||||
Just (y, z) -> Just (x, y, z)
|
||||
Nothing -> Nothing
|
||||
|
||||
doubleFindSucc :: (Enum a,Enum b) => [a] -> [b] -> PTE.TrieMap a (PTE.TrieMap b c) -> Maybe ([a],[b],c)
|
||||
doubleFindSucc :: (Enum a, Enum b) => [a] -> [b] -> PTE.TrieMap a (PTE.TrieMap b c) -> Maybe ([a], [b], c)
|
||||
doubleFindSucc xs ys m = case PTE.lookup xs m of
|
||||
Just m' -> case PTE.findSuccessor ys m' of
|
||||
Just (ys',z) -> Just (xs,ys',z)
|
||||
Just (ys', z) -> Just (xs, ys', z)
|
||||
Nothing -> dfs xs m
|
||||
Nothing -> dfs xs m
|
||||
where
|
||||
dfs xs' m' = case PTE.findSuccessor xs' m' of
|
||||
Just (xs'',n) -> case PTE.findMin n of
|
||||
Just (ys',z) -> Just (xs'',ys',z)
|
||||
Just (xs'', n) -> case PTE.findMin n of
|
||||
Just (ys', z) -> Just (xs'', ys', z)
|
||||
Nothing -> dfs xs'' m'
|
||||
Nothing -> Nothing
|
||||
|
||||
-- there are edge cases where this doesn't behave as might be expected
|
||||
doubleFindMax :: (Enum a,Enum b) => PTE.TrieMap a (PTE.TrieMap b c) -> Maybe ([a],[b],c)
|
||||
doubleFindMax :: (Enum a, Enum b) => PTE.TrieMap a (PTE.TrieMap b c) -> Maybe ([a], [b], c)
|
||||
doubleFindMax m = do
|
||||
(x,n) <- PTE.findMax m
|
||||
(x, n) <- PTE.findMax m
|
||||
case PTE.findMax n of
|
||||
Just (y,z) -> Just (x,y,z)
|
||||
Just (y, z) -> Just (x, y, z)
|
||||
Nothing -> Nothing
|
||||
|
||||
doubleFindPred :: (Enum a,Enum b) => [a] -> [b] -> PTE.TrieMap a (PTE.TrieMap b c) -> Maybe ([a],[b],c)
|
||||
doubleFindPred ::
|
||||
(Enum a, Enum b) => [a] -> [b] -> PTE.TrieMap a (PTE.TrieMap b c) -> Maybe ([a], [b], c)
|
||||
doubleFindPred xs ys m = case PTE.lookup xs m of
|
||||
Just m' -> case PTE.findPredecessor ys m' of
|
||||
Just (ys',z) -> Just (xs,ys',z)
|
||||
Just (ys', z) -> Just (xs, ys', z)
|
||||
Nothing -> dfs xs m
|
||||
Nothing -> dfs xs m
|
||||
where
|
||||
dfs xs' m' = case PTE.findPredecessor xs' m' of
|
||||
Just (xs'',n) -> case PTE.findMax n of
|
||||
Just (ys',z) -> Just (xs'',ys',z)
|
||||
Just (xs'', n) -> case PTE.findMax n of
|
||||
Just (ys', z) -> Just (xs'', ys', z)
|
||||
Nothing -> dfs xs'' m'
|
||||
Nothing -> Nothing
|
||||
|
||||
|
||||
Reference in New Issue
Block a user