frame-of-mind/src/singletons/main/main.gd

127 lines
3.5 KiB
GDScript3
Raw Normal View History

2026-01-11 23:15:05 +00:00
extends Node
2023-12-02 16:37:42 +00:00
var normal_boot : bool = false
@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
@onready var curtain: Curtain = %Curtain
@onready var credits_roll: Control = %CreditsRoll
@onready var main_menu: MainMenu = %MainMenu
2026-01-22 14:12:24 +00:00
@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
}
2025-12-10 17:52:09 +00:00
2025-12-15 16:57:26 +00:00
enum AppState {BOOT, MENU, PLAY, PAUSE, CREDITS}
2026-01-22 14:12:24 +00:00
var state: AppState = AppState.BOOT:
2025-12-15 16:57:26 +00:00
set(value):
2026-01-22 14:12:24 +00:00
state = value
print("main.gd: app_state changing to: %s" % str(state))
match state:
2025-12-15 16:57:26 +00:00
AppState.BOOT:
credits_roll.hide()
main_menu.hide()
pause_menu.hide()
AppState.MENU:
credits_roll.hide()
pause_menu.hide()
2025-12-19 19:39:56 +00:00
await main_menu.execute()
2025-12-15 16:57:26 +00:00
AppState.PLAY:
credits_roll.hide()
main_menu.hide()
pause_menu.hide()
AppState.PAUSE:
credits_roll.hide()
main_menu.hide()
pause_menu.appear()
2025-12-15 16:57:26 +00:00
AppState.CREDITS:
main_menu.hide()
pause_menu.hide()
2025-12-19 19:39:56 +00:00
credits_roll.play()
2025-12-15 16:57:26 +00:00
func _enter_tree() -> void:
print("main.gd: _enter_tree()")
2025-12-15 16:57:26 +00:00
func _ready() -> void:
print("main.gd: _ready()")
2026-01-22 14:12:24 +00:00
main_menu.continue_button.pressed.connect(func(): state = AppState.PLAY)
main_menu.credits_button.pressed.connect(func(): state = AppState.CREDITS)
2025-12-15 16:57:26 +00:00
#TODO: Load the last savegame(?)
await %Loading.stop()
if normal_boot:
print("main.gd: normal boot (loading last save and showing main menu)")
2026-01-22 14:12:24 +00:00
state = AppState.MENU
else:
print("main.gd: direct boot (hiding menus and entering main loop)")
2026-01-22 14:12:24 +00:00
state = AppState.PLAY
2025-12-19 19:39:56 +00:00
func start_game(save: SaveGame) -> void:
print("main.gd: play_game()")
2025-12-15 16:57:26 +00:00
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:
2026-01-18 20:53:19 +00:00
await curtain.close()
2025-12-19 19:39:56 +00:00
%Loading.play()
if State.room:
State.room.unload()
State.room.queue_free()
2025-12-15 16:57:26 +00:00
State.room = null
2025-12-19 19:39:56 +00:00
ResourceLoader.load_threaded_request(scene_path, "PackedScene", true)
while true:
await get_tree().process_frame
2026-01-22 14:12:24 +00:00
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.")
2025-12-15 16:57:26 +00:00
break
assert(false, "Couldn't load room %s" % scene_path)
2026-01-22 14:12:24 +00:00
var last_mode := DisplayServer.WINDOW_MODE_WINDOWED
2026-01-22 14:12:24 +00:00
func _unhandled_input(event: InputEvent) -> void:
2026-01-22 16:05:27 +00:00
#if event.is_action_type(): print_debug("Unhandled Input", event)
if event.is_action_pressed("ui_pause"):
2026-01-22 14:12:24 +00:00
state = AppState.PAUSE
if not Engine.is_editor_hint():
if event.is_action_pressed("toggle_fullscreen"):
# I have no idea why I wrote thit as convoluted,
# but it works(TM) so I am not gonna change it :D
if DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_FULLSCREEN:
DisplayServer.window_set_mode(last_mode)
else:
last_mode = DisplayServer.window_get_mode()
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
#endregion