class_name GameHost extends Node signal game_loaded(game: ArcadeGame) signal game_unloaded var current_game: ArcadeGame func load_game(game_definition: GameDefinition) -> ArcadeGame: unload_game() if game_definition == null: push_error("GameHost received a null GameDefinition.") return null if game_definition.scene == null: push_error( "Game '%s' has no scene assigned." % game_definition.game_id ) return null var instance := game_definition.scene.instantiate() if not instance is ArcadeGame: push_error( "Game scene '%s' does not inherit from ArcadeGame." % game_definition.game_id ) instance.queue_free() return null current_game = instance as ArcadeGame add_child(current_game) current_game.game_started.connect(_on_game_started) current_game.game_won.connect(_on_game_won) current_game.game_lost.connect(_on_game_lost) current_game.game_reset.connect(_on_game_reset) game_loaded.emit(current_game) print( "[GAME HOST] Loaded '%s'" % game_definition.display_name ) return current_game func unload_game() -> void: if current_game == null: return print("[GAME HOST] Unloading current game.") current_game.queue_free() current_game = null game_unloaded.emit() func _on_game_started() -> void: RoomRuntime.fire_game_event(GameEvents.STARTED) func _on_game_won() -> void: RoomRuntime.fire_game_event(GameEvents.WON) func _on_game_lost() -> void: RoomRuntime.fire_game_event(GameEvents.LOST) func _on_game_reset() -> void: RoomRuntime.fire_game_event(GameEvents.RESET)