Skip to content

Commit b58fe2d

Browse files
committed
refactor: rename ArrayModel::get() to at()
This avoids conflicts with the get() method in Object and better self-documents its purpose.
1 parent 377417c commit b58fe2d

File tree

8 files changed

+14
-12
lines changed

8 files changed

+14
-12
lines changed

levels/bubble_sort.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func _init(array).(array):
2222
pass
2323

2424
func next(action):
25-
if array.get(_index) > array.get(_index + 1):
25+
if array.at(_index) > array.at(_index + 1):
2626
if action != null and action != ACTIONS.SWAP:
2727
return emit_signal("mistake")
2828
array.swap(_index, _index + 1)

levels/insertion_sort.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func _init(array).(array):
2222
pass
2323

2424
func next(action):
25-
if array.get(_index - 1) > array.get(_index):
25+
if array.at(_index - 1) > array.at(_index):
2626
if action != null and action != ACTIONS.SWAP:
2727
return emit_signal("mistake")
2828
array.swap(_index - 1, _index)

levels/merge_sort.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func next(action):
3232
if action != null and action != ACTIONS.LEFT:
3333
return emit_signal("mistake")
3434
_left += 1
35-
elif array.get(_left) <= array.get(_right):
35+
elif array.at(_left) <= array.at(_right):
3636
if action != null and action != ACTIONS.LEFT:
3737
return emit_signal("mistake")
3838
_left += 1

levels/selection_sort.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func _init(array).(array):
2222
pass
2323

2424
func next(action):
25-
if array.get(_base) > array.get(_index):
25+
if array.at(_base) > array.at(_index):
2626
if action != null and action != ACTIONS.SWAP:
2727
return emit_signal("mistake")
2828
array.swap(_base, _index)

models/array_model.gd

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
"""
2-
A plain old one-dimensional random access array wrapper around the
3-
built-in class.
4-
"""
5-
61
class_name ArrayModel
72
extends Reference
83

@@ -16,7 +11,7 @@ func _init(size=16):
1611
array.shuffle()
1712
self.size = size
1813

19-
func get(i):
14+
func at(i):
2015
"""Retrieve the value of the element at index i."""
2116
return array[i]
2217

project.godot

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ _global_script_classes=[ {
4545
"path": "res://levels/merge_sort.gd"
4646
}, {
4747
"base": "ComparisonSort",
48+
"class": "QuickSort",
49+
"language": "GDScript",
50+
"path": "res://levels/quick_sort.gd"
51+
}, {
52+
"base": "ComparisonSort",
4853
"class": "SelectionSort",
4954
"language": "GDScript",
5055
"path": "res://levels/selection_sort.gd"
@@ -57,6 +62,7 @@ _global_script_class_icons={
5762
"ComparisonSort": "",
5863
"InsertionSort": "",
5964
"MergeSort": "",
65+
"QuickSort": "",
6066
"SelectionSort": ""
6167
}
6268

scripts/levels.gd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var levels = [
55
InsertionSort,
66
SelectionSort,
77
MergeSort,
8+
QuickSort,
89
]
910
var level: ComparisonSort
1011

@@ -27,7 +28,7 @@ func _ready():
2728
bottom_button.focus_neighbour_bottom = top_button.get_path()
2829
# If no last played level, autofocus first level
2930
if GlobalScene.get_param("level") == null:
30-
top_button.grab_focus()
31+
bottom_button.grab_focus()
3132

3233
func _on_Button_focus_changed():
3334
"""Initialize the preview section."""

views/array_view.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func _process(delta):
2525
for i in range(level.array.size):
2626
rects[i].rect_scale.y = -1 # HACK: Override scale to bypass weird behavior
2727
rects[i].color = level.get_effect(i)
28-
rects[i].rect_size.y = rect_size.y * level.array.get(i) / level.array.size
28+
rects[i].rect_size.y = rect_size.y * level.array.at(i) / level.array.size
2929

3030
func _on_Level_mistake():
3131
"""Flash the border red on mistakes."""

0 commit comments

Comments
 (0)