Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing undo redo stack issues in godot4 #200

Open
wants to merge 1 commit into
base: 169-fix-parent-rotations-for-curves
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions addons/road-generator/plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,7 @@ func _add_next_rp_on_click(pos: Vector3, nrm: Vector3, selection: Node) -> void:
elif selection is RoadManager:
add_container = true
t_manager = selection
_sel = selection
else: # RoadManager or RoadLane.
push_error("Invalid selection context, need RoadContainer parent")
return
Expand All @@ -1006,13 +1007,17 @@ func _add_next_rp_on_click(pos: Vector3, nrm: Vector3, selection: Node) -> void:
undo_redo.add_undo_property(selection, "global_transform", selection.global_transform)
undo_redo.add_do_method(self, "_add_next_rp_on_click_do", pos, nrm, _sel, parent, handle_mag)
if parent is RoadContainer:
undo_redo.add_do_method(parent, "update_edges")
undo_redo.add_undo_method(parent, "update_edges")
undo_redo.add_do_method(self, "_call_update_edges", parent)
undo_redo.add_undo_method(self, "_call_update_edges", parent)
undo_redo.add_undo_method(self, "_add_next_rp_on_click_undo", pos, _sel, parent)

undo_redo.commit_action()


func _call_update_edges(container: RoadContainer) -> void:
container.update_edges()


func _add_next_rp_on_click_do(pos: Vector3, nrm: Vector3, selection: Node, parent: Node, handle_mag: float) -> void:

var next_rp = RoadPoint.new()
Expand Down Expand Up @@ -1481,19 +1486,18 @@ func _create_roadpoint_pressed() -> void:
var editor_selected:Array = _edi.get_selection().get_selected_nodes()
var rp := RoadPoint.new()
rp.name = "RP_001"
undo_redo.add_do_reference(rp)
undo_redo.add_do_method(selected_node, "add_child", rp, true)
undo_redo.add_do_method(rp, "set_owner", get_tree().get_edited_scene_root())
undo_redo.add_do_method(self, "set_selection", rp)
undo_redo.add_undo_method(selected_node, "remove_child", rp)
undo_redo.add_undo_method(rp, "set_owner", null)
undo_redo.add_undo_method(self, "set_selection_list", editor_selected)
undo_redo.add_do_method(t_container, "update_edges")
undo_redo.add_undo_method(t_container, "update_edges")
undo_redo.add_do_reference(rp)
else:
undo_redo.add_do_method(self, "_create_roadpoint_do", t_container)
undo_redo.add_undo_method(self, "_create_roadpoint_undo", t_container)
undo_redo.add_do_method(t_container, "update_edges")
undo_redo.add_undo_method(t_container, "update_edges")
undo_redo.add_do_method(self, "_call_update_edges", t_container)
undo_redo.add_undo_method(self, "_call_update_edges", t_container)
undo_redo.commit_action()


Expand Down