Introduce idea of world event flags

This commit is contained in:
2023-02-23 11:46:45 +00:00
parent da49d7003e
commit fc0fd5fa37
7 changed files with 87 additions and 60 deletions
+22 -14
View File
@@ -7,8 +7,7 @@ Description : Simulation update
module Dodge.Update (updateUniverse) where
--import Dodge.InputFocus
import Dodge.DisplayInventory
import Dodge.ScrollValue
import Color
import Control.Applicative
import Data.List
@@ -21,6 +20,7 @@ import Dodge.CrGroupUpdate
import Dodge.Creature.Update
--import Dodge.Data.SelectionList
import Dodge.Data.Universe
import Dodge.DisplayInventory
import Dodge.Distortion
import Dodge.DrWdWd
import Dodge.EnergyBall
@@ -43,6 +43,7 @@ import Dodge.Projectile.Update
import Dodge.Prop.Update
import Dodge.RadarBlip
import Dodge.RadarSweep
import Dodge.ScrollValue
import Dodge.Shockwave.Update
import Dodge.SoundLogic
import Dodge.Spark
@@ -69,10 +70,10 @@ updateUniverse :: Universe -> Universe
updateUniverse u =
updateUniverseLast
. advanceScrollAmount
. updateWorldEventFlags
. maybeOpenTerminal
. over (uvWorld . input . textInput) (const mempty)
. updateUniverseMid
. updatePositionHUD
. updateUseInput
. over uvWorld (updateCamera cfig)
. over (uvWorld . input) updateScrollTestValue
@@ -81,6 +82,17 @@ updateUniverse u =
where
cfig = u ^. uvConfig
updateWorldEventFlags :: Universe -> Universe
updateWorldEventFlags u =
(uvWorld . worldEventFlags .~ mempty)
. updateInventoryPositioning
$ foldr updateWorldEventFlag u (u ^. uvWorld . worldEventFlags)
updateWorldEventFlag :: WorldEventFlag -> Universe -> Universe
updateWorldEventFlag wef = case wef of
InventoryChange -> id -- TODO determine more precisely when the inventory does change
CombineInventoryChange -> updateCombinePositioning
maybeOpenTerminal :: Universe -> Universe
maybeOpenTerminal u = case u ^. uvWorld . input . pressedKeys . at ScancodeSemicolon of
Just InitialPress -> gotoTerminal u
@@ -91,11 +103,6 @@ gotoTerminal w = case _uvScreenLayers w of
(InputScreen{} : _) -> w
_ -> w & uvScreenLayers .:~ InputScreen mempty "Enter command"
updateUniverseLast :: Universe -> Universe
updateUniverseLast =
over uvWorld (input . mouseButtons . each .~ True) -- to determine if the mouse button is held
@@ -248,13 +255,12 @@ functionalUpdate w =
-- where
-- y = w ^. input . scrollAmount
updateWheelEvents :: World -> World
updateWheelEvents w
updateWheelEvents w
| yi == 0 = w
| otherwise = updateWheelEvent yi w
where
yi = w ^. input . scrollAmount
advanceScrollAmount :: Universe -> Universe
advanceScrollAmount u =
u
@@ -267,10 +273,11 @@ updatePastWorlds w = w & pastWorlds %~ (forceFoldable . take 100 . ((w ^. lWorld
--updatePastWorlds w = w & pastWorlds .~ []
doWorldEvents :: World -> World
doWorldEvents w = foldl'
(flip doWdWd)
(w & cWorld . lWorld . worldEvents .~ [])
(w ^. cWorld . lWorld . worldEvents)
doWorldEvents w =
foldl'
(flip doWdWd)
(w & cWorld . lWorld . worldEvents .~ [])
(w ^. cWorld . lWorld . worldEvents)
updateLasers :: World -> World
updateLasers w =
@@ -565,6 +572,7 @@ updateSeenWalls w = foldl' markWallSeen w (map (_wlID . snd) $ allVisibleWalls w
markWallSeen :: World -> Int -> World
markWallSeen w i = w & cWorld . seenWalls . at i ?~ ()
--markWallSeen !w !i = w & cWorld . lWorld . walls %~ IM.adjust markSeen i
-- in the past there might have been a space leak, which the following was meant
-- to fix