@papercraftgames/estragon 0.0.0-stage → 0.1.0-beta.2

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 (88) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/LICENSE +20 -0
  3. package/README.md +28 -2
  4. package/addons/estragon/compiler/bindable.gd +213 -0
  5. package/addons/estragon/compiler/bindable.gd.uid +1 -0
  6. package/addons/estragon/compiler/compiler.gd +24 -0
  7. package/addons/estragon/compiler/compiler.gd.uid +1 -0
  8. package/addons/estragon/compiler/composition.gd +51 -0
  9. package/addons/estragon/compiler/composition.gd.uid +1 -0
  10. package/addons/estragon/compiler/diagnostic_capture.gd.txt +18 -0
  11. package/addons/estragon/compiler/emitter.gd +209 -0
  12. package/addons/estragon/compiler/emitter.gd.uid +1 -0
  13. package/addons/estragon/compiler/frontend.gd +22 -0
  14. package/addons/estragon/compiler/frontend.gd.uid +1 -0
  15. package/addons/estragon/compiler/lexer.gd +78 -0
  16. package/addons/estragon/compiler/lexer.gd.uid +1 -0
  17. package/addons/estragon/compiler/model.gd +87 -0
  18. package/addons/estragon/compiler/model.gd.uid +1 -0
  19. package/addons/estragon/compiler/native/resolver.gd +200 -0
  20. package/addons/estragon/compiler/native/resolver.gd.uid +1 -0
  21. package/addons/estragon/compiler/parser.gd +252 -0
  22. package/addons/estragon/compiler/parser.gd.uid +1 -0
  23. package/addons/estragon/compiler/script_validation.gd +80 -0
  24. package/addons/estragon/compiler/script_validation.gd.uid +1 -0
  25. package/addons/estragon/compiler/source.gd +65 -0
  26. package/addons/estragon/compiler/source.gd.uid +1 -0
  27. package/addons/estragon/compiler/source_map.gd +59 -0
  28. package/addons/estragon/compiler/source_map.gd.uid +1 -0
  29. package/addons/estragon/compiler/validator.gd +277 -0
  30. package/addons/estragon/compiler/validator.gd.uid +1 -0
  31. package/addons/estragon/editor/buffer_guard.gd +84 -0
  32. package/addons/estragon/editor/buffer_guard.gd.uid +1 -0
  33. package/addons/estragon/editor/build_service.gd +252 -0
  34. package/addons/estragon/editor/build_service.gd.uid +1 -0
  35. package/addons/estragon/editor/highlighter.gd +116 -0
  36. package/addons/estragon/editor/highlighter.gd.uid +1 -0
  37. package/addons/estragon/editor/highlighter_association.gd +80 -0
  38. package/addons/estragon/editor/highlighter_association.gd.uid +1 -0
  39. package/addons/estragon/editor/plugin.cfg +7 -0
  40. package/addons/estragon/editor/plugin.gd +225 -0
  41. package/addons/estragon/editor/plugin.gd.uid +1 -0
  42. package/addons/estragon/editor/script_dependencies.gd +45 -0
  43. package/addons/estragon/editor/script_dependencies.gd.uid +1 -0
  44. package/addons/estragon/runtime/composition/binding.gd +62 -0
  45. package/addons/estragon/runtime/composition/binding.gd.uid +1 -0
  46. package/addons/estragon/runtime/composition/computation.gd +477 -0
  47. package/addons/estragon/runtime/composition/computation.gd.uid +1 -0
  48. package/addons/estragon/runtime/composition/element.gd +23 -0
  49. package/addons/estragon/runtime/composition/element.gd.uid +1 -0
  50. package/addons/estragon/runtime/composition/profile.gd +21 -0
  51. package/addons/estragon/runtime/composition/profile.gd.uid +1 -0
  52. package/addons/estragon/runtime/composition/profile.tres +6 -0
  53. package/addons/estragon/runtime/composition/state.gd +65 -0
  54. package/addons/estragon/runtime/composition/state.gd.uid +1 -0
  55. package/addons/estragon/runtime/composition/state.tres +6 -0
  56. package/addons/estragon/runtime/node/button.gd +53 -0
  57. package/addons/estragon/runtime/node/button.gd.uid +1 -0
  58. package/addons/estragon/runtime/node/component_2d.gd +105 -0
  59. package/addons/estragon/runtime/node/component_2d.gd.uid +1 -0
  60. package/addons/estragon/runtime/node/component_3d.gd +91 -0
  61. package/addons/estragon/runtime/node/component_3d.gd.uid +1 -0
  62. package/addons/estragon/runtime/node/estragon_2d.gd +32 -0
  63. package/addons/estragon/runtime/node/estragon_2d.gd.uid +1 -0
  64. package/addons/estragon/runtime/node/estragon_3d.gd +15 -0
  65. package/addons/estragon/runtime/node/estragon_3d.gd.uid +1 -0
  66. package/addons/estragon/runtime/node/hbox.gd +6 -0
  67. package/addons/estragon/runtime/node/hbox.gd.uid +1 -0
  68. package/addons/estragon/runtime/node/internal/coordinator.gd +145 -0
  69. package/addons/estragon/runtime/node/internal/coordinator.gd.uid +1 -0
  70. package/addons/estragon/runtime/node/internal/layout_core.gd +115 -0
  71. package/addons/estragon/runtime/node/internal/layout_core.gd.uid +1 -0
  72. package/addons/estragon/runtime/node/internal/native_bounds.gd +103 -0
  73. package/addons/estragon/runtime/node/internal/native_bounds.gd.uid +1 -0
  74. package/addons/estragon/runtime/node/internal/pointer_2d.gd +70 -0
  75. package/addons/estragon/runtime/node/internal/pointer_2d.gd.uid +1 -0
  76. package/addons/estragon/runtime/node/native_2d.gd +40 -0
  77. package/addons/estragon/runtime/node/native_2d.gd.uid +1 -0
  78. package/addons/estragon/runtime/node/native_3d.gd +40 -0
  79. package/addons/estragon/runtime/node/native_3d.gd.uid +1 -0
  80. package/addons/estragon/runtime/node/rect.gd +15 -0
  81. package/addons/estragon/runtime/node/rect.gd.uid +1 -0
  82. package/addons/estragon/runtime/node/text.gd +66 -0
  83. package/addons/estragon/runtime/node/text.gd.uid +1 -0
  84. package/addons/estragon/runtime/node/toggle.gd +23 -0
  85. package/addons/estragon/runtime/node/toggle.gd.uid +1 -0
  86. package/addons/estragon/runtime/node/vbox.gd +6 -0
  87. package/addons/estragon/runtime/node/vbox.gd.uid +1 -0
  88. package/package.json +31 -4
@@ -0,0 +1,225 @@
1
+ @tool
2
+ extends EditorPlugin
3
+ ## Native ScriptEditor authoring and direct Godot compilation before every Play.
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")
9
+ const TEXT_EXTENSIONS_SETTING := "docks/filesystem/textfile_extensions"
10
+
11
+ var _highlighter: EditorSyntaxHighlighter
12
+ var _interface: EditorInterface
13
+ var _highlighter_association: RefCounted
14
+ var _timer: Timer
15
+ var _diagnostics: RichTextLabel
16
+ var _building: bool = false
17
+ var _active: bool = false
18
+ var _extensions_pending: bool = true
19
+ var _rescan_pending: bool = false
20
+ var _play_save_failed: bool = false
21
+ var _generated_editors: Dictionary = {}
22
+ var last_report: Dictionary = {}
23
+ var build_count: int = 0
24
+
25
+
26
+ func _enter_tree() -> void:
27
+ if _active: return
28
+ _interface = get_editor_interface()
29
+ _active = true
30
+ _extensions_pending = true
31
+ var settings := _interface.get_editor_settings()
32
+ if settings.has_setting(TEXT_EXTENSIONS_SETTING):
33
+ var existing := str(settings.get_setting(TEXT_EXTENSIONS_SETTING))
34
+ var registered := false
35
+ for extension in existing.split(","):
36
+ if extension == "gogo":
37
+ registered = true
38
+ if not registered:
39
+ settings.set_setting(TEXT_EXTENSIONS_SETTING, existing + ("," if not existing.is_empty() else "") + "gogo")
40
+ _highlighter = Highlighter.new()
41
+ _interface.get_script_editor().register_syntax_highlighter(_highlighter)
42
+ _highlighter_association = HighlighterAssociation.new()
43
+ _highlighter_association.start(_interface)
44
+ _timer = Timer.new()
45
+ _timer.one_shot = true
46
+ _timer.wait_time = 0.4
47
+ _timer.timeout.connect(_compile_saved)
48
+ add_child(_timer)
49
+ _diagnostics = RichTextLabel.new()
50
+ _diagnostics.name = "EstragonDiagnostics"
51
+ _diagnostics.custom_minimum_size = Vector2(0, 120)
52
+ _diagnostics.selection_enabled = true
53
+ add_control_to_bottom_panel(_diagnostics, "Gogo")
54
+ _interface.get_resource_filesystem().filesystem_changed.connect(_schedule)
55
+ _interface.get_resource_filesystem().sources_changed.connect(_sources_changed)
56
+ resource_saved.connect(_resource_saved)
57
+ _interface.get_script_editor().editor_script_changed.connect(_script_changed)
58
+ # Native GGX with explicit imports can build before the editor restores
59
+ # scenes. Waiting for a specific framework class races missing generated
60
+ # scripts on cold 4.0 projects and couples plain-Node Gogo to the UI runtime.
61
+ _compile()
62
+ if last_report.is_empty() or not _apply_extension_setting(): _schedule()
63
+
64
+
65
+ func _filesystem_busy() -> bool:
66
+ var filesystem := _interface.get_resource_filesystem()
67
+ if filesystem.is_scanning(): return true
68
+ # Older editors expose scanning but not a separate import-status query.
69
+ return filesystem.has_method("is_importing") and filesystem.call("is_importing")
70
+
71
+
72
+ func _apply_extension_setting() -> bool:
73
+ if not _extensions_pending: return true
74
+ if _filesystem_busy(): return false
75
+ var settings := _interface.get_editor_settings()
76
+ if settings.has_method("mark_setting_changed"):
77
+ settings.call("mark_setting_changed", TEXT_EXTENSIONS_SETTING)
78
+ # set_setting alone does not update EditorNode's cached text extensions.
79
+ # Use the public notification consumed by Godot's own settings UI.
80
+ get_tree().root.propagate_notification(EditorSettings.NOTIFICATION_EDITOR_SETTINGS_CHANGED)
81
+ _extensions_pending = false
82
+ return true
83
+
84
+
85
+ func _schedule() -> void:
86
+ if _active and not _building and not _play_save_failed:
87
+ _timer.start()
88
+
89
+
90
+ func _script_changed(script: Script) -> void:
91
+ var scripts := _interface.get_script_editor()
92
+ if script == null or scripts.get_current_script() != script: return
93
+ var editor := scripts.get_current_editor()
94
+ if editor == null: return
95
+ _generated_editors[script.resource_path] = {"editor": weakref(editor), "script": weakref(script)}
96
+ _schedule()
97
+
98
+
99
+ 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()
129
+
130
+
131
+ func _sources_changed(_changed: bool) -> void:
132
+ _schedule()
133
+
134
+
135
+ func _resource_saved(resource: Resource) -> void:
136
+ if resource.resource_path.ends_with(".gogo"):
137
+ _play_save_failed = false
138
+ _schedule()
139
+
140
+
141
+ func _save_external_data() -> void:
142
+ _schedule()
143
+
144
+
145
+ func _compile_saved() -> void:
146
+ if _active and not _play_save_failed:
147
+ if _filesystem_busy() or not _apply_extension_setting():
148
+ _schedule()
149
+ return
150
+ _timer.stop()
151
+ _compile()
152
+
153
+
154
+ func _build() -> bool:
155
+ if not _active or _building:
156
+ return false
157
+ _timer.stop()
158
+ var saved := BufferGuard.save_and_verify(_interface.get_script_editor(), _highlighter_association._path.bind(false))
159
+ _timer.stop()
160
+ _play_save_failed = not saved.ok
161
+ if not saved.ok:
162
+ last_report = {"ok": false, "changed": [], "outputs": [], "diagnostics": saved.diagnostics}
163
+ _show_report()
164
+ return false
165
+ return _compile()
166
+
167
+
168
+ func _compile() -> bool:
169
+ if not _active or _building: return false
170
+ _building = true
171
+ build_count += 1
172
+ last_report = BuildService.run_build()
173
+ _show_report()
174
+ if last_report.ok: _refresh_generated_editors()
175
+ # Refresh paths without reimporting authored source. The child game's fresh
176
+ # process reads these exact bytes; editor resources are synchronized as well.
177
+ var filesystem := _interface.get_resource_filesystem()
178
+ _rescan_pending = _rescan_pending or not last_report.get("changed", []).is_empty()
179
+ if _rescan_pending and not _filesystem_busy():
180
+ _rescan_pending = false
181
+ filesystem.scan()
182
+ _building = false
183
+ return last_report.ok
184
+
185
+
186
+ func _show_report() -> void:
187
+ _diagnostics.text = "Gogo build succeeded." if last_report.ok else "\n\n".join(PackedStringArray(last_report.diagnostics))
188
+ if not last_report.ok:
189
+ make_bottom_panel_item_visible(_diagnostics)
190
+ push_warning("Estragon: Gogo compilation failed; Play blocked.\n" + _diagnostics.text)
191
+
192
+
193
+ func _exit_tree() -> void:
194
+ _active = false
195
+ _building = false
196
+ _rescan_pending = false
197
+ _play_save_failed = false
198
+ if is_instance_valid(_interface):
199
+ var filesystem := _interface.get_resource_filesystem()
200
+ if filesystem.filesystem_changed.is_connected(_schedule):
201
+ filesystem.filesystem_changed.disconnect(_schedule)
202
+ if filesystem.sources_changed.is_connected(_sources_changed):
203
+ filesystem.sources_changed.disconnect(_sources_changed)
204
+ if is_instance_valid(_interface):
205
+ var scripts := _interface.get_script_editor()
206
+ if scripts.editor_script_changed.is_connected(_script_changed):
207
+ scripts.editor_script_changed.disconnect(_script_changed)
208
+ _generated_editors.clear()
209
+ if resource_saved.is_connected(_resource_saved):
210
+ resource_saved.disconnect(_resource_saved)
211
+ if _timer != null:
212
+ _timer.stop()
213
+ _timer.free()
214
+ _timer = null
215
+ if _highlighter_association != null:
216
+ _highlighter_association.stop()
217
+ _highlighter_association = null
218
+ if _highlighter != null and is_instance_valid(_interface):
219
+ _interface.get_script_editor().unregister_syntax_highlighter(_highlighter)
220
+ _highlighter = null
221
+ if _diagnostics != null:
222
+ remove_control_from_bottom_panel(_diagnostics)
223
+ _diagnostics.free()
224
+ _diagnostics = null
225
+ _interface = null
@@ -0,0 +1 @@
1
+ uid://d0c5xydsltgy8
@@ -0,0 +1,45 @@
1
+ @tool
2
+ extends RefCounted
3
+ ## Static resource edges for ordering native validation/reloads. Reuses N01's
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")
7
+
8
+ static func paths(code: String, output: String) -> PackedStringArray:
9
+ var file := Source.new(code)
10
+ var lexer := Lexer.new(file)
11
+ var tokens: Array = []
12
+ var cursor: int = 0
13
+ while cursor < code.length():
14
+ var token := lexer.next_token(cursor)
15
+ if token == null: return [] # The full mapped semantic validator diagnoses it.
16
+ cursor = token.span.end.index
17
+ if token.kind not in ["whitespace", "comment", "newline", "continuation"]: tokens.append(token)
18
+ var result: PackedStringArray = []
19
+ for index in range(tokens.size()):
20
+ var token = tokens[index]
21
+ if token.kind != "identifier" or token.text not in ["extends", "preload"]: continue
22
+ var next := index + (2 if token.text == "preload" else 1)
23
+ if token.text == "preload" and (index + 1 >= tokens.size() or tokens[index + 1].text != "("): continue
24
+ if next >= tokens.size(): continue
25
+ var raw: bool = tokens[next].kind == "identifier" and tokens[next].text == "r"
26
+ if raw: next += 1
27
+ if next >= tokens.size(): continue
28
+ if tokens[next].kind == "identifier" and token.text == "extends":
29
+ for entry in ProjectSettings.get_global_class_list():
30
+ if str(entry["class"]) == tokens[next].text: result.append(entry.path)
31
+ elif tokens[next].kind == "string":
32
+ # Only one lexer-proven literal is evaluated, never an authored
33
+ # expression, component or application. This handles Godot escapes,
34
+ # Unicode, raw and multiline strings without a second string grammar.
35
+ var literal := GDScript.new()
36
+ literal.source_code = "@tool\nextends RefCounted\nstatic func value() -> String:\n\treturn " + ("r" if raw else "") + tokens[next].text + "\n"
37
+ if literal.reload() != OK: continue
38
+ var path: String = literal.call("value")
39
+ if path.begins_with("uid://"):
40
+ var uid := ResourceUID.text_to_id(path)
41
+ if not ResourceUID.has_id(uid): continue
42
+ path = ResourceUID.get_id_path(uid)
43
+ elif not path.is_absolute_path(): path = output.get_base_dir().path_join(path).simplify_path()
44
+ result.append(path)
45
+ return result
@@ -0,0 +1 @@
1
+ uid://d36ewdiplk8ue
@@ -0,0 +1,62 @@
1
+ @tool
2
+ extends RefCounted
3
+ const Profile = preload("res://addons/estragon/runtime/composition/profile.tres")
4
+ ## Desired typed linkage, owned only by external description/mount records.
5
+ var root: WeakRef
6
+ var source: WeakRef
7
+ var field: StringName
8
+ var route: String
9
+ var read: Callable
10
+ var write: Callable
11
+ var value: Variant
12
+ var valid := false
13
+ var node: WeakRef
14
+ var computation: WeakRef
15
+ var connected := false
16
+ var writing := false
17
+ func _init(owner: Object, reader: Callable, property: StringName, writer: Callable, identity: String) -> void:
18
+ route = identity
19
+ root = weakref(owner)
20
+ read = reader
21
+ write = writer
22
+ field = property
23
+ var endpoint = current()
24
+ if endpoint == null: return
25
+ source = weakref(endpoint)
26
+ value = endpoint.get(field)
27
+ valid = typeof(value)==TYPE_BOOL and endpoint.has_signal(str(field)+"_changed")
28
+ func current():
29
+ var owner = root.get_ref()
30
+ var endpoint = read.call(owner) if is_instance_valid(owner) else null
31
+ return endpoint if is_instance_valid(endpoint) else null
32
+ func same(other) -> bool:
33
+ return other!=null and valid and other.valid and source.get_ref()==other.source.get_ref() and root.get_ref()==other.root.get_ref() and field==other.field and route==other.route
34
+ func attach(target: Node, scope) -> void:
35
+ node = weakref(target)
36
+ computation = weakref(scope)
37
+ if not connected:
38
+ connected = target.connect("value_changed",edit)==OK
39
+ if connected and Profile.is_enabled(): Profile.add("binding_connects")
40
+ if connected and not target.tree_exiting.is_connected(_target_exit): target.tree_exiting.connect(_target_exit)
41
+ func disconnect_edit() -> void:
42
+ var target = node.get_ref() if node!=null else null
43
+ if target!=null and target.is_connected("value_changed",edit): target.disconnect("value_changed",edit)
44
+ if connected and Profile.is_enabled(): Profile.add("binding_disconnects")
45
+ if target!=null and target.tree_exiting.is_connected(_target_exit): target.tree_exiting.disconnect(_target_exit)
46
+ connected = false
47
+ func _target_exit() -> void:
48
+ disconnect_edit()
49
+ var scope = computation.get_ref() if computation!=null else null
50
+ if scope!=null and scope.active and not scope.disposed: scope.schedule()
51
+ func edit(next: bool) -> void:
52
+ var scope = computation.get_ref() if computation!=null else null
53
+ var target = node.get_ref() if node!=null else null
54
+ var endpoint = source.get_ref() if source!=null else null
55
+ if not connected or writing or scope==null or scope.disposed or not scope.active or target==null or not target.is_inside_tree() or target.is_queued_for_deletion() or endpoint==null or current()!=endpoint: return
56
+ if is_same(endpoint.get(field),next): return
57
+ writing = true
58
+ write.call(endpoint,next)
59
+ writing = false
60
+ # Reentrant model callbacks can restore the old value; commit must still
61
+ # restore a control whose local user value diverged from its snapshot.
62
+ scope.schedule()
@@ -0,0 +1 @@
1
+ uid://9mxz909ku8g