2025-12-10 17:52:09 +00:00
|
|
|
extends Control
|
2023-12-02 16:37:42 +00:00
|
|
|
|
2025-12-13 23:53:48 +00:00
|
|
|
var normal_boot : bool = false
|
|
|
|
|
|
2024-10-01 23:30:03 +00:00
|
|
|
@export_file(".tscn") var youth_room_path: String
|
2024-10-16 10:29:20 +00:00
|
|
|
@export_file(".tscn") var transition_room_path: String
|
|
|
|
|
@export_file(".tscn") var adulthood_room_path: String
|
|
|
|
|
@export_file(".tscn") var ending_path: String
|
2024-10-01 23:30:03 +00:00
|
|
|
|
2025-12-13 23:53:48 +00:00
|
|
|
@onready var curtain: Curtain = %Curtain
|
|
|
|
|
@onready var credits_roll: Control = %CreditsRoll
|
2025-12-12 23:22:21 +00:00
|
|
|
@onready var main_menu: MainMenu = %MainMenu
|
|
|
|
|
@onready var pause_menu: PauseManu = %PauseMenu
|
|
|
|
|
|
|
|
|
|
@onready var room_paths := {
|
|
|
|
|
State.rooms.NULL: youth_room_path, # Maybe Draeven story?
|
|
|
|
|
State.rooms.YOUTH: youth_room_path,
|
|
|
|
|
State.rooms.TRANSITION: transition_room_path,
|
|
|
|
|
State.rooms.ADULTHOOD: adulthood_room_path,
|
|
|
|
|
State.rooms.ENDING: ending_path
|
|
|
|
|
}
|
2025-12-10 17:52:09 +00:00
|
|
|
|
2025-12-15 16:57:26 +00:00
|
|
|
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()
|
|
|
|
|
main_menu.execute()
|
|
|
|
|
AppState.PLAY:
|
|
|
|
|
credits_roll.hide()
|
|
|
|
|
main_menu.hide()
|
|
|
|
|
pause_menu.hide()
|
|
|
|
|
curtain.hide()
|
|
|
|
|
AppState.PAUSE:
|
|
|
|
|
credits_roll.hide()
|
|
|
|
|
main_menu.hide()
|
|
|
|
|
pause_menu.show()
|
|
|
|
|
AppState.CREDITS:
|
|
|
|
|
main_menu.hide()
|
|
|
|
|
pause_menu.hide()
|
|
|
|
|
await credits_roll.play()
|
|
|
|
|
|
|
|
|
|
func _enter_tree() -> void:
|
|
|
|
|
print_debug("main.gd: _enter_tree()")
|
|
|
|
|
|
2025-12-12 15:33:06 +00:00
|
|
|
func _ready() -> void:
|
2025-12-13 23:53:48 +00:00
|
|
|
print_debug("main.gd: _ready()")
|
|
|
|
|
await get_tree().process_frame
|
2025-12-15 16:57:26 +00:00
|
|
|
main_menu.continue_button.pressed.connect(func(): app_state = AppState.PLAY)
|
|
|
|
|
main_menu.credits_button.pressed.connect(func(): app_state = AppState.CREDITS)
|
|
|
|
|
|
2025-12-13 23:53:48 +00:00
|
|
|
if normal_boot:
|
2025-12-15 16:57:26 +00:00
|
|
|
print_debug("main.gd: normal boot (loading last save and showing main menu)")
|
|
|
|
|
app_state = AppState.MENU
|
2025-12-12 23:22:21 +00:00
|
|
|
else:
|
2025-12-15 16:57:26 +00:00
|
|
|
print_debug("main.gd: direct boot (hiding menus and entering main loop)")
|
|
|
|
|
app_state = AppState.PLAY
|
2025-12-13 23:53:48 +00:00
|
|
|
#await _mainloop() # Debug functionality
|
2025-12-12 23:22:21 +00:00
|
|
|
|
2025-12-15 16:57:26 +00:00
|
|
|
func load_game(save: SaveGame) -> void:
|
|
|
|
|
print_debug("main.gd: _load_game()")
|
|
|
|
|
var room_path := room_paths.get(save.current_room, youth_room_path) as String
|
|
|
|
|
await _load_room(room_path)
|
2025-12-12 23:22:21 +00:00
|
|
|
|
2025-12-15 16:57:26 +00:00
|
|
|
func _load_room(next_path: String) -> bool:
|
2025-12-12 23:22:21 +00:00
|
|
|
if State.room != null:
|
|
|
|
|
State.room.unload()
|
2025-12-15 16:57:26 +00:00
|
|
|
State.room = null
|
|
|
|
|
await curtain.show()
|
2025-12-12 23:22:21 +00:00
|
|
|
ResourceLoader.load_threaded_request(next_path, "PackedScene", true)
|
|
|
|
|
while true:
|
|
|
|
|
await get_tree().process_frame
|
|
|
|
|
var state := ResourceLoader.load_threaded_get_status(next_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)
|
2025-12-15 16:57:26 +00:00
|
|
|
await State.room.get_ready()
|
|
|
|
|
await curtain.hide()
|
|
|
|
|
return true
|
2025-12-12 23:22:21 +00:00
|
|
|
ResourceLoader.THREAD_LOAD_FAILED:
|
|
|
|
|
push_error("Failed to load youth room scene.")
|
2025-12-15 16:57:26 +00:00
|
|
|
break
|
|
|
|
|
return false
|
2025-12-12 15:33:06 +00:00
|
|
|
|
|
|
|
|
|
2025-12-10 17:52:09 +00:00
|
|
|
#
|
|
|
|
|
#var in_game = false
|
|
|
|
|
#
|
|
|
|
|
#var current_room: RoomTemplate
|
|
|
|
|
#var currently_loading_room: String = "":
|
|
|
|
|
# set(path):
|
|
|
|
|
# if path != "":
|
|
|
|
|
# ResourceLoader.load_threaded_request(path, "PackedScene")
|
|
|
|
|
# menu_animation["parameters/conditions/loading_done"] = false
|
|
|
|
|
# menu_animation["parameters/conditions/load_save"] = true
|
|
|
|
|
# else:
|
|
|
|
|
# menu_animation["parameters/conditions/loading_done"] = true
|
|
|
|
|
# menu_animation["parameters/conditions/load_save"] = false
|
|
|
|
|
#
|
|
|
|
|
# currently_loading_room = path
|
|
|
|
|
#
|
|
|
|
|
## Called when the node enters the scene tree for the first time.
|
|
|
|
|
#func _ready():
|
|
|
|
|
# main_menu.start_game.connect(load_save)
|
|
|
|
|
# main_menu.roll_credits.connect(func(): state_machine.travel("credits_roll"))
|
|
|
|
|
# get_tree().tree_process_mode_changed.connect(pause_mode_changed)
|
|
|
|
|
# await get_tree().process_frame
|
|
|
|
|
# currently_loading_room = get_room_path_from_id(main_menu.save_game_handle.get_most_recent_save().current_room)
|
|
|
|
|
# State.pass_stage_to(main_menu)
|
|
|
|
|
#
|
|
|
|
|
# Scenes.scene_starting.connect(prepare_transition)
|
|
|
|
|
# Scenes.scene_finished.connect(transition)
|
|
|
|
|
#
|
|
|
|
|
#func _process(_delta: float) -> void:
|
|
|
|
|
# if currently_loading_room != "" and not await_swap:
|
|
|
|
|
# if ResourceLoader.load_threaded_get_status(currently_loading_room) == 3:
|
|
|
|
|
# if not current_room == null:
|
|
|
|
|
# current_room.queue_free()
|
|
|
|
|
# State.onready_room = get_room_id_from_path(currently_loading_room)
|
|
|
|
|
# current_room = ResourceLoader.load_threaded_get(currently_loading_room).instantiate()
|
2025-12-13 10:06:15 +00:00
|
|
|
# print_debug("add room")
|
2025-12-10 17:52:09 +00:00
|
|
|
# add_child(current_room)
|
|
|
|
|
# State.onready_room = State.rooms.NULL
|
|
|
|
|
# move_child(current_room, 0)
|
|
|
|
|
# currently_loading_room = ""
|
|
|
|
|
# room_loaded.emit()
|
|
|
|
|
#
|
|
|
|
|
# if Input.is_action_just_pressed("reset_demo") and (OS.has_feature("demo") or true):
|
|
|
|
|
# State.stage_list = [self]
|
|
|
|
|
# _return_to_menu()
|
|
|
|
|
#
|
2025-12-12 23:22:21 +00:00
|
|
|
func _unhandled_input(event: InputEvent) -> void:
|
|
|
|
|
if event is InputEvent:
|
2025-12-15 16:57:26 +00:00
|
|
|
match app_state:
|
|
|
|
|
AppState.BOOT:
|
|
|
|
|
pass
|
|
|
|
|
AppState.MENU:
|
|
|
|
|
pass
|
|
|
|
|
AppState.PLAY:
|
|
|
|
|
if event.is_action_pressed("ui_menu"):
|
|
|
|
|
app_state = AppState.PAUSE
|
|
|
|
|
AppState.PAUSE:
|
|
|
|
|
if event.is_action_pressed("ui_menu"):
|
|
|
|
|
app_state = AppState.PLAY
|
2025-12-12 23:22:21 +00:00
|
|
|
|
2025-12-10 17:52:09 +00:00
|
|
|
# if not get_tree().paused:
|
|
|
|
|
# get_tree().paused = true
|
|
|
|
|
# var state_machine := menu_animation["parameters/playback"]
|
|
|
|
|
# state_machine.travel("reveal_pause_menu")
|
|
|
|
|
# Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
|
|
|
|
# else:
|
|
|
|
|
# get_tree().paused = false
|
|
|
|
|
# var state_machine := menu_animation["parameters/playback"]
|
|
|
|
|
# state_machine.travel("start_game")
|
|
|
|
|
#
|
|
|
|
|
# if State.stage_list[0] is Player:
|
|
|
|
|
# Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
|
|
|
|
|
|
|
|
|
#func debug_youth():
|
|
|
|
|
# get_child(1).hide()
|
|
|
|
|
# get_child(2).hide()
|
|
|
|
|
# get_child(3).hide()
|
|
|
|
|
# get_child(0).get_ready()
|
|
|
|
|
# get_child(0).start()
|
|
|
|
|
#
|
|
|
|
|
#func _return_to_menu():
|
|
|
|
|
# State.active_save_game = null
|
|
|
|
|
#
|
|
|
|
|
# menu_animation["parameters/conditions/start_game"] = false
|
|
|
|
|
#
|
|
|
|
|
# State.pass_stage_to(main_menu)
|
|
|
|
|
#
|
|
|
|
|
# currently_loading_room = get_room_path_from_id(main_menu.save_game_handle.get_most_recent_save().current_room)
|
|
|
|
|
#
|
|
|
|
|
# menu_animation["parameters/conditions/return_to_menu"] = true
|
|
|
|
|
# await(get_tree().create_timer(0.5).timeout)
|
|
|
|
|
# menu_animation["parameters/conditions/return_to_menu"] = false
|
|
|
|
|
# _on_ready_to_unload()
|
|
|
|
|
#
|
|
|
|
|
#func load_save(save: SaveGame):
|
|
|
|
|
#
|
|
|
|
|
# if currently_loading_room != "":
|
|
|
|
|
# await(room_loaded)
|
|
|
|
|
#
|
|
|
|
|
# if save.current_room != current_room.id:
|
|
|
|
|
# # TODO Prevent race condition from appearing when save is loaded while room is still loading.
|
|
|
|
|
# currently_loading_room = get_room_path_from_id(save.current_room)
|
|
|
|
|
# await(room_loaded)
|
|
|
|
|
#
|
|
|
|
|
# menu_animation["parameters/conditions/start_game"] = true
|
|
|
|
|
#
|
|
|
|
|
# State.active_save_game = save
|
|
|
|
|
# in_game = true
|
|
|
|
|
# current_room.start_room()
|
|
|
|
|
#
|
|
|
|
|
#func _on_ready_to_unload():
|
|
|
|
|
# if get_child(0) is Node3D:
|
|
|
|
|
# get_child(0).free()
|
|
|
|
|
#
|
|
|
|
|
#func get_room_path_from_id(id: State.rooms) -> String:
|
|
|
|
|
# match id:
|
|
|
|
|
# State.rooms.YOUTH, State.rooms.NULL:
|
|
|
|
|
# return youth_room_path
|
|
|
|
|
# State.rooms.TRANSITION:
|
|
|
|
|
# return transition_room_path
|
|
|
|
|
# State.rooms.ADULTHOOD:
|
|
|
|
|
# return adulthood_room_path
|
|
|
|
|
# _:
|
|
|
|
|
# return ending_path
|
|
|
|
|
#
|
|
|
|
|
#func get_room_id_from_path(path: String) -> State.rooms:
|
|
|
|
|
# match path:
|
|
|
|
|
# youth_room_path:
|
|
|
|
|
# return State.rooms.YOUTH
|
|
|
|
|
# transition_room_path:
|
|
|
|
|
# return State.rooms.TRANSITION
|
|
|
|
|
# adulthood_room_path:
|
|
|
|
|
# return State.rooms.ADULTHOOD
|
|
|
|
|
# _:
|
|
|
|
|
# return State.rooms.NULL
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
#func start_demo():
|
|
|
|
|
# #FIXME this causes the room to reload
|
|
|
|
|
# #load_save(SaveGame.new())
|
|
|
|
|
# current_room.start_room()
|
|
|
|
|
# in_game = true
|
|
|
|
|
#
|
|
|
|
|
#func pause_mode_changed():
|
2025-12-13 10:06:15 +00:00
|
|
|
# print_debug(get_tree().paused)
|
2025-12-10 17:52:09 +00:00
|
|
|
#
|
|
|
|
|
#var await_swap: bool = false
|
|
|
|
|
#func prepare_transition(scene_id: Scenes.id, _repeat):
|
|
|
|
|
# if scene_id == Scenes.id.TRANSITION:
|
|
|
|
|
# await_swap = true
|
|
|
|
|
# #FIXME: this does not need to be part of the sequence
|
|
|
|
|
# await(get_tree().process_frame)
|
|
|
|
|
# current_room.prepare_transition()
|
|
|
|
|
# if not _repeat:
|
|
|
|
|
# currently_loading_room = get_room_path_from_id(State.rooms.TRANSITION)
|
|
|
|
|
# else:
|
|
|
|
|
#
|
|
|
|
|
# currently_loading_room = get_room_path_from_id(State.rooms.ADULTHOOD)
|
|
|
|
|
#
|
|
|
|
|
#func transition(scene_id: Scenes.id, _repeat):
|
|
|
|
|
# if scene_id == Scenes.id.TRANSITION:
|
|
|
|
|
# State.reset_focus()
|
|
|
|
|
# await_swap = false
|
|
|
|
|
# await room_loaded
|
|
|
|
|
# if not _repeat:
|
|
|
|
|
# State.queue_for_stage(current_room)
|
|
|
|
|
# Scenes.end_current_sequence()
|
|
|
|
|
# else:
|
|
|
|
|
# State.pass_stage_to(current_room)
|