@papercraftgames/estragon 0.1.0-beta.6 → 0.1.0-beta.8
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.
|
@@ -261,9 +261,9 @@ static func creation_check(path: String) -> Dictionary:
|
|
|
261
261
|
if not path.begins_with("res://") or path.get_extension() != "gogo" or "\\" in relative or ":" in relative:
|
|
262
262
|
return {"ok":false,"message":"Choose a .gogo file beneath res://."}
|
|
263
263
|
for part in relative.split("/"):
|
|
264
|
-
if part.begins_with(".") or part in EXCLUDED: return {"ok":false,"message":"This path is excluded from Gogo compilation. Choose a configured source root."}
|
|
264
|
+
if part.is_empty() or not part.is_valid_filename() or part.begins_with(".") or part in EXCLUDED: return {"ok":false,"message":"This path is invalid or excluded from Gogo compilation. Choose a valid filename in a configured source root."}
|
|
265
265
|
if FileAccess.file_exists(path) or DirAccess.dir_exists_absolute(path):
|
|
266
|
-
return {"ok":false,"message":"A file or directory already exists. New Gogo
|
|
266
|
+
return {"ok":false,"message":"A file or directory already exists. New Gogo Component never overwrites existing source; choose another filename."}
|
|
267
267
|
if not DirAccess.dir_exists_absolute(path.get_base_dir()): return {"ok":false,"message":"Create/select an existing project directory first."}
|
|
268
268
|
var check := new()
|
|
269
269
|
check._project = ProjectSettings.globalize_path("res://").trim_suffix("/")
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends EditorContextMenuPlugin
|
|
3
|
+
## Parsed only when the public native context-menu API is available.
|
|
4
|
+
var create: Callable
|
|
5
|
+
var root_context := false
|
|
6
|
+
func _popup_menu(paths: PackedStringArray) -> void:
|
|
7
|
+
root_context = paths.is_empty()
|
|
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:
|
|
12
|
+
# The engine supplies a current directory to callbacks even when popup
|
|
13
|
+
# paths were empty. Empty-space creation deliberately starts at project root.
|
|
14
|
+
if create.is_valid(): create.call(paths[0] if not root_context and not paths.is_empty() else "res://",spatial)
|
|
@@ -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
|
|
@@ -20,47 +17,39 @@ func start(parent: Node) -> void:
|
|
|
20
17
|
# 4.0 registers EditorFileDialog abstract; do not reference its unavailable
|
|
21
18
|
# constructor even in a dead branch. Both paths use public native dialogs.
|
|
22
19
|
dialog = ClassDB.instantiate("EditorFileDialog") if ClassDB.can_instantiate("EditorFileDialog") else FileDialog.new()
|
|
23
|
-
dialog.name = "
|
|
20
|
+
dialog.name = "NewGogoComponent"
|
|
24
21
|
if dialog is FileDialog: dialog.mode_overrides_title = false
|
|
25
|
-
dialog.title = "New Gogo
|
|
22
|
+
dialog.title = "New Gogo Component"
|
|
26
23
|
dialog.access = EditorFileDialog.ACCESS_RESOURCES
|
|
27
24
|
dialog.file_mode = EditorFileDialog.FILE_MODE_SAVE_FILE
|
|
28
25
|
if dialog is EditorFileDialog: dialog.disable_overwrite_warning = true
|
|
29
|
-
|
|
26
|
+
# Native save filters append their suffix even to explicit wrong extensions
|
|
27
|
+
# (Bad.txt becomes Bad.txt.gogo). Let the shared validator own suffixes.
|
|
28
|
+
dialog.add_filter("*","Gogo Component (.gogo)")
|
|
30
29
|
dimension = OptionButton.new()
|
|
31
30
|
dimension.name = "GogoTemplate"
|
|
32
|
-
dimension.add_item("Node2D —
|
|
33
|
-
dimension.add_item("Node3D —
|
|
31
|
+
dimension.add_item("Node2D — blank component")
|
|
32
|
+
dimension.add_item("Node3D — blank component")
|
|
34
33
|
dialog.get_vbox().add_child(dimension)
|
|
35
34
|
dialog.file_selected.connect(_selected)
|
|
36
35
|
parent.add_child(dialog)
|
|
37
36
|
error = AcceptDialog.new()
|
|
38
|
-
error.title = "New Gogo
|
|
37
|
+
error.title = "New Gogo Component"
|
|
39
38
|
parent.add_child(error)
|
|
40
|
-
func show_dialog() -> void:
|
|
39
|
+
func show_dialog(context_directory: String = "", spatial: bool = false) -> void:
|
|
41
40
|
if not active: return
|
|
42
|
-
var directory := interface.get_current_directory()
|
|
43
|
-
if not directory.begins_with("res://"): directory = "res://"
|
|
44
|
-
if FileAccess.file_exists("res://gogo.config.json"):
|
|
45
|
-
var config = JSON.parse_string(FileAccess.get_file_as_string("res://gogo.config.json"))
|
|
46
|
-
if config is Dictionary and config.get("source_roots") is Array and not config.source_roots.is_empty():
|
|
47
|
-
var root = config.source_roots[0]
|
|
48
|
-
if root is String:
|
|
49
|
-
var preferred: String = "res://"+root
|
|
50
|
-
if preferred.ends_with(".gogo"): preferred = preferred.get_base_dir()
|
|
51
|
-
if DirAccess.dir_exists_absolute(preferred): directory = preferred
|
|
41
|
+
var directory := context_directory if not context_directory.is_empty() else interface.get_current_directory()
|
|
42
|
+
if not directory.begins_with("res://") or not DirAccess.dir_exists_absolute(directory): directory = "res://"
|
|
52
43
|
dialog.current_dir = directory
|
|
53
|
-
dialog.current_file = "
|
|
44
|
+
dialog.current_file = "NewComponent.gogo"
|
|
45
|
+
dimension.select(1 if spatial else 0)
|
|
54
46
|
dialog.popup_centered_ratio(0.65)
|
|
55
47
|
static func template(path: String, spatial: bool) -> String:
|
|
48
|
+
var kind := "Node3D" if spatial else "Node2D"
|
|
56
49
|
var directory := Build.output_for(path).get_base_dir()
|
|
57
50
|
var element := JSON.stringify(Source.relative_path(directory,(Element as Script).resource_path))
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if spatial:
|
|
61
|
-
return result+"\nfunc build_view() -> Element:\n\treturn <Entry name=\"Layout\" width={4.0} height={2.0} depth={1.0} />\n"
|
|
62
|
-
var text := JSON.stringify(Source.relative_path(directory,(Text as Script).resource_path))
|
|
63
|
-
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"
|
|
64
53
|
func _selected(path: String) -> void:
|
|
65
54
|
if not active: return
|
|
66
55
|
if path.get_extension().is_empty(): path += ".gogo"
|
|
@@ -12,6 +12,7 @@ const NewScript = preload("new_script.gd")
|
|
|
12
12
|
var _services: Node
|
|
13
13
|
var _navigation: RefCounted
|
|
14
14
|
var _new_script: RefCounted
|
|
15
|
+
var _creation_menu: RefCounted
|
|
15
16
|
const TEXT_EXTENSIONS_SETTING := "docks/filesystem/textfile_extensions"
|
|
16
17
|
|
|
17
18
|
var _highlighter: EditorSyntaxHighlighter
|
|
@@ -54,7 +55,16 @@ func _enter_tree() -> void:
|
|
|
54
55
|
_highlighter_association.start(_interface)
|
|
55
56
|
_new_script = NewScript.new(_interface,_navigation)
|
|
56
57
|
_new_script.start(self)
|
|
57
|
-
add_tool_menu_item("New Gogo
|
|
58
|
+
add_tool_menu_item("New Gogo Component (2D)…",_new_script.show_dialog.bind("",false))
|
|
59
|
+
add_tool_menu_item("New Gogo Component (3D)…",_new_script.show_dialog.bind("",true))
|
|
60
|
+
# Never parse a script extending a newer native class on Godot 4.0.
|
|
61
|
+
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"):
|
|
62
|
+
var adapter := GDScript.new()
|
|
63
|
+
adapter.source_code = FileAccess.get_file_as_string((get_script() as Script).resource_path.get_base_dir().path_join("creation_menu.gd.txt"))
|
|
64
|
+
if adapter.reload() == OK:
|
|
65
|
+
_creation_menu = adapter.new()
|
|
66
|
+
_creation_menu.create = _new_script.show_dialog
|
|
67
|
+
call("add_context_menu_plugin",3,_creation_menu) # CONTEXT_SLOT_FILESYSTEM_CREATE
|
|
58
68
|
add_tool_menu_item("Add Missing Gogo Imports",_services.add_missing_imports)
|
|
59
69
|
_timer = Timer.new()
|
|
60
70
|
_timer.one_shot = true
|
|
@@ -235,7 +245,12 @@ func _show_report() -> void:
|
|
|
235
245
|
|
|
236
246
|
func _exit_tree() -> void:
|
|
237
247
|
_active = false
|
|
238
|
-
remove_tool_menu_item("New Gogo
|
|
248
|
+
remove_tool_menu_item("New Gogo Component (2D)…")
|
|
249
|
+
remove_tool_menu_item("New Gogo Component (3D)…")
|
|
250
|
+
if _creation_menu != null:
|
|
251
|
+
call("remove_context_menu_plugin",_creation_menu)
|
|
252
|
+
_creation_menu.create = Callable()
|
|
253
|
+
_creation_menu = null
|
|
239
254
|
remove_tool_menu_item("Add Missing Gogo Imports")
|
|
240
255
|
if _navigation != null: _navigation.stop()
|
|
241
256
|
if _new_script != null: _new_script.stop(); _new_script = null
|
package/package.json
CHANGED