Basic drawing now disallows drawing X over existing lines and vice versa

This commit is contained in:
Luke Hubmayer-Werner 2020-05-21 15:36:05 +09:30
parent ed2e2c5006
commit 07a4e47201
2 changed files with 42 additions and 74 deletions

View File

@ -58,69 +58,3 @@ class IntArray2D extends PoolArray2D:
func clear_flag(row: int, col: int, value: int):
_array.set(row + col*_rows, _array[row + col*_rows]&(value^XORMASK))
#class ByteArray2D:
# var _array: PoolByteArray
# var _rows := 1
# var _cols := 1
# const XORMASK := (1<<8)-1
# func _init(rows:=1, cols:=1):
# assert(rows>0)
# assert(cols>0)
# _rows = rows
# _cols = cols
# _array = PoolByteArray()
# _array.resize(rows*cols)
#
# func set_cell(row: int, col: int, value: int):
# assert(row < _rows)
# assert(col < _cols)
# _array.set(row + col*_rows, value)
#
# func get_cell(row: int, col: int) -> int:
# assert(row < _rows)
# assert(col < _cols)
# return _array[row + col*_rows]
#
# func get_flag(row: int, col: int, value: int) -> bool:
# return bool(_array[row + col*_rows] & value)
#
# func set_flag(row: int, col: int, value: int):
# _array.set(row + col*_rows, _array[row + col*_rows]|value)
#
# func clear_flag(row: int, col: int, value: int):
# _array.set(row + col*_rows, _array[row + col*_rows]&(value^XORMASK))
#class IntArray2D:
# var _array: PoolIntArray
# var _rows := 1
# var _cols := 1
# const XORMASK := (1<<32)-1
# func _init(rows:=1, cols:=1):
# assert(rows>0)
# assert(cols>0)
# _rows = rows
# _cols = cols
# _array = PoolIntArray()
# _array.resize(rows*cols)
#
# func set_cell(row: int, col: int, value: int):
# assert(row < _rows)
# assert(col < _cols)
# _array.set(row + col*_rows, value)
#
# func get_cell(row: int, col: int) -> int:
# assert(row < _rows)
# assert(col < _cols)
# return _array[row + col*_rows]
#
# func get_flag(row: int, col: int, value: int) -> bool:
# return bool(_array[row + col*_rows] & value)
#
# func set_flag(row: int, col: int, value: int):
# _array.set(row + col*_rows, _array[row + col*_rows] | value)
#
# func clear_flag(row: int, col: int, value: int):
# _array.set(row + col*_rows, _array[row + col*_rows]&(value^XORMASK))

View File

@ -242,26 +242,60 @@ func _input(event: InputEvent) -> void:
match drag_action:
DragAction.DRAW_LINE:
if adx < threshold and ady > threshold:
corner_marks.set_flag(int(gridpos.y), int(round(gridpos.x)), CornerMark.L_DOWN)
set_line_down(int(gridpos.y), int(round(gridpos.x)))
elif adx > threshold and ady < threshold:
corner_marks.set_flag(int(round(gridpos.y)), int(gridpos.x), CornerMark.L_RIGHT)
set_line_right(int(round(gridpos.y)), int(gridpos.x))
DragAction.REMOVE_LINE:
if adx < threshold and ady > threshold:
corner_marks.clear_flag(int(gridpos.y), int(round(gridpos.x)), CornerMark.L_DOWN)
clear_line_down(int(gridpos.y), int(round(gridpos.x)))
elif adx > threshold and ady < threshold:
corner_marks.clear_flag(int(round(gridpos.y)), int(gridpos.x), CornerMark.L_RIGHT)
clear_line_right(int(round(gridpos.y)), int(gridpos.x))
DragAction.DRAW_X:
if adx < threshold and ady > threshold:
corner_marks.set_flag(int(gridpos.y), int(round(gridpos.x)), CornerMark.X_DOWN)
set_x_down(int(gridpos.y), int(round(gridpos.x)))
elif adx > threshold and ady < threshold:
corner_marks.set_flag(int(round(gridpos.y)), int(gridpos.x), CornerMark.X_RIGHT)
set_x_right(int(round(gridpos.y)), int(gridpos.x))
DragAction.REMOVE_X:
if adx < threshold and ady > threshold:
corner_marks.clear_flag(int(gridpos.y), int(round(gridpos.x)), CornerMark.X_DOWN)
clear_x_down(int(gridpos.y), int(round(gridpos.x)))
elif adx > threshold and ady < threshold:
corner_marks.clear_flag(int(round(gridpos.y)), int(gridpos.x), CornerMark.X_RIGHT)
clear_x_right(int(round(gridpos.y)), int(gridpos.x))
DragAction.DRAW_COLOR:
sel_row = int(gridpos.y)
sel_col = int(gridpos.x)
cell_colors.set_cell(sel_row, sel_col, drag_color)
var undo_stack = []
func set_line_right(row, col):
if !corner_marks.get_flag(row, col, CornerMark.L_RIGHT) and !corner_marks.get_flag(row, col, CornerMark.X_RIGHT):
corner_marks.set_flag(row, col, CornerMark.L_RIGHT)
# TODO: Add undo stack entry
func set_line_down(row, col):
if !corner_marks.get_flag(row, col, CornerMark.L_DOWN) and !corner_marks.get_flag(row, col, CornerMark.X_DOWN):
corner_marks.set_flag(row, col, CornerMark.L_DOWN)
func clear_line_right(row, col):
if corner_marks.get_flag(row, col, CornerMark.L_RIGHT):
corner_marks.clear_flag(row, col, CornerMark.L_RIGHT)
func clear_line_down(row, col):
if corner_marks.get_flag(row, col, CornerMark.L_DOWN):
corner_marks.clear_flag(row, col, CornerMark.L_DOWN)
func set_x_right(row, col):
if !corner_marks.get_flag(row, col, CornerMark.L_RIGHT) and !corner_marks.get_flag(row, col, CornerMark.X_RIGHT):
corner_marks.set_flag(row, col, CornerMark.X_RIGHT)
func set_x_down(row, col):
if !corner_marks.get_flag(row, col, CornerMark.L_DOWN) and !corner_marks.get_flag(row, col, CornerMark.X_DOWN):
corner_marks.set_flag(row, col, CornerMark.X_DOWN)
func clear_x_right(row, col):
if corner_marks.get_flag(row, col, CornerMark.X_RIGHT):
corner_marks.clear_flag(row, col, CornerMark.X_RIGHT)
func clear_x_down(row, col):
if corner_marks.get_flag(row, col, CornerMark.X_DOWN):
corner_marks.clear_flag(row, col, CornerMark.X_DOWN)