From a1d11d6fb79c074f082dd0c82fc972ee6508d347 Mon Sep 17 00:00:00 2001 From: Luke Hubmayer-Werner Date: Fri, 22 May 2020 23:43:32 +0930 Subject: [PATCH] Fixed first x placed/cleared not being undoable --- scripts/GameField.gd | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/scripts/GameField.gd b/scripts/GameField.gd index 2cb6a3a..fea48c6 100644 --- a/scripts/GameField.gd +++ b/scripts/GameField.gd @@ -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