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: PauseManu = %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 app_state: AppState = AppState.BOOT: set(value): app_state = value print_debug("main.gd: app_state changing to: %s" % str(app_state)) match app_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_debug("main.gd: _enter_tree()") func _ready() -> void: print_debug("main.gd: _ready()") await get_tree().process_frame main_menu.continue_button.pressed.connect(func(): app_state = AppState.PLAY) main_menu.credits_button.pressed.connect(func(): app_state = AppState.CREDITS) #TODO: Load the last savegame(?) await %Loading.stop() if normal_boot: print_debug("main.gd: normal boot (loading last save and showing main menu)") app_state = AppState.MENU else: print_debug("main.gd: direct boot (hiding menus and entering main loop)") app_state = AppState.PLAY func start_game(save: SaveGame) -> void: print_debug("main.gd: play_game()") var room_path := room_paths.get(save.current_room, youth_room_path) as String await _load_room(room_path) await State.room.play() func load_subway(): await curtain.close() if State.room: State.room.queue_free() await _load_room(transition_room_path) await State.room.play() func _load_room(scene_path: String) -> void: await curtain.close() %Loading.play() if State.room != null: State.room.unload() State.room = null ResourceLoader.load_threaded_request(scene_path, "PackedScene", true) while true: await get_tree().process_frame var state := ResourceLoader.load_threaded_get_status(scene_path) match state: ResourceLoader.THREAD_LOAD_LOADED: var next_scene := ResourceLoader.load_threaded_get(youth_room_path) as PackedScene State.room = next_scene.instantiate() as RoomTemplate get_tree().root.add_child(State.room) await get_tree().process_frame await State.room.get_ready() %Loading.stop() return ResourceLoader.THREAD_LOAD_FAILED: push_error("Failed to load room.") break assert(false, "Couldn't load room %s" % scene_path)