@@ -10,32 +10,44 @@ const LEVELS = [
10
10
const MIN_WAIT = 1.0 / 32 # Should be greater than maximum frame time
11
11
const MAX_WAIT = 4
12
12
const MIN_SIZE = 8
13
- const MAX_SIZE = 128
13
+ const MAX_SIZE = 256
14
14
15
15
var _level = LEVELS [0 ].new (ArrayModel .new (
16
16
GlobalScene .get_param ("size" , ArrayModel .DEFAULT_SIZE )))
17
17
18
18
func _ready ():
19
+ var buttons = $ LevelsBorder/Levels/LevelsContainer/Buttons
19
20
for level in LEVELS :
20
21
var button = Button .new ()
21
22
button .text = level .NAME
22
23
button .align = Button .ALIGN_LEFT
23
24
button .connect ("focus_entered" , self , "_on_Button_focus_entered" )
24
25
button .connect ("pressed" , self , "_on_Button_pressed" , [level ])
25
- $ LevelsBorder/Levels .add_child (button )
26
- # Autofocus last played level
27
- if GlobalScene .get_param ("level" ) == level :
26
+ buttons .add_child (button )
27
+ var score = Label .new ()
28
+ score .align = Label .ALIGN_RIGHT
29
+ $ LevelsBorder/Levels/LevelsContainer/Scores .add_child (score )
30
+ # Autofocus last played level
31
+ for button in buttons .get_children ():
32
+ if button .text == _level .NAME :
28
33
button .grab_focus ()
29
- var top_button = $ LevelsBorder/Levels .get_children ()[0 ]
30
- var bottom_button = $ LevelsBorder/Levels .get_children ()[- 1 ]
34
+ var top_button = buttons .get_children ()[0 ]
35
+ var bottom_button = buttons .get_children ()[- 1 ]
31
36
# Allow looping from ends of list
32
37
top_button .focus_neighbour_top = bottom_button .get_path ()
33
38
bottom_button .focus_neighbour_bottom = top_button .get_path ()
34
- # If no last played level, autofocus first level
35
- if GlobalScene .get_param ("level" ) == null :
36
- top_button .grab_focus ()
37
39
38
40
func _on_Button_focus_entered (size = _level .array .size ):
41
+ # Update high scores
42
+ var buttons = $ LevelsBorder/Levels/LevelsContainer/Buttons
43
+ var scores = $ LevelsBorder/Levels/LevelsContainer/Scores
44
+ var save = GlobalScene .read_save ()
45
+ for i in range (LEVELS .size ()):
46
+ var name = buttons .get_child (i ).text
47
+ if name in save and str (size ) in save [name ]:
48
+ scores .get_child (i ).text = "%.3f " % save [name ][str (size )]
49
+ else :
50
+ scores .get_child (i ).text = "INF"
39
51
# Pause a bit to show completely sorted array
40
52
if _level .array .is_sorted ():
41
53
$ Timer .stop ()
0 commit comments