Fixed first x placed/cleared not being undoable
This commit is contained in:
parent
c5232db66e
commit
a1d11d6fb7
|
@ -126,7 +126,8 @@ func _draw() -> void:
|
||||||
# print(action)
|
# print(action)
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
update()
|
# update()
|
||||||
|
pass
|
||||||
|
|
||||||
const num_dict := {'.': NUMBER_NONE, '0': 0, '1': 1, '2': 2, '3': 3}
|
const num_dict := {'.': NUMBER_NONE, '0': 0, '1': 1, '2': 2, '3': 3}
|
||||||
const colornum_dict := {'0': 0, '1': 1, '2': 2}
|
const colornum_dict := {'0': 0, '1': 1, '2': 2}
|
||||||
|
@ -216,20 +217,20 @@ func _input(event: InputEvent) -> void:
|
||||||
sel_col = int(round(gridpos.x))
|
sel_col = int(round(gridpos.x))
|
||||||
if corner_marks.get_flag(sel_row, sel_col, CornerMark.X_DOWN):
|
if corner_marks.get_flag(sel_row, sel_col, CornerMark.X_DOWN):
|
||||||
drag_action = DragAction.REMOVE_X
|
drag_action = DragAction.REMOVE_X
|
||||||
corner_marks.clear_flag(sel_row, sel_col, CornerMark.X_DOWN)
|
clear_x_down(sel_row, sel_col)
|
||||||
else:
|
else:
|
||||||
drag_action = DragAction.DRAW_X
|
drag_action = DragAction.DRAW_X
|
||||||
corner_marks.set_flag(sel_row, sel_col, CornerMark.X_DOWN)
|
set_x_down(sel_row, sel_col)
|
||||||
else:
|
else:
|
||||||
if ady < threshold:
|
if ady < threshold:
|
||||||
sel_row = int(round(gridpos.y))
|
sel_row = int(round(gridpos.y))
|
||||||
sel_col = int(gridpos.x)
|
sel_col = int(gridpos.x)
|
||||||
if corner_marks.get_flag(sel_row, sel_col, CornerMark.X_RIGHT):
|
if corner_marks.get_flag(sel_row, sel_col, CornerMark.X_RIGHT):
|
||||||
drag_action = DragAction.REMOVE_X
|
drag_action = DragAction.REMOVE_X
|
||||||
corner_marks.clear_flag(sel_row, sel_col, CornerMark.X_RIGHT)
|
clear_x_right(sel_row, sel_col)
|
||||||
else:
|
else:
|
||||||
drag_action = DragAction.DRAW_X
|
drag_action = DragAction.DRAW_X
|
||||||
corner_marks.set_flag(sel_row, sel_col, CornerMark.X_RIGHT)
|
set_x_right(sel_row, sel_col)
|
||||||
else:
|
else:
|
||||||
sel_row = int(gridpos.y)
|
sel_row = int(gridpos.y)
|
||||||
sel_col = int(gridpos.x)
|
sel_col = int(gridpos.x)
|
||||||
|
@ -283,12 +284,14 @@ var undo_preview_pos := 0 setget set_undo_preview_pos
|
||||||
func apply_undo_preview():
|
func apply_undo_preview():
|
||||||
undo_stack.resize(len(undo_stack)-undo_preview_pos)
|
undo_stack.resize(len(undo_stack)-undo_preview_pos)
|
||||||
undo_preview_pos = 0
|
undo_preview_pos = 0
|
||||||
|
update()
|
||||||
|
|
||||||
func do_action(action):
|
func do_action(action):
|
||||||
if undo_preview_pos > 0:
|
if undo_preview_pos > 0:
|
||||||
apply_undo_preview()
|
apply_undo_preview()
|
||||||
action.activate()
|
action.activate()
|
||||||
undo_stack.append(action)
|
undo_stack.append(action)
|
||||||
|
update()
|
||||||
|
|
||||||
func undo():
|
func undo():
|
||||||
if !undo_stack.empty():
|
if !undo_stack.empty():
|
||||||
|
@ -297,6 +300,7 @@ func undo():
|
||||||
else:
|
else:
|
||||||
var action = undo_stack.pop_back()
|
var action = undo_stack.pop_back()
|
||||||
action.undo()
|
action.undo()
|
||||||
|
update()
|
||||||
|
|
||||||
func set_undo_preview_pos(value):
|
func set_undo_preview_pos(value):
|
||||||
if value < 0: # Negative is past the end of the stack
|
if value < 0: # Negative is past the end of the stack
|
||||||
|
@ -313,6 +317,7 @@ func set_undo_preview_pos(value):
|
||||||
elif delta < 0: # We are redoing
|
elif delta < 0: # We are redoing
|
||||||
for i in -delta:
|
for i in -delta:
|
||||||
undo_stack[-old_pos+i].activate()
|
undo_stack[-old_pos+i].activate()
|
||||||
|
update()
|
||||||
|
|
||||||
class UndoAction:
|
class UndoAction:
|
||||||
var action_type
|
var action_type
|
||||||
|
|
Loading…
Reference in New Issue