Skip to content

Commit

Permalink
OOPS: Restored scene manager previous
Browse files Browse the repository at this point in the history
  • Loading branch information
davesmith00000 committed Apr 13, 2024
1 parent 5e02245 commit cc29a57
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
13 changes: 13 additions & 0 deletions indigo/indigo/src/main/scala/indigo/scenes/SceneManager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@ class SceneManager[StartUpData, GameModel, ViewModel](

Outcome(model, events)

case SceneEvent.Previous =>
lastSceneChangeAt = frameContext.gameTime.running

val from = finderInstance.current.name
finderInstance = finderInstance.backward
val to = finderInstance.current.name

val events =
if from == to then Batch.empty
else Batch(SceneEvent.SceneChange(from, to, lastSceneChangeAt))

Outcome(model, events)

case SceneEvent.LoopPrevious =>
lastSceneChangeAt = frameContext.gameTime.running

Expand Down
8 changes: 6 additions & 2 deletions indigo/indigo/src/test/scala/indigo/scenes/TestScenes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ final case class TestSceneA(id: String) extends Scene[Unit, TestGameModel, TestV
val subSystems: Set[SubSystem] = Set()

def updateModel(context: SceneContext[Unit], sceneModel: TestSceneModelA): GlobalEvent => Outcome[TestSceneModelA] =
_ => Outcome(sceneModel.copy(count = sceneModel.count + 1))
_ =>
// println(s"A - before: ${sceneModel.count}, after: ${sceneModel.count + 1}")
Outcome(sceneModel.copy(count = sceneModel.count + 1))

def updateViewModel(
context: SceneContext[Unit],
Expand Down Expand Up @@ -125,7 +127,9 @@ final case class TestSceneB(id: String) extends Scene[Unit, TestGameModel, TestV
val subSystems: Set[SubSystem] = Set()

def updateModel(context: SceneContext[Unit], sceneModel: TestSceneModelB): GlobalEvent => Outcome[TestSceneModelB] =
_ => Outcome(sceneModel.copy(count = sceneModel.count + 10))
_ =>
// println(s"B - before: ${sceneModel.count}, after: ${sceneModel.count + 10}")
Outcome(sceneModel.copy(count = sceneModel.count + 10))

def updateViewModel(
context: SceneContext[Unit],
Expand Down

0 comments on commit cc29a57

Please sign in to comment.