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)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
update()
|
||||
# update()
|
||||
pass
|
||||
|
||||
const num_dict := {'.': NUMBER_NONE, '0': 0, '1': 1, '2': 2, '3': 3}
|
||||
const colornum_dict := {'0': 0, '1': 1, '2': 2}
|
||||
|
@ -216,20 +217,20 @@ func _input(event: InputEvent) -> void:
|
|||
sel_col = int(round(gridpos.x))
|
||||
if corner_marks.get_flag(sel_row, sel_col, CornerMark.X_DOWN):
|
||||
drag_action = DragAction.REMOVE_X
|
||||
corner_marks.clear_flag(sel_row, sel_col, CornerMark.X_DOWN)
|
||||
clear_x_down(sel_row, sel_col)
|
||||
else:
|
||||
drag_action = DragAction.DRAW_X
|
||||
corner_marks.set_flag(sel_row, sel_col, CornerMark.X_DOWN)
|
||||
set_x_down(sel_row, sel_col)
|
||||
else:
|
||||
if ady < threshold:
|
||||
sel_row = int(round(gridpos.y))
|
||||
sel_col = int(gridpos.x)
|
||||
if corner_marks.get_flag(sel_row, sel_col, CornerMark.X_RIGHT):
|
||||
drag_action = DragAction.REMOVE_X
|
||||
corner_marks.clear_flag(sel_row, sel_col, CornerMark.X_RIGHT)
|
||||
clear_x_right(sel_row, sel_col)
|
||||
else:
|
||||
drag_action = DragAction.DRAW_X
|
||||
corner_marks.set_flag(sel_row, sel_col, CornerMark.X_RIGHT)
|
||||
set_x_right(sel_row, sel_col)
|
||||
else:
|
||||
sel_row = int(gridpos.y)
|
||||
sel_col = int(gridpos.x)
|
||||
|
@ -283,12 +284,14 @@ var undo_preview_pos := 0 setget set_undo_preview_pos
|
|||
func apply_undo_preview():
|
||||
undo_stack.resize(len(undo_stack)-undo_preview_pos)
|
||||
undo_preview_pos = 0
|
||||
update()
|
||||
|
||||
func do_action(action):
|
||||
if undo_preview_pos > 0:
|
||||
apply_undo_preview()
|
||||
action.activate()
|
||||
undo_stack.append(action)
|
||||
update()
|
||||
|
||||
func undo():
|
||||
if !undo_stack.empty():
|
||||
|
@ -297,6 +300,7 @@ func undo():
|
|||
else:
|
||||
var action = undo_stack.pop_back()
|
||||
action.undo()
|
||||
update()
|
||||
|
||||
func set_undo_preview_pos(value):
|
||||
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
|
||||
for i in -delta:
|
||||
undo_stack[-old_pos+i].activate()
|
||||
update()
|
||||
|
||||
class UndoAction:
|
||||
var action_type
|
||||
|
|
Loading…
Reference in New Issue