From 7bcf34e7ca5519cd77ed94ceaafcf6ae8b3ea2e1 Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Sat, 16 Nov 2024 22:01:30 +0100 Subject: [PATCH] Can now specify game profile to use on startup. --- root_ui.gd | 21 +++++++++++++-------- root_ui.tscn | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/root_ui.gd b/root_ui.gd index 4ea050c..c3e7920 100644 --- a/root_ui.gd +++ b/root_ui.gd @@ -1,9 +1,11 @@ class_name RootUI extends CanvasLayer +const GAME_PROFILE_FOLDER:String = "game_profiles" + @export var startup_scene:PackedScene @export var game_scene:PackedScene -@export var autostart_game_scene:bool = true +@export var autostart_game_profile:String = "" @onready var scene = %Scene @onready var ui_panels:Array = [ %MainMenuUI, %StartGameMenuUI, %CreateGameUI, %GameUI ] @@ -19,10 +21,11 @@ var current_game_profile_directory:String = "" var _game_build_system:BuildSystem = null func _ready(): - if autostart_game_scene: - load_scene(game_scene) - set_root_ui_state(ROOT_UI_STATE.GAME) - else: + var autostart_load_success = false + if not autostart_game_profile.is_empty(): + autostart_load_success = _on_start_game_profile("user://" + GAME_PROFILE_FOLDER + "/" + autostart_game_profile + "/game.tres") + + if not autostart_load_success: set_root_ui_state(ROOT_UI_STATE.MENU) %CreateGameUI.start_game.connect(_on_start_game_profile) @@ -157,7 +160,7 @@ func set_root_ui_state(state:ROOT_UI_STATE): _root_ui_state = state -func _on_start_game_profile(profile_path:String) -> void: +func _on_start_game_profile(profile_path:String) -> bool: current_game_profile = null current_game_profile_directory = "" @@ -165,7 +168,7 @@ func _on_start_game_profile(profile_path:String) -> void: current_game_profile = ResourceLoader.load(profile_path) if current_game_profile == null: push_error("Error loading game profile " + profile_path) - return + return false # Update last_played timestamp current_game_profile.last_played = Time.get_datetime_string_from_system() @@ -180,7 +183,9 @@ func _on_start_game_profile(profile_path:String) -> void: load_game() - activate_ui_panel(%GameUI) + activate_ui_panel(%GameUI) + + return true func _is_savegame_available() -> bool: if current_game_profile_directory == "": diff --git a/root_ui.tscn b/root_ui.tscn index e29ca5a..5a0a3c4 100644 --- a/root_ui.tscn +++ b/root_ui.tscn @@ -212,7 +212,7 @@ unique_name_in_owner = true script = ExtResource("1_7fnkg") startup_scene = ExtResource("2_1untt") game_scene = ExtResource("3_w1gpn") -autostart_game_scene = false +autostart_game_profile = "Development" [node name="MainMenuUI" type="Panel" parent="."] unique_name_in_owner = true