new timer + save times to save files (#3)
This commit is contained in:
parent
7ae566720c
commit
ac1f29d111
7 changed files with 269 additions and 37 deletions
81
elements/timer.tscn
Normal file
81
elements/timer.tscn
Normal file
|
@ -0,0 +1,81 @@
|
|||
[gd_scene load_steps=5 format=3 uid="uid://xd3nsiglcdfc"]
|
||||
|
||||
[ext_resource type="FontFile" uid="uid://c3fsj6knyiuhl" path="res://fonts/Knewave/Knewave-Regular.ttf" id="1_m1tld"]
|
||||
|
||||
[sub_resource type="GDScript" id="GDScript_q235s"]
|
||||
script/source = "extends VBoxContainer
|
||||
|
||||
var enabled := false:
|
||||
get: return enabled
|
||||
set(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
|
||||
|
||||
var seconds_spent_total := 0.0:
|
||||
get: return seconds_spent_total
|
||||
set(value):
|
||||
seconds_spent_total = value
|
||||
$Total.text = \"Total: \" + seconds_to_readable(seconds_spent_total)
|
||||
var seconds_spent_level_attempt := 0.0:
|
||||
get: return seconds_spent_level_attempt
|
||||
set(value):
|
||||
seconds_spent_level_attempt = value
|
||||
$Level.text = \"Level: \" + seconds_to_readable(seconds_spent_level_attempt)
|
||||
|
||||
func _ready():
|
||||
var data = SaveFiles.read(SaveFiles.selected_file)
|
||||
if data.has(\"played_for\") and data.played_for is float:
|
||||
seconds_spent_total = data.played_for
|
||||
|
||||
func seconds_to_readable(seconds: float) -> String:
|
||||
var minutes: int = floor(seconds / 60)
|
||||
return (\"%0*d\" % [2, minutes]) + \":\" + (\"%0*.3f\" % [6, seconds - (minutes * 60)])
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if enabled:
|
||||
seconds_spent_total += delta
|
||||
seconds_spent_level_attempt += delta
|
||||
"
|
||||
|
||||
[sub_resource type="LabelSettings" id="LabelSettings_m1tld"]
|
||||
font = ExtResource("1_m1tld")
|
||||
font_size = 32
|
||||
outline_size = 8
|
||||
outline_color = Color(1, 0, 1, 1)
|
||||
shadow_size = 8
|
||||
shadow_color = Color(0, 0, 0, 1)
|
||||
|
||||
[sub_resource type="LabelSettings" id="LabelSettings_2a86r"]
|
||||
font = ExtResource("1_m1tld")
|
||||
font_size = 24
|
||||
outline_size = 8
|
||||
outline_color = Color(0, 0, 1, 1)
|
||||
shadow_size = 8
|
||||
shadow_color = Color(0, 0, 0, 1)
|
||||
|
||||
[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
|
||||
theme_override_constants/separation = -5
|
||||
script = SubResource("GDScript_q235s")
|
||||
|
||||
[node name="Total" type="Label" parent="."]
|
||||
layout_mode = 2
|
||||
text = "Total timer"
|
||||
label_settings = SubResource("LabelSettings_m1tld")
|
||||
|
||||
[node name="Level" type="Label" parent="."]
|
||||
layout_mode = 2
|
||||
text = "Level timer"
|
||||
label_settings = SubResource("LabelSettings_2a86r")
|
BIN
fonts/Knewave/Knewave-Regular.ttf
Normal file
BIN
fonts/Knewave/Knewave-Regular.ttf
Normal file
Binary file not shown.
35
fonts/Knewave/Knewave-Regular.ttf.import
Normal file
35
fonts/Knewave/Knewave-Regular.ttf.import
Normal file
|
@ -0,0 +1,35 @@
|
|||
[remap]
|
||||
|
||||
importer="font_data_dynamic"
|
||||
type="FontFile"
|
||||
uid="uid://c3fsj6knyiuhl"
|
||||
path="res://.godot/imported/Knewave-Regular.ttf-621ce63e5403426c07f1520fe86b0560.fontdata"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://fonts/Knewave/Knewave-Regular.ttf"
|
||||
dest_files=["res://.godot/imported/Knewave-Regular.ttf-621ce63e5403426c07f1520fe86b0560.fontdata"]
|
||||
|
||||
[params]
|
||||
|
||||
Rendering=null
|
||||
antialiasing=1
|
||||
generate_mipmaps=false
|
||||
disable_embedded_bitmaps=true
|
||||
multichannel_signed_distance_field=false
|
||||
msdf_pixel_range=8
|
||||
msdf_size=48
|
||||
allow_system_fallback=true
|
||||
force_autohinter=false
|
||||
hinting=1
|
||||
subpixel_positioning=4
|
||||
keep_rounding_remainders=true
|
||||
oversampling=0.0
|
||||
Fallbacks=null
|
||||
fallbacks=[]
|
||||
Compress=null
|
||||
compress=true
|
||||
preload=[]
|
||||
language_support={}
|
||||
script_support={}
|
||||
opentype_features={}
|
93
fonts/Knewave/OFL.txt
Normal file
93
fonts/Knewave/OFL.txt
Normal file
|
@ -0,0 +1,93 @@
|
|||
Copyright (c) 2010, Tyler Finck <hello@sursly.com>, with Reserved Font Name: "Knewave".
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at:
|
||||
https://openfontlicense.org
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
42
index.tscn
42
index.tscn
|
@ -1,10 +1,11 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://ccgnnif026wb4"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://ccgnnif026wb4"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://xd3nsiglcdfc" path="res://elements/timer.tscn" id="1_356j3"]
|
||||
|
||||
[sub_resource type="GDScript" id="GDScript_8n212"]
|
||||
script/source = "extends Node
|
||||
|
||||
var playing: bool = false
|
||||
var seconds_spent: float = 0.00
|
||||
var changing_level: bool = false
|
||||
|
||||
var current_level_int: int = 0
|
||||
|
@ -15,6 +16,8 @@ var levels = [
|
|||
]
|
||||
var area_resource = preload(\"res://menus/main/area.tscn\")
|
||||
|
||||
@onready var timer := $GUI/Timer
|
||||
|
||||
func _ready() -> void:
|
||||
var os_name = OS.get_name()
|
||||
if os_name == \"Web\": ## we can't quit the game on web
|
||||
|
@ -58,11 +61,15 @@ func start_level(level_scene: PackedScene) -> void:
|
|||
Vector3.DOWN
|
||||
)
|
||||
changing_level = false
|
||||
timer.seconds_spent_level_attempt = 0.0
|
||||
timer.enabled = true
|
||||
|
||||
func stop_level() -> void:
|
||||
timer.enabled = false
|
||||
PhysicsServer3D.area_set_param(get_viewport().find_world_3d().space, PhysicsServer3D.AREA_PARAM_GRAVITY, 1)
|
||||
playing = false
|
||||
changing_level = true
|
||||
SaveFiles.change_property(\"played_for\", timer.seconds_spent_total, SaveFiles.selected_file)
|
||||
|
||||
var current_levels = get_current_levels()
|
||||
for level in current_levels:
|
||||
|
@ -95,6 +102,7 @@ func restart_level() -> void:
|
|||
start_level(levels[current_level_int])
|
||||
|
||||
func pause_game() -> void:
|
||||
SaveFiles.change_property(\"played_for\", timer.seconds_spent_total, SaveFiles.selected_file)
|
||||
if $Levels.process_mode == PROCESS_MODE_INHERIT:
|
||||
$Levels.process_mode = Node.PROCESS_MODE_DISABLED
|
||||
playing = false
|
||||
|
@ -114,7 +122,6 @@ func fullscreen_game() -> void:
|
|||
DisplayServer.window_set_mode(DisplayServer.WindowMode.WINDOW_MODE_WINDOWED)
|
||||
|
||||
func start_game() -> void:
|
||||
seconds_spent = 0.0
|
||||
current_level_int = 0
|
||||
|
||||
var current_levels = $Levels.get_children(true)
|
||||
|
@ -125,14 +132,7 @@ func start_game() -> void:
|
|||
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
|
||||
start_level(levels[0])
|
||||
|
||||
func update_timer(delta: float) -> void:
|
||||
if playing:
|
||||
seconds_spent += delta
|
||||
var minutes = floor(seconds_spent / 60)
|
||||
$Informations/MarginContainer/Timer.text = (\"%0*d\" % [2, minutes]) + \":\" + (\"%0*.2f\" % [5, seconds_spent - (minutes * 60)])
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
update_timer(delta)
|
||||
func _process(_delta: float) -> void:
|
||||
var current_levels = get_current_levels()
|
||||
if len(current_levels):
|
||||
var current_level = current_levels[0]
|
||||
|
@ -166,6 +166,18 @@ outline_color = Color(0, 0, 0, 1)
|
|||
[node name="Game" type="Node"]
|
||||
script = SubResource("GDScript_8n212")
|
||||
|
||||
[node name="GUI" type="MarginContainer" parent="."]
|
||||
offset_right = 201.0
|
||||
offset_bottom = 104.0
|
||||
rotation = 0.0523599
|
||||
theme_override_constants/margin_left = 15
|
||||
theme_override_constants/margin_top = 15
|
||||
theme_override_constants/margin_right = 15
|
||||
theme_override_constants/margin_bottom = 15
|
||||
|
||||
[node name="Timer" parent="GUI" instance=ExtResource("1_356j3")]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Informations" type="Control" parent="."]
|
||||
visible = false
|
||||
layout_mode = 3
|
||||
|
@ -186,14 +198,6 @@ grow_vertical = 2
|
|||
theme_override_constants/margin_left = 10
|
||||
theme_override_constants/margin_right = 10
|
||||
|
||||
[node name="Timer" type="Label" parent="Informations/MarginContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 0
|
||||
size_flags_vertical = 8
|
||||
text = "00:00.0"
|
||||
label_settings = SubResource("LabelSettings_0s07t")
|
||||
vertical_alignment = 2
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="Informations/MarginContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = -5
|
||||
|
|
|
@ -5,33 +5,37 @@ script/source = "extends Control
|
|||
|
||||
signal request_start
|
||||
|
||||
@onready var label = $VBoxContainer/MarginContainer/VBoxContainer/Label
|
||||
@onready var label_name = $VBoxContainer/MarginContainer/VBoxContainer/Description/Name
|
||||
@onready var label_time = $VBoxContainer/MarginContainer/VBoxContainer/Description/Time
|
||||
|
||||
func _on_save_1_pressed() -> void:
|
||||
label.text = $VBoxContainer/Save1.text
|
||||
label_name.text = $VBoxContainer/Save1.text
|
||||
display_file_data(SaveFiles.read(SaveFiles.names[0]))
|
||||
|
||||
func _on_save_2_pressed() -> void:
|
||||
label.text = $VBoxContainer/Save2.text
|
||||
label_name.text = $VBoxContainer/Save2.text
|
||||
display_file_data(SaveFiles.read(SaveFiles.names[1]))
|
||||
|
||||
func _on_save_3_pressed() -> void:
|
||||
label.text = $VBoxContainer/Save3.text
|
||||
label_name.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
|
||||
label_time.text = \" | \"
|
||||
if data.has(\"played_for\") and data.played_for is float:
|
||||
var seconds: float = data.played_for
|
||||
var minutes: int = floor(seconds / 60)
|
||||
label_time.text += (\"%0*d\" % [2, minutes]) + \":\" + (\"%0*.3f\" % [6, seconds - (minutes * 60)])
|
||||
else:
|
||||
label.text += \"00:00\"
|
||||
label_time.text += \"00:00\"
|
||||
|
||||
func _on_start_pressed() -> void:
|
||||
request_start.emit()
|
||||
|
||||
func _on_delete_pressed() -> void:
|
||||
SaveFiles.empty(SaveFiles.selected_file)
|
||||
display_file_data(SaveFiles.read(SaveFiles.selected_file))
|
||||
"
|
||||
|
||||
[node name="SaveFileManager" type="Control"]
|
||||
|
@ -69,7 +73,6 @@ layout_mode = 2
|
|||
text = "Save file #3"
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="VBoxContainer"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
theme_override_constants/margin_left = 30
|
||||
theme_override_constants/margin_top = 30
|
||||
|
@ -79,27 +82,34 @@ 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"]
|
||||
[node name="Description" type="HBoxContainer" parent="VBoxContainer/MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
alignment = 1
|
||||
|
||||
[node name="Name" type="Label" parent="VBoxContainer/MarginContainer/VBoxContainer/Description"]
|
||||
layout_mode = 2
|
||||
text = "Save File"
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/MarginContainer/VBoxContainer"]
|
||||
[node name="Time" type="Label" parent="VBoxContainer/MarginContainer/VBoxContainer/Description"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Buttons" 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"]
|
||||
[node name="Start" type="Button" parent="VBoxContainer/MarginContainer/VBoxContainer/Buttons"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
text = "Start"
|
||||
|
||||
[node name="Delete" type="Button" parent="VBoxContainer/MarginContainer/VBoxContainer/HBoxContainer"]
|
||||
[node name="Delete" type="Button" parent="VBoxContainer/MarginContainer/VBoxContainer/Buttons"]
|
||||
layout_mode = 2
|
||||
text = "Delete"
|
||||
|
||||
[connection signal="pressed" from="VBoxContainer/Save1" to="." method="_on_save_1_pressed"]
|
||||
[connection signal="pressed" from="VBoxContainer/Save2" to="." method="_on_save_2_pressed"]
|
||||
[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="VBoxContainer/MarginContainer/VBoxContainer/Buttons/Start" to="." method="_on_start_pressed"]
|
||||
[connection signal="pressed" from="VBoxContainer/MarginContainer/VBoxContainer/Buttons/Delete" to="." method="_on_delete_pressed"]
|
||||
|
|
|
@ -19,9 +19,7 @@ func ensure_existence(save_file_name: String) -> void:
|
|||
|
||||
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")
|
||||
write(JSON.stringify({}), save_file_name)
|
||||
|
||||
func read(save_file_name: String) -> Variant:
|
||||
ensure_existence(save_file_name)
|
||||
|
@ -36,3 +34,14 @@ func read(save_file_name: String) -> Variant:
|
|||
return {}
|
||||
|
||||
return json.data
|
||||
|
||||
func write(json_string: String, save_file_name: String) -> void:
|
||||
var save_file := FileAccess.open(save_file_name, FileAccess.WRITE)
|
||||
save_file.store_line(json_string)
|
||||
save_file.store_line("FOR YOUR SAFETY, ALWAYS CHECK IF THE DATA OF THE FILES YOU DOWNLOAD LOOKS OKAY")
|
||||
|
||||
func change_property(property: String, value, save_file_name: String) -> void:
|
||||
ensure_existence(save_file_name)
|
||||
var data = read(save_file_name)
|
||||
data[property] = value
|
||||
write(JSON.stringify(data), save_file_name)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue