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