@papercraftgames/estragon 0.1.0-beta.2 → 0.1.0-beta.21

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.
Files changed (95) hide show
  1. package/CHANGELOG.md +7 -3
  2. package/README.md +11 -8
  3. package/addons/estragon/compiler/bindable.gd +3 -3
  4. package/addons/estragon/compiler/compiler.gd +8 -8
  5. package/addons/estragon/compiler/composition.gd +5 -4
  6. package/addons/estragon/compiler/emitter.gd +34 -8
  7. package/addons/estragon/compiler/frontend.gd +8 -8
  8. package/addons/estragon/compiler/lexer.gd +2 -2
  9. package/addons/estragon/compiler/model.gd +2 -0
  10. package/addons/estragon/compiler/native/resolver.gd +125 -29
  11. package/addons/estragon/compiler/parser.gd +3 -3
  12. package/addons/estragon/compiler/project_sources.gd +91 -0
  13. package/addons/estragon/compiler/project_sources.gd.uid +1 -0
  14. package/addons/estragon/compiler/script_validation.gd +3 -3
  15. package/addons/estragon/compiler/source.gd +19 -2
  16. package/addons/estragon/compiler/source_map.gd +3 -3
  17. package/addons/estragon/compiler/validator.gd +74 -10
  18. package/addons/estragon/editor/build_service.gd +91 -72
  19. package/addons/estragon/editor/color_property.gd +37 -0
  20. package/addons/estragon/editor/color_property.gd.uid +1 -0
  21. package/addons/estragon/editor/completion.gd +531 -0
  22. package/addons/estragon/editor/completion.gd.uid +1 -0
  23. package/addons/estragon/editor/completion_edit.gd +7 -0
  24. package/addons/estragon/editor/completion_edit.gd.uid +1 -0
  25. package/addons/estragon/editor/components.gd +20 -0
  26. package/addons/estragon/editor/components.gd.uid +1 -0
  27. package/addons/estragon/editor/creation_menu.gd.txt +14 -0
  28. package/addons/estragon/editor/generated_editors.gd +256 -0
  29. package/addons/estragon/editor/generated_editors.gd.uid +1 -0
  30. package/addons/estragon/editor/highlighter.gd +62 -103
  31. package/addons/estragon/editor/highlighter_association.gd +11 -2
  32. package/addons/estragon/editor/imports.gd +47 -0
  33. package/addons/estragon/editor/imports.gd.uid +1 -0
  34. package/addons/estragon/editor/language_services.gd +288 -0
  35. package/addons/estragon/editor/language_services.gd.uid +1 -0
  36. package/addons/estragon/editor/length_property.gd +22 -0
  37. package/addons/estragon/editor/length_property.gd.uid +1 -0
  38. package/addons/estragon/editor/lexical_context.gd +159 -0
  39. package/addons/estragon/editor/lexical_context.gd.uid +1 -0
  40. package/addons/estragon/editor/navigation.gd +30 -0
  41. package/addons/estragon/editor/navigation.gd.uid +1 -0
  42. package/addons/estragon/editor/new_script.gd +77 -0
  43. package/addons/estragon/editor/new_script.gd.uid +1 -0
  44. package/addons/estragon/editor/plugin.cfg +1 -1
  45. package/addons/estragon/editor/plugin.gd +113 -40
  46. package/addons/estragon/editor/scene_components.gd +267 -0
  47. package/addons/estragon/editor/scene_components.gd.uid +1 -0
  48. package/addons/estragon/editor/scene_inspector.gd +42 -0
  49. package/addons/estragon/editor/scene_inspector.gd.uid +1 -0
  50. package/addons/estragon/editor/script_dependencies.gd +5 -3
  51. package/addons/estragon/runtime/composition/binding.gd +1 -1
  52. package/addons/estragon/runtime/composition/computation.gd +141 -9
  53. package/addons/estragon/runtime/composition/element.gd +3 -1
  54. package/addons/estragon/runtime/composition/layout_host.gd +58 -0
  55. package/addons/estragon/runtime/composition/layout_host.gd.uid +1 -0
  56. package/addons/estragon/runtime/composition/profile.tres +1 -1
  57. package/addons/estragon/runtime/composition/projection.gd +32 -0
  58. package/addons/estragon/runtime/composition/projection.gd.uid +1 -0
  59. package/addons/estragon/runtime/composition/state.gd +13 -2
  60. package/addons/estragon/runtime/composition/state.tres +1 -1
  61. package/addons/estragon/runtime/node/box.gd +57 -0
  62. package/addons/estragon/runtime/node/box.gd.uid +1 -0
  63. package/addons/estragon/runtime/node/button.gd +44 -15
  64. package/addons/estragon/runtime/node/component_2d.gd +167 -24
  65. package/addons/estragon/runtime/node/component_3d.gd +54 -18
  66. package/addons/estragon/runtime/node/estragon_2d.gd +2 -11
  67. package/addons/estragon/runtime/node/estragon_3d.gd +1 -10
  68. package/addons/estragon/runtime/node/hbox.gd +4 -1
  69. package/addons/estragon/runtime/node/internal/component_2d_icon.tres +4 -0
  70. package/addons/estragon/runtime/node/internal/composition_hosts.gd +159 -0
  71. package/addons/estragon/runtime/node/internal/composition_hosts.gd.uid +1 -0
  72. package/addons/estragon/runtime/node/internal/composition_hosts.tres +6 -0
  73. package/addons/estragon/runtime/node/internal/control_participant.gd +164 -0
  74. package/addons/estragon/runtime/node/internal/control_participant.gd.uid +1 -0
  75. package/addons/estragon/runtime/node/internal/coordinator.gd +79 -27
  76. package/addons/estragon/runtime/node/internal/grid_definition.gd +75 -0
  77. package/addons/estragon/runtime/node/internal/grid_definition.gd.uid +1 -0
  78. package/addons/estragon/runtime/node/internal/layout_core.gd +205 -22
  79. package/addons/estragon/runtime/node/internal/length.gd +94 -0
  80. package/addons/estragon/runtime/node/internal/length.gd.uid +1 -0
  81. package/addons/estragon/runtime/node/internal/stack_contract.gd +21 -0
  82. package/addons/estragon/runtime/node/internal/stack_contract.gd.uid +1 -0
  83. package/addons/estragon/runtime/node/internal/stack_policy.gd +59 -0
  84. package/addons/estragon/runtime/node/internal/stack_policy.gd.uid +1 -0
  85. package/addons/estragon/runtime/node/internal/visual_style_2d.gd +75 -0
  86. package/addons/estragon/runtime/node/internal/visual_style_2d.gd.uid +1 -0
  87. package/addons/estragon/runtime/node/native_2d.gd +5 -5
  88. package/addons/estragon/runtime/node/native_3d.gd +5 -5
  89. package/addons/estragon/runtime/node/rect.gd +13 -13
  90. package/addons/estragon/runtime/node/spacer.gd +4 -0
  91. package/addons/estragon/runtime/node/spacer.gd.uid +1 -0
  92. package/addons/estragon/runtime/node/text.gd +5 -3
  93. package/addons/estragon/runtime/node/toggle.gd +18 -5
  94. package/addons/estragon/runtime/node/vbox.gd +4 -1
  95. package/package.json +1 -1
@@ -2,10 +2,19 @@
2
2
  extends EditorPlugin
3
3
  ## Native ScriptEditor authoring and direct Godot compilation before every Play.
4
4
 
5
- const BufferGuard = preload("res://addons/estragon/editor/buffer_guard.gd")
6
- const BuildService = preload("res://addons/estragon/editor/build_service.gd")
7
- const HighlighterAssociation = preload("res://addons/estragon/editor/highlighter_association.gd")
8
- const Highlighter = preload("res://addons/estragon/editor/highlighter.gd")
5
+ const BufferGuard = preload("buffer_guard.gd")
6
+ const BuildService = preload("build_service.gd")
7
+ const HighlighterAssociation = preload("highlighter_association.gd")
8
+ const Highlighter = preload("highlighter.gd")
9
+ const Services = preload("language_services.gd")
10
+ const Navigation = preload("navigation.gd")
11
+ const NewScript = preload("new_script.gd")
12
+ const SceneComponents = preload("scene_components.gd")
13
+ var _scene_components: RefCounted
14
+ var _services: Node
15
+ var _navigation: RefCounted
16
+ var _new_script: RefCounted
17
+ var _creation_menu: RefCounted
9
18
  const TEXT_EXTENSIONS_SETTING := "docks/filesystem/textfile_extensions"
10
19
 
11
20
  var _highlighter: EditorSyntaxHighlighter
@@ -18,7 +27,8 @@ var _active: bool = false
18
27
  var _extensions_pending: bool = true
19
28
  var _rescan_pending: bool = false
20
29
  var _play_save_failed: bool = false
21
- var _generated_editors: Dictionary = {}
30
+ const GeneratedEditors = preload("generated_editors.gd")
31
+ var _generated_editors: RefCounted
22
32
  var last_report: Dictionary = {}
23
33
  var build_count: int = 0
24
34
 
@@ -37,10 +47,35 @@ func _enter_tree() -> void:
37
47
  registered = true
38
48
  if not registered:
39
49
  settings.set_setting(TEXT_EXTENSIONS_SETTING, existing + ("," if not existing.is_empty() else "") + "gogo")
40
- _highlighter = Highlighter.new()
50
+ _highlighter = Highlighter.new(settings)
41
51
  _interface.get_script_editor().register_syntax_highlighter(_highlighter)
42
52
  _highlighter_association = HighlighterAssociation.new()
53
+ _navigation = Navigation.new(_interface)
54
+ _generated_editors = GeneratedEditors.new(self,_navigation,_highlighter_association)
55
+ _highlighter_association.associated.connect(_generated_editors.attach)
56
+ _services = Services.new(_interface,_navigation)
57
+ add_child(_services)
58
+ _services.diagnostics_changed.connect(_typing_report)
59
+ _highlighter_association.associated.connect(_services.attach)
43
60
  _highlighter_association.start(_interface)
61
+ _new_script = NewScript.new(_interface,_navigation)
62
+ _new_script.start(self)
63
+ _scene_components = SceneComponents.new(self,_navigation)
64
+ _scene_components.start()
65
+ _services.source_edited.connect(_scene_components.suspend_source)
66
+ add_tool_menu_item("Attach/Change Gogo Component…",_scene_components.attach_selected)
67
+ add_tool_menu_item("Add Gogo Component…",_scene_components.add_selected)
68
+ add_tool_menu_item("New Gogo Component (2D)…",_new_script.show_dialog.bind("",false))
69
+ add_tool_menu_item("New Gogo Component (3D)…",_new_script.show_dialog.bind("",true))
70
+ # Never parse a script extending a newer native class on Godot 4.0.
71
+ 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"):
72
+ var adapter := GDScript.new()
73
+ adapter.source_code = FileAccess.get_file_as_string((get_script() as Script).resource_path.get_base_dir().path_join("creation_menu.gd.txt"))
74
+ if adapter.reload() == OK:
75
+ _creation_menu = adapter.new()
76
+ _creation_menu.create = _new_script.show_dialog
77
+ call("add_context_menu_plugin",3,_creation_menu) # CONTEXT_SLOT_FILESYSTEM_CREATE
78
+ add_tool_menu_item("Add Missing Gogo Imports",_services.add_missing_imports)
44
79
  _timer = Timer.new()
45
80
  _timer.one_shot = true
46
81
  _timer.wait_time = 0.4
@@ -50,9 +85,12 @@ func _enter_tree() -> void:
50
85
  _diagnostics.name = "EstragonDiagnostics"
51
86
  _diagnostics.custom_minimum_size = Vector2(0, 120)
52
87
  _diagnostics.selection_enabled = true
88
+ _diagnostics.bbcode_enabled = true
89
+ _diagnostics.meta_clicked.connect(_diagnostic_clicked)
53
90
  add_control_to_bottom_panel(_diagnostics, "Gogo")
54
- _interface.get_resource_filesystem().filesystem_changed.connect(_schedule)
91
+ _interface.get_resource_filesystem().filesystem_changed.connect(_filesystem_changed)
55
92
  _interface.get_resource_filesystem().sources_changed.connect(_sources_changed)
93
+ scene_changed.connect(_scene_context_changed)
56
94
  resource_saved.connect(_resource_saved)
57
95
  _interface.get_script_editor().editor_script_changed.connect(_script_changed)
58
96
  # Native GGX with explicit imports can build before the editor restores
@@ -92,43 +130,24 @@ func _script_changed(script: Script) -> void:
92
130
  if script == null or scripts.get_current_script() != script: return
93
131
  var editor := scripts.get_current_editor()
94
132
  if editor == null: return
95
- _generated_editors[script.resource_path] = {"editor": weakref(editor), "script": weakref(script)}
133
+ _generated_editors.prepare()
96
134
  _schedule()
97
135
 
98
136
 
99
137
  func _refresh_generated_editors() -> void:
100
- # Native ScriptEditor buffers otherwise write pre-build text back into the
101
- # Script cache and even disk on shutdown. Match only public signal/current
102
- # editor associations and paths this successful build owns. Never edit Gogo.
103
- var scripts := _interface.get_script_editor()
104
- var current := scripts.get_current_script()
105
- if current != null and scripts.get_current_editor() != null:
106
- _generated_editors[current.resource_path] = {"editor": weakref(scripts.get_current_editor()), "script": weakref(current)}
107
- for output in last_report.get("outputs", []):
108
- var path := "res://" + str(output)
109
- if not _generated_editors.has(path): continue
110
- var editor = _generated_editors[path].editor.get_ref()
111
- var script = _generated_editors[path].script.get_ref()
112
- if editor == null or script == null or script.resource_path != path:
113
- _generated_editors.erase(path)
114
- continue
115
- var code = editor.get_base_editor()
116
- if not code is CodeEdit: continue
117
- var text := FileAccess.get_file_as_string(path)
118
- if code.text != text:
119
- var line: int = code.get_caret_line()
120
- var column: int = code.get_caret_column()
121
- var vertical: float = code.scroll_vertical
122
- var horizontal: int = code.scroll_horizontal
123
- code.text = text
124
- code.set_caret_line(line)
125
- code.set_caret_column(column)
126
- code.scroll_vertical = vertical
127
- code.scroll_horizontal = horizontal
128
- code.tag_saved_version()
138
+ _generated_editors.refresh()
139
+
140
+ func _filesystem_changed() -> void:
141
+ if _services != null: _services.invalidate()
142
+ _schedule()
143
+
144
+
145
+ func _scene_context_changed(_root: Node) -> void:
146
+ if _services != null: _services.invalidate()
129
147
 
130
148
 
131
149
  func _sources_changed(_changed: bool) -> void:
150
+ _services.invalidate()
132
151
  _schedule()
133
152
 
134
153
 
@@ -139,6 +158,7 @@ func _resource_saved(resource: Resource) -> void:
139
158
 
140
159
 
141
160
  func _save_external_data() -> void:
161
+ if _active and _generated_editors != null: _generated_editors.prepare()
142
162
  _schedule()
143
163
 
144
164
 
@@ -152,26 +172,47 @@ func _compile_saved() -> void:
152
172
 
153
173
 
154
174
  func _build() -> bool:
175
+ if not _build_sources(): return false
176
+ var problem: String = _scene_components.validate_scenes()
177
+ if problem.is_empty(): return true
178
+ last_report.ok = false
179
+ last_report.diagnostics.append(problem)
180
+ _show_report()
181
+ return false
182
+
183
+ func _build_sources() -> bool:
155
184
  if not _active or _building:
156
185
  return false
157
186
  _timer.stop()
187
+ if not _generated_editors.prepare(): return _generated_failure()
158
188
  var saved := BufferGuard.save_and_verify(_interface.get_script_editor(), _highlighter_association._path.bind(false))
159
189
  _timer.stop()
160
190
  _play_save_failed = not saved.ok
161
191
  if not saved.ok:
162
192
  last_report = {"ok": false, "changed": [], "outputs": [], "diagnostics": saved.diagnostics}
193
+ _scene_components.refresh(last_report)
163
194
  _show_report()
164
195
  return false
165
196
  return _compile()
166
197
 
167
198
 
199
+ func _generated_failure() -> bool:
200
+ last_report = {"ok":false,"outputs":[],"changed":[],"diagnostics":[_generated_editors.problem]}
201
+ _show_report()
202
+ return false
203
+
168
204
  func _compile() -> bool:
169
205
  if not _active or _building: return false
206
+ if not _generated_editors.prepare(): return _generated_failure()
170
207
  _building = true
171
208
  build_count += 1
172
209
  last_report = BuildService.run_build()
210
+ _scene_components.refresh(last_report)
173
211
  _show_report()
174
212
  if last_report.ok: _refresh_generated_editors()
213
+ for entry in _services.entries.values():
214
+ var code = entry.code.get_ref()
215
+ if code != null and code.get_version() != code.get_saved_version(): _scene_components.suspend_source(entry.path)
175
216
  # Refresh paths without reimporting authored source. The child game's fresh
176
217
  # process reads these exact bytes; editor resources are synchronized as well.
177
218
  var filesystem := _interface.get_resource_filesystem()
@@ -183,8 +224,23 @@ func _compile() -> bool:
183
224
  return last_report.ok
184
225
 
185
226
 
227
+ func _typing_report(records: Array, phase: String) -> void:
228
+ if not _active or _building: return
229
+ _diagnostics.clear()
230
+ _diagnostics.add_text(phase+"\n")
231
+ for record in records: _diagnostic_link(record)
232
+ func _diagnostic_link(record: Dictionary) -> void:
233
+ _diagnostics.push_meta(record)
234
+ _diagnostics.add_text("%s:%d:%d: %s\n" % [record.source,record.line,record.column,record.message])
235
+ _diagnostics.pop()
236
+ func _diagnostic_clicked(record: Variant) -> void:
237
+ if record is Dictionary: _services.navigate(record)
186
238
  func _show_report() -> void:
239
+ _services.report_build(last_report)
187
240
  _diagnostics.text = "Gogo build succeeded." if last_report.ok else "\n\n".join(PackedStringArray(last_report.diagnostics))
241
+ if not last_report.get("source_diagnostics",[]).is_empty():
242
+ _diagnostics.clear()
243
+ for record in last_report.source_diagnostics: _diagnostic_link(record)
188
244
  if not last_report.ok:
189
245
  make_bottom_panel_item_visible(_diagnostics)
190
246
  push_warning("Estragon: Gogo compilation failed; Play blocked.\n" + _diagnostics.text)
@@ -192,20 +248,37 @@ func _show_report() -> void:
192
248
 
193
249
  func _exit_tree() -> void:
194
250
  _active = false
251
+ remove_tool_menu_item("Attach/Change Gogo Component…")
252
+ remove_tool_menu_item("Add Gogo Component…")
253
+ if _scene_components != null: _scene_components.stop(); _scene_components = null
254
+ remove_tool_menu_item("New Gogo Component (2D)…")
255
+ remove_tool_menu_item("New Gogo Component (3D)…")
256
+ if _creation_menu != null:
257
+ call("remove_context_menu_plugin",_creation_menu)
258
+ _creation_menu.create = Callable()
259
+ _creation_menu = null
260
+ remove_tool_menu_item("Add Missing Gogo Imports")
261
+ if _generated_editors != null:
262
+ _highlighter_association.associated.disconnect(_generated_editors.attach)
263
+ _generated_editors.stop()
264
+ _generated_editors = null
265
+ if _navigation != null: _navigation.stop()
266
+ if _new_script != null: _new_script.stop(); _new_script = null
267
+ if _services != null: _services.stop(); _services.free(); _services = null
268
+ _navigation = null
195
269
  _building = false
196
270
  _rescan_pending = false
197
271
  _play_save_failed = false
198
272
  if is_instance_valid(_interface):
199
273
  var filesystem := _interface.get_resource_filesystem()
200
- if filesystem.filesystem_changed.is_connected(_schedule):
201
- filesystem.filesystem_changed.disconnect(_schedule)
274
+ if filesystem.filesystem_changed.is_connected(_filesystem_changed):
275
+ filesystem.filesystem_changed.disconnect(_filesystem_changed)
202
276
  if filesystem.sources_changed.is_connected(_sources_changed):
203
277
  filesystem.sources_changed.disconnect(_sources_changed)
204
278
  if is_instance_valid(_interface):
205
279
  var scripts := _interface.get_script_editor()
206
280
  if scripts.editor_script_changed.is_connected(_script_changed):
207
281
  scripts.editor_script_changed.disconnect(_script_changed)
208
- _generated_editors.clear()
209
282
  if resource_saved.is_connected(_resource_saved):
210
283
  resource_saved.disconnect(_resource_saved)
211
284
  if _timer != null:
@@ -0,0 +1,267 @@
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
+ return source_path(script.resource_path)
62
+ static func source_path(path: String) -> String:
63
+ if not path.begins_with("res://") or path.contains("::") or path.simplify_path() != path: return ""
64
+ if not FileAccess.file_exists(path+".map.json"): return ""
65
+ var map = JSON.parse_string(FileAccess.get_file_as_string(path+".map.json"))
66
+ 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 ""
67
+ var source := _res(map.sourceName)
68
+ return source if source.ends_with(".gogo") and source.simplify_path() == source and Build.output_for(source) == path else ""
69
+ static func eligible(script: Script) -> bool:
70
+ if not script is GDScript: return false
71
+ var base := script.get_instance_base_type()
72
+ if not ClassDB.class_exists(base) or not ClassDB.is_parent_class(base,"Node") or not ClassDB.can_instantiate(base): return false
73
+ # Non-tool can_instantiate() is false in editor even for valid scene scripts.
74
+ if script.has_method("is_abstract") and script.call("is_abstract"): return false
75
+ # Public method metadata lists the derived class before its bases. Only
76
+ # the effective constructor's arguments are required from a new caller;
77
+ # a zero-argument override can supply its base's required arguments.
78
+ for method in script.get_script_method_list():
79
+ if method.name == "_init": return method.args.size() <= method.default_args.size()
80
+ return true
81
+ func refresh(report: Dictionary) -> void:
82
+ if not active: return
83
+ var next := {}
84
+ var counts := {}
85
+ if report.get("ok",false):
86
+ for output in report.get("outputs",[]):
87
+ var path := _res(str(output))
88
+ var script: Script = load(path)
89
+ var source := source_for(script)
90
+ if source.is_empty() or not FileAccess.file_exists(source) or not eligible(script): continue
91
+ var name := source.get_file().get_basename()
92
+ counts[name] = int(counts.get(name,0))+1
93
+ next[source] = {"source":source,"output":path,"script":script,"base":script.get_instance_base_type(),"name":name}
94
+ for source in next:
95
+ var item: Dictionary = next[source]
96
+ item.label = item.name+(" ["+source.get_base_dir().trim_prefix("res://")+"]" if counts[item.name] > 1 else "")+" (Gogo Component)"
97
+ item.fingerprint = item.label+"|"+item.base+"|"+item.output+"|"+str(item.script.get_instance_id())
98
+ for source in registered.keys():
99
+ if next.has(source) and registered[source].fingerprint == next[source].fingerprint: continue
100
+ plugin.remove_custom_type(registered[source].label)
101
+ registered.erase(source)
102
+ for source in next:
103
+ if registered.has(source): continue
104
+ var item: Dictionary = next[source]
105
+ 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
106
+ plugin.add_custom_type(item.label,item.base,item.script,icon)
107
+ registered[source] = item
108
+ items = next
109
+ func suspend_source(source: String) -> void:
110
+ # Never offer last-built code as a new native component while its authored
111
+ # buffer is changing. Re-registration requires the existing saved build.
112
+ if not active or not registered.has(source): return
113
+ plugin.remove_custom_type(registered[source].label)
114
+ registered.erase(source)
115
+ func editable(node: Node) -> bool:
116
+ if not active or not is_instance_valid(node): return false
117
+ var root := interface.get_edited_scene_root()
118
+ return root != null and (node == root or root.is_ancestor_of(node) and node.owner == root)
119
+ func _selected() -> WeakRef:
120
+ var selected := interface.get_selection().get_selected_nodes()
121
+ return weakref(selected[0]) if selected.size() == 1 else null
122
+ func attach_selected() -> void: choose("attach",_selected())
123
+ func add_selected() -> void: choose("add",_selected())
124
+ func choose(action: String, selected: WeakRef) -> void:
125
+ if not active: return
126
+ var node = selected.get_ref() if selected != null else null
127
+ if node == null or not editable(node): _fail("Select one local scene Node first."); return
128
+ if not plugin._build_sources(): _fail("Fix the Gogo build diagnostics before choosing a component."); return
129
+ target = selected
130
+ scene = weakref(interface.get_edited_scene_root())
131
+ previous = node.get_script()
132
+ mode = action
133
+ list.clear()
134
+ var sources := items.keys()
135
+ sources.sort()
136
+ for source in sources:
137
+ var item: Dictionary = items[source]
138
+ list.add_item(item.label+" — "+item.base+" — "+source)
139
+ list.set_item_metadata(list.item_count-1,source)
140
+ list.set_item_tooltip(list.item_count-1,source)
141
+ message.text = "Attach to "+str(node.name) if mode == "attach" else "Add a native child beneath "+str(node.name)
142
+ if sources.is_empty(): message.text += "\nNo eligible Node components. Create/fix a Gogo component in the configured source roots."
143
+ picker.get_ok_button().disabled = true
144
+ picker.popup_centered()
145
+ func _accepted() -> void:
146
+ if not active or list.get_selected_items().is_empty(): return
147
+ pending = str(list.get_item_metadata(list.get_selected_items()[0]))
148
+ picker.hide()
149
+ _prepare.call_deferred()
150
+ func _valid_target() -> Node:
151
+ var node = target.get_ref() if target != null else null
152
+ var root = scene.get_ref() if scene != null else null
153
+ if node == null or root != interface.get_edited_scene_root() or not editable(node): return null
154
+ if node.get_script() != previous: return null
155
+ return node
156
+ func _prepare() -> void:
157
+ if not active: return
158
+ var node := _valid_target()
159
+ if node == null: _fail("The scene, node or attached script changed. Choose the component again."); return
160
+ 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
161
+ var item: Dictionary = items[pending]
162
+ 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
163
+ if mode == "attach" and previous == item.script: return
164
+ if mode == "attach" and previous != null:
165
+ 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."
166
+ replace.popup_centered()
167
+ else: _commit()
168
+ func _replace_confirmed() -> void:
169
+ replace.hide()
170
+ _commit.call_deferred()
171
+ func _commit() -> void:
172
+ if not active: return
173
+ var node := _valid_target()
174
+ if node == null or not plugin._build_sources() or not items.has(pending): _fail("Scene/component changed; repair and choose again."); return
175
+ var item: Dictionary = items[pending]
176
+ var root := interface.get_edited_scene_root()
177
+ var undo := plugin.get_undo_redo()
178
+ if mode == "attach":
179
+ if not ClassDB.is_parent_class(node.get_class(),item.base): _fail("Component host type changed; choose a compatible node."); return
180
+ var values := {}
181
+ if previous != null:
182
+ # Placeholder/editor property lists do not consistently carry the
183
+ # SCRIPT_VARIABLE bit. Script metadata identifies owned stored fields.
184
+ for prop in previous.get_script_property_list():
185
+ if prop.name != "script" and int(prop.usage) & PROPERTY_USAGE_STORAGE: values[prop.name] = node.get(prop.name)
186
+ undo.create_action("Attach Gogo Component",UndoRedo.MERGE_DISABLE,root)
187
+ undo.add_do_method(node,"set_script",item.script)
188
+ undo.add_undo_method(node,"set_script",previous)
189
+ for name in values: undo.add_undo_property(node,name,values[name])
190
+ undo.add_do_method(node,"notify_property_list_changed")
191
+ undo.add_undo_method(node,"notify_property_list_changed")
192
+ else:
193
+ var child: Node = ClassDB.instantiate(item.base)
194
+ child.name = str(item.name).validate_node_name()
195
+ child.set_script(item.script)
196
+ undo.create_action("Add Gogo Component",UndoRedo.MERGE_DISABLE,root)
197
+ undo.add_do_method(node,"add_child",child,true)
198
+ undo.add_do_property(child,"owner",root)
199
+ undo.add_undo_method(node,"remove_child",child)
200
+ undo.add_do_reference(child)
201
+ undo.commit_action()
202
+ func open_source(source: String) -> void:
203
+ if not active: return
204
+ if not FileAccess.file_exists(source): _fail("Gogo source is missing: "+source+". Restore it or attach a replacement."); return
205
+ navigation.open(source)
206
+ func _fail(text: String) -> void:
207
+ if not active: return
208
+ error.dialog_text = text
209
+ error.popup_centered()
210
+ func _script_error(script: Script) -> String:
211
+ var source := source_for(script)
212
+ if source.is_empty(): return ""
213
+ if not items.has(source): return "Attached Gogo component is missing, invalid or excluded: "+source+". Restore/recompile or reattach it before Play."
214
+ return ""
215
+ func validate_scenes() -> String:
216
+ var root := interface.get_edited_scene_root()
217
+ if root != null:
218
+ var problem := _validate_node(root)
219
+ if not problem.is_empty(): return problem
220
+ var paths := Array(interface.get_open_scenes())
221
+ var main := str(ProjectSettings.get_setting("application/run/main_scene",""))
222
+ if not main.is_empty(): paths.append(main)
223
+ var visited := {}
224
+ for path in paths:
225
+ if root != null and path == root.scene_file_path: continue
226
+ var problem := _validate_saved(str(path),visited)
227
+ if not problem.is_empty(): return problem
228
+ return ""
229
+ func _validate_node(node: Node) -> String:
230
+ var problem := _script_error(node.get_script())
231
+ if not problem.is_empty(): return problem
232
+ for child in node.get_children():
233
+ problem = _validate_node(child)
234
+ if not problem.is_empty(): return problem
235
+ return ""
236
+ func _validate_saved(path: String, visited: Dictionary) -> String:
237
+ if path.is_empty() or visited.has(path): return ""
238
+ visited[path] = true
239
+ if not ResourceLoader.exists(path,"PackedScene"): return "Cannot validate scene before Play: "+path
240
+ var packed: PackedScene = load(path)
241
+ if packed == null: return "Cannot load scene before Play: "+path
242
+ var state := packed.get_state()
243
+ for index in range(state.get_node_count()):
244
+ for prop in range(state.get_node_property_count(index)):
245
+ if state.get_node_property_name(index,prop) == "script":
246
+ var problem := _script_error(state.get_node_property_value(index,prop))
247
+ if not problem.is_empty(): return problem
248
+ # Native dependency data includes inherited/instanced scenes on 4.0 too.
249
+ for dependency in ResourceLoader.get_dependencies(path):
250
+ for part in str(dependency).split("::"):
251
+ if part.begins_with("res://") and part.get_extension() in ["tscn","scn"]:
252
+ var problem := _validate_saved(part,visited)
253
+ if not problem.is_empty(): return problem
254
+ return ""
255
+ func stop() -> void:
256
+ active = false
257
+ for item in registered.values(): plugin.remove_custom_type(item.label)
258
+ registered.clear()
259
+ items.clear()
260
+ plugin.remove_inspector_plugin(inspector)
261
+ inspector.service = null
262
+ inspector = null
263
+ for reference in controls:
264
+ var control = reference.get_ref()
265
+ if control != null: control.free()
266
+ controls.clear()
267
+ for dialog in [picker,error,replace]: dialog.free()
@@ -0,0 +1 @@
1
+ uid://cccu2jpv66ms
@@ -0,0 +1,42 @@
1
+ @tool
2
+ extends EditorInspectorPlugin
3
+ ## Authored-source presentation alongside the untouched native Script property.
4
+ const VisualStyle = preload("../runtime/node/internal/visual_style_2d.gd")
5
+ const ColorProperty = preload("color_property.gd")
6
+ const Length = preload("../runtime/node/internal/length.gd")
7
+ const LengthProperty = preload("length_property.gd")
8
+ var service: WeakRef
9
+ func _can_handle(object: Object) -> bool:
10
+ var owner = service.get_ref() if service != null else null
11
+ return owner != null and owner.active and object is Node and (owner.editable(object) or object.has_method("_get_layout_coordinator"))
12
+ func _parse_property(object: Object, _type: Variant.Type, name: String, _hint: PropertyHint, _hint_text: String, _usage: int, _wide: bool) -> bool:
13
+ if VisualStyle.registered(object.get_script(),name):
14
+ add_property_editor(name,ColorProperty.new())
15
+ return true
16
+ if not Length.registered(object.get_script(),name): return false
17
+ add_property_editor(name,LengthProperty.new())
18
+ return true
19
+ func _parse_begin(object: Object) -> void:
20
+ var owner = service.get_ref() if service != null else null
21
+ if owner == null or not owner.editable(object): return
22
+ var panel := VBoxContainer.new()
23
+ panel.name = "GogoSceneComponent"
24
+ var label := Label.new()
25
+ var source: String = owner.source_for(object.get_script())
26
+ label.text = "Gogo Component" if source.is_empty() else "Gogo source: "+source
27
+ label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
28
+ panel.add_child(label)
29
+ if not source.is_empty():
30
+ var open := Button.new()
31
+ open.text = "Open Gogo Source"
32
+ # Navigation/build can rebuild the Inspector and free this sender.
33
+ open.pressed.connect(owner.open_source.bind(source),CONNECT_DEFERRED)
34
+ panel.add_child(open)
35
+ for mode in ["attach","add"]:
36
+ var button := Button.new()
37
+ button.text = "Attach/Change Gogo Component…" if mode == "attach" else "Add Gogo Child…"
38
+ button.pressed.connect(owner.choose.bind(mode,weakref(object)),CONNECT_DEFERRED)
39
+ panel.add_child(button)
40
+ owner.controls = owner.controls.filter(func(reference): return reference.get_ref() != null)
41
+ owner.controls.append(weakref(panel))
42
+ add_custom_control(panel)
@@ -0,0 +1 @@
1
+ uid://b6wswjs8u4p1o
@@ -2,10 +2,10 @@
2
2
  extends RefCounted
3
3
  ## Static resource edges for ordering native validation/reloads. Reuses N01's
4
4
  ## lexer; Godot decodes string literals and remains the semantic authority.
5
- const Lexer = preload("res://addons/estragon/compiler/lexer.gd")
6
- const Source = preload("res://addons/estragon/compiler/source.gd")
5
+ const Lexer = preload("../compiler/lexer.gd")
6
+ const Source = preload("../compiler/source.gd")
7
7
 
8
- static func paths(code: String, output: String) -> PackedStringArray:
8
+ static func paths(code: String, output: String, locations: Dictionary = {}) -> PackedStringArray:
9
9
  var file := Source.new(code)
10
10
  var lexer := Lexer.new(file)
11
11
  var tokens: Array = []
@@ -41,5 +41,7 @@ static func paths(code: String, output: String) -> PackedStringArray:
41
41
  if not ResourceUID.has_id(uid): continue
42
42
  path = ResourceUID.get_id_path(uid)
43
43
  elif not path.is_absolute_path(): path = output.get_base_dir().path_join(path).simplify_path()
44
+ path = path.simplify_path()
44
45
  result.append(path)
46
+ locations[path] = tokens[next].span.start
45
47
  return result
@@ -1,6 +1,6 @@
1
1
  @tool
2
2
  extends RefCounted
3
- const Profile = preload("res://addons/estragon/runtime/composition/profile.tres")
3
+ const Profile = preload("profile.tres")
4
4
  ## Desired typed linkage, owned only by external description/mount records.
5
5
  var root: WeakRef
6
6
  var source: WeakRef