@@ -24,11 +24,11 @@ func _init(array).(array):
2424 pass
2525
2626func next (action ):
27- if _left == - 1 :
27+ if _left == _get_middle () :
2828 if action != null and action != ACTIONS .RIGHT :
2929 return emit_signal ("mistake" )
3030 _right += 1
31- elif _right == - 1 :
31+ elif _right == _get_end () :
3232 if action != null and action != ACTIONS .LEFT :
3333 return emit_signal ("mistake" )
3434 _left += 1
@@ -40,30 +40,26 @@ func next(action):
4040 if action != null and action != ACTIONS .RIGHT :
4141 return emit_signal ("mistake" )
4242 _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
4843 # 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 () :
5045 array .sort (_get_begin (), _get_end ())
5146 _sub_no += 1
52- _left = _get_begin ()
53- _right = _get_middle ()
5447 # If last block has been completed, go up a level
5548 if _sub_no == array .size / (_sub_size ):
5649 _sub_size *= 2
5750 _sub_no = 0
58- _left = _get_begin ()
59- _right = _get_middle ()
6051 if _sub_size == array .size * 2 :
6152 emit_signal ("done" )
53+ # Update pointers
54+ _left = _get_begin ()
55+ _right = _get_middle ()
6256
6357func 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 :
6561 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 () :
6763 return EFFECTS .DIMMED
6864 return EFFECTS .NONE
6965
0 commit comments