33 lines
1 KiB
GDScript
33 lines
1 KiB
GDScript
class_name SceneRouter
|
|
## Moves between the menu and a game (the project's only scene changes), carrying what the next
|
|
## scene needs in `args`.
|
|
|
|
const MENU := "res://scenes/menu.tscn"
|
|
const GAME := "res://scenes/game.tscn"
|
|
|
|
## What the scene being entered should start with, e.g. {game: {seed, human, style}, settings}.
|
|
## The scene takes it with take().
|
|
static var args := {}
|
|
|
|
|
|
## Opens a game with `opts` ({seed, human, style}) and `settings`.
|
|
static func to_game(opts: Dictionary, settings: Dictionary) -> void:
|
|
args = {"game": opts, "settings": settings}
|
|
_tree().change_scene_to_file.call_deferred(GAME)
|
|
|
|
|
|
## Back to the menu; `screen` is "" for the title or "setup" for the new-game screen.
|
|
static func to_menu(screen := "") -> void:
|
|
args = {"screen": screen}
|
|
_tree().change_scene_to_file.call_deferred(MENU)
|
|
|
|
|
|
## The args left for this scene, cleared so a reload doesn't reuse them.
|
|
static func take() -> Dictionary:
|
|
var out := args
|
|
args = {}
|
|
return out
|
|
|
|
|
|
static func _tree() -> SceneTree:
|
|
return Engine.get_main_loop() as SceneTree
|