From 2d3c4c231f5230a7e5f38a965d03810350329361 Mon Sep 17 00:00:00 2001 From: betalars Date: Fri, 18 Oct 2024 17:31:46 +0200 Subject: [PATCH] finalize implement savegame loading trough main menu --- src/main.gd | 69 ++++++++++++++++++++++++++++- src/main_menu.tscn | 106 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 171 insertions(+), 4 deletions(-) diff --git a/src/main.gd b/src/main.gd index 618757ea..8a4da871 100644 --- a/src/main.gd +++ b/src/main.gd @@ -1,13 +1,25 @@ extends Node3D +signal room_loaded + +var has_stage: bool = false: + set(stage): + has_stage = stage + if in_game and has_stage: + in_game = false + _return_to_menu() + @export_file(".tscn") var youth_room_path: String @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 main_menu:MainMenu = %"Main Menu" @onready var menu_animation: AnimationTree = %MenuAnimationTree @onready var focus_forward = %"Main Menu" +var current_room_id: State.rooms + var in_game = false var current_loaded_room: Node3D @@ -29,12 +41,17 @@ func _ready(): func _process(delta: float) -> void: if currently_loading_room != "": - var progress:Array - if ResourceLoader.load_threaded_get_status(youth_room_path, progress) == 3: + if ResourceLoader.load_threaded_get_status(currently_loading_room) == 3: current_loaded_room = ResourceLoader.load_threaded_get(youth_room_path).instantiate() add_child(current_loaded_room) move_child(current_loaded_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() + $"Messe-Menue".show() func debug_youth(): get_child(1).hide() @@ -42,3 +59,51 @@ func debug_youth(): 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 + State.pass_stage_to(get_child(0)) + +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.MENU, State.rooms.DRAVEN: + return youth_room_path + State.rooms.TRANSITION: + return transition_room_path + State.rooms.ADULTHOOD: + return adulthood_room_path + _: + return ending_path + +func start_demo(): + load_save(SaveGame.new()) + $"Messe-Menue".hide() diff --git a/src/main_menu.tscn b/src/main_menu.tscn index 9eb14761..e66c6411 100644 --- a/src/main_menu.tscn +++ b/src/main_menu.tscn @@ -1,6 +1,6 @@ -[gd_scene load_steps=16 format=3 uid="uid://b51wdql4mby47"] +[gd_scene load_steps=27 format=3 uid="uid://b51wdql4mby47"] -[ext_resource type="Theme" uid="uid://b056fn288p8ha" path="res://logic-scenes/themes/easy-handwriting.theme" id="1_2dg4n"] +[ext_resource type="Theme" uid="uid://b056fn288p8ha" path="res://logic-scenes/themes/handwriting.theme" id="1_2dg4n"] [ext_resource type="Script" path="res://logic-scenes/main menu/main_menu.gd" id="2_rm576"] [ext_resource type="PackedScene" uid="uid://gmxenhavh1lp" path="res://logic-scenes/main menu/video_settings.tscn" id="3_f0dcd"] [ext_resource type="Texture2D" uid="uid://d3ewjumh0b0g6" path="res://logic-scenes/main menu/logo.png" id="3_xb2np"] @@ -10,6 +10,8 @@ [ext_resource type="PackedScene" uid="uid://dxwqkxq6qjk7i" path="res://logic-scenes/main menu/gameplay_settings.tscn" id="6_p7ypt"] [ext_resource type="PackedScene" uid="uid://chal0ioagspx0" path="res://logic-scenes/main menu/content_settings.tscn" id="7_pnd48"] [ext_resource type="Script" path="res://logic-scenes/main menu/save_game_list.gd" id="8_o0cpj"] +[ext_resource type="Script" path="res://dev-util/savegame.gd" id="11_cspq7"] +[ext_resource type="Texture2D" uid="uid://bk5ja14r7r6i4" path="res://import/interface-elements/empty_save_slot.png" id="12_6qu04"] [sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_njt06"] @@ -247,6 +249,105 @@ _data = { "vanish": SubResource("Animation_a3iyq") } +[sub_resource type="Resource" id="Resource_civda"] +script = ExtResource("11_cspq7") +filepath = "" +unique_save_name = "frame_of_mind_2024-10-10_16:20:34" +current_room = 0 +mementos_complete = 0 +board_state = {} +thumbnail = ExtResource("12_6qu04") +last_saved = 1.72857e+09 +is_save_file_valid = false + +[sub_resource type="Resource" id="Resource_ny8h2"] +script = ExtResource("11_cspq7") +filepath = "" +unique_save_name = "frame_of_mind_2024-10-11_15:37:47" +current_room = 0 +mementos_complete = 0 +board_state = {} +thumbnail = ExtResource("12_6qu04") +last_saved = 1.72865e+09 +is_save_file_valid = false + +[sub_resource type="Resource" id="Resource_eypce"] +script = ExtResource("11_cspq7") +filepath = "" +unique_save_name = "frame_of_mind_2024-10-12_00:52:41" +current_room = 0 +mementos_complete = 0 +board_state = {} +thumbnail = ExtResource("12_6qu04") +last_saved = 1.72869e+09 +is_save_file_valid = false + +[sub_resource type="Resource" id="Resource_0aleq"] +script = ExtResource("11_cspq7") +filepath = "" +unique_save_name = "frame_of_mind_2024-10-16_00:20:28" +current_room = 0 +mementos_complete = 0 +board_state = {} +thumbnail = ExtResource("12_6qu04") +last_saved = 1.72903e+09 +is_save_file_valid = false + +[sub_resource type="Resource" id="Resource_yamni"] +script = ExtResource("11_cspq7") +filepath = "" +unique_save_name = "frame_of_mind_2024-10-16_01:04:19" +current_room = 0 +mementos_complete = 0 +board_state = {} +thumbnail = ExtResource("12_6qu04") +last_saved = 1.72903e+09 +is_save_file_valid = false + +[sub_resource type="Resource" id="Resource_ofqsy"] +script = ExtResource("11_cspq7") +filepath = "" +unique_save_name = "frame_of_mind_2024-10-16_01:25:54" +current_room = 0 +mementos_complete = 0 +board_state = {} +thumbnail = ExtResource("12_6qu04") +last_saved = 1.72903e+09 +is_save_file_valid = false + +[sub_resource type="Resource" id="Resource_775qv"] +script = ExtResource("11_cspq7") +filepath = "" +unique_save_name = "frame_of_mind_2024-10-16_01:41:58" +current_room = 0 +mementos_complete = 0 +board_state = {} +thumbnail = ExtResource("12_6qu04") +last_saved = 1.72904e+09 +is_save_file_valid = false + +[sub_resource type="Resource" id="Resource_epdda"] +script = ExtResource("11_cspq7") +filepath = "" +unique_save_name = "frame_of_mind_2024-10-16_02:39:09" +current_room = 0 +mementos_complete = 0 +board_state = {} +thumbnail = ExtResource("12_6qu04") +last_saved = 1.72904e+09 +is_save_file_valid = false + +[sub_resource type="Resource" id="Resource_idh7b"] +script = ExtResource("11_cspq7") +filepath = "" +unique_save_name = "frame_of_mind_2024-10-16_02:46:05" +current_room = 0 +mementos_complete = 0 +board_state = {} +thumbnail = ExtResource("12_6qu04") +last_saved = 1.72904e+09 +is_save_file_valid = false + [node name="Main Menu" type="Panel"] anchors_preset = 15 anchor_right = 1.0 @@ -396,6 +497,7 @@ anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 script = ExtResource("8_o0cpj") +saves = Array[ExtResource("11_cspq7")]([SubResource("Resource_civda"), SubResource("Resource_ny8h2"), SubResource("Resource_eypce"), SubResource("Resource_0aleq"), SubResource("Resource_yamni"), SubResource("Resource_ofqsy"), SubResource("Resource_775qv"), SubResource("Resource_epdda"), SubResource("Resource_idh7b")]) [node name="ScrollContainer" type="ScrollContainer" parent="."] layout_mode = 0