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:
|
||||
get: return enabled
|
||||
set(value):
|
||||
if enabled == value:
|
||||
return
|
||||
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:
|
||||
$AnimationPlayer.play(\"scale_linear\")
|
||||
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
|
||||
$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:
|
||||
var minutes: int = floor(seconds / 60)
|
||||
return (\"%0*d\" % [2, minutes]) + \":\" + (\"%0*.3f\" % [6, seconds - (minutes * 60)])
|
||||
|
@ -115,27 +119,24 @@ _data = {
|
|||
|
||||
[node name="Timer" type="VBoxContainer"]
|
||||
process_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_right = -992.0
|
||||
offset_bottom = -563.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
offset_right = 315.0
|
||||
offset_bottom = 85.0
|
||||
theme_override_constants/separation = -5
|
||||
script = SubResource("GDScript_q235s")
|
||||
|
||||
[node name="Total" type="Label" parent="."]
|
||||
layout_mode = 2
|
||||
text = "Total timer"
|
||||
text = "Total: 0:00.000"
|
||||
label_settings = SubResource("LabelSettings_m1tld")
|
||||
|
||||
[node name="Level" type="Label" parent="."]
|
||||
layout_mode = 2
|
||||
text = "Level timer"
|
||||
text = "Level: 0:00.000"
|
||||
label_settings = SubResource("LabelSettings_2a86r")
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
libraries = {
|
||||
&"": SubResource("AnimationLibrary_jmgpn")
|
||||
}
|
||||
|
||||
[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue