@papercraftgames/estragon 0.1.0-beta.7 → 0.1.0-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/addons/estragon/editor/creation_menu.gd.txt +5 -3
- package/addons/estragon/editor/language_services.gd +2 -0
- package/addons/estragon/editor/new_script.gd +7 -12
- package/addons/estragon/editor/plugin.cfg +1 -1
- package/addons/estragon/editor/plugin.gd +28 -2
- package/addons/estragon/editor/scene_components.gd +265 -0
- package/addons/estragon/editor/scene_components.gd.uid +1 -0
- package/addons/estragon/editor/scene_inspector.gd +31 -0
- package/addons/estragon/editor/scene_inspector.gd.uid +1 -0
- package/package.json +1 -1
|
@@ -5,8 +5,10 @@ var create: Callable
|
|
|
5
5
|
var root_context := false
|
|
6
6
|
func _popup_menu(paths: PackedStringArray) -> void:
|
|
7
7
|
root_context = paths.is_empty()
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
var prefix := "New " if paths.is_empty() else ""
|
|
9
|
+
add_context_menu_item(prefix+"Gogo Component (2D)…",_selected.bind(false))
|
|
10
|
+
add_context_menu_item(prefix+"Gogo Component (3D)…",_selected.bind(true))
|
|
11
|
+
func _selected(paths: PackedStringArray, spatial: bool) -> void:
|
|
10
12
|
# The engine supplies a current directory to callbacks even when popup
|
|
11
13
|
# paths were empty. Empty-space creation deliberately starts at project root.
|
|
12
|
-
if create.is_valid(): create.call(paths[0] if not root_context and not paths.is_empty() else "res://")
|
|
14
|
+
if create.is_valid(): create.call(paths[0] if not root_context and not paths.is_empty() else "res://",spatial)
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
extends Node
|
|
3
3
|
## Owns only authenticated Gogo CodeEdit connections and a dedicated gutter.
|
|
4
4
|
signal diagnostics_changed(records, phase)
|
|
5
|
+
signal source_edited(path)
|
|
5
6
|
const Context = preload("lexical_context.gd")
|
|
6
7
|
const Acceptance = preload("completion_edit.gd")
|
|
7
8
|
const Catalog = preload("components.gd")
|
|
@@ -93,6 +94,7 @@ func _changed(id: int, request_completion: bool = true) -> void:
|
|
|
93
94
|
if not _active or not entries.has(id) or entries[id].mutating: return
|
|
94
95
|
var entry: Dictionary = entries[id]
|
|
95
96
|
entry.pending = true
|
|
97
|
+
source_edited.emit(entry.path)
|
|
96
98
|
entry.records = []
|
|
97
99
|
_mark(entry)
|
|
98
100
|
var code = entry.code.get_ref()
|
|
@@ -4,9 +4,6 @@ extends RefCounted
|
|
|
4
4
|
const Build = preload("build_service.gd")
|
|
5
5
|
const Source = preload("../compiler/source.gd")
|
|
6
6
|
const Element = preload("../runtime/composition/element.gd")
|
|
7
|
-
const Entry2D = preload("../runtime/node/estragon_2d.gd")
|
|
8
|
-
const Entry3D = preload("../runtime/node/estragon_3d.gd")
|
|
9
|
-
const Text = preload("../runtime/node/text.gd")
|
|
10
7
|
var dialog: Variant
|
|
11
8
|
var dimension: OptionButton
|
|
12
9
|
var error: AcceptDialog
|
|
@@ -31,30 +28,28 @@ func start(parent: Node) -> void:
|
|
|
31
28
|
dialog.add_filter("*","Gogo Component (.gogo)")
|
|
32
29
|
dimension = OptionButton.new()
|
|
33
30
|
dimension.name = "GogoTemplate"
|
|
34
|
-
dimension.add_item("Node2D —
|
|
35
|
-
dimension.add_item("Node3D —
|
|
31
|
+
dimension.add_item("Node2D — blank component")
|
|
32
|
+
dimension.add_item("Node3D — blank component")
|
|
36
33
|
dialog.get_vbox().add_child(dimension)
|
|
37
34
|
dialog.file_selected.connect(_selected)
|
|
38
35
|
parent.add_child(dialog)
|
|
39
36
|
error = AcceptDialog.new()
|
|
40
37
|
error.title = "New Gogo Component"
|
|
41
38
|
parent.add_child(error)
|
|
42
|
-
func show_dialog(context_directory: String = "") -> void:
|
|
39
|
+
func show_dialog(context_directory: String = "", spatial: bool = false) -> void:
|
|
43
40
|
if not active: return
|
|
44
41
|
var directory := context_directory if not context_directory.is_empty() else interface.get_current_directory()
|
|
45
42
|
if not directory.begins_with("res://") or not DirAccess.dir_exists_absolute(directory): directory = "res://"
|
|
46
43
|
dialog.current_dir = directory
|
|
47
44
|
dialog.current_file = "NewComponent.gogo"
|
|
45
|
+
dimension.select(1 if spatial else 0)
|
|
48
46
|
dialog.popup_centered_ratio(0.65)
|
|
49
47
|
static func template(path: String, spatial: bool) -> String:
|
|
48
|
+
var kind := "Node3D" if spatial else "Node2D"
|
|
50
49
|
var directory := Build.output_for(path).get_base_dir()
|
|
51
50
|
var element := JSON.stringify(Source.relative_path(directory,(Element as Script).resource_path))
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if spatial:
|
|
55
|
-
return result+"\nfunc build_view() -> Element:\n\treturn <Entry name=\"Layout\" width={4.0} height={2.0} depth={1.0} />\n"
|
|
56
|
-
var text := JSON.stringify(Source.relative_path(directory,(Text as Script).resource_path))
|
|
57
|
-
return result+"const Text = preload("+text+")\n\nfunc build_view() -> Element:\n\treturn <Entry name=\"UI\" viewport_width_scale={0.9}>\n\t\t<Text name=\"Greeting\" text=\"Hello Gogo\" />\n\t</Entry>\n"
|
|
51
|
+
# Ordinary native grouping node: no drawing, layout scope or configuration.
|
|
52
|
+
return "extends "+kind+"\nconst Element = preload("+element+")\n\nfunc build_view() -> Element:\n\treturn <"+kind+" />\n"
|
|
58
53
|
func _selected(path: String) -> void:
|
|
59
54
|
if not active: return
|
|
60
55
|
if path.get_extension().is_empty(): path += ".gogo"
|
|
@@ -9,6 +9,8 @@ const Highlighter = preload("highlighter.gd")
|
|
|
9
9
|
const Services = preload("language_services.gd")
|
|
10
10
|
const Navigation = preload("navigation.gd")
|
|
11
11
|
const NewScript = preload("new_script.gd")
|
|
12
|
+
const SceneComponents = preload("scene_components.gd")
|
|
13
|
+
var _scene_components: RefCounted
|
|
12
14
|
var _services: Node
|
|
13
15
|
var _navigation: RefCounted
|
|
14
16
|
var _new_script: RefCounted
|
|
@@ -55,7 +57,13 @@ func _enter_tree() -> void:
|
|
|
55
57
|
_highlighter_association.start(_interface)
|
|
56
58
|
_new_script = NewScript.new(_interface,_navigation)
|
|
57
59
|
_new_script.start(self)
|
|
58
|
-
|
|
60
|
+
_scene_components = SceneComponents.new(self,_navigation)
|
|
61
|
+
_scene_components.start()
|
|
62
|
+
_services.source_edited.connect(_scene_components.suspend_source)
|
|
63
|
+
add_tool_menu_item("Attach/Change Gogo Component…",_scene_components.attach_selected)
|
|
64
|
+
add_tool_menu_item("Add Gogo Component…",_scene_components.add_selected)
|
|
65
|
+
add_tool_menu_item("New Gogo Component (2D)…",_new_script.show_dialog.bind("",false))
|
|
66
|
+
add_tool_menu_item("New Gogo Component (3D)…",_new_script.show_dialog.bind("",true))
|
|
59
67
|
# Never parse a script extending a newer native class on Godot 4.0.
|
|
60
68
|
if has_method("add_context_menu_plugin") and has_method("remove_context_menu_plugin") and ClassDB.class_exists("EditorContextMenuPlugin") and "CONTEXT_SLOT_FILESYSTEM_CREATE" in ClassDB.class_get_integer_constant_list("EditorContextMenuPlugin"):
|
|
61
69
|
var adapter := GDScript.new()
|
|
@@ -189,6 +197,15 @@ func _compile_saved() -> void:
|
|
|
189
197
|
|
|
190
198
|
|
|
191
199
|
func _build() -> bool:
|
|
200
|
+
if not _build_sources(): return false
|
|
201
|
+
var problem: String = _scene_components.validate_scenes()
|
|
202
|
+
if problem.is_empty(): return true
|
|
203
|
+
last_report.ok = false
|
|
204
|
+
last_report.diagnostics.append(problem)
|
|
205
|
+
_show_report()
|
|
206
|
+
return false
|
|
207
|
+
|
|
208
|
+
func _build_sources() -> bool:
|
|
192
209
|
if not _active or _building:
|
|
193
210
|
return false
|
|
194
211
|
_timer.stop()
|
|
@@ -197,6 +214,7 @@ func _build() -> bool:
|
|
|
197
214
|
_play_save_failed = not saved.ok
|
|
198
215
|
if not saved.ok:
|
|
199
216
|
last_report = {"ok": false, "changed": [], "outputs": [], "diagnostics": saved.diagnostics}
|
|
217
|
+
_scene_components.refresh(last_report)
|
|
200
218
|
_show_report()
|
|
201
219
|
return false
|
|
202
220
|
return _compile()
|
|
@@ -207,8 +225,12 @@ func _compile() -> bool:
|
|
|
207
225
|
_building = true
|
|
208
226
|
build_count += 1
|
|
209
227
|
last_report = BuildService.run_build()
|
|
228
|
+
_scene_components.refresh(last_report)
|
|
210
229
|
_show_report()
|
|
211
230
|
if last_report.ok: _refresh_generated_editors()
|
|
231
|
+
for entry in _services.entries.values():
|
|
232
|
+
var code = entry.code.get_ref()
|
|
233
|
+
if code != null and code.get_version() != code.get_saved_version(): _scene_components.suspend_source(entry.path)
|
|
212
234
|
# Refresh paths without reimporting authored source. The child game's fresh
|
|
213
235
|
# process reads these exact bytes; editor resources are synchronized as well.
|
|
214
236
|
var filesystem := _interface.get_resource_filesystem()
|
|
@@ -244,7 +266,11 @@ func _show_report() -> void:
|
|
|
244
266
|
|
|
245
267
|
func _exit_tree() -> void:
|
|
246
268
|
_active = false
|
|
247
|
-
remove_tool_menu_item("
|
|
269
|
+
remove_tool_menu_item("Attach/Change Gogo Component…")
|
|
270
|
+
remove_tool_menu_item("Add Gogo Component…")
|
|
271
|
+
if _scene_components != null: _scene_components.stop(); _scene_components = null
|
|
272
|
+
remove_tool_menu_item("New Gogo Component (2D)…")
|
|
273
|
+
remove_tool_menu_item("New Gogo Component (3D)…")
|
|
248
274
|
if _creation_menu != null:
|
|
249
275
|
call("remove_context_menu_plugin",_creation_menu)
|
|
250
276
|
_creation_menu.create = Callable()
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends RefCounted
|
|
3
|
+
## Editor-only registry/transactions. Native Script references + compiler maps
|
|
4
|
+
## provide the durable authored association; no fields/meta on user Nodes.
|
|
5
|
+
const Build = preload("build_service.gd")
|
|
6
|
+
const Inspector = preload("scene_inspector.gd")
|
|
7
|
+
var plugin: EditorPlugin
|
|
8
|
+
var interface: EditorInterface
|
|
9
|
+
var navigation: RefCounted
|
|
10
|
+
var active := true
|
|
11
|
+
var items: Dictionary = {}
|
|
12
|
+
var registered: Dictionary = {}
|
|
13
|
+
var controls: Array[WeakRef] = []
|
|
14
|
+
var inspector: EditorInspectorPlugin
|
|
15
|
+
var picker: ConfirmationDialog
|
|
16
|
+
var list: ItemList
|
|
17
|
+
var message: Label
|
|
18
|
+
var error: AcceptDialog
|
|
19
|
+
var replace: ConfirmationDialog
|
|
20
|
+
var target: WeakRef
|
|
21
|
+
var scene: WeakRef
|
|
22
|
+
var previous: Script
|
|
23
|
+
var mode := "attach"
|
|
24
|
+
var pending := ""
|
|
25
|
+
func _init(owner: EditorPlugin, navigator: RefCounted) -> void:
|
|
26
|
+
plugin = owner
|
|
27
|
+
interface = owner.get_editor_interface()
|
|
28
|
+
navigation = navigator
|
|
29
|
+
func start() -> void:
|
|
30
|
+
inspector = Inspector.new()
|
|
31
|
+
inspector.service = weakref(self)
|
|
32
|
+
plugin.add_inspector_plugin(inspector)
|
|
33
|
+
picker = ConfirmationDialog.new()
|
|
34
|
+
picker.name = "GogoScenePicker"
|
|
35
|
+
picker.title = "Choose Gogo Component"
|
|
36
|
+
picker.min_size = Vector2i(640,360)
|
|
37
|
+
var box := VBoxContainer.new()
|
|
38
|
+
picker.add_child(box)
|
|
39
|
+
message = Label.new()
|
|
40
|
+
message.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
|
41
|
+
box.add_child(message)
|
|
42
|
+
list = ItemList.new()
|
|
43
|
+
list.custom_minimum_size = Vector2(620,240)
|
|
44
|
+
list.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
|
45
|
+
box.add_child(list)
|
|
46
|
+
list.item_selected.connect(func(_index): picker.get_ok_button().disabled = false)
|
|
47
|
+
list.item_activated.connect(func(_index): _accepted())
|
|
48
|
+
picker.confirmed.connect(_accepted)
|
|
49
|
+
plugin.add_child(picker)
|
|
50
|
+
error = AcceptDialog.new()
|
|
51
|
+
error.title = "Gogo Component"
|
|
52
|
+
plugin.add_child(error)
|
|
53
|
+
replace = ConfirmationDialog.new()
|
|
54
|
+
replace.title = "Replace attached script?"
|
|
55
|
+
replace.confirmed.connect(_replace_confirmed)
|
|
56
|
+
plugin.add_child(replace)
|
|
57
|
+
static func _res(path: String) -> String:
|
|
58
|
+
return path if path.begins_with("res://") else "res://"+path
|
|
59
|
+
static func source_for(script: Script) -> String:
|
|
60
|
+
if script == null or script.resource_path.is_empty(): return ""
|
|
61
|
+
var path := script.resource_path
|
|
62
|
+
if not FileAccess.file_exists(path+".map.json"): return ""
|
|
63
|
+
var map = JSON.parse_string(FileAccess.get_file_as_string(path+".map.json"))
|
|
64
|
+
if not map is Dictionary or map.get("format") != "estragon.gogo.source-map" or map.get("version") != 1 or not map.get("sourceName") is String: return ""
|
|
65
|
+
var source := _res(map.sourceName)
|
|
66
|
+
return source if Build.output_for(source) == path else ""
|
|
67
|
+
static func eligible(script: Script) -> bool:
|
|
68
|
+
if not script is GDScript: return false
|
|
69
|
+
var base := script.get_instance_base_type()
|
|
70
|
+
if not ClassDB.class_exists(base) or not ClassDB.is_parent_class(base,"Node") or not ClassDB.can_instantiate(base): return false
|
|
71
|
+
# Non-tool can_instantiate() is false in editor even for valid scene scripts.
|
|
72
|
+
if script.has_method("is_abstract") and script.call("is_abstract"): return false
|
|
73
|
+
# Public method metadata lists the derived class before its bases. Only
|
|
74
|
+
# the effective constructor's arguments are required from a new caller;
|
|
75
|
+
# a zero-argument override can supply its base's required arguments.
|
|
76
|
+
for method in script.get_script_method_list():
|
|
77
|
+
if method.name == "_init": return method.args.size() <= method.default_args.size()
|
|
78
|
+
return true
|
|
79
|
+
func refresh(report: Dictionary) -> void:
|
|
80
|
+
if not active: return
|
|
81
|
+
var next := {}
|
|
82
|
+
var counts := {}
|
|
83
|
+
if report.get("ok",false):
|
|
84
|
+
for output in report.get("outputs",[]):
|
|
85
|
+
var path := _res(str(output))
|
|
86
|
+
var script: Script = load(path)
|
|
87
|
+
var source := source_for(script)
|
|
88
|
+
if source.is_empty() or not FileAccess.file_exists(source) or not eligible(script): continue
|
|
89
|
+
var name := source.get_file().get_basename()
|
|
90
|
+
counts[name] = int(counts.get(name,0))+1
|
|
91
|
+
next[source] = {"source":source,"output":path,"script":script,"base":script.get_instance_base_type(),"name":name}
|
|
92
|
+
for source in next:
|
|
93
|
+
var item: Dictionary = next[source]
|
|
94
|
+
item.label = item.name+(" ["+source.get_base_dir().trim_prefix("res://")+"]" if counts[item.name] > 1 else "")+" (Gogo Component)"
|
|
95
|
+
item.fingerprint = item.label+"|"+item.base+"|"+item.output+"|"+str(item.script.get_instance_id())
|
|
96
|
+
for source in registered.keys():
|
|
97
|
+
if next.has(source) and registered[source].fingerprint == next[source].fingerprint: continue
|
|
98
|
+
plugin.remove_custom_type(registered[source].label)
|
|
99
|
+
registered.erase(source)
|
|
100
|
+
for source in next:
|
|
101
|
+
if registered.has(source): continue
|
|
102
|
+
var item: Dictionary = next[source]
|
|
103
|
+
var icon := interface.get_base_control().get_theme_icon(item.base,"EditorIcons") if interface.get_base_control().has_theme_icon(item.base,"EditorIcons") else null
|
|
104
|
+
plugin.add_custom_type(item.label,item.base,item.script,icon)
|
|
105
|
+
registered[source] = item
|
|
106
|
+
items = next
|
|
107
|
+
func suspend_source(source: String) -> void:
|
|
108
|
+
# Never offer last-built code as a new native component while its authored
|
|
109
|
+
# buffer is changing. Re-registration requires the existing saved build.
|
|
110
|
+
if not active or not registered.has(source): return
|
|
111
|
+
plugin.remove_custom_type(registered[source].label)
|
|
112
|
+
registered.erase(source)
|
|
113
|
+
func editable(node: Node) -> bool:
|
|
114
|
+
if not active or not is_instance_valid(node): return false
|
|
115
|
+
var root := interface.get_edited_scene_root()
|
|
116
|
+
return root != null and (node == root or root.is_ancestor_of(node) and node.owner == root)
|
|
117
|
+
func _selected() -> WeakRef:
|
|
118
|
+
var selected := interface.get_selection().get_selected_nodes()
|
|
119
|
+
return weakref(selected[0]) if selected.size() == 1 else null
|
|
120
|
+
func attach_selected() -> void: choose("attach",_selected())
|
|
121
|
+
func add_selected() -> void: choose("add",_selected())
|
|
122
|
+
func choose(action: String, selected: WeakRef) -> void:
|
|
123
|
+
if not active: return
|
|
124
|
+
var node = selected.get_ref() if selected != null else null
|
|
125
|
+
if node == null or not editable(node): _fail("Select one local scene Node first."); return
|
|
126
|
+
if not plugin._build_sources(): _fail("Fix the Gogo build diagnostics before choosing a component."); return
|
|
127
|
+
target = selected
|
|
128
|
+
scene = weakref(interface.get_edited_scene_root())
|
|
129
|
+
previous = node.get_script()
|
|
130
|
+
mode = action
|
|
131
|
+
list.clear()
|
|
132
|
+
var sources := items.keys()
|
|
133
|
+
sources.sort()
|
|
134
|
+
for source in sources:
|
|
135
|
+
var item: Dictionary = items[source]
|
|
136
|
+
list.add_item(item.label+" — "+item.base+" — "+source)
|
|
137
|
+
list.set_item_metadata(list.item_count-1,source)
|
|
138
|
+
list.set_item_tooltip(list.item_count-1,source)
|
|
139
|
+
message.text = "Attach to "+str(node.name) if mode == "attach" else "Add a native child beneath "+str(node.name)
|
|
140
|
+
if sources.is_empty(): message.text += "\nNo eligible Node components. Create/fix a Gogo component in the configured source roots."
|
|
141
|
+
picker.get_ok_button().disabled = true
|
|
142
|
+
picker.popup_centered()
|
|
143
|
+
func _accepted() -> void:
|
|
144
|
+
if not active or list.get_selected_items().is_empty(): return
|
|
145
|
+
pending = str(list.get_item_metadata(list.get_selected_items()[0]))
|
|
146
|
+
picker.hide()
|
|
147
|
+
_prepare.call_deferred()
|
|
148
|
+
func _valid_target() -> Node:
|
|
149
|
+
var node = target.get_ref() if target != null else null
|
|
150
|
+
var root = scene.get_ref() if scene != null else null
|
|
151
|
+
if node == null or root != interface.get_edited_scene_root() or not editable(node): return null
|
|
152
|
+
if node.get_script() != previous: return null
|
|
153
|
+
return node
|
|
154
|
+
func _prepare() -> void:
|
|
155
|
+
if not active: return
|
|
156
|
+
var node := _valid_target()
|
|
157
|
+
if node == null: _fail("The scene, node or attached script changed. Choose the component again."); return
|
|
158
|
+
if not plugin._build_sources() or not items.has(pending): _fail("Component is missing, invalid or outside the configured source roots. Repair/reselect it."); return
|
|
159
|
+
var item: Dictionary = items[pending]
|
|
160
|
+
if mode == "attach" and not ClassDB.is_parent_class(node.get_class(),item.base): _fail("This component requires "+item.base+"; selected node is "+node.get_class()+"."); return
|
|
161
|
+
if mode == "attach" and previous == item.script: return
|
|
162
|
+
if mode == "attach" and previous != null:
|
|
163
|
+
replace.dialog_text = "Replace "+(source_for(previous) if not source_for(previous).is_empty() else previous.resource_path)+" with "+pending+"? Undo restores the previous script and stored properties."
|
|
164
|
+
replace.popup_centered()
|
|
165
|
+
else: _commit()
|
|
166
|
+
func _replace_confirmed() -> void:
|
|
167
|
+
replace.hide()
|
|
168
|
+
_commit.call_deferred()
|
|
169
|
+
func _commit() -> void:
|
|
170
|
+
if not active: return
|
|
171
|
+
var node := _valid_target()
|
|
172
|
+
if node == null or not plugin._build_sources() or not items.has(pending): _fail("Scene/component changed; repair and choose again."); return
|
|
173
|
+
var item: Dictionary = items[pending]
|
|
174
|
+
var root := interface.get_edited_scene_root()
|
|
175
|
+
var undo := plugin.get_undo_redo()
|
|
176
|
+
if mode == "attach":
|
|
177
|
+
if not ClassDB.is_parent_class(node.get_class(),item.base): _fail("Component host type changed; choose a compatible node."); return
|
|
178
|
+
var values := {}
|
|
179
|
+
if previous != null:
|
|
180
|
+
# Placeholder/editor property lists do not consistently carry the
|
|
181
|
+
# SCRIPT_VARIABLE bit. Script metadata identifies owned stored fields.
|
|
182
|
+
for prop in previous.get_script_property_list():
|
|
183
|
+
if prop.name != "script" and int(prop.usage) & PROPERTY_USAGE_STORAGE: values[prop.name] = node.get(prop.name)
|
|
184
|
+
undo.create_action("Attach Gogo Component",UndoRedo.MERGE_DISABLE,root)
|
|
185
|
+
undo.add_do_method(node,"set_script",item.script)
|
|
186
|
+
undo.add_undo_method(node,"set_script",previous)
|
|
187
|
+
for name in values: undo.add_undo_property(node,name,values[name])
|
|
188
|
+
undo.add_do_method(node,"notify_property_list_changed")
|
|
189
|
+
undo.add_undo_method(node,"notify_property_list_changed")
|
|
190
|
+
else:
|
|
191
|
+
var child: Node = ClassDB.instantiate(item.base)
|
|
192
|
+
child.name = str(item.name).validate_node_name()
|
|
193
|
+
child.set_script(item.script)
|
|
194
|
+
undo.create_action("Add Gogo Component",UndoRedo.MERGE_DISABLE,root)
|
|
195
|
+
undo.add_do_method(node,"add_child",child,true)
|
|
196
|
+
undo.add_do_property(child,"owner",root)
|
|
197
|
+
undo.add_undo_method(node,"remove_child",child)
|
|
198
|
+
undo.add_do_reference(child)
|
|
199
|
+
undo.commit_action()
|
|
200
|
+
func open_source(source: String) -> void:
|
|
201
|
+
if not active: return
|
|
202
|
+
if not FileAccess.file_exists(source): _fail("Gogo source is missing: "+source+". Restore it or attach a replacement."); return
|
|
203
|
+
navigation.open(source)
|
|
204
|
+
func _fail(text: String) -> void:
|
|
205
|
+
if not active: return
|
|
206
|
+
error.dialog_text = text
|
|
207
|
+
error.popup_centered()
|
|
208
|
+
func _script_error(script: Script) -> String:
|
|
209
|
+
var source := source_for(script)
|
|
210
|
+
if source.is_empty(): return ""
|
|
211
|
+
if not items.has(source): return "Attached Gogo component is missing, invalid or excluded: "+source+". Restore/recompile or reattach it before Play."
|
|
212
|
+
return ""
|
|
213
|
+
func validate_scenes() -> String:
|
|
214
|
+
var root := interface.get_edited_scene_root()
|
|
215
|
+
if root != null:
|
|
216
|
+
var problem := _validate_node(root)
|
|
217
|
+
if not problem.is_empty(): return problem
|
|
218
|
+
var paths := Array(interface.get_open_scenes())
|
|
219
|
+
var main := str(ProjectSettings.get_setting("application/run/main_scene",""))
|
|
220
|
+
if not main.is_empty(): paths.append(main)
|
|
221
|
+
var visited := {}
|
|
222
|
+
for path in paths:
|
|
223
|
+
if root != null and path == root.scene_file_path: continue
|
|
224
|
+
var problem := _validate_saved(str(path),visited)
|
|
225
|
+
if not problem.is_empty(): return problem
|
|
226
|
+
return ""
|
|
227
|
+
func _validate_node(node: Node) -> String:
|
|
228
|
+
var problem := _script_error(node.get_script())
|
|
229
|
+
if not problem.is_empty(): return problem
|
|
230
|
+
for child in node.get_children():
|
|
231
|
+
problem = _validate_node(child)
|
|
232
|
+
if not problem.is_empty(): return problem
|
|
233
|
+
return ""
|
|
234
|
+
func _validate_saved(path: String, visited: Dictionary) -> String:
|
|
235
|
+
if path.is_empty() or visited.has(path): return ""
|
|
236
|
+
visited[path] = true
|
|
237
|
+
if not ResourceLoader.exists(path,"PackedScene"): return "Cannot validate scene before Play: "+path
|
|
238
|
+
var packed: PackedScene = load(path)
|
|
239
|
+
if packed == null: return "Cannot load scene before Play: "+path
|
|
240
|
+
var state := packed.get_state()
|
|
241
|
+
for index in range(state.get_node_count()):
|
|
242
|
+
for prop in range(state.get_node_property_count(index)):
|
|
243
|
+
if state.get_node_property_name(index,prop) == "script":
|
|
244
|
+
var problem := _script_error(state.get_node_property_value(index,prop))
|
|
245
|
+
if not problem.is_empty(): return problem
|
|
246
|
+
# Native dependency data includes inherited/instanced scenes on 4.0 too.
|
|
247
|
+
for dependency in ResourceLoader.get_dependencies(path):
|
|
248
|
+
for part in str(dependency).split("::"):
|
|
249
|
+
if part.begins_with("res://") and part.get_extension() in ["tscn","scn"]:
|
|
250
|
+
var problem := _validate_saved(part,visited)
|
|
251
|
+
if not problem.is_empty(): return problem
|
|
252
|
+
return ""
|
|
253
|
+
func stop() -> void:
|
|
254
|
+
active = false
|
|
255
|
+
for item in registered.values(): plugin.remove_custom_type(item.label)
|
|
256
|
+
registered.clear()
|
|
257
|
+
items.clear()
|
|
258
|
+
plugin.remove_inspector_plugin(inspector)
|
|
259
|
+
inspector.service = null
|
|
260
|
+
inspector = null
|
|
261
|
+
for reference in controls:
|
|
262
|
+
var control = reference.get_ref()
|
|
263
|
+
if control != null: control.free()
|
|
264
|
+
controls.clear()
|
|
265
|
+
for dialog in [picker,error,replace]: dialog.free()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://cccu2jpv66ms
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends EditorInspectorPlugin
|
|
3
|
+
## Authored-source presentation alongside the untouched native Script property.
|
|
4
|
+
var service: WeakRef
|
|
5
|
+
func _can_handle(object: Object) -> bool:
|
|
6
|
+
var owner = service.get_ref() if service != null else null
|
|
7
|
+
return owner != null and owner.active and object is Node and owner.editable(object)
|
|
8
|
+
func _parse_begin(object: Object) -> void:
|
|
9
|
+
var owner = service.get_ref() if service != null else null
|
|
10
|
+
if owner == null: return
|
|
11
|
+
var panel := VBoxContainer.new()
|
|
12
|
+
panel.name = "GogoSceneComponent"
|
|
13
|
+
var label := Label.new()
|
|
14
|
+
var source: String = owner.source_for(object.get_script())
|
|
15
|
+
label.text = "Gogo Component" if source.is_empty() else "Gogo source: "+source
|
|
16
|
+
label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
|
17
|
+
panel.add_child(label)
|
|
18
|
+
if not source.is_empty():
|
|
19
|
+
var open := Button.new()
|
|
20
|
+
open.text = "Open Gogo Source"
|
|
21
|
+
# Navigation/build can rebuild the Inspector and free this sender.
|
|
22
|
+
open.pressed.connect(owner.open_source.bind(source),CONNECT_DEFERRED)
|
|
23
|
+
panel.add_child(open)
|
|
24
|
+
for mode in ["attach","add"]:
|
|
25
|
+
var button := Button.new()
|
|
26
|
+
button.text = "Attach/Change Gogo Component…" if mode == "attach" else "Add Gogo Child…"
|
|
27
|
+
button.pressed.connect(owner.choose.bind(mode,weakref(object)),CONNECT_DEFERRED)
|
|
28
|
+
panel.add_child(button)
|
|
29
|
+
owner.controls = owner.controls.filter(func(reference): return reference.get_ref() != null)
|
|
30
|
+
owner.controls.append(weakref(panel))
|
|
31
|
+
add_custom_control(panel)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://b6wswjs8u4p1o
|
package/package.json
CHANGED