From 5a981c91ee0f3c3f86c5008c316480f052d9bbba Mon Sep 17 00:00:00 2001 From: hzhang Date: Sat, 15 Feb 2025 08:25:01 +0000 Subject: [PATCH 1/5] draft: texture button --- .../Nodes/Buttons/PoloniumTextureButton.cs | 40 +++++++++++++++++++ .../{ => Nodes}/Scenes/CameraScene.cs | 9 ++++- .../{ => Nodes}/Scenes/DissolveScene.cs | 10 ++--- GlobalClasses/{ => Nodes}/Scenes/RootScene.cs | 35 +++++++++++----- GlobalClasses/{ => Nodes}/Scenes/Scene.cs | 0 Package/build/Polonium.targets | 19 +++++++++ Polonium.csproj | 14 ++++++- build | 17 ++++++++ src/Attributes/ProxyProperty.cs | 6 +++ src/DataStructures/TextureSet.cs | 33 +++++++++++++++ src/Utils.cs | 28 +++++++++++++ 11 files changed, 193 insertions(+), 18 deletions(-) create mode 100644 GlobalClasses/Nodes/Buttons/PoloniumTextureButton.cs rename GlobalClasses/{ => Nodes}/Scenes/CameraScene.cs (85%) rename GlobalClasses/{ => Nodes}/Scenes/DissolveScene.cs (79%) rename GlobalClasses/{ => Nodes}/Scenes/RootScene.cs (62%) rename GlobalClasses/{ => Nodes}/Scenes/Scene.cs (100%) create mode 100644 build create mode 100644 src/Attributes/ProxyProperty.cs create mode 100644 src/DataStructures/TextureSet.cs diff --git a/GlobalClasses/Nodes/Buttons/PoloniumTextureButton.cs b/GlobalClasses/Nodes/Buttons/PoloniumTextureButton.cs new file mode 100644 index 0000000..ebb24ec --- /dev/null +++ b/GlobalClasses/Nodes/Buttons/PoloniumTextureButton.cs @@ -0,0 +1,40 @@ +using Godot; +using Polonium.Attributes; +using Polonium.DataStructures; +using System.Collections.Generic; + + +namespace GlobalClasses; +[GlobalClass] +[Tool] +[ProxyNode] +public partial class PoloniumTextureButton : TextureButton +{ + [ProxyProperty] + public virtual TextureSet TextureSet => null; + + [Export] + public GlobalRegistry.TextureSetName TextureSetName { get; set; } + + public sealed override void _Ready() + { + TextureSet t = TextureSet; + if (t is null) + t = GlobalRegistry.TextureSetMap.GetValueOrDefault(TextureSetName, null); + if (t is not null) + { + TextureNormal = t.Normal; + TextureHover = t.Hover; + TexturePressed = t.Pressed; + TextureDisabled = t.Disabled; + TextureFocused = t.Focused; + } + + __Ready(); + base._Ready(); + } + [ProxyMethod] + public virtual void __Ready() + { + } +} \ No newline at end of file diff --git a/GlobalClasses/Scenes/CameraScene.cs b/GlobalClasses/Nodes/Scenes/CameraScene.cs similarity index 85% rename from GlobalClasses/Scenes/CameraScene.cs rename to GlobalClasses/Nodes/Scenes/CameraScene.cs index 02a5d59..7b31902 100644 --- a/GlobalClasses/Scenes/CameraScene.cs +++ b/GlobalClasses/Nodes/Scenes/CameraScene.cs @@ -20,9 +20,16 @@ public partial class CameraScene : Scene get => Camera.Zoom.X; set => Camera.Zoom = value * Vector2.One; } - public override void _Ready() + + [ProxyMethod] + public virtual void __Ready() + { + } + + public sealed override void _Ready() { Camera = GetNode("Camera"); + __Ready(); base._Ready(); } protected void ZoomIn() => Zoom = Mathf.Max(Zoom * (1 + ZoomRate), MaxZoom); diff --git a/GlobalClasses/Scenes/DissolveScene.cs b/GlobalClasses/Nodes/Scenes/DissolveScene.cs similarity index 79% rename from GlobalClasses/Scenes/DissolveScene.cs rename to GlobalClasses/Nodes/Scenes/DissolveScene.cs index 2094e2c..1059652 100644 --- a/GlobalClasses/Scenes/DissolveScene.cs +++ b/GlobalClasses/Nodes/Scenes/DissolveScene.cs @@ -12,7 +12,7 @@ public partial class DissolveScene : Scene private bool Finished { get; set; } = false; private bool Terminated { get; set; } = false; - public override void _Process(double delta) + public sealed override void _Process(double delta) { if(Finished && !Terminated) { @@ -21,15 +21,15 @@ public partial class DissolveScene : Scene return; } - Process(delta); + __Process(delta); base._Process(delta); } [ProxyMethod] - public virtual void Enter() + public virtual void __Enter() { } [ProxyMethod] - public virtual void Process(double delta) + public virtual void __Process(double delta) { } @@ -37,7 +37,7 @@ public partial class DissolveScene : Scene { Finished = false; Terminated = false; - Enter(); + __Enter(); base._EnterTree(); } } diff --git a/GlobalClasses/Scenes/RootScene.cs b/GlobalClasses/Nodes/Scenes/RootScene.cs similarity index 62% rename from GlobalClasses/Scenes/RootScene.cs rename to GlobalClasses/Nodes/Scenes/RootScene.cs index ab81dfb..7eb507f 100644 --- a/GlobalClasses/Scenes/RootScene.cs +++ b/GlobalClasses/Nodes/Scenes/RootScene.cs @@ -19,28 +19,43 @@ public partial class RootScene : Scene CurrentScene = scene; } - public override void _Ready() - { - GlobalRegistry.RootScene = this; - base._Ready(); - } - [ProxyMethod] - public virtual void Enter() + public virtual void __Enter() { } - public override void _EnterTree() + [ProxyMethod] + public virtual void __Ready() { - Enter(); + } + + [ProxyMethod] + public virtual void __Process(double delta) + { + } + + public sealed override void _EnterTree() + { + GlobalRegistry.Prepare(); + GlobalRegistry.Start(); + __Enter(); base._EnterTree(); } - public override void _Process(double delta) + public sealed override void _Process(double delta) { if(!GlobalRegistry.Paused) foreach (ITimeConsumer tc in GlobalRegistry.TimeConsumers) tc.Process(delta); + __Process(delta); base._Process(delta); } + + public sealed override void _Ready() + { + GlobalRegistry.RootScene = this; + __Ready(); + base._Ready(); + } + } diff --git a/GlobalClasses/Scenes/Scene.cs b/GlobalClasses/Nodes/Scenes/Scene.cs similarity index 100% rename from GlobalClasses/Scenes/Scene.cs rename to GlobalClasses/Nodes/Scenes/Scene.cs diff --git a/Package/build/Polonium.targets b/Package/build/Polonium.targets index bcd3c70..a4d1ab6 100644 --- a/Package/build/Polonium.targets +++ b/Package/build/Polonium.targets @@ -13,7 +13,11 @@ + + + + + + + + + + + + + + + + diff --git a/Polonium.csproj b/Polonium.csproj index e7c6aa5..c2fed99 100644 --- a/Polonium.csproj +++ b/Polonium.csproj @@ -16,13 +16,14 @@ - + + + + + + + diff --git a/build b/build new file mode 100644 index 0000000..070fbd2 --- /dev/null +++ b/build @@ -0,0 +1,17 @@ +#! /bin/bash +rm -rf ~/.nuget/packages/polonium* +cd ../Polonium.Tasks +dotnet clean Polonium.Tasks.csproj +dotnet restore Polonium.Tasks.csproj +dotnet build Polonium.Tasks.csproj + +cd ../Polonium.Generators +dotnet clean Polonium.Generators.csproj +dotnet restore Polonium.Generators.csproj +dotnet build Polonium.Generators.csproj + +cd ../Polonium +rm -rf ~/.nuget/packages/polonium* +dotnet clean Polonium.csproj +dotnet restore Polonium.csproj +dotnet build Polonium.csproj diff --git a/src/Attributes/ProxyProperty.cs b/src/Attributes/ProxyProperty.cs new file mode 100644 index 0000000..a5cc0e3 --- /dev/null +++ b/src/Attributes/ProxyProperty.cs @@ -0,0 +1,6 @@ +namespace Polonium.Attributes; +[AttributeUsage(AttributeTargets.Property)] +public class ProxyProperty : Attribute +{ + +} \ No newline at end of file diff --git a/src/DataStructures/TextureSet.cs b/src/DataStructures/TextureSet.cs new file mode 100644 index 0000000..5617c17 --- /dev/null +++ b/src/DataStructures/TextureSet.cs @@ -0,0 +1,33 @@ +using Godot; +using FileAccess = Godot.FileAccess; + +namespace Polonium.DataStructures; + +public class TextureSet +{ + public TextureSet(string path) + { + Normal = LoadTexture($"{path}/Normal"); + Pressed = LoadTexture($"{path}/Pressed"); + Disabled = LoadTexture($"{path}/Disabled"); + Hover = LoadTexture($"{path}/Hover"); + Focused = LoadTexture($"{path}/Focused"); + } + public Texture2D Normal { get; init; } + public Texture2D Pressed { get; init; } + public Texture2D Hover { get; init; } + public Texture2D Disabled { get; init; } + public Texture2D Focused { get; init; } + + private static Texture2D LoadTexture(string path) + { + Texture2D res = new(); + if(FileAccess.FileExists($"{path}.png")) + res = ResourceLoader.Load($"{path}.png"); + else if(DirAccess.DirExistsAbsolute($"{path}.at_dir")) + res = Utils.LoadAnimatedTextureFromDirectory($"{path}.at_dir"); + return res; + } + + +} \ No newline at end of file diff --git a/src/Utils.cs b/src/Utils.cs index 63dd29d..ae1d1a8 100644 --- a/src/Utils.cs +++ b/src/Utils.cs @@ -1,4 +1,5 @@ using System.Reflection; +using Godot; namespace Polonium; @@ -15,4 +16,31 @@ public static class Utils return e.Types.Where(t => t != null); } } + + private static Dictionary AnimatedTextureCache = new (); + public static AnimatedTexture LoadAnimatedTextureFromDirectory(StringName path) + { + try + { + if (!AnimatedTextureCache.ContainsKey(path)) + { + AnimatedTextureCache[path] = new AnimatedTexture(); + int f = 0; + foreach (string fname in DirAccess.GetFilesAt(path)) + { + if (!fname.EndsWith(".png")) + continue; + AnimatedTextureCache[path].SetFrameTexture(f, ResourceLoader.Load(fname)); + } + } + + return AnimatedTextureCache[path]; + } + catch (Exception e) + { + return null; + } + } + + } \ No newline at end of file From f290b52fa3e1003a86edcc24b6937f3de7c2d4ec Mon Sep 17 00:00:00 2001 From: hzhang Date: Sun, 16 Feb 2025 22:36:38 +0000 Subject: [PATCH 2/5] refactor: redesign project structure --- Package/build/Polonium.props | 6 ++ Package/build/Polonium.targets | 88 +++++++------------ .../Nodes/Buttons/PoloniumTextureButton.cs | 7 +- .../Nodes/Scenes/CameraScene.cs | 2 +- .../Nodes/Scenes/DissolveScene.cs | 4 +- .../GlobalClasses}/Nodes/Scenes/RootScene.cs | 4 +- .../GlobalClasses}/Nodes/Scenes/Scene.cs | 4 +- Package/embedded/Patches/GlobalRegistry.p.cs | 57 ++++++++++++ Polonium.csproj | 40 +++------ Polonium.sln | 16 ---- src/Interfaces/IGlobalRegistry.cs | 8 ++ src/Utils.cs | 13 +-- 12 files changed, 136 insertions(+), 113 deletions(-) create mode 100644 Package/build/Polonium.props rename {GlobalClasses => Package/embedded/GlobalClasses}/Nodes/Buttons/PoloniumTextureButton.cs (89%) rename {GlobalClasses => Package/embedded/GlobalClasses}/Nodes/Scenes/CameraScene.cs (95%) rename {GlobalClasses => Package/embedded/GlobalClasses}/Nodes/Scenes/DissolveScene.cs (89%) rename {GlobalClasses => Package/embedded/GlobalClasses}/Nodes/Scenes/RootScene.cs (91%) rename {GlobalClasses => Package/embedded/GlobalClasses}/Nodes/Scenes/Scene.cs (57%) create mode 100644 Package/embedded/Patches/GlobalRegistry.p.cs create mode 100644 src/Interfaces/IGlobalRegistry.cs diff --git a/Package/build/Polonium.props b/Package/build/Polonium.props new file mode 100644 index 0000000..bdb10e4 --- /dev/null +++ b/Package/build/Polonium.props @@ -0,0 +1,6 @@ + + + $(ProjectDir)script_templates/ + $(ProjectDir)embedded/templates.polonium.manifest + + \ No newline at end of file diff --git a/Package/build/Polonium.targets b/Package/build/Polonium.targets index a4d1ab6..5ec5bfc 100644 --- a/Package/build/Polonium.targets +++ b/Package/build/Polonium.targets @@ -1,12 +1,20 @@ - - $(ProjectDir)script_templates/ - $(PoloniumTemplateTargetPath).polonium.manifest - - + + + + + + + + + + + + - + + @@ -16,27 +24,9 @@ - - - - - - - - + + - + - + + + + - + + + + + - - - - - - - - - - - - - - - - - - - - - - + + diff --git a/GlobalClasses/Nodes/Buttons/PoloniumTextureButton.cs b/Package/embedded/GlobalClasses/Nodes/Buttons/PoloniumTextureButton.cs similarity index 89% rename from GlobalClasses/Nodes/Buttons/PoloniumTextureButton.cs rename to Package/embedded/GlobalClasses/Nodes/Buttons/PoloniumTextureButton.cs index ebb24ec..3e087bb 100644 --- a/GlobalClasses/Nodes/Buttons/PoloniumTextureButton.cs +++ b/Package/embedded/GlobalClasses/Nodes/Buttons/PoloniumTextureButton.cs @@ -1,9 +1,9 @@ +#pragma warning disable IDE0130 using Godot; using Polonium.Attributes; using Polonium.DataStructures; using System.Collections.Generic; - - +// ReSharper disable once CheckNamespace namespace GlobalClasses; [GlobalClass] [Tool] @@ -37,4 +37,5 @@ public partial class PoloniumTextureButton : TextureButton public virtual void __Ready() { } -} \ No newline at end of file +} +#pragma warning restore IDE0130 diff --git a/GlobalClasses/Nodes/Scenes/CameraScene.cs b/Package/embedded/GlobalClasses/Nodes/Scenes/CameraScene.cs similarity index 95% rename from GlobalClasses/Nodes/Scenes/CameraScene.cs rename to Package/embedded/GlobalClasses/Nodes/Scenes/CameraScene.cs index 7b31902..6e0ad7a 100644 --- a/GlobalClasses/Nodes/Scenes/CameraScene.cs +++ b/Package/embedded/GlobalClasses/Nodes/Scenes/CameraScene.cs @@ -1,6 +1,6 @@ using Godot; using Polonium.Attributes; - +// ReSharper disable once CheckNamespace namespace GlobalClasses; [ProxyNode] [GlobalClass] diff --git a/GlobalClasses/Nodes/Scenes/DissolveScene.cs b/Package/embedded/GlobalClasses/Nodes/Scenes/DissolveScene.cs similarity index 89% rename from GlobalClasses/Nodes/Scenes/DissolveScene.cs rename to Package/embedded/GlobalClasses/Nodes/Scenes/DissolveScene.cs index 1059652..0722035 100644 --- a/GlobalClasses/Nodes/Scenes/DissolveScene.cs +++ b/Package/embedded/GlobalClasses/Nodes/Scenes/DissolveScene.cs @@ -1,6 +1,7 @@ +#pragma warning disable IDE0130 using Godot; using Polonium.Attributes; - +// ReSharper disable once CheckNamespace namespace GlobalClasses; [ProxyNode] [GlobalClass] @@ -41,3 +42,4 @@ public partial class DissolveScene : Scene base._EnterTree(); } } +#pragma warning restore IDE0130 \ No newline at end of file diff --git a/GlobalClasses/Nodes/Scenes/RootScene.cs b/Package/embedded/GlobalClasses/Nodes/Scenes/RootScene.cs similarity index 91% rename from GlobalClasses/Nodes/Scenes/RootScene.cs rename to Package/embedded/GlobalClasses/Nodes/Scenes/RootScene.cs index 7eb507f..e1db00c 100644 --- a/GlobalClasses/Nodes/Scenes/RootScene.cs +++ b/Package/embedded/GlobalClasses/Nodes/Scenes/RootScene.cs @@ -1,7 +1,8 @@ +#pragma warning disable IDE0130 using Godot; using Polonium.Attributes; using Polonium.Interfaces; - +// ReSharper disable once CheckNamespace namespace GlobalClasses; [ProxyNode] [GlobalClass] @@ -59,3 +60,4 @@ public partial class RootScene : Scene } } +#pragma warning restore IDE0130 diff --git a/GlobalClasses/Nodes/Scenes/Scene.cs b/Package/embedded/GlobalClasses/Nodes/Scenes/Scene.cs similarity index 57% rename from GlobalClasses/Nodes/Scenes/Scene.cs rename to Package/embedded/GlobalClasses/Nodes/Scenes/Scene.cs index 1a1e7dd..c3135e0 100644 --- a/GlobalClasses/Nodes/Scenes/Scene.cs +++ b/Package/embedded/GlobalClasses/Nodes/Scenes/Scene.cs @@ -1,6 +1,7 @@ +#pragma warning disable IDE0130 using Godot; using Polonium.Attributes; - +// ReSharper disable once CheckNamespace namespace GlobalClasses; [ProxyNode] [GlobalClass] @@ -9,3 +10,4 @@ public partial class Scene : Node2D { } +#pragma warning restore IDE0130 diff --git a/Package/embedded/Patches/GlobalRegistry.p.cs b/Package/embedded/Patches/GlobalRegistry.p.cs new file mode 100644 index 0000000..ee28e05 --- /dev/null +++ b/Package/embedded/Patches/GlobalRegistry.p.cs @@ -0,0 +1,57 @@ +#pragma warning disable IDE0130 +#pragma warning disable CA1000 +using Godot; +using System; +using System.Linq; +using System.Reflection; +using Polonium.Attributes; +using Polonium; +using Polonium.Interfaces; +using System.Collections.Generic; + +// ReSharper disable once CheckNamespace +public static partial class GlobalRegistry +{ + public static void Start() + { + PoloniumRegistry.Prepare(); + Assembly assembly = Assembly.GetExecutingAssembly(); + IEnumerable registerTypes = Utils.GetLoadableTypes(assembly); + registerTypes = registerTypes.Where(t => t.IsClass && t.GetCustomAttributes(typeof(AutoRegister), false).Any()); + foreach (Type t in registerTypes) + { + MethodInfo registerMethod = t.GetMethod("Register", BindingFlags.Static | BindingFlags.Public); + if (registerMethod != null) + registerMethod.Invoke(null, null); + } + } + + public static class Asset where T : Node + { + private static readonly Queue Pool = new(); + // ReSharper disable once StaticMemberInGenericType + // ReSharper disable once UnusedAutoPropertyAccessor.Global + public static PackedScene Scene { get; set; } + private static T Instance => Scene.Instantiate(); + public static T Get() => Pool.Count > 0 ? Pool.Dequeue() : Instance; + + public static void Return(T obj) + { + if(Pool.Count < 10) + Pool.Enqueue(obj); + else + obj.QueueFree(); + } + } + public static PoloniumRegistry PoloniumRegistry => PoloniumRegistry.Instance; + public static bool Paused { get; set; } + public static HashSet TimeConsumers { get; } = []; + public static void Prepare() => PoloniumRegistry.Prepare(); + + // ReSharper disable once PartialTypeWithSinglePart + public static partial class TextureSets + { + } +} +#pragma warning restore IDE0130 +#pragma warning restore CA1000 diff --git a/Polonium.csproj b/Polonium.csproj index c2fed99..996962f 100644 --- a/Polonium.csproj +++ b/Polonium.csproj @@ -13,47 +13,27 @@ true - + + - - - - + + + - - - - - - - + + + diff --git a/Polonium.sln b/Polonium.sln index 98c8a12..7162937 100644 --- a/Polonium.sln +++ b/Polonium.sln @@ -16,28 +16,12 @@ Global GlobalSection(ProjectConfigurationPlatforms) = postSolution {5BA39DF8-7098-4348-A670-B3F34269F48F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {5BA39DF8-7098-4348-A670-B3F34269F48F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5BA39DF8-7098-4348-A670-B3F34269F48F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5BA39DF8-7098-4348-A670-B3F34269F48F}.Release|Any CPU.Build.0 = Release|Any CPU {41B784D2-841C-44D6-90F3-9219BC264B19}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {41B784D2-841C-44D6-90F3-9219BC264B19}.Debug|Any CPU.Build.0 = Debug|Any CPU {41B784D2-841C-44D6-90F3-9219BC264B19}.Release|Any CPU.ActiveCfg = Release|Any CPU {41B784D2-841C-44D6-90F3-9219BC264B19}.Release|Any CPU.Build.0 = Release|Any CPU {3BADB215-214B-41C1-B94E-89AF4A972F30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {3BADB215-214B-41C1-B94E-89AF4A972F30}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3BADB215-214B-41C1-B94E-89AF4A972F30}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3BADB215-214B-41C1-B94E-89AF4A972F30}.Release|Any CPU.Build.0 = Release|Any CPU - {1B24F8AC-B185-48D0-835B-59857AF907E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1B24F8AC-B185-48D0-835B-59857AF907E5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1B24F8AC-B185-48D0-835B-59857AF907E5}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1B24F8AC-B185-48D0-835B-59857AF907E5}.Release|Any CPU.Build.0 = Release|Any CPU - {D2BA966D-140F-4C04-8EE1-88FFE5FEB67C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D2BA966D-140F-4C04-8EE1-88FFE5FEB67C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D2BA966D-140F-4C04-8EE1-88FFE5FEB67C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D2BA966D-140F-4C04-8EE1-88FFE5FEB67C}.Release|Any CPU.Build.0 = Release|Any CPU - {25595747-BE10-4F36-BDE0-9400576EA921}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {25595747-BE10-4F36-BDE0-9400576EA921}.Debug|Any CPU.Build.0 = Debug|Any CPU - {25595747-BE10-4F36-BDE0-9400576EA921}.Release|Any CPU.ActiveCfg = Release|Any CPU - {25595747-BE10-4F36-BDE0-9400576EA921}.Release|Any CPU.Build.0 = Release|Any CPU {5F0664A8-563F-408A-9EB6-05B2F25F5DC5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {5F0664A8-563F-408A-9EB6-05B2F25F5DC5}.Debug|Any CPU.Build.0 = Debug|Any CPU {5F0664A8-563F-408A-9EB6-05B2F25F5DC5}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/src/Interfaces/IGlobalRegistry.cs b/src/Interfaces/IGlobalRegistry.cs new file mode 100644 index 0000000..6542a3e --- /dev/null +++ b/src/Interfaces/IGlobalRegistry.cs @@ -0,0 +1,8 @@ +namespace Polonium.Interfaces; + +public interface IGlobalRegistry +{ + public bool Paused { get; set; } + public void Start(); + public void Prepare(); +} \ No newline at end of file diff --git a/src/Utils.cs b/src/Utils.cs index ae1d1a8..24eab63 100644 --- a/src/Utils.cs +++ b/src/Utils.cs @@ -1,3 +1,5 @@ +#pragma warning disable CS0618 +#pragma warning disable CS0168 using System.Reflection; using Godot; @@ -16,8 +18,9 @@ public static class Utils return e.Types.Where(t => t != null); } } - - private static Dictionary AnimatedTextureCache = new (); + + private static Dictionary AnimatedTextureCache { get; } = new(); + public static AnimatedTexture LoadAnimatedTextureFromDirectory(StringName path) { try @@ -41,6 +44,6 @@ public static class Utils return null; } } - - -} \ No newline at end of file +} +#pragma warning restore CS0618 +#pragma warning restore CS0168 \ No newline at end of file From 604b7dd6d8d06346a62c65ccd7a2fc45fd48dc62 Mon Sep 17 00:00:00 2001 From: hzhang Date: Mon, 17 Feb 2025 02:49:21 +0000 Subject: [PATCH 3/5] refactor: redesign project structures --- Package/build/Polonium.props | 4 ++++ Package/build/Polonium.targets | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Package/build/Polonium.props b/Package/build/Polonium.props index bdb10e4..2ffe488 100644 --- a/Package/build/Polonium.props +++ b/Package/build/Polonium.props @@ -3,4 +3,8 @@ $(ProjectDir)script_templates/ $(ProjectDir)embedded/templates.polonium.manifest + \ No newline at end of file diff --git a/Package/build/Polonium.targets b/Package/build/Polonium.targets index 5ec5bfc..be0041a 100644 --- a/Package/build/Polonium.targets +++ b/Package/build/Polonium.targets @@ -1,8 +1,6 @@ - - From f9a6dbe55bbebc825034231d6ddfc14efa56e84b Mon Sep 17 00:00:00 2001 From: hzhang Date: Tue, 18 Feb 2025 11:41:05 +0000 Subject: [PATCH 4/5] add: sdk --- Package/build/Polonium.props | 5 +---- Package/build/Polonium.targets | 5 ++--- Polonium.csproj | 12 +++++------- Polonium.sln | 6 ------ build | 0 5 files changed, 8 insertions(+), 20 deletions(-) mode change 100644 => 100755 build diff --git a/Package/build/Polonium.props b/Package/build/Polonium.props index 2ffe488..cfe2713 100644 --- a/Package/build/Polonium.props +++ b/Package/build/Polonium.props @@ -3,8 +3,5 @@ $(ProjectDir)script_templates/ $(ProjectDir)embedded/templates.polonium.manifest - + \ No newline at end of file diff --git a/Package/build/Polonium.targets b/Package/build/Polonium.targets index be0041a..d7ec3f6 100644 --- a/Package/build/Polonium.targets +++ b/Package/build/Polonium.targets @@ -1,6 +1,5 @@ - @@ -46,13 +45,13 @@ DestinationFolder="$(ProjectDir)embedded/%(RecursiveDir)" /> - + - + - @@ -51,14 +50,13 @@ - - - + + + - - - + + diff --git a/Polonium.sln b/Polonium.sln index 7162937..c944752 100644 --- a/Polonium.sln +++ b/Polonium.sln @@ -2,12 +2,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Polonium", "Polonium.csproj", "{5BA39DF8-7098-4348-A670-B3F34269F48F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Polonium.Generators", "..\Polonium.Generators\Polonium.Generators.csproj", "{41B784D2-841C-44D6-90F3-9219BC264B19}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Polonium.Generators.Test", "..\Polonium.Generators.Test\Polonium.Generators.Test.csproj", "{3BADB215-214B-41C1-B94E-89AF4A972F30}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Polonium.Tasks", "..\Polonium.Tasks\Polonium.Tasks.csproj", "{5F0664A8-563F-408A-9EB6-05B2F25F5DC5}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/build b/build old mode 100644 new mode 100755 From a95de5aa59b28e1eab1d6be57cda1d8226fe8817 Mon Sep 17 00:00:00 2001 From: hzhang Date: Tue, 18 Feb 2025 14:28:26 +0000 Subject: [PATCH 5/5] improve: dynamic textureset --- .../Nodes/Buttons/PoloniumTextureButton.cs | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Package/embedded/GlobalClasses/Nodes/Buttons/PoloniumTextureButton.cs b/Package/embedded/GlobalClasses/Nodes/Buttons/PoloniumTextureButton.cs index 3e087bb..03a3550 100644 --- a/Package/embedded/GlobalClasses/Nodes/Buttons/PoloniumTextureButton.cs +++ b/Package/embedded/GlobalClasses/Nodes/Buttons/PoloniumTextureButton.cs @@ -3,6 +3,8 @@ using Godot; using Polonium.Attributes; using Polonium.DataStructures; using System.Collections.Generic; +using Polonium.Interfaces; + // ReSharper disable once CheckNamespace namespace GlobalClasses; [GlobalClass] @@ -13,8 +15,26 @@ public partial class PoloniumTextureButton : TextureButton [ProxyProperty] public virtual TextureSet TextureSet => null; - [Export] - public GlobalRegistry.TextureSetName TextureSetName { get; set; } + private GlobalRegistry.TextureSetName PrivateTextureSetName { get; set; } + + [Export] + public GlobalRegistry.TextureSetName TextureSetName + { + get => PrivateTextureSetName; + set + { + PrivateTextureSetName = value; + t = GlobalRegistry.TextureSetMap.GetValueOrDefault(value, null); + if (t is not null) + { + TextureNormal = t.Normal; + TextureHover = t.Hover; + TexturePressed = t.Pressed; + TextureDisabled = t.Disabled; + TextureFocused = t.Focused; + } + } + } public sealed override void _Ready() {