integrate a semi-working manager for save files (#3)
This commit is contained in:
parent
18dae312eb
commit
7ae566720c
7 changed files with 131 additions and 84 deletions
|
@ -23,10 +23,10 @@ func _ready() -> void:
|
||||||
$Menus/Panel1.change_menu(sm, false)
|
$Menus/Panel1.change_menu(sm, false)
|
||||||
|
|
||||||
func start() -> void:
|
func start() -> void:
|
||||||
request_start.emit()
|
var svm = save_file_manager.instantiate()
|
||||||
#var svm = save_file_manager.instantiate()
|
svm.connect(\"request_start\", func(): request_start.emit())
|
||||||
#$Menus/Panel2.change_menu(svm)
|
$Menus/Panel2.change_menu(svm)
|
||||||
#rotate_cube_to(90)
|
rotate_cube_to(90)
|
||||||
|
|
||||||
func settings() -> void:
|
func settings() -> void:
|
||||||
var sm = settings_menu.instantiate()
|
var sm = settings_menu.instantiate()
|
||||||
|
|
|
@ -1,102 +1,105 @@
|
||||||
[gd_scene load_steps=5 format=3 uid="uid://w5te3qujco7d"]
|
[gd_scene load_steps=2 format=3 uid="uid://w5te3qujco7d"]
|
||||||
|
|
||||||
[sub_resource type="GDScript" id="GDScript_a5kgg"]
|
[sub_resource type="GDScript" id="GDScript_a5kgg"]
|
||||||
script/source = "extends MarginContainer
|
script/source = "extends Control
|
||||||
|
|
||||||
func _ready() -> void:
|
signal request_start
|
||||||
$HSplitContainer/CenterContainer/Label.hide()
|
|
||||||
|
|
||||||
|
@onready var label = $VBoxContainer/MarginContainer/VBoxContainer/Label
|
||||||
|
|
||||||
func _on_button_pressed() -> void:
|
func _on_save_1_pressed() -> void:
|
||||||
$HSplitContainer/CenterContainer/Label.show()
|
label.text = $VBoxContainer/Save1.text
|
||||||
$AnimationPlayer.play(\"add_information\")
|
display_file_data(SaveFiles.read(SaveFiles.names[0]))
|
||||||
|
|
||||||
|
func _on_save_2_pressed() -> void:
|
||||||
|
label.text = $VBoxContainer/Save2.text
|
||||||
|
display_file_data(SaveFiles.read(SaveFiles.names[1]))
|
||||||
|
|
||||||
|
func _on_save_3_pressed() -> void:
|
||||||
|
label.text = $VBoxContainer/Save3.text
|
||||||
|
display_file_data(SaveFiles.read(SaveFiles.names[2]))
|
||||||
|
|
||||||
|
func display_file_data(data: Variant) -> void:
|
||||||
|
$VBoxContainer/MarginContainer.show()
|
||||||
|
label.text += \" | \"
|
||||||
|
if data.has(\"played_for\"):
|
||||||
|
label.text += data.played_for
|
||||||
|
else:
|
||||||
|
label.text += \"00:00\"
|
||||||
|
|
||||||
|
func _on_start_pressed() -> void:
|
||||||
|
request_start.emit()
|
||||||
|
|
||||||
|
func _on_delete_pressed() -> void:
|
||||||
|
SaveFiles.empty(SaveFiles.selected_file)
|
||||||
"
|
"
|
||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_a5kgg"]
|
[node name="SaveFileManager" type="Control"]
|
||||||
resource_name = "add_information"
|
layout_mode = 3
|
||||||
length = 0.2
|
|
||||||
step = 0.2
|
|
||||||
tracks/0/type = "value"
|
|
||||||
tracks/0/imported = false
|
|
||||||
tracks/0/enabled = true
|
|
||||||
tracks/0/path = NodePath("HSplitContainer/CenterContainer:size_flags_stretch_ratio")
|
|
||||||
tracks/0/interp = 2
|
|
||||||
tracks/0/loop_wrap = true
|
|
||||||
tracks/0/keys = {
|
|
||||||
"times": PackedFloat32Array(0, 0.2),
|
|
||||||
"transitions": PackedFloat32Array(1, 1),
|
|
||||||
"update": 0,
|
|
||||||
"values": [0.0, 2.0]
|
|
||||||
}
|
|
||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_xs01b"]
|
|
||||||
length = 0.001
|
|
||||||
tracks/0/type = "value"
|
|
||||||
tracks/0/imported = false
|
|
||||||
tracks/0/enabled = true
|
|
||||||
tracks/0/path = NodePath("HSplitContainer/CenterContainer:size_flags_stretch_ratio")
|
|
||||||
tracks/0/interp = 1
|
|
||||||
tracks/0/loop_wrap = true
|
|
||||||
tracks/0/keys = {
|
|
||||||
"times": PackedFloat32Array(0),
|
|
||||||
"transitions": PackedFloat32Array(1),
|
|
||||||
"update": 0,
|
|
||||||
"values": [0.0]
|
|
||||||
}
|
|
||||||
|
|
||||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_36lt1"]
|
|
||||||
_data = {
|
|
||||||
&"RESET": SubResource("Animation_xs01b"),
|
|
||||||
&"add_information": SubResource("Animation_a5kgg")
|
|
||||||
}
|
|
||||||
|
|
||||||
[node name="SaveFileManager" type="MarginContainer"]
|
|
||||||
anchors_preset = 15
|
anchors_preset = 15
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
size_flags_horizontal = 4
|
|
||||||
size_flags_vertical = 4
|
|
||||||
theme_override_constants/margin_left = 20
|
|
||||||
theme_override_constants/margin_top = 20
|
|
||||||
theme_override_constants/margin_right = 20
|
|
||||||
theme_override_constants/margin_bottom = 20
|
|
||||||
script = SubResource("GDScript_a5kgg")
|
script = SubResource("GDScript_a5kgg")
|
||||||
|
|
||||||
[node name="HSplitContainer" type="HSplitContainer" parent="."]
|
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||||
layout_mode = 2
|
layout_mode = 1
|
||||||
|
anchors_preset = 14
|
||||||
[node name="VBoxContainer" type="VBoxContainer" parent="HSplitContainer"]
|
anchor_top = 0.5
|
||||||
layout_mode = 2
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 0.5
|
||||||
|
offset_top = -50.5
|
||||||
|
offset_bottom = 50.5
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
alignment = 1
|
alignment = 1
|
||||||
|
|
||||||
[node name="Button" type="Button" parent="HSplitContainer/VBoxContainer"]
|
[node name="Save1" type="Button" parent="VBoxContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Save file"
|
text = "Save file #1"
|
||||||
|
|
||||||
[node name="Button2" type="Button" parent="HSplitContainer/VBoxContainer"]
|
[node name="Save2" type="Button" parent="VBoxContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Save file"
|
text = "Save file #2"
|
||||||
|
|
||||||
[node name="Button3" type="Button" parent="HSplitContainer/VBoxContainer"]
|
[node name="Save3" type="Button" parent="VBoxContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Save file"
|
text = "Save file #3"
|
||||||
|
|
||||||
[node name="CenterContainer" type="CenterContainer" parent="HSplitContainer"]
|
[node name="MarginContainer" type="MarginContainer" parent="VBoxContainer"]
|
||||||
|
visible = false
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_constants/margin_left = 30
|
||||||
|
theme_override_constants/margin_top = 30
|
||||||
|
theme_override_constants/margin_right = 30
|
||||||
|
theme_override_constants/margin_bottom = 30
|
||||||
|
|
||||||
|
[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer/MarginContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="Label" type="Label" parent="VBoxContainer/MarginContainer/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Save File"
|
||||||
|
horizontal_alignment = 1
|
||||||
|
|
||||||
|
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/MarginContainer/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_constants/separation = 10
|
||||||
|
alignment = 1
|
||||||
|
|
||||||
|
[node name="Start" type="Button" parent="VBoxContainer/MarginContainer/VBoxContainer/HBoxContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
size_flags_stretch_ratio = 0.0
|
text = "Start"
|
||||||
|
|
||||||
[node name="Label" type="Label" parent="HSplitContainer/CenterContainer"]
|
[node name="Delete" type="Button" parent="VBoxContainer/MarginContainer/VBoxContainer/HBoxContainer"]
|
||||||
show_behind_parent = true
|
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Information"
|
text = "Delete"
|
||||||
|
|
||||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
[connection signal="pressed" from="VBoxContainer/Save1" to="." method="_on_save_1_pressed"]
|
||||||
libraries = {
|
[connection signal="pressed" from="VBoxContainer/Save2" to="." method="_on_save_2_pressed"]
|
||||||
&"": SubResource("AnimationLibrary_36lt1")
|
[connection signal="pressed" from="VBoxContainer/Save3" to="." method="_on_save_3_pressed"]
|
||||||
}
|
[connection signal="pressed" from="VBoxContainer/MarginContainer/VBoxContainer/HBoxContainer/Start" to="." method="_on_start_pressed"]
|
||||||
|
[connection signal="pressed" from="VBoxContainer/MarginContainer/VBoxContainer/HBoxContainer/Delete" to="." method="_on_delete_pressed"]
|
||||||
[connection signal="pressed" from="HSplitContainer/VBoxContainer/Button" to="." method="_on_button_pressed"]
|
|
||||||
|
|
|
@ -27,12 +27,9 @@ script = SubResource("GDScript_vfuxb")
|
||||||
|
|
||||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 14
|
anchors_preset = 15
|
||||||
anchor_top = 0.5
|
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
anchor_bottom = 0.5
|
anchor_bottom = 1.0
|
||||||
offset_top = -50.5
|
|
||||||
offset_bottom = 50.5
|
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
alignment = 1
|
alignment = 1
|
||||||
|
|
|
@ -33,10 +33,17 @@ func add(node: Control, return_button: bool):
|
||||||
link_to_sounds(node)
|
link_to_sounds(node)
|
||||||
|
|
||||||
func link_to_sounds(node: Control):
|
func link_to_sounds(node: Control):
|
||||||
var buttons := node.find_children(\"*\", \"Button\", true, false)
|
var children := node.find_children(\"*\", \"\", true, false)
|
||||||
|
|
||||||
|
var buttons := children.filter(func(child): return is_instance_of(child, Button))
|
||||||
for button in buttons as Array[Button]:
|
for button in buttons as Array[Button]:
|
||||||
button.mouse_entered.connect(func(): $Select.play())
|
button.mouse_entered.connect(func(): $Select.play())
|
||||||
button.pressed.connect(func(): $Confirm.play())
|
button.pressed.connect(func(): $Confirm.play())
|
||||||
|
|
||||||
|
var sliders := children.filter(func(child): return is_instance_of(child, HSlider))
|
||||||
|
for slider in sliders as Array[HSlider]:
|
||||||
|
slider.mouse_entered.connect(func(): $Select.play())
|
||||||
|
slider.drag_ended.connect(func(_value): $Confirm.play())
|
||||||
|
|
||||||
func disable():
|
func disable():
|
||||||
$VSplitContainer/AnimationPlayer.play_backwards(\"split_offset\")
|
$VSplitContainer/AnimationPlayer.play_backwards(\"split_offset\")
|
||||||
|
|
|
@ -23,6 +23,7 @@ config/windows_native_icon="res://icon.ico"
|
||||||
[autoload]
|
[autoload]
|
||||||
|
|
||||||
Settings="*res://settings.gd"
|
Settings="*res://settings.gd"
|
||||||
|
SaveFiles="*res://save_files.gd"
|
||||||
|
|
||||||
[input]
|
[input]
|
||||||
|
|
||||||
|
|
38
save_files.gd
Normal file
38
save_files.gd
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
extends Node
|
||||||
|
|
||||||
|
const names := [
|
||||||
|
"user://save_file_1.save",
|
||||||
|
"user://save_file_2.save",
|
||||||
|
"user://save_file_3.save",
|
||||||
|
]
|
||||||
|
|
||||||
|
var selected_file := names[0]
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
for save_file_name in names:
|
||||||
|
ensure_existence(save_file_name)
|
||||||
|
|
||||||
|
func ensure_existence(save_file_name: String) -> void:
|
||||||
|
if save_file_name in names and not FileAccess.file_exists(save_file_name):
|
||||||
|
print("Save file ", save_file_name, " not found, creating it")
|
||||||
|
empty(save_file_name)
|
||||||
|
|
||||||
|
func empty(save_file_name: String) -> void:
|
||||||
|
print("Writing an empty object on ", save_file_name)
|
||||||
|
var save_file := FileAccess.open(save_file_name, FileAccess.WRITE)
|
||||||
|
save_file.store_line(JSON.stringify({}))
|
||||||
|
save_file.store_line("FOR YOUR SAFETY, ALWAYS CHECK IF THE DATA OF THE FILES YOU DOWNLOAD LOOKS OKAY")
|
||||||
|
|
||||||
|
func read(save_file_name: String) -> Variant:
|
||||||
|
ensure_existence(save_file_name)
|
||||||
|
selected_file = save_file_name
|
||||||
|
|
||||||
|
var save_file := FileAccess.open(save_file_name, FileAccess.READ)
|
||||||
|
var json := JSON.new()
|
||||||
|
var json_string := save_file.get_line()
|
||||||
|
|
||||||
|
if json.parse(json_string) != OK:
|
||||||
|
print("(SAVES) JSON Parse Error: ", json.get_error_message(), " in ", json_string, " at line ", json.get_error_line())
|
||||||
|
return {}
|
||||||
|
|
||||||
|
return json.data
|
1
save_files.gd.uid
Normal file
1
save_files.gd.uid
Normal file
|
@ -0,0 +1 @@
|
||||||
|
uid://crfwrvs7rlc5h
|
Loading…
Add table
Add a link
Reference in a new issue