Can now specify game profile to use on startup.

main
Martin Felis 2024-11-16 22:01:30 +01:00
parent 563b291a6f
commit 7bcf34e7ca
2 changed files with 14 additions and 9 deletions

View File

@ -1,9 +1,11 @@
class_name RootUI class_name RootUI
extends CanvasLayer extends CanvasLayer
const GAME_PROFILE_FOLDER:String = "game_profiles"
@export var startup_scene:PackedScene @export var startup_scene:PackedScene
@export var game_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 scene = %Scene
@onready var ui_panels:Array = [ %MainMenuUI, %StartGameMenuUI, %CreateGameUI, %GameUI ] @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 var _game_build_system:BuildSystem = null
func _ready(): func _ready():
if autostart_game_scene: var autostart_load_success = false
load_scene(game_scene) if not autostart_game_profile.is_empty():
set_root_ui_state(ROOT_UI_STATE.GAME) autostart_load_success = _on_start_game_profile("user://" + GAME_PROFILE_FOLDER + "/" + autostart_game_profile + "/game.tres")
else:
if not autostart_load_success:
set_root_ui_state(ROOT_UI_STATE.MENU) set_root_ui_state(ROOT_UI_STATE.MENU)
%CreateGameUI.start_game.connect(_on_start_game_profile) %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 _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 = null
current_game_profile_directory = "" current_game_profile_directory = ""
@ -165,7 +168,7 @@ func _on_start_game_profile(profile_path:String) -> void:
current_game_profile = ResourceLoader.load(profile_path) current_game_profile = ResourceLoader.load(profile_path)
if current_game_profile == null: if current_game_profile == null:
push_error("Error loading game profile " + profile_path) push_error("Error loading game profile " + profile_path)
return return false
# Update last_played timestamp # Update last_played timestamp
current_game_profile.last_played = Time.get_datetime_string_from_system() current_game_profile.last_played = Time.get_datetime_string_from_system()
@ -182,6 +185,8 @@ func _on_start_game_profile(profile_path:String) -> void:
activate_ui_panel(%GameUI) activate_ui_panel(%GameUI)
return true
func _is_savegame_available() -> bool: func _is_savegame_available() -> bool:
if current_game_profile_directory == "": if current_game_profile_directory == "":
return false return false

View File

@ -212,7 +212,7 @@ unique_name_in_owner = true
script = ExtResource("1_7fnkg") script = ExtResource("1_7fnkg")
startup_scene = ExtResource("2_1untt") startup_scene = ExtResource("2_1untt")
game_scene = ExtResource("3_w1gpn") game_scene = ExtResource("3_w1gpn")
autostart_game_scene = false autostart_game_profile = "Development"
[node name="MainMenuUI" type="Panel" parent="."] [node name="MainMenuUI" type="Panel" parent="."]
unique_name_in_owner = true unique_name_in_owner = true