extends Node var normal_boot : bool = false @export_file(".tscn") var youth_room_path: String @export_file(".tscn") var transition_room_path: String @export_file(".tscn") var adulthood_room_path: String @export_file(".tscn") var ending_path: String @onready var curtain: Curtain = %Curtain @onready var credits_roll: Control = %CreditsRoll @onready var main_menu: MainMenu = %MainMenu @onready var pause_menu: PauseMenu = %PauseMenu @onready var room_paths := { State.rooms.NULL: youth_room_path, # Maybe Draven story? State.rooms.YOUTH: youth_room_path, State.rooms.TRANSITION: transition_room_path, State.rooms.ADULTHOOD: adulthood_room_path, State.rooms.ENDING: ending_path } enum AppState {BOOT, MENU, PLAY, PAUSE, CREDITS} var state: AppState = AppState.BOOT: set(value): state = value print("main.gd: app_state changing to: %s" % str(state)) match state: AppState.BOOT: credits_roll.hide() main_menu.hide() pause_menu.hide() AppState.MENU: credits_roll.hide() pause_menu.hide() await main_menu.execute() AppState.PLAY: credits_roll.hide() main_menu.hide() pause_menu.hide() AppState.PAUSE: credits_roll.hide() main_menu.hide() pause_menu.show() AppState.CREDITS: main_menu.hide() pause_menu.hide() credits_roll.play() func _enter_tree() -> void: print("main.gd: _enter_tree()") func _ready() -> void: print("main.gd: _ready()") main_menu.continue_button.pressed.connect(func(): state = AppState.PLAY) main_menu.credits_button.pressed.connect(func(): state = AppState.CREDITS) #TODO: Load the last savegame(?) await %Loading.stop() if normal_boot: print("main.gd: normal boot (loading last save and showing main menu)") state = AppState.MENU else: print("main.gd: direct boot (hiding menus and entering main loop)") state = AppState.PLAY func start_game(save: SaveGame) -> void: print("main.gd: play_game()") var room_path := room_paths.get(save.current_room, youth_room_path) as String while room_path: await _load_room(room_path) room_path = await State.room.play() # Ending? Roll credits? func _load_room(scene_path: String) -> void: await curtain.close() %Loading.play() if State.room: State.room.unload() State.room.queue_free() State.room = null ResourceLoader.load_threaded_request(scene_path, "PackedScene", true) while true: await get_tree().process_frame var load_state := ResourceLoader.load_threaded_get_status(scene_path) match load_state: ResourceLoader.THREAD_LOAD_LOADED: var next_scene := ResourceLoader.load_threaded_get(scene_path) as PackedScene State.room = next_scene.instantiate() as Room get_tree().root.add_child(State.room) await get_tree().process_frame %Loading.stop() return ResourceLoader.THREAD_LOAD_FAILED: push_error("Failed to load room.") break assert(false, "Couldn't load room %s" % scene_path) func _unhandled_input(event: InputEvent) -> void: if event.is_action_type(): print_debug("Unhandled Input", event) if event.is_action_pressed("ui_pause"): state = AppState.PAUSE