@@ -24,11 +24,11 @@ func _init(array).(array):
24
24
pass
25
25
26
26
func next (action ):
27
- if _left == - 1 :
27
+ if _left == _get_middle () :
28
28
if action != null and action != ACTIONS .RIGHT :
29
29
return emit_signal ("mistake" )
30
30
_right += 1
31
- elif _right == - 1 :
31
+ elif _right == _get_end () :
32
32
if action != null and action != ACTIONS .LEFT :
33
33
return emit_signal ("mistake" )
34
34
_left += 1
@@ -40,30 +40,26 @@ func next(action):
40
40
if action != null and action != ACTIONS .RIGHT :
41
41
return emit_signal ("mistake" )
42
42
_right += 1
43
- # Test if end of subarrays have been reached
44
- if _left == _get_middle ():
45
- _left = - 1
46
- if _right == _get_end ():
47
- _right = - 1
48
43
# If both ends have been reached, merge and advance to next block
49
- if _left == - 1 and _right == - 1 :
44
+ if _left == _get_middle () and _right == _get_end () :
50
45
array .sort (_get_begin (), _get_end ())
51
46
_sub_no += 1
52
- _left = _get_begin ()
53
- _right = _get_middle ()
54
47
# If last block has been completed, go up a level
55
48
if _sub_no == array .size / (_sub_size ):
56
49
_sub_size *= 2
57
50
_sub_no = 0
58
- _left = _get_begin ()
59
- _right = _get_middle ()
60
51
if _sub_size == array .size * 2 :
61
52
emit_signal ("done" )
53
+ # Update pointers
54
+ _left = _get_begin ()
55
+ _right = _get_middle ()
62
56
63
57
func get_effect (i ):
64
- if i == _left or i == _right :
58
+ var is_left = _left != _get_middle () and i == _left
59
+ var is_right = _right != _get_end () and i == _right
60
+ if is_left or is_right :
65
61
return EFFECTS .HIGHLIGHTED
66
- if i < _sub_no * _sub_size or i >= _sub_no * _sub_size + _sub_size :
62
+ if i < _left or i >= _get_middle () and i < _right or i >= _get_end () :
67
63
return EFFECTS .DIMMED
68
64
return EFFECTS .NONE
69
65
0 commit comments