Skip to content

Commit

Permalink
✨ Add statistics view
Browse files Browse the repository at this point in the history
Also store number of game
  • Loading branch information
EmilienLeroy committed Nov 25, 2022
1 parent 6950250 commit d6f0062
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 5 deletions.
9 changes: 5 additions & 4 deletions locales/locales.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ SAVE_NAME,Name,Nom
SAVE_CONFIRM,Save,Sauvegarder
SAVE_CANCEL,Cancel,Annuler
SAVE_ERROR_NAME,Name is missing,Le nom est manquant
SAVE_ERROR_LOADING,Can't load the leaderboard,Impossible de charger le leaderboard
SAVE_ERROR_LOADING,Can't load the leaderboard,Impossible de charger le classement
SAVE_ERROR_SEND,Can't send your score,Impossible d'envoyer votre score
SAVE_SUCCESS_SEND,Score send !,Score envoyé !
RANK_TITLE,Rank,Rang
LEADERBOARD_GLOBAL,Global,Général
LEADERBOARD_ME,My Scores,Mes scores
LEADERBOARD_TITLE,Leaderboard,Leaderboard
LEADERBOARD_TITLE,Leaderboard,Classement
LEADERBOARD_TOP,TOP 50,TOP 50
HOME_PLAY,Play,Jouer
HOME_INFO,Information,Information
HOME_LEADERBOARD,Leaderboard,Leaderboard
HOME_LEADERBOARD,Leaderboard,Classement
HOME_OPTIONS,Options,Options
HOME_STATISTICS,Statistics,Statistiques
GLOBAL_SCORE,Score,Score
LOSE_REPLAY,Replay,Rejouer
LOSE_HOME,Home,Acceuil
LOSE_HOME,Home,Accueil
12 changes: 12 additions & 0 deletions main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var SaveView = preload("res://views/save.tscn");
var RankView = preload("res://views/rank.tscn");
var OptionsView = preload("res://views/options.tscn");
var LeaderboardView = preload("res://views/leaderboard.tscn");
var StatisticView = preload("res://views/statistics.tscn");

var current;

Expand All @@ -22,6 +23,7 @@ func create_home():
home.connect("play", self, 'on_play');
home.connect("info", self, 'on_info');
home.connect("options", self, 'on_options');
home.connect("statistics", self, 'on_statistics');
home.connect("leaderboard", self, 'on_leaderboard');

return home;
Expand Down Expand Up @@ -87,6 +89,13 @@ func create_options():
options.connect("back", self, "on_home");

return options;

func create_statistics():
var statistics = StatisticView.instance();

statistics.connect("back", self, "on_home");

return statistics;

func update_current_view(view):
$Fade.fade_in();
Expand All @@ -110,6 +119,9 @@ func on_play():

func on_options():
update_current_view(create_options());

func on_statistics():
update_current_view(create_statistics());

func on_lose(score, stats, save = false):
update_current_view(create_lose(score, stats, save));
Expand Down
5 changes: 5 additions & 0 deletions views/home.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ signal play;
signal leaderboard;
signal options
signal info;
signal statistics;

func _ready():
$Play.connect("button_down", self, "_on_play_down");
$About.connect("button_down", self, "_on_info_down");
$Options.connect("button_down", self, "_on_options_down");
$Statistics.connect("button_down", self, "_on_stats_down");
$Leaderboard.connect("button_down", self, "_on_leaderboard_down");
pass

Expand All @@ -23,3 +25,6 @@ func _on_options_down():

func _on_leaderboard_down():
emit_signal("leaderboard");

func _on_stats_down():
emit_signal("statistics");
13 changes: 12 additions & 1 deletion views/home.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,25 @@ text = "HOME_INFO"

[node name="Options" type="Button" parent="."]
margin_left = 88.0
margin_top = 585.0
margin_right = 272.0
margin_bottom = 635.0
rect_scale = Vector2( 0.8, 0.8 )
rect_pivot_offset = Vector2( 137, 17 )
theme = ExtResource( 2 )
custom_styles/normal = SubResource( 2 )
text = "HOME_OPTIONS"

[node name="Statistics" type="Button" parent="."]
margin_left = 88.0
margin_top = 486.0
margin_right = 272.0
margin_bottom = 536.0
rect_scale = Vector2( 0.8, 0.8 )
rect_pivot_offset = Vector2( 137, 17 )
theme = ExtResource( 2 )
custom_styles/normal = SubResource( 2 )
text = "HOME_OPTIONS"
text = "HOME_STATISTICS"

[node name="Leaderboard" type="Button" parent="."]
margin_left = 88.0
Expand Down
2 changes: 2 additions & 0 deletions views/lose.gd
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ func save_stats(s):
new_stats.bomb = s.bomb + prev.bomb;
new_stats.restore = s.restore + prev.restore;
new_stats.reset = s.reset + prev.reset;
new_stats.game = prev.game + 1;
else:
new_stats.square = s.square;
new_stats.bomb = s.bomb;
new_stats.restore = s.restore;
new_stats.reset = s.reset;
new_stats.game = 1;

file.open("user://stats.save", File.WRITE);
file.store_string(var2str(new_stats));
Expand Down
25 changes: 25 additions & 0 deletions views/statistics.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
extends Node2D

signal back;
var stats;

func _ready():
$Back.connect("button_down", self, "_on_back_down");
stats = get_stats();

if (stats):
$Stats.set_stats(stats);

pass

func _on_back_down():
emit_signal("back");

func get_stats():
var file = File.new();

file.open("user://stats.save", File.READ);
var stats = str2var(file.get_as_text());
file.close();

return stats;
33 changes: 33 additions & 0 deletions views/statistics.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[gd_scene load_steps=6 format=2]

[ext_resource path="res://assets/fonts/Inter-BlackItalic.ttf" type="DynamicFontData" id=1]
[ext_resource path="res://components/stats.tscn" type="PackedScene" id=2]
[ext_resource path="res://assets/icons/back.png" type="Texture" id=3]
[ext_resource path="res://views/statistics.gd" type="Script" id=4]

[sub_resource type="DynamicFont" id=1]
size = 35
font_data = ExtResource( 1 )

[node name="Statistics" type="Node2D"]
script = ExtResource( 4 )

[node name="Label" type="Label" parent="."]
margin_top = 22.0
margin_right = 360.0
margin_bottom = 140.0
custom_colors/font_color = Color( 0, 0, 0, 1 )
custom_fonts/font = SubResource( 1 )
text = "HOME_STATISTICS"
align = 1
valign = 1

[node name="Stats" parent="." instance=ExtResource( 2 )]
position = Vector2( 0, 108 )

[node name="Back" type="TextureButton" parent="."]
margin_left = 136.0
margin_top = 686.0
margin_right = 226.0
margin_bottom = 776.0
texture_normal = ExtResource( 3 )

0 comments on commit d6f0062

Please sign in to comment.