From ec38d8edef00f4648a104fc691ec91c7f87347c2 Mon Sep 17 00:00:00 2001 From: Tiger Jove Date: Fri, 12 Dec 2025 16:33:06 +0100 Subject: [PATCH] fix: loading order, savegame directory creation --- src/.idea/gdProjectSettings.xml | 6 +++++ src/code/button_themer.gd | 1 + src/dev-util/savegame.gd | 2 -- src/singletons/main/main.gd | 10 ++++++-- src/singletons/main/main.tscn | 2 +- src/ui/menu_main/main_menu.gd | 39 +++++++++++++++--------------- src/ui/menu_main/save_game_list.gd | 14 +++++++---- 7 files changed, 45 insertions(+), 29 deletions(-) create mode 100644 src/.idea/gdProjectSettings.xml diff --git a/src/.idea/gdProjectSettings.xml b/src/.idea/gdProjectSettings.xml new file mode 100644 index 0000000..2335eed --- /dev/null +++ b/src/.idea/gdProjectSettings.xml @@ -0,0 +1,6 @@ + + + + warn + + \ No newline at end of file diff --git a/src/code/button_themer.gd b/src/code/button_themer.gd index 28663b8..5709a21 100644 --- a/src/code/button_themer.gd +++ b/src/code/button_themer.gd @@ -6,6 +6,7 @@ class_name ThemedButton extends Button @onready var lower_corner_decor := load("res://import/interface-elements/lower_corner.png") func _ready() -> void: + print(owner) rebuild() theme_changed.connect(rebuild) resized.connect(rebuild) diff --git a/src/dev-util/savegame.gd b/src/dev-util/savegame.gd index a94ac2b..6c3408d 100644 --- a/src/dev-util/savegame.gd +++ b/src/dev-util/savegame.gd @@ -215,9 +215,7 @@ func validate_board_state() -> bool: if not (sticky is int or sticky is Vector2 or board_state.cards.keys().has(sticky)): push_error("Save %s could not be parsed: Corrupted Sticky Notes.") return false - return true - return false func parse_vec_from_string(string: String) -> Vector2: diff --git a/src/singletons/main/main.gd b/src/singletons/main/main.gd index 939f92b..a9dd5da 100644 --- a/src/singletons/main/main.gd +++ b/src/singletons/main/main.gd @@ -1,7 +1,5 @@ extends Control -signal room_loaded - var has_stage: bool = false # set(stage): # has_stage = stage @@ -20,6 +18,14 @@ var has_stage: bool = false @onready var state_machine = menu_animation["parameters/playback"] @onready var focus_forward = %MainMenu +func _ready() -> void: + await get_tree().create_timer(1.0).timeout + print("main.gd: ready()") + main_menu.has_stage = true + +# TODO: Find out if we want this. +signal room_loaded + # #var in_game = false # diff --git a/src/singletons/main/main.tscn b/src/singletons/main/main.tscn index 8349d18..5b34efe 100644 --- a/src/singletons/main/main.tscn +++ b/src/singletons/main/main.tscn @@ -1146,7 +1146,7 @@ states/reveal_pause_menu/position = Vector2(783.91, -112.734) states/start_game/node = SubResource("AnimationNodeAnimation_5umfs") states/start_game/position = Vector2(698, 32) transitions = ["Start", "init", SubResource("AnimationNodeStateMachineTransition_dxdg4"), "init", "loading", SubResource("AnimationNodeStateMachineTransition_0hpxy"), "loading", "loading_done", SubResource("AnimationNodeStateMachineTransition_ipapo"), "loading_done", "start_game", SubResource("AnimationNodeStateMachineTransition_0t1lp"), "start_game", "init", SubResource("AnimationNodeStateMachineTransition_66nmg"), "loading_done", "load_savegame", SubResource("AnimationNodeStateMachineTransition_6b86u"), "load_savegame", "loading_game", SubResource("AnimationNodeStateMachineTransition_y626i"), "loading_game", "start_game", SubResource("AnimationNodeStateMachineTransition_52bss"), "start_game", "credits_roll", SubResource("AnimationNodeStateMachineTransition_x8oth"), "credits_roll", "loading_done", SubResource("AnimationNodeStateMachineTransition_5ge3a"), "loading_done", "credits_roll", SubResource("AnimationNodeStateMachineTransition_44pd3"), "start_game", "reveal_pause_menu", SubResource("AnimationNodeStateMachineTransition_pc6pe"), "reveal_pause_menu", "hide_pause_menu", SubResource("AnimationNodeStateMachineTransition_dx61n"), "hide_pause_menu", "start_game", SubResource("AnimationNodeStateMachineTransition_lp1dx"), "hide_pause_menu", "init", SubResource("AnimationNodeStateMachineTransition_mqlnh")] -graph_offset = Vector2(163.75, -42.73401) +graph_offset = Vector2(166.75, -196.73401) [sub_resource type="Shader" id="Shader_cegan"] code = "shader_type canvas_item; diff --git a/src/ui/menu_main/main_menu.gd b/src/ui/menu_main/main_menu.gd index 2966298..2ac56f8 100644 --- a/src/ui/menu_main/main_menu.gd +++ b/src/ui/menu_main/main_menu.gd @@ -3,25 +3,25 @@ class_name MainMenu extends Panel var has_stage: bool = false: set(value): has_stage = value - if is_node_ready(): - if save_game_handle.get_most_recent_save().current_room == 0: - continue_button.visible = false - continue_button.disabled = true - new_game_button.theme_type_variation = "H1Button" + assert(is_node_ready(), "MainMenu node not ready yet!") + if save_game_handle.get_most_recent_save().current_room == 0: + continue_button.visible = false + continue_button.disabled = true + new_game_button.theme_type_variation = "H1Button" + else: + continue_button.visible = true + continue_button.disabled = not has_stage + new_game_button.theme_type_variation = "" + load_game_button.disabled = not save_game_handle.has_existing_saves() + for child: Control in $PanelContainer.get_children(): + child.focus_mode = FOCUS_ALL if has_stage else FOCUS_NONE + child.modulate = Color.WHITE if has_stage else Color.WEB_GRAY + child.mouse_filter = Control.MOUSE_FILTER_STOP if has_stage else Control.MOUSE_FILTER_IGNORE + if has_stage: + if continue_button.visible: + continue_button.grab_focus() else: - continue_button.visible = true - continue_button.disabled = not has_stage - new_game_button.theme_type_variation = "" - load_game_button.disabled = not save_game_handle.has_existing_saves() - for child: Control in $PanelContainer.get_children(): - child.focus_mode = FOCUS_ALL if has_stage else FOCUS_NONE - child.modulate = Color.WHITE if has_stage else Color.WEB_GRAY - child.mouse_filter = Control.MOUSE_FILTER_STOP if has_stage else Control.MOUSE_FILTER_IGNORE - if has_stage: - if continue_button.visible: - continue_button.grab_focus() - else: - new_game_button.grab_focus() + new_game_button.grab_focus() signal start_game(savegame: SaveGame) signal open_settings(new_game: bool) @@ -43,6 +43,7 @@ var await_new_game: bool = false # Called when the node enters the scene tree for the first time. func _ready() -> void: + print("main_menu.gd: ready()") save_game_handle.picked.connect(_on_save_picked) if save_game_handle.get_most_recent_save().current_room == 0: continue_button.disabled = true @@ -56,7 +57,7 @@ func _ready() -> void: quit_button.pressed.connect(get_tree().quit) credits_button.pressed.connect(roll_credits.emit) - State.take_stage(self) + #State.take_stage(self) func _on_save_picked(save: SaveGame): start_game.emit(save) diff --git a/src/ui/menu_main/save_game_list.gd b/src/ui/menu_main/save_game_list.gd index abce82f..484e152 100644 --- a/src/ui/menu_main/save_game_list.gd +++ b/src/ui/menu_main/save_game_list.gd @@ -23,14 +23,18 @@ func _validate_property(property: Dictionary) -> void: func _ready() -> void: - var dir = DirAccess.open(State.user_saves_path) - if DirAccess.get_open_error() != OK: - printerr("Error while opening User Save Directory: %s" % error_string(DirAccess.get_open_error())) - # Invalid Error being raised when Directory does not exist. + var dir := DirAccess.open(State.user_saves_path) + + # Create dir if needed. if DirAccess.get_open_error() == ERR_INVALID_PARAMETER: dir = DirAccess.open("user://") - dir.make_dir_recursive(State.user_saves_path) + dir.make_dir_recursive(State.user_saves_path) + + if DirAccess.get_open_error() != OK: + printerr("Error while opening User Save Directory: %s" % error_string(DirAccess.get_open_error())) + load_games() + for i in range(save_buttons.size()): save_buttons[i].pressed.connect(func(): picked.emit(saves[i]))