From 439ec27f30032dce5af900740f2e9f086308ae96 Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Sat, 23 Sep 2023 23:42:37 -0400 Subject: [PATCH] This gets past the first problem: the issue seems to be the broken uid that gets produced for ext_resource --- .../SwiftResourceFormatLoader.swift | 13 +++++++++++-- TestEditor/node_2d.tscn | 5 ++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Sources/SwiftGodotEditorExtension/SwiftResourceFormatLoader.swift b/Sources/SwiftGodotEditorExtension/SwiftResourceFormatLoader.swift index f123ba5bd..69fbe53a3 100644 --- a/Sources/SwiftGodotEditorExtension/SwiftResourceFormatLoader.swift +++ b/Sources/SwiftGodotEditorExtension/SwiftResourceFormatLoader.swift @@ -78,14 +78,23 @@ class SwiftResourceFormatLoader: ResourceFormatLoader { } open override func _load(path: String, originalPath: String, useSubThreads: Bool, cacheMode: Int32) -> Variant { - pm ("Request to load path=\(path) originalPath=\(originalPath) useSubthreads=\(useSubThreads) cacheMode=\(cacheMode) -> RETURNING 1") - var rootPath = ProjectSettings.shared.globalizePath(path) + pm ("Request to load path=\(path) originalPath=\(originalPath) useSubthreads=\(useSubThreads) cacheMode=\(cacheMode)") + var rootPath: String + + if path.hasSuffix("res://Sources/\(extensionName)/") { + rootPath = ProjectSettings.shared.globalizePath(path) + } else { + rootPath = ProjectSettings.shared.globalizePath("res://Sources/\(extensionName)/\(path.dropFirst (6))") + } + pm ("RESOLVED PATH: \(rootPath)") guard let contents = try? String (contentsOfFile: rootPath) else { + pm ("_LOAD: Failed to load the contents of \(rootPath)") return Variant (Int (GodotError.errCantOpen.rawValue)) } let script = SwiftScript() script.resourcePath = path script.sourceCode = contents + pm ("_LOAD: RETURNING SCRIPT") return Variant (script) } } diff --git a/TestEditor/node_2d.tscn b/TestEditor/node_2d.tscn index 83ddd113a..606cb8282 100644 --- a/TestEditor/node_2d.tscn +++ b/TestEditor/node_2d.tscn @@ -1,7 +1,10 @@ -[gd_scene format=3 uid="uid://b2yh1fspd2mci"] +[gd_scene load_steps=2 format=3 uid="uid://b2yh1fspd2mci"] + +[ext_resource type="Script" path="res://Anotjer.swift" id="1_8tx7h"] [node name="Node2D" type="Node2D"] [node name="Node" type="Node" parent="."] +script = ExtResource("1_8tx7h") [node name="Node2" type="Node" parent="."]