Fix memory leak and save file deletion + other stuff
might also be the commit where timer starts only when you move
This commit is contained in:
parent
709ce8eea3
commit
edf99640cf
6 changed files with 45 additions and 57 deletions
|
@ -8,13 +8,9 @@ script/source = "extends VBoxContainer
|
||||||
var enabled := false:
|
var enabled := false:
|
||||||
get: return enabled
|
get: return enabled
|
||||||
set(value):
|
set(value):
|
||||||
|
if enabled == value:
|
||||||
|
return
|
||||||
enabled = value
|
enabled = value
|
||||||
if value == true:
|
|
||||||
var save_file = SaveFiles.read(SaveFiles.selected_file)
|
|
||||||
if save_file.has(\"played_for\") and save_file.played_for is float:
|
|
||||||
seconds_spent_total = save_file.played_for
|
|
||||||
else:
|
|
||||||
seconds_spent_total = 0.0
|
|
||||||
if value == false:
|
if value == false:
|
||||||
$AnimationPlayer.play(\"scale_linear\")
|
$AnimationPlayer.play(\"scale_linear\")
|
||||||
await get_tree().create_timer($AnimationPlayer.current_animation_length).timeout
|
await get_tree().create_timer($AnimationPlayer.current_animation_length).timeout
|
||||||
|
@ -31,6 +27,14 @@ var seconds_spent_level_attempt := 0.0:
|
||||||
seconds_spent_level_attempt = value
|
seconds_spent_level_attempt = value
|
||||||
$Level.text = \"Level: \" + seconds_to_readable(seconds_spent_level_attempt)
|
$Level.text = \"Level: \" + seconds_to_readable(seconds_spent_level_attempt)
|
||||||
|
|
||||||
|
func _on_visibility_changed() -> void:
|
||||||
|
if self.visible and len(SaveFiles.selected_file):
|
||||||
|
var save_file = SaveFiles.read(SaveFiles.selected_file)
|
||||||
|
if save_file.has(\"played_for\") and save_file.played_for is float:
|
||||||
|
seconds_spent_total = save_file.played_for
|
||||||
|
else:
|
||||||
|
seconds_spent_total = 0.0
|
||||||
|
|
||||||
func seconds_to_readable(seconds: float) -> String:
|
func seconds_to_readable(seconds: float) -> String:
|
||||||
var minutes: int = floor(seconds / 60)
|
var minutes: int = floor(seconds / 60)
|
||||||
return (\"%0*d\" % [2, minutes]) + \":\" + (\"%0*.3f\" % [6, seconds - (minutes * 60)])
|
return (\"%0*d\" % [2, minutes]) + \":\" + (\"%0*.3f\" % [6, seconds - (minutes * 60)])
|
||||||
|
@ -115,27 +119,24 @@ _data = {
|
||||||
|
|
||||||
[node name="Timer" type="VBoxContainer"]
|
[node name="Timer" type="VBoxContainer"]
|
||||||
process_mode = 3
|
process_mode = 3
|
||||||
anchors_preset = 15
|
offset_right = 315.0
|
||||||
anchor_right = 1.0
|
offset_bottom = 85.0
|
||||||
anchor_bottom = 1.0
|
|
||||||
offset_right = -992.0
|
|
||||||
offset_bottom = -563.0
|
|
||||||
grow_horizontal = 2
|
|
||||||
grow_vertical = 2
|
|
||||||
theme_override_constants/separation = -5
|
theme_override_constants/separation = -5
|
||||||
script = SubResource("GDScript_q235s")
|
script = SubResource("GDScript_q235s")
|
||||||
|
|
||||||
[node name="Total" type="Label" parent="."]
|
[node name="Total" type="Label" parent="."]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Total timer"
|
text = "Total: 0:00.000"
|
||||||
label_settings = SubResource("LabelSettings_m1tld")
|
label_settings = SubResource("LabelSettings_m1tld")
|
||||||
|
|
||||||
[node name="Level" type="Label" parent="."]
|
[node name="Level" type="Label" parent="."]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Level timer"
|
text = "Level: 0:00.000"
|
||||||
label_settings = SubResource("LabelSettings_2a86r")
|
label_settings = SubResource("LabelSettings_2a86r")
|
||||||
|
|
||||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||||
libraries = {
|
libraries = {
|
||||||
&"": SubResource("AnimationLibrary_jmgpn")
|
&"": SubResource("AnimationLibrary_jmgpn")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"]
|
||||||
|
|
44
index.tscn
44
index.tscn
|
@ -1,4 +1,4 @@
|
||||||
[gd_scene load_steps=8 format=3 uid="uid://ccgnnif026wb4"]
|
[gd_scene load_steps=7 format=3 uid="uid://ccgnnif026wb4"]
|
||||||
|
|
||||||
[ext_resource type="PackedScene" uid="uid://xd3nsiglcdfc" path="res://gui/timer.tscn" id="1_356j3"]
|
[ext_resource type="PackedScene" uid="uid://xd3nsiglcdfc" path="res://gui/timer.tscn" id="1_356j3"]
|
||||||
[ext_resource type="PackedScene" uid="uid://dw0xl8644x166" path="res://gui/gravity.tscn" id="1_ir7so"]
|
[ext_resource type="PackedScene" uid="uid://dw0xl8644x166" path="res://gui/gravity.tscn" id="1_ir7so"]
|
||||||
|
@ -31,8 +31,6 @@ func _ready() -> void:
|
||||||
$DevInfos.text += \"build \" + ProjectSettings.get_setting(\"application/config/version\") + \" (\" + OS.get_name() + \")\"
|
$DevInfos.text += \"build \" + ProjectSettings.get_setting(\"application/config/version\") + \" (\" + OS.get_name() + \")\"
|
||||||
|
|
||||||
## Hide UI stuff that shouldn't be visible until later in the game
|
## Hide UI stuff that shouldn't be visible until later in the game
|
||||||
$VictoryScreen.hide()
|
|
||||||
$GUI.hide()
|
|
||||||
pause_menu.hide()
|
pause_menu.hide()
|
||||||
|
|
||||||
## Connect to necessary signals
|
## Connect to necessary signals
|
||||||
|
@ -42,8 +40,11 @@ func _ready() -> void:
|
||||||
|
|
||||||
set_main_menu()
|
set_main_menu()
|
||||||
|
|
||||||
func set_main_menu():
|
func set_main_menu() -> void:
|
||||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||||
|
$GUI.hide()
|
||||||
|
|
||||||
|
## If no main menu exists yet, create one
|
||||||
if !is_instance_valid(main_menu):
|
if !is_instance_valid(main_menu):
|
||||||
main_menu = res_main_menu.instantiate()
|
main_menu = res_main_menu.instantiate()
|
||||||
main_menu.connect(\"request_play_level\", start_level)
|
main_menu.connect(\"request_play_level\", start_level)
|
||||||
|
@ -59,6 +60,7 @@ func start_level(level: Level, scene: PackedScene) -> void:
|
||||||
current_level_scene = scene
|
current_level_scene = scene
|
||||||
add_child(current_level)
|
add_child(current_level)
|
||||||
|
|
||||||
|
current_level.connect(\"started_playing\", func(): gui_timer.enabled = true)
|
||||||
current_level.connect(\"gravity_change\", gui_gravity.react_to_gravity_change)
|
current_level.connect(\"gravity_change\", gui_gravity.react_to_gravity_change)
|
||||||
current_level.connect(\"completed\", finish_current_level)
|
current_level.connect(\"completed\", finish_current_level)
|
||||||
current_level.connect(\"ring_collected\", func():
|
current_level.connect(\"ring_collected\", func():
|
||||||
|
@ -73,7 +75,6 @@ func start_level(level: Level, scene: PackedScene) -> void:
|
||||||
playing = true
|
playing = true
|
||||||
changing_level = false
|
changing_level = false
|
||||||
gui_timer.seconds_spent_level_attempt = 0.0
|
gui_timer.seconds_spent_level_attempt = 0.0
|
||||||
gui_timer.enabled = true
|
|
||||||
|
|
||||||
func finish_current_level() -> void:
|
func finish_current_level() -> void:
|
||||||
gui_timer.enabled = false
|
gui_timer.enabled = false
|
||||||
|
@ -91,15 +92,10 @@ func finish_current_level() -> void:
|
||||||
await get_tree().create_timer(2).timeout
|
await get_tree().create_timer(2).timeout
|
||||||
current_level.queue_free()
|
current_level.queue_free()
|
||||||
|
|
||||||
win_game()
|
|
||||||
|
|
||||||
func win_game() -> void:
|
|
||||||
$VictoryScreen.show()
|
|
||||||
await get_tree().create_timer(2).timeout
|
|
||||||
set_main_menu()
|
set_main_menu()
|
||||||
$VictoryScreen.hide()
|
|
||||||
|
|
||||||
func restart_level() -> void:
|
func restart_level() -> void:
|
||||||
|
gui_timer.enabled = false
|
||||||
if !current_level or changing_level:
|
if !current_level or changing_level:
|
||||||
return
|
return
|
||||||
if current_level_scene is not PackedScene:
|
if current_level_scene is not PackedScene:
|
||||||
|
@ -143,11 +139,6 @@ func _on_btn_quit_pressed() -> void:
|
||||||
get_tree().quit()
|
get_tree().quit()
|
||||||
"
|
"
|
||||||
|
|
||||||
[sub_resource type="LabelSettings" id="LabelSettings_1bs00"]
|
|
||||||
font_size = 160
|
|
||||||
outline_size = 20
|
|
||||||
outline_color = Color(0, 0, 0, 1)
|
|
||||||
|
|
||||||
[node name="Game" type="Node"]
|
[node name="Game" type="Node"]
|
||||||
script = SubResource("GDScript_8n212")
|
script = SubResource("GDScript_8n212")
|
||||||
|
|
||||||
|
@ -206,27 +197,6 @@ theme_override_constants/margin_bottom = 15
|
||||||
[node name="Rings" parent="GUI/BottomRight" instance=ExtResource("3_mbj17")]
|
[node name="Rings" parent="GUI/BottomRight" instance=ExtResource("3_mbj17")]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
||||||
[node name="VictoryScreen" type="Control" parent="."]
|
|
||||||
layout_mode = 3
|
|
||||||
anchors_preset = 15
|
|
||||||
anchor_right = 1.0
|
|
||||||
anchor_bottom = 1.0
|
|
||||||
grow_horizontal = 2
|
|
||||||
grow_vertical = 2
|
|
||||||
mouse_filter = 2
|
|
||||||
|
|
||||||
[node name="Label" type="Label" parent="VictoryScreen"]
|
|
||||||
layout_mode = 1
|
|
||||||
anchors_preset = 15
|
|
||||||
anchor_right = 1.0
|
|
||||||
anchor_bottom = 1.0
|
|
||||||
grow_horizontal = 2
|
|
||||||
grow_vertical = 2
|
|
||||||
text = "YOU WON!"
|
|
||||||
label_settings = SubResource("LabelSettings_1bs00")
|
|
||||||
horizontal_alignment = 1
|
|
||||||
vertical_alignment = 1
|
|
||||||
|
|
||||||
[node name="DevInfos" type="Label" parent="."]
|
[node name="DevInfos" type="Label" parent="."]
|
||||||
anchors_preset = 12
|
anchors_preset = 12
|
||||||
anchor_top = 1.0
|
anchor_top = 1.0
|
||||||
|
|
|
@ -17,6 +17,7 @@ var rings: Array[Ring] = []
|
||||||
|
|
||||||
var finished_rings_count: int = 0
|
var finished_rings_count: int = 0
|
||||||
var velocity: float = 0.0
|
var velocity: float = 0.0
|
||||||
|
var has_started_playing: bool = false
|
||||||
|
|
||||||
func _init() -> void:
|
func _init() -> void:
|
||||||
assert(len(id) > 0, self.name + " has no id!")
|
assert(len(id) > 0, self.name + " has no id!")
|
||||||
|
@ -69,7 +70,9 @@ func _input(_event: InputEvent) -> void:
|
||||||
var down := Input.is_action_just_pressed("gravity_down")
|
var down := Input.is_action_just_pressed("gravity_down")
|
||||||
|
|
||||||
if up or left or right or down:
|
if up or left or right or down:
|
||||||
started_playing.emit()
|
if !has_started_playing:
|
||||||
|
has_started_playing = true
|
||||||
|
started_playing.emit()
|
||||||
PhysicsServer3D.area_set_param(
|
PhysicsServer3D.area_set_param(
|
||||||
get_viewport().find_world_3d().space,
|
get_viewport().find_world_3d().space,
|
||||||
PhysicsServer3D.AREA_PARAM_GRAVITY,
|
PhysicsServer3D.AREA_PARAM_GRAVITY,
|
||||||
|
|
|
@ -62,6 +62,16 @@ func _on_play_button_pressed() -> void:
|
||||||
func seconds_to_readable(seconds: float) -> String:
|
func seconds_to_readable(seconds: float) -> String:
|
||||||
var minutes: int = floor(seconds / 60)
|
var minutes: int = floor(seconds / 60)
|
||||||
return (\"%0*d\" % [2, minutes]) + \":\" + (\"%0*.3f\" % [6, seconds - (minutes * 60)])
|
return (\"%0*d\" % [2, minutes]) + \":\" + (\"%0*.3f\" % [6, seconds - (minutes * 60)])
|
||||||
|
|
||||||
|
## This prevents a memory leak that is possible when this menu is destroyed
|
||||||
|
## and the loaded_level becomes unavailable to the rest of the game
|
||||||
|
## For example in the main menu, go to this menu, select a level,
|
||||||
|
## press \"return\" and go to this menu again, boom, memory leak prevented by this
|
||||||
|
func _notification(what: int) -> void:
|
||||||
|
match what:
|
||||||
|
NOTIFICATION_PREDELETE:
|
||||||
|
if is_instance_valid(loaded_level) && !loaded_level.is_inside_tree():
|
||||||
|
loaded_level.queue_free()
|
||||||
"
|
"
|
||||||
|
|
||||||
[node name="LevelSelectionMenu" type="Control"]
|
[node name="LevelSelectionMenu" type="Control"]
|
||||||
|
|
|
@ -6,7 +6,9 @@ script/source = "extends Control
|
||||||
signal request_start
|
signal request_start
|
||||||
|
|
||||||
@onready var label_name = $VBoxContainer/MarginContainer/VBoxContainer/Description/Name
|
@onready var label_name = $VBoxContainer/MarginContainer/VBoxContainer/Description/Name
|
||||||
@onready var label_time = $VBoxContainer/MarginContainer/VBoxContainer/Description/Time
|
|
||||||
|
func _ready() -> void:
|
||||||
|
$VBoxContainer/MarginContainer.hide()
|
||||||
|
|
||||||
## Get the newest \"played_for\" when the main menu appears again
|
## Get the newest \"played_for\" when the main menu appears again
|
||||||
func _enter_tree() -> void:
|
func _enter_tree() -> void:
|
||||||
|
@ -26,6 +28,8 @@ func _on_save_3_pressed() -> void:
|
||||||
display_file_data(SaveFiles.names[2])
|
display_file_data(SaveFiles.names[2])
|
||||||
|
|
||||||
func display_file_data(file_name: String) -> void:
|
func display_file_data(file_name: String) -> void:
|
||||||
|
$VBoxContainer/MarginContainer.show()
|
||||||
|
var label_time := $VBoxContainer/MarginContainer/VBoxContainer/Description/Time
|
||||||
var data = SaveFiles.read(file_name)
|
var data = SaveFiles.read(file_name)
|
||||||
$VBoxContainer/MarginContainer.show()
|
$VBoxContainer/MarginContainer.show()
|
||||||
label_time.text = \" | \"
|
label_time.text = \" | \"
|
||||||
|
@ -34,14 +38,14 @@ func display_file_data(file_name: String) -> void:
|
||||||
var minutes: int = floor(seconds / 60)
|
var minutes: int = floor(seconds / 60)
|
||||||
label_time.text += (\"%0*d\" % [2, minutes]) + \":\" + (\"%0*.3f\" % [6, seconds - (minutes * 60)])
|
label_time.text += (\"%0*d\" % [2, minutes]) + \":\" + (\"%0*.3f\" % [6, seconds - (minutes * 60)])
|
||||||
else:
|
else:
|
||||||
label_time.text += \"00:00\"
|
label_time.text += \"00:00.000\"
|
||||||
|
|
||||||
func _on_start_pressed() -> void:
|
func _on_start_pressed() -> void:
|
||||||
request_start.emit()
|
request_start.emit()
|
||||||
|
|
||||||
func _on_delete_pressed() -> void:
|
func _on_delete_pressed() -> void:
|
||||||
SaveFiles.empty(SaveFiles.selected_file)
|
SaveFiles.empty(SaveFiles.selected_file)
|
||||||
display_file_data(SaveFiles.read(SaveFiles.selected_file))
|
display_file_data(SaveFiles.selected_file)
|
||||||
"
|
"
|
||||||
|
|
||||||
[node name="SaveFileManager" type="Control"]
|
[node name="SaveFileManager" type="Control"]
|
||||||
|
|
|
@ -13,7 +13,7 @@ config_version=5
|
||||||
config/name="DreamBall"
|
config/name="DreamBall"
|
||||||
config/description="Manipulate the gravity to make a ball go through every ring!
|
config/description="Manipulate the gravity to make a ball go through every ring!
|
||||||
https://kitsunes.dev/Taevas/DreamBall"
|
https://kitsunes.dev/Taevas/DreamBall"
|
||||||
config/version="20250423.0"
|
config/version="20250503.0"
|
||||||
run/main_scene="res://index.tscn"
|
run/main_scene="res://index.tscn"
|
||||||
config/features=PackedStringArray("4.4", "GL Compatibility")
|
config/features=PackedStringArray("4.4", "GL Compatibility")
|
||||||
boot_splash/show_image=false
|
boot_splash/show_image=false
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue