From 99b8624ce302bcc2dfc8940fa1ae4a5b0bb8b8ee Mon Sep 17 00:00:00 2001 From: Matt Pewsey <23442063+mpewsey@users.noreply.github.com> Date: Thu, 15 Aug 2024 07:59:03 -0400 Subject: [PATCH 1/2] Add backup load paths --- addons/mpewsey.maniamap/ManiaMapPlugin.cs | 6 ++--- addons/mpewsey.maniamap/plugin.cfg | 2 +- .../scripts/runtime/ManiaMapResources.cs | 9 ++++--- .../scripts/runtime/SceneRef.cs | 26 +++++++++++++++++++ 4 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 addons/mpewsey.maniamap/scripts/runtime/SceneRef.cs diff --git a/addons/mpewsey.maniamap/ManiaMapPlugin.cs b/addons/mpewsey.maniamap/ManiaMapPlugin.cs index 434bfb6..a9c41f8 100644 --- a/addons/mpewsey.maniamap/ManiaMapPlugin.cs +++ b/addons/mpewsey.maniamap/ManiaMapPlugin.cs @@ -124,7 +124,7 @@ private static Node FindContainingRoom(GodotObject obj) private void AddGraphEditorDock() { - var scene = ResourceLoader.Load(ManiaMapResources.Scenes.LayoutGraphEditorScene); + var scene = ManiaMapResources.Scenes.LayoutGraphEditorScene.Load(); GraphEditor = scene.Instantiate(); GraphEditorDockButton = AddControlToBottomPanel(GraphEditor, GraphEditorDockButtonName); GraphEditorDockButton.Visible = false; @@ -155,7 +155,7 @@ private void CreateRoomNode2DToolbar() var mainScreen2d = EditorInterface.Singleton.GetEditorMainScreen().GetChild(0); var hFlowContainers = mainScreen2d.FindChildren("*", nameof(HFlowContainer), true, false); var buttonContainer = (HFlowContainer)hFlowContainers[0]; - var scene = ResourceLoader.Load(ManiaMapResources.Scenes.RoomNode2DToolbarScene); + var scene = ManiaMapResources.Scenes.RoomNode2DToolbarScene.Load(); var toolbar = scene.Instantiate(); RoomNode2DToolbar = toolbar; buttonContainer.AddChild(toolbar); @@ -167,7 +167,7 @@ private void CreateRoomNode3DToolbar() var mainScreen3d = EditorInterface.Singleton.GetEditorMainScreen().GetChild(1); var hFlowContainers = mainScreen3d.FindChildren("*", nameof(HFlowContainer), true, false); var buttonContainer = (HFlowContainer)hFlowContainers[0]; - var scene = ResourceLoader.Load(ManiaMapResources.Scenes.RoomNode3DToolbarScene); + var scene = ManiaMapResources.Scenes.RoomNode3DToolbarScene.Load(); var toolbar = scene.Instantiate(); RoomNode3DToolbar = toolbar; buttonContainer.AddChild(toolbar); diff --git a/addons/mpewsey.maniamap/plugin.cfg b/addons/mpewsey.maniamap/plugin.cfg index d4c277a..b91e86d 100644 --- a/addons/mpewsey.maniamap/plugin.cfg +++ b/addons/mpewsey.maniamap/plugin.cfg @@ -3,5 +3,5 @@ name="ManiaMap.Godot" description="Procedural generation of metroidvania style maps for Godot .NET." author="Matt Pewsey" -version="1.0.1" +version="1.0.2" script="ManiaMapPlugin.cs" diff --git a/addons/mpewsey.maniamap/scripts/runtime/ManiaMapResources.cs b/addons/mpewsey.maniamap/scripts/runtime/ManiaMapResources.cs index 5acb7c7..58e0b00 100644 --- a/addons/mpewsey.maniamap/scripts/runtime/ManiaMapResources.cs +++ b/addons/mpewsey.maniamap/scripts/runtime/ManiaMapResources.cs @@ -23,9 +23,9 @@ public static class Enums /// public static class Scenes { - public const string LayoutGraphEditorScene = "uid://ckyjrhwvcs6fi"; - public const string RoomNode2DToolbarScene = "uid://ceij50wkmgvyi"; - public const string RoomNode3DToolbarScene = "uid://b25t77npx7a3l"; + public static SceneRef LayoutGraphEditorScene { get; } = new SceneRef("uid://ckyjrhwvcs6fi", "res://addons/mpewsey.maniamap/scenes/layout_graph_editor/layout_graph_editor.tscn"); + public static SceneRef RoomNode2DToolbarScene { get; } = new SceneRef("uid://ceij50wkmgvyi", "res://addons/mpewsey.maniamap/scenes/room_node_2d_toolbar/room_node_2d_toolbar.tscn"); + public static SceneRef RoomNode3DToolbarScene { get; } = new SceneRef("uid://b25t77npx7a3l", "res://addons/mpewsey.maniamap/scenes/room_node_3d_toolbar/room_node_3d_toolbar.tscn"); } /// @@ -33,7 +33,8 @@ public static class Scenes /// public static class Materials { - public static Material AlbedoMaterial { get; } = ResourceLoader.Load("uid://ppa2shs6thgv"); + public static SceneRef AlbedoMaterialPath { get; } = new SceneRef("uid://ppa2shs6thgv", "res://addons/mpewsey.maniamap/materials/albedo_material.tres"); + public static Material AlbedoMaterial { get; } = AlbedoMaterialPath.Load(); } /// diff --git a/addons/mpewsey.maniamap/scripts/runtime/SceneRef.cs b/addons/mpewsey.maniamap/scripts/runtime/SceneRef.cs new file mode 100644 index 0000000..6b780e9 --- /dev/null +++ b/addons/mpewsey.maniamap/scripts/runtime/SceneRef.cs @@ -0,0 +1,26 @@ +using Godot; + +namespace MPewsey.ManiaMapGodot +{ + public readonly struct SceneRef + { + public string UidPath { get; } + public string ResPath { get; } + + public SceneRef(string uidPath, string resPath) + { + UidPath = uidPath; + ResPath = resPath; + } + + public string GetLoadPath() + { + return ResourceLoader.Exists(UidPath) ? UidPath : ResPath; + } + + public T Load() where T : class + { + return ResourceLoader.Load(GetLoadPath()); + } + } +} \ No newline at end of file From a5be4af35cb76db4de717ac953e8365ff7c3583f Mon Sep 17 00:00:00 2001 From: Matt Pewsey <23442063+mpewsey@users.noreply.github.com> Date: Thu, 15 Aug 2024 08:15:20 -0400 Subject: [PATCH 2/2] Change SceneRef to PathRef --- .../mpewsey.maniamap/scripts/runtime/ManiaMapResources.cs | 8 ++++---- .../scripts/runtime/{SceneRef.cs => PathRef.cs} | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) rename addons/mpewsey.maniamap/scripts/runtime/{SceneRef.cs => PathRef.cs} (71%) diff --git a/addons/mpewsey.maniamap/scripts/runtime/ManiaMapResources.cs b/addons/mpewsey.maniamap/scripts/runtime/ManiaMapResources.cs index 58e0b00..0c6aee1 100644 --- a/addons/mpewsey.maniamap/scripts/runtime/ManiaMapResources.cs +++ b/addons/mpewsey.maniamap/scripts/runtime/ManiaMapResources.cs @@ -23,9 +23,9 @@ public static class Enums /// public static class Scenes { - public static SceneRef LayoutGraphEditorScene { get; } = new SceneRef("uid://ckyjrhwvcs6fi", "res://addons/mpewsey.maniamap/scenes/layout_graph_editor/layout_graph_editor.tscn"); - public static SceneRef RoomNode2DToolbarScene { get; } = new SceneRef("uid://ceij50wkmgvyi", "res://addons/mpewsey.maniamap/scenes/room_node_2d_toolbar/room_node_2d_toolbar.tscn"); - public static SceneRef RoomNode3DToolbarScene { get; } = new SceneRef("uid://b25t77npx7a3l", "res://addons/mpewsey.maniamap/scenes/room_node_3d_toolbar/room_node_3d_toolbar.tscn"); + public static PathRef LayoutGraphEditorScene { get; } = new PathRef("uid://ckyjrhwvcs6fi", "res://addons/mpewsey.maniamap/scenes/layout_graph_editor/layout_graph_editor.tscn"); + public static PathRef RoomNode2DToolbarScene { get; } = new PathRef("uid://ceij50wkmgvyi", "res://addons/mpewsey.maniamap/scenes/room_node_2d_toolbar/room_node_2d_toolbar.tscn"); + public static PathRef RoomNode3DToolbarScene { get; } = new PathRef("uid://b25t77npx7a3l", "res://addons/mpewsey.maniamap/scenes/room_node_3d_toolbar/room_node_3d_toolbar.tscn"); } /// @@ -33,7 +33,7 @@ public static class Scenes /// public static class Materials { - public static SceneRef AlbedoMaterialPath { get; } = new SceneRef("uid://ppa2shs6thgv", "res://addons/mpewsey.maniamap/materials/albedo_material.tres"); + public static PathRef AlbedoMaterialPath { get; } = new PathRef("uid://ppa2shs6thgv", "res://addons/mpewsey.maniamap/materials/albedo_material.tres"); public static Material AlbedoMaterial { get; } = AlbedoMaterialPath.Load(); } diff --git a/addons/mpewsey.maniamap/scripts/runtime/SceneRef.cs b/addons/mpewsey.maniamap/scripts/runtime/PathRef.cs similarity index 71% rename from addons/mpewsey.maniamap/scripts/runtime/SceneRef.cs rename to addons/mpewsey.maniamap/scripts/runtime/PathRef.cs index 6b780e9..0fd7008 100644 --- a/addons/mpewsey.maniamap/scripts/runtime/SceneRef.cs +++ b/addons/mpewsey.maniamap/scripts/runtime/PathRef.cs @@ -2,12 +2,12 @@ namespace MPewsey.ManiaMapGodot { - public readonly struct SceneRef + public readonly struct PathRef { public string UidPath { get; } public string ResPath { get; } - public SceneRef(string uidPath, string resPath) + public PathRef(string uidPath, string resPath) { UidPath = uidPath; ResPath = resPath; @@ -15,7 +15,7 @@ public SceneRef(string uidPath, string resPath) public string GetLoadPath() { - return ResourceLoader.Exists(UidPath) ? UidPath : ResPath; + return ResourceLoader.Exists(ResPath) ? ResPath : UidPath; } public T Load() where T : class