Skip to content

Commit

Permalink
feat: added EngineService onVarsInitialized() to notify services when…
Browse files Browse the repository at this point in the history
… game vars are ready to use
  • Loading branch information
AlmasB committed Mar 17, 2024
1 parent 7b85fe0 commit 75fc7f1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ abstract class EngineService : Updatable, SerializableType {
*/
open fun onMainLoopStarting() { }

/**
* Called after initGameVars() is completed.
* This is called on a background thread.
*/
open fun onVarsInitialized(vars: PropertyMap) { }

/**
* Called when initGame(), initPhysics(), initUI() all completed and
* the game is ready to be played.
Expand Down
4 changes: 4 additions & 0 deletions fxgl/src/main/kotlin/com/almasb/fxgl/app/Engine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ internal class Engine(val settings: ReadOnlyGameSettings) {
services.forEach { it.onGameUpdate(tpf) }
}

fun onVarsInitialized(vars: PropertyMap) {
services.forEach { it.onVarsInitialized(vars) }
}

fun onGameReady(vars: PropertyMap) {
services.forEach { it.onGameReady(vars) }
}
Expand Down
2 changes: 2 additions & 0 deletions fxgl/src/main/kotlin/com/almasb/fxgl/app/FXGLApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ class FXGLApplication : Application() {
FXGL.getWorldProperties().setValue(name, value)
}

engine.onVarsInitialized(FXGL.getWorldProperties())

app.initGame();
}

Expand Down

0 comments on commit 75fc7f1

Please sign in to comment.