Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Flossy Gnu
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Purism
Flossy Gnu
Commits
72ae3cda
Commit
72ae3cda
authored
Mar 15, 2019
by
Nathan Lovato
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add arcade-style high score table, including save and load from disk
parent
eb690c9e
Pipeline
#5064
passed with stage
in 4 minutes and 16 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
69 additions
and
20 deletions
+69
-20
game/ScoreBoard/ScoreBoard.gd
game/ScoreBoard/ScoreBoard.gd
+10
-5
game/ScoreBoard/ScoreBoard.tscn
game/ScoreBoard/ScoreBoard.tscn
+1
-10
game/ScoreBoard/ScoreLoader.gd
game/ScoreBoard/ScoreLoader.gd
+53
-0
game/ScoreBoard/ScoreRow.gd
game/ScoreBoard/ScoreRow.gd
+3
-3
game/ScoreBoard/ScoreRow.tscn
game/ScoreBoard/ScoreRow.tscn
+2
-2
No files found.
game/ScoreBoard/ScoreBoard.gd
View file @
72ae3cda
...
...
@@ -2,14 +2,19 @@ extends Control
onready
var
scores_column
=
$
Column
/
ScoresColumn
const
score_row
=
preload
(
"res://ScoreBoard/ScoreRow.tscn"
)
const
ScoreRow
=
preload
(
"ScoreRow.tscn"
)
const
ScoreLoader
=
preload
(
"ScoreLoader.gd"
)
func
start
():
var
loader
:
=
ScoreLoader
.
new
()
var
scores
=
loader
.
get_scores
()
for
i
in
range
(
10
):
var
score_instance
=
score_row
.
instance
()
scores_column
.
add_child
(
score_instance
)
score_instance
.
setup
(
i
)
score_instance
.
start
()
var
row
=
ScoreRow
.
instance
()
scores_column
.
add_child
(
row
)
row
.
setup
(
i
,
scores
[
i
])
for
row
in
scores_column
.
get_children
():
row
.
start
()
yield
(
get_tree
()
.
create_timer
(
0.07
),
"timeout"
)
func
_ready
()
->
void
:
...
...
game/ScoreBoard/ScoreBoard.tscn
View file @
72ae3cda
[gd_scene load_steps=
4
format=2]
[gd_scene load_steps=
3
format=2]
[ext_resource path="res://ScoreBoard/ScoreBoard.gd" type="Script" id=1]
[ext_resource path="res://assets/fonts/ScoreTitle.tres" type="DynamicFont" id=2]
[ext_resource path="res://ScoreBoard/ScoreRow.tscn" type="PackedScene" id=3]
[node name="ScoreBoard" type="Control"]
anchor_right = 1.0
...
...
@@ -36,11 +35,3 @@ margin_right = 840.0
margin_bottom = 1180.0
size_flags_vertical = 3
[node name="ScoreRow" parent="Column/ScoresColumn" instance=ExtResource( 3 )]
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_top = 0.0
margin_right = 840.0
margin_bottom = 88.0
game/ScoreBoard/ScoreLoader.gd
0 → 100644
View file @
72ae3cda
"""
Saves and loads scores to/from the disk
Each score is a dictionary of the form
{ initials:String, score:int }
"""
const
SCORES_PATH
:
=
"user://scores"
const
SCORE_SECTION
:
=
"scores"
const
DEFAULT_SCORE
:
=
{
initials
=
"RMS"
,
score
=
1
,
}
func
score_file_exists
()
->
bool
:
return
Directory
.
new
()
.
file_exists
(
SCORES_PATH
)
func
_get_default_scores
()
->
Array
:
var
scores
:
=
[]
for
i
in
range
(
10
):
scores
.
append
(
DEFAULT_SCORE
)
return
scores
func
save
(
scores
:
Array
=
[])
->
void
:
if
not
scores
.
size
()
in
[
0
,
10
]:
return
if
scores
==
[]:
scores
=
_get_default_scores
()
var
file
:
=
ConfigFile
.
new
()
for
i
in
range
(
scores
.
size
()):
file
.
set_value
(
SCORE_SECTION
,
str
(
i
),
scores
[
i
])
file
.
save
(
SCORES_PATH
)
func
get_scores
()
->
Array
:
"""
Loads scores from the disk and returns them as a list
"""
if
not
score_file_exists
():
return
_get_default_scores
()
var
file
:
=
ConfigFile
.
new
()
if
file
.
load
(
SCORES_PATH
)
!=
OK
:
return
[]
var
scores
:
=
[]
for
i
in
range
(
10
):
var
score
:
Dictionary
=
file
.
get_value
(
SCORE_SECTION
,
str
(
i
),
DEFAULT_SCORE
)
scores
.
append
(
score
)
return
scores
game/ScoreBoard/ScoreRow.gd
View file @
72ae3cda
...
...
@@ -9,10 +9,10 @@ const COLOR_TRANSPARENT = Color('00ffffff')
const
COLOR_OPAQUE
=
Color
(
'
00ffffff'
)
func
setup
(
index
:
int
,
score
:
int
=
1
,
initials
:
String
=
"rms"
)
->
void
:
func
setup
(
index
:
int
,
score
:
Dictionary
=
{}
)
->
void
:
rank_label
.
set_rank
(
index
)
score_label
.
text
=
"
%03d
"
%
score
initials_label
.
text
=
initials
score_label
.
text
=
"
%03d
"
%
score
.
score
initials_label
.
text
=
score
.
initials
func
start
()
->
void
:
...
...
game/ScoreBoard/ScoreRow.tscn
View file @
72ae3cda
...
...
@@ -23,7 +23,7 @@ func set_rank(index:int) -> void:
[sub_resource type="Animation" id=2]
resource_name = "fade_in"
length = 0.
4
length = 0.
3
tracks/0/type = "value"
tracks/0/path = NodePath(".:modulate")
tracks/0/interp = 1
...
...
@@ -31,7 +31,7 @@ tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.
4
),
"times": PoolRealArray( 0, 0.
3
),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 1 ) ]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment