The current implementation
To achieve this goal, I tried using the undo_redo feature of the editor. So far, I have made the code to add the dialogue box as a sibling of the original node in the tree.
To that end, I produced the following three scripts...
The main plugin script:
@tool
extends EditorPlugin
func enter_tree():
add_custom_type("Dialogue", "MarginContainer", preload("res://addons/arta_vn/nodes/dialogue_template.gd"), preload("res://Assets/icon.svg"))
func exit_tree():
remove_custom_type("Dialogue")
The dialogue node that you can add to a scene:
@tool
class_name Dialogue
extends MarginContainer
const SceneTemplate = preload("res://addons/arta_vn/nodes/dialogue_scene.tscn")
# Replace self with scene instance
func _enter_tree():
NodeUtil.replace_with_scene(self, SceneTemplate)
And the actual replacement code, which for now just replaces the original Dialogue node with an instantiated scene for the purposes of testing: