From 5810c2262a0cfb611a404b278c767cabd9312956 Mon Sep 17 00:00:00 2001 From: justin Date: Mon, 16 Jan 2023 01:52:12 +0000 Subject: [PATCH] Get rid of world hammers --- src/Dodge/Bullet.hs | 2 +- src/Dodge/Combine.hs | 35 +++++++-------------------- src/Dodge/Data/Input.hs | 14 ----------- src/Dodge/Data/SelectionList.hs | 1 - src/Dodge/Default/World.hs | 5 ---- src/Dodge/Render/HUD.hs | 15 ++++++++++-- src/Dodge/SelectionList.hs | 6 ++--- src/Dodge/Update.hs | 5 ---- src/Dodge/Update/UsingInput.hs | 43 ++++++++++++--------------------- 9 files changed, 40 insertions(+), 86 deletions(-) diff --git a/src/Dodge/Bullet.hs b/src/Dodge/Bullet.hs index 830a6b80d..d992289b7 100644 --- a/src/Dodge/Bullet.hs +++ b/src/Dodge/Bullet.hs @@ -94,7 +94,7 @@ bulletSpawn bu = case _buSpawn bu of BulSpark -> Nothing BulFlak -> Just (makeFlak bu) BulFrag -> Just makeFragBullets - BulGas -> Just (flip makeGasCloud (V2 0 0)) + BulGas -> Just (`makeGasCloud` V2 0 0) BulBall IncBall -> Just incBallAt BulBall ConcBall -> Just $ \p -> cWorld . lWorld . shockwaves .:~ concBall p BulBall TeslaBall -> Just makeStaticBall diff --git a/src/Dodge/Combine.hs b/src/Dodge/Combine.hs index 48ce821e2..59beb817a 100644 --- a/src/Dodge/Combine.hs +++ b/src/Dodge/Combine.hs @@ -2,10 +2,10 @@ module Dodge.Combine ( toggleCombineInv, enterCombineInv, - combineListSelection, - picsToSelectable, + combineList, ) where +import SelectionIntMap import Dodge.Data.Combine import Dodge.Item.Display import Color @@ -108,29 +108,12 @@ toggleCombineInv w = case w ^. hud . hudElement of _ -> w & enterCombineInv enterCombineInv :: World -> World -enterCombineInv w = w & hud . hudElement . subInventory .~ CombineInventory - (combineListSelection w mi "" False) +enterCombineInv w = w & hud . hudElement . subInventory .~ CombineInventory sm where - mi = 0 <$ listToMaybe (combineList w) - -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) - } - -picsToSelectable :: Int -> [String] -> SelectionItem () -picsToSelectable wdth pics = - SelectionItem - { _siPictures = pics - , _siHeight = length pics - , _siIsSelectable = True - , _siWidth = wdth - , _siColor = white - , _siOffX = 0 - , _siPayload = () + sm = initialSelPos $ SelectionIntMap + { _smItems = combineList w + , _smSelPos = Nothing + , _smRegex = "" + , _smRegexInput = False + , _smShownItems = IM.fromAscList $ zip [0..] (combineList w) } diff --git a/src/Dodge/Data/Input.hs b/src/Dodge/Data/Input.hs index ef51efb76..f2538d1fe 100644 --- a/src/Dodge/Data/Input.hs +++ b/src/Dodge/Data/Input.hs @@ -5,7 +5,6 @@ module Dodge.Data.Input where import Control.Lens import qualified Data.Map.Strict as M -import Dodge.Data.CWorld import Geometry.Data import SDL (MouseButton, Scancode) @@ -14,13 +13,6 @@ data PressType = InitialPress | LongPress deriving (Eq,Show) -data MouseButtonInfo = MouseButtonInfo - { _mbHeldDown :: Bool - , _mbFlags :: [MouseButtonFlag] - } -data MouseButtonFlag - = PressedStartRewind - data Input = Input { _mousePos :: Point2 , _mouseMoving :: Bool @@ -28,7 +20,6 @@ data Input = Input , _mouseButtons :: M.Map MouseButton Bool -- shortpress False, repeatpress True , _scrollAmount :: Int , _previousScrollAmount :: Int - , _hammers :: M.Map WorldHammer HammerPosition , _lLine :: (Point2, Point2) , _rLine :: (Point2, Point2) , _lrLine :: (Point2, Point2) @@ -39,9 +30,4 @@ data Input = Input , _scrollTestValue :: Float } -data WorldHammer - = SubInvHam - | DoubleMouseHam - deriving (Eq, Ord, Show, Read, Enum, Bounded) - makeLenses ''Input diff --git a/src/Dodge/Data/SelectionList.hs b/src/Dodge/Data/SelectionList.hs index 42009712f..f8cf16c42 100644 --- a/src/Dodge/Data/SelectionList.hs +++ b/src/Dodge/Data/SelectionList.hs @@ -33,7 +33,6 @@ data SelectionList a = SelectionList data SelectionIntMap a = SelectionIntMap { _smItems :: [SelectionItem a] , _smSelPos :: Maybe Int - , _smLength :: Int , _smRegex :: String , _smRegexInput :: Bool , _smShownItems :: IntMap (SelectionItem a) diff --git a/src/Dodge/Default/World.hs b/src/Dodge/Default/World.hs index ef1e5f2bd..e29cd3300 100644 --- a/src/Dodge/Default/World.hs +++ b/src/Dodge/Default/World.hs @@ -3,7 +3,6 @@ module Dodge.Default.World where --import Dodge.Data.SelectionList import Data.Graph.Inductive.Graph hiding ((&)) import qualified Data.Map as M -import qualified Data.Set as S import Dodge.Data.World import Geometry.Data import Geometry.Polygon @@ -21,7 +20,6 @@ defaultInput = , _mouseMoving = False , _scrollAmount = 0 , _previousScrollAmount = 0 - , _hammers = defaultWorldHammers , _lrLine = (0, 0) , _lLine = (0, 0) , _rLine = (0, 0) @@ -154,9 +152,6 @@ defaultHUD = , _closeObjects = [] } -defaultWorldHammers :: M.Map WorldHammer HammerPosition -defaultWorldHammers = M.fromSet (const HammerUp) $ S.fromList [minBound .. maxBound] - --youLight :: TempLightSource --youLight = TLS -- { _tlsParam = LSParam diff --git a/src/Dodge/Render/HUD.hs b/src/Dodge/Render/HUD.hs index a09eb0078..7f2f48587 100644 --- a/src/Dodge/Render/HUD.hs +++ b/src/Dodge/Render/HUD.hs @@ -6,7 +6,6 @@ module Dodge.Render.HUD ( import SelectionIntMap import Dodge.Data.Combine import Dodge.Default.SelectionList -import Dodge.Combine import Dodge.Creature.Info import Control.Lens import qualified Data.Map.Strict as M @@ -90,7 +89,7 @@ drawSubInventory subinv cfig w = case subinv of let mi = _smSelPos sl in titledSub' cfig - ("COMBINE") + "COMBINE" sl <> combineInventoryExtra sl mi cfig w @@ -445,6 +444,18 @@ mainListCursor c = openCursorAt 120 c 5 0 textSelItems :: [String] -> [SelectionItem ()] textSelItems = map (picsToSelectable 15 . (: [])) +picsToSelectable :: Int -> [String] -> SelectionItem () +picsToSelectable wdth pics = + SelectionItem + { _siPictures = pics + , _siHeight = length pics + , _siIsSelectable = True + , _siWidth = wdth + , _siColor = white + , _siOffX = 0 + , _siPayload = () + } + openCursorAt :: -- | Width Float -> diff --git a/src/Dodge/SelectionList.hs b/src/Dodge/SelectionList.hs index 7d0545ee7..683331d44 100644 --- a/src/Dodge/SelectionList.hs +++ b/src/Dodge/SelectionList.hs @@ -1,12 +1,10 @@ module Dodge.SelectionList where ---import Color ---import Dodge.WindowLayout import Color import Regex import Dodge.Data.Universe import LensHelp ---import Data.Maybe +import Data.Maybe getAvailableListLines :: ListDisplayParams -> Configuration -> Int getAvailableListLines ldps cfig = floor ((dToBot - vgap) / itmHeight) @@ -42,7 +40,7 @@ moveSelectionListSelection :: Int -> SelectionList a -> SelectionList a moveSelectionListSelection yi sl = sl & slSelPos %~ f where f x | maxsel == 0 = Nothing - | x == Nothing = Just 0 + | isNothing x = Just 0 | otherwise = fmap ((`mod` maxsel) . subtract yi) x maxsel = case _slRegex sl of "" -> length (_slItems sl) diff --git a/src/Dodge/Update.hs b/src/Dodge/Update.hs index d4997a9c3..d051ad59a 100644 --- a/src/Dodge/Update.hs +++ b/src/Dodge/Update.hs @@ -24,7 +24,6 @@ import Dodge.DrWdWd import Dodge.EnergyBall import Dodge.Flame import Dodge.Flare -import Dodge.Hammer import Dodge.InputFocus import Dodge.Inventory import Dodge.Item.Location @@ -261,7 +260,6 @@ functionalUpdate w = checkEndGame . over uvWorld (cWorld . lWorld . lClock +~ 1) . over uvWorld updateWorldSelect' - . moveHammersUp . over uvWorld updateDistortions . over uvWorld updateCreatureSoundPositions . over uvWorld ppEvents @@ -355,9 +353,6 @@ updatePastWorlds w = w & pastWorlds %~ (forceFoldable . take 100 . ((w ^. lWorld --updatePastWorlds w = w & pastWorlds .~ [] -moveHammersUp :: Universe -> Universe -moveHammersUp = uvWorld . input . hammers %~ M.map moveHammerUp - doWorldEvents :: World -> World doWorldEvents w = foldl' (flip doWdWd) diff --git a/src/Dodge/Update/UsingInput.hs b/src/Dodge/Update/UsingInput.hs index 69fb7a923..ed9a18c27 100644 --- a/src/Dodge/Update/UsingInput.hs +++ b/src/Dodge/Update/UsingInput.hs @@ -3,6 +3,8 @@ module Dodge.Update.UsingInput ( updateUsingInput, ) where +import Dodge.Combine +import SelectionIntMap import Dodge.Data.Combine import Dodge.Data.SelectionList import Control.Lens @@ -27,46 +29,32 @@ updateUsingInput w = case w ^. hud . hudElement of pressedMBEffects :: SubInventory -> M.Map MouseButton Bool -> World -> World pressedMBEffects subinv pkeys w = case subinv of - NoSubInventory - | ButtonLeft `M.member` pkeys && w ^?! input . hammers . ix SubInvHam /= HammerUp -> - w & input . hammers . ix SubInvHam .~ HammerDown - | otherwise -> pressedMBEffectsNoInventory pkeys w + NoSubInventory -> pressedMBEffectsNoInventory pkeys w CombineInventory SelectionIntMap {_smSelPos = mi, _smRegexInput = False} - | pkeys ^? ix ButtonLeft == Just False -> - maybeexitcombine (maybe id doCombine mi w) & input . hammers . ix SubInvHam .~ HammerDown + | lbinitialpress -> maybeexitcombine (maybe id doCombine mi w) CombineInventory SelectionIntMap {_smRegexInput = True} - | pkeys ^? ix ButtonLeft == Just False - -> w & hud . hudElement . subInventory . subInvMap . smRegexInput .~ False + | lbinitialpress -> w & hud . hudElement . subInventory . subInvMap . smRegexInput .~ False DisplayTerminal tmid - | pkeys ^? ix ButtonLeft == Just False && inTermFocus w -> + | lbinitialpress && inTermFocus w -> doTerminalEffectLB (w ^?! cWorld . lWorld . terminals . ix tmid) w - & input . hammers . ix SubInvHam .~ HammerDown - | pkeys ^? ix ButtonLeft == Just False -> + | lbinitialpress -> w & cWorld . lWorld . terminals . ix tmid . tmInput . tiFocus %~ const True - & input . hammers . ix SubInvHam .~ HammerDown - _ - | ButtonLeft `M.member` pkeys -> - w & input . hammers . ix SubInvHam .~ HammerDown _ -> w where - maybeexitcombine - | ButtonRight `M.member` _mouseButtons (_input w) = id - | otherwise = hud . hudElement . subInventory .~ NoSubInventory + lbinitialpress = pkeys ^? ix ButtonLeft == Just False + maybeexitcombine w' + | ButtonRight `M.member` _mouseButtons (_input w) + = (hud . hudElement . subInventory . subInvMap %~ setShownIntMap) + $ (hud . hudElement . subInventory . subInvMap . smItems .~ combineList w') w' + | otherwise = w' & hud . hudElement . subInventory .~ NoSubInventory pressedMBEffectsNoInventory :: M.Map MouseButton Bool -> World -> World pressedMBEffectsNoInventory pkeys w - | isDown ButtonLeft && isDown ButtonRight && inTopInv = - useItem (you w) w & input . hammers . ix DoubleMouseHam .~ HammerDown - | isDown ButtonLeft && inTopInv - && w ^?! input . hammers . ix DoubleMouseHam == HammerUp = - useLeftItem 0 w - | isDown ButtonLeft && inTopInv = - w & input . hammers . ix DoubleMouseHam .~ HammerDown - | isDown ButtonRight && inTopInv = w + | isDown ButtonLeft && isDown ButtonRight && inTopInv = useItem (you w) w + | isDown ButtonLeft && inTopInv = useLeftItem 0 w | isDown ButtonMiddle = w & cWorld . camPos . camRot -~ rotation & input . clickMousePos .~ _mousePos (_input w) - | isDown ButtonLeft = w & input . hammers . ix DoubleMouseHam .~ HammerDown | otherwise = w where inTopInv = case w ^. hud . hudElement of @@ -81,7 +69,6 @@ doCombine :: Int -> World -> World doCombine i w = case w ^? hud . hudElement . subInventory . subInvMap . smShownItems . ix i . siPayload of Nothing -> w Just (CombinableItem is it _) -> - -- set (hud . hudElement) (DisplayInventory NoSubInventory) selectinv --enterCombineInv . createPutItem it $ foldr (rmInvItem 0) w (sort is)