Skip to content

Commit be42b56

Browse files
committed
feat: remove tier system
It added a lot of complexity and is imperfect and possibly confusing for little benefit.
1 parent ae43975 commit be42b56

File tree

4 files changed

+19
-72
lines changed

4 files changed

+19
-72
lines changed

levels/comparison_sort.gd

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ var DESCRIPTION = _get_header().split(" ")[1]
1616
var CONTROLS = _get_header().split(" ")[2]
1717

1818
var array: ArrayModel
19-
var moves = 0
20-
var test = _get_header().split(" ")[0]
2119

2220
var _timer = Timer.new()
2321

@@ -39,7 +37,6 @@ func _ready():
3937
func _input(event):
4038
"""Pass input events for checking and take appropriate action."""
4139
if event.is_pressed():
42-
moves += 1
4340
return next(event.as_text())
4441

4542
func next(action):

scripts/levels.gd

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,9 @@ func _ready():
3030
button.connect("focus_entered", self, "_on_Button_focus_entered")
3131
button.connect("pressed", self, "_on_Button_pressed", [level])
3232
buttons.add_child(button)
33-
var score = HBoxContainer.new()
34-
var time = Label.new()
35-
time.align = Label.ALIGN_RIGHT
36-
time.size_flags_horizontal = Control.SIZE_EXPAND_FILL
37-
var tier = Label.new()
38-
score.add_child(time)
39-
score.add_child(tier)
33+
var score = Label.new()
34+
score.align = Label.ALIGN_RIGHT
35+
score.size_flags_horizontal = Control.SIZE_EXPAND_FILL
4036
scores.add_child(score)
4137
# Autofocus last played level
4238
for button in buttons.get_children():
@@ -50,21 +46,11 @@ func _ready():
5046

5147
func _on_Button_focus_entered(size=_level.array.size):
5248
# Update high scores
53-
var buttons = $LevelsBorder/Levels/LevelsContainer/Buttons
49+
var container = $LevelsBorder/Levels/LevelsContainer
5450
for i in range(LEVELS.size()):
55-
var score = $LevelsBorder/Levels/LevelsContainer/Scores.get_child(i)
56-
var name = buttons.get_child(i).text
51+
var name = container.get_node("Buttons").get_child(i).text
5752
var time = GlobalScore.get_time(name, size)
58-
if time == INF:
59-
score.get_child(0).text = ""
60-
score.get_child(1).text = "INF"
61-
score.get_child(1).add_color_override(
62-
"font_color", GlobalTheme.GREEN)
63-
else:
64-
score.get_child(0).text = "%.3f" % time
65-
score.get_child(1).text = GlobalScore.get_tier(name, size)
66-
score.get_child(1).add_color_override(
67-
"font_color", GlobalScore.get_color(name, size))
53+
container.get_node("Scores").get_child(i).text = "INF" if time == INF else "%.3f" % time
6854
# Pause a bit to show completely sorted array
6955
if _level.array.is_sorted():
7056
# Prevent race condition caused by keyboard input during pause

scripts/play.gd

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ func _input(event):
3030

3131
func _on_Level_done(level):
3232
set_process(false)
33-
var name = level.NAME
34-
var size = level.array.size
35-
var score = get_score()
33+
var time = get_score()
3634
var moves = level.moves
3735
var restart = Button.new()
3836
restart.text = "RESTART LEVEL"
@@ -42,24 +40,18 @@ func _on_Level_done(level):
4240
var back = Button.new()
4341
back.text = "BACK TO LEVEL SELECT"
4442
back.connect("pressed", self, "_on_Button_pressed", ["levels"])
45-
var time = Label.new()
46-
time.text = "%.3f" % score
47-
time.align = Label.ALIGN_RIGHT
48-
time.size_flags_horizontal = Control.SIZE_EXPAND_FILL
49-
var tier = Label.new()
50-
tier.text = GlobalScore.calculate_tier(score, moves)
51-
tier.align = Label.ALIGN_RIGHT
52-
tier.add_color_override(
53-
"font_color", GlobalScore.calculate_color(score, moves))
43+
var score = Label.new()
44+
score.text = "%.3f" % time
45+
score.align = Label.ALIGN_RIGHT
46+
score.size_flags_horizontal = Control.SIZE_EXPAND_FILL
5447
$HUDBorder/HUD/Level.queue_free()
5548
$HUDBorder/HUD/Score.queue_free()
5649
$HUDBorder/HUD.add_child(restart)
5750
$HUDBorder/HUD.add_child(separator)
5851
$HUDBorder/HUD.add_child(back)
59-
$HUDBorder/HUD.add_child(time)
60-
$HUDBorder/HUD.add_child(tier)
52+
$HUDBorder/HUD.add_child(score)
6153
restart.grab_focus()
62-
GlobalScore.save_score(name, size, score, moves)
54+
GlobalScore.save_score(level.NAME, level.array.size, time)
6355

6456
func _on_Button_pressed(scene):
6557
GlobalScene.change_scene("res://scenes/" + scene + ".tscn",

scripts/score.gd

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,7 @@ Common helper library for scoring functions.
44

55
extends Node
66

7-
const TIERS = ["F", "D", "C", "B", "A", "S"]
8-
const COLORS = [
9-
Color("f44336"),
10-
Color("ff9800"),
11-
Color("ffeb3b"),
12-
Color("4caf50"),
13-
Color("03a9f4"),
14-
Color("e040fb"),
15-
]
7+
const VERSION = 0 # Increment when changing save file format
168

179
var _save: Dictionary
1810

@@ -24,39 +16,19 @@ func _init():
2416

2517
func get_time(name, size):
2618
if name in _save and str(size) in _save[name]:
27-
return _save[name][str(size)][0]
19+
return _save[name][str(size)]
2820
return INF
2921

30-
func get_tier(name, size):
31-
if name in _save and str(size) in _save[name]:
32-
return _save[name][str(size)][1]
33-
return ""
34-
35-
func get_color(name, size):
36-
var tier = get_tier(name, size)
37-
return Color.black if tier.empty() else COLORS[TIERS.find(tier)]
38-
39-
func calculate_tier(time, moves):
40-
return TIERS[min(int(moves / time), TIERS.size() - 1)]
41-
42-
func calculate_color(time, moves):
43-
return COLORS[TIERS.find(calculate_tier(time, moves))]
44-
45-
func save_score(name, size, time, moves):
22+
func save_score(name, size, time):
4623
if not name in _save:
4724
_save[name] = {}
4825
if not str(size) in _save[name]:
49-
_save[name][str(size)] = [INF, ""]
50-
var prev_time = get_time(name, size)
51-
var prev_tier = get_tier(name, size)
52-
var tier = calculate_tier(time, moves)
53-
var tier_index = TIERS.find(tier)
54-
if (prev_tier.empty() or tier_index > TIERS.find(prev_tier)
55-
or tier_index == TIERS.find(prev_tier) and time < prev_time):
56-
_save[name][str(size)] = [time, tier]
26+
_save[name][str(size)] = INF
27+
_save[name][str(size)] = min(time, get_time(name, size))
5728
_save()
5829

5930
func _save():
31+
_save["VERSION"] = VERSION
6032
var file = File.new()
6133
file.open("user://save.json", File.WRITE)
6234
file.store_line(to_json(_save))

0 commit comments

Comments
 (0)