refactored some collisions

This commit is contained in:
Richard Hájek 2020-09-13 16:59:24 +02:00
parent 2b3e40d39e
commit 85e6e8807e
4 changed files with 12 additions and 12 deletions

View file

@ -291,8 +291,8 @@ func _reflow_smaller(new_cols: int, new_rows: int) -> void:
# Record original lines so they don't get overridden when we rearrange the list # Record original lines so they don't get overridden when we rearrange the list
var original_lines = [] var original_lines = []
for i in range(lines.length): for j in range(lines.length):
original_lines.append(lines.get_line(i)) original_lines.append(lines.get_line(j))
var original_lines_length = lines.length var original_lines_length = lines.length
var original_line_index = original_lines_length - 1 var original_line_index = original_lines_length - 1
@ -322,10 +322,10 @@ func _reflow_smaller(new_cols: int, new_rows: int) -> void:
# Update markers # Update markers
var insert_count_emitted = 0 var insert_count_emitted = 0
for i in range(insert_events.size() - 1, -1, -1): for k in range(insert_events.size() - 1, -1, -1):
insert_events[i].index += insert_count_emitted insert_events[k].index += insert_count_emitted
lines.emit_signal("inserted", insert_events[i]) lines.emit_signal("inserted", insert_events[k])
insert_count_emitted += insert_events[i].amount insert_count_emitted += insert_events[k].amount
var amount_to_trim = max(0, original_lines_length + count_to_insert - lines.max_length) var amount_to_trim = max(0, original_lines_length + count_to_insert - lines.max_length)
if amount_to_trim > 0: if amount_to_trim > 0:
lines.emit_signal("trimmed", amount_to_trim) lines.emit_signal("trimmed", amount_to_trim)

View file

@ -132,8 +132,8 @@ func insert_cells(pos: int, n: int, fill_cell_data, erase_attr = null) -> void:
while i >= 0: while i >= 0:
set_cell(pos + n + i, load_cell(pos + i, cell)) set_cell(pos + n + i, load_cell(pos + i, cell))
i -= 1 i -= 1
for i in range(n): for j in range(n):
set_cell(pos + i, fill_cell_data) set_cell(pos + j, fill_cell_data)
else: else:
for i in range(pos, length): for i in range(pos, length):
set_cell(i, fill_cell_data) set_cell(i, fill_cell_data)

View file

@ -75,8 +75,8 @@ static func reflow_larger_get_lines_to_remove(lines, old_cols: int, new_cols: in
# Work backwards and remove any rows at the end that only contain null cells # Work backwards and remove any rows at the end that only contain null cells
var count_to_remove = 0 var count_to_remove = 0
for i in range(wrapped_lines.size() - 1, 0, -1): for j in range(wrapped_lines.size() - 1, 0, -1):
if i > dest_line_index or wrapped_lines[i].get_trimmed_length() == 0: if j > dest_line_index or wrapped_lines[j].get_trimmed_length() == 0:
count_to_remove += 1 count_to_remove += 1
else: else:
break break

View file

@ -128,8 +128,8 @@ func splice(start: int, delete_count: int, items: Array = []) -> void:
while i >= start: while i >= start:
_array[_get_cyclic_index(i + items.size())] = _array[_get_cyclic_index(i)] _array[_get_cyclic_index(i + items.size())] = _array[_get_cyclic_index(i)]
i -= 1 i -= 1
for i in range(items.size()): for j in range(items.size()):
_array[_get_cyclic_index(start + i)] = items[i] _array[_get_cyclic_index(start + j)] = items[j]
# Adjust length as needed # Adjust length as needed
if length + items.size() > max_length: if length + items.size() > max_length: