forked from MrBSmith/StateGraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStateGraph.gd
More file actions
81 lines (45 loc) · 1.73 KB
/
StateGraph.gd
File metadata and controls
81 lines (45 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
tool
extends EditorPlugin
class_name StateGraph
var fsm_editor_scene = preload("res://addons/StateGraph/GraphEditor/GraphEditor.tscn")
var edited_scene_path = ""
var fsm_editor : Node = null
var fsm_editor_button : ToolButton = null
#### ACCESSORS ####
func is_class(value: String): return value == "StateMachineHandler" or .is_class(value)
func get_class() -> String: return "StateMachineHandler"
#### BUILT-IN ####
func _ready() -> void:
var __ = connect("scene_changed", self, "_on_scene_changed")
__ = fsm_editor.connect("inspect_node_query", self, "_on_inspect_node_query")
__ = fsm_editor.connect("visibility_changed", self, "_on_fsm_editor_visibility_changed")
func _enter_tree() -> void:
fsm_editor = fsm_editor_scene.instance()
fsm_editor_button = add_control_to_bottom_panel(fsm_editor, "StateMachine")
func _exit_tree() -> void:
remove_control_from_bottom_panel(fsm_editor)
#### VIRTUALS ####
func handles(obj: Object) -> bool:
var handled = obj is StateMachine or (obj is State && obj.get_parent() is StateMachine)
fsm_editor_button.set_visible(obj is State)
if fsm_editor_button.pressed:
fsm_editor.set_visible(obj is State)
return handled
func edit(obj: Object) -> void:
var handled_fsm = obj if obj is StateMachine else obj.get_parent()
fsm_editor.feed(handled_fsm)
#### LOGIC ####
#### INPUTS ####
#### SIGNAL RESPONSES ####
func _on_scene_changed(scene_root: Node) -> void:
if scene_root == null:
edited_scene_path = ""
else:
edited_scene_path = scene_root.filename
func _on_inspect_node_query(node: Node) -> void:
var interface = get_editor_interface()
var selection = interface.get_selection()
selection.clear()
selection.add_node(node)
func _on_fsm_editor_visibility_changed() -> void:
pass