diff --git a/Package/build/Polonium.props b/Package/build/Polonium.props
new file mode 100644
index 0000000..cfe2713
--- /dev/null
+++ b/Package/build/Polonium.props
@@ -0,0 +1,7 @@
+
+
+ $(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 bcd3c70..d7ec3f6 100644
--- a/Package/build/Polonium.targets
+++ b/Package/build/Polonium.targets
@@ -1,38 +1,29 @@
-
- $(ProjectDir)script_templates/
- $(PoloniumTemplateTargetPath).polonium.manifest
-
-
+
+
+
+
+
+
+
+
+
-
+
+
+
+
-
-
-
-
-
-
+
+
-
+
-
+
+
+
+
-
+
+
+
+
+
-
-
+
+
-
-
-
-
-
-
-
-
-
+
+
diff --git a/Package/embedded/GlobalClasses/Nodes/Buttons/PoloniumTextureButton.cs b/Package/embedded/GlobalClasses/Nodes/Buttons/PoloniumTextureButton.cs
new file mode 100644
index 0000000..03a3550
--- /dev/null
+++ b/Package/embedded/GlobalClasses/Nodes/Buttons/PoloniumTextureButton.cs
@@ -0,0 +1,61 @@
+#pragma warning disable IDE0130
+using Godot;
+using Polonium.Attributes;
+using Polonium.DataStructures;
+using System.Collections.Generic;
+using Polonium.Interfaces;
+
+// ReSharper disable once CheckNamespace
+namespace GlobalClasses;
+[GlobalClass]
+[Tool]
+[ProxyNode]
+public partial class PoloniumTextureButton : TextureButton
+{
+ [ProxyProperty]
+ public virtual TextureSet TextureSet => null;
+
+ 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()
+ {
+ 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()
+ {
+ }
+}
+#pragma warning restore IDE0130
diff --git a/GlobalClasses/Scenes/CameraScene.cs b/Package/embedded/GlobalClasses/Nodes/Scenes/CameraScene.cs
similarity index 81%
rename from GlobalClasses/Scenes/CameraScene.cs
rename to Package/embedded/GlobalClasses/Nodes/Scenes/CameraScene.cs
index 02a5d59..6e0ad7a 100644
--- a/GlobalClasses/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]
@@ -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/Package/embedded/GlobalClasses/Nodes/Scenes/DissolveScene.cs
similarity index 71%
rename from GlobalClasses/Scenes/DissolveScene.cs
rename to Package/embedded/GlobalClasses/Nodes/Scenes/DissolveScene.cs
index 2094e2c..0722035 100644
--- a/GlobalClasses/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]
@@ -12,7 +13,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 +22,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 +38,8 @@ public partial class DissolveScene : Scene
{
Finished = false;
Terminated = false;
- Enter();
+ __Enter();
base._EnterTree();
}
}
+#pragma warning restore IDE0130
\ No newline at end of file
diff --git a/GlobalClasses/Scenes/RootScene.cs b/Package/embedded/GlobalClasses/Nodes/Scenes/RootScene.cs
similarity index 57%
rename from GlobalClasses/Scenes/RootScene.cs
rename to Package/embedded/GlobalClasses/Nodes/Scenes/RootScene.cs
index ab81dfb..e1db00c 100644
--- a/GlobalClasses/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]
@@ -19,28 +20,44 @@ 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();
+ }
+
}
+#pragma warning restore IDE0130
diff --git a/GlobalClasses/Scenes/Scene.cs b/Package/embedded/GlobalClasses/Nodes/Scenes/Scene.cs
similarity index 57%
rename from GlobalClasses/Scenes/Scene.cs
rename to Package/embedded/GlobalClasses/Nodes/Scenes/Scene.cs
index 1a1e7dd..c3135e0 100644
--- a/GlobalClasses/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 e7c6aa5..2336965 100644
--- a/Polonium.csproj
+++ b/Polonium.csproj
@@ -13,37 +13,26 @@
true
-
-
+
+
+
+
-
-
-
+
+
+
-
-
-
+
+
@@ -61,14 +50,13 @@
-
-
-
+
+
+
-
-
-
+
+
diff --git a/Polonium.sln b/Polonium.sln
index 98c8a12..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
@@ -16,28 +10,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/build b/build
new file mode 100755
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/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 63dd29d..24eab63 100644
--- a/src/Utils.cs
+++ b/src/Utils.cs
@@ -1,4 +1,7 @@
+#pragma warning disable CS0618
+#pragma warning disable CS0168
using System.Reflection;
+using Godot;
namespace Polonium;
@@ -15,4 +18,32 @@ public static class Utils
return e.Types.Where(t => t != null);
}
}
-}
\ No newline at end of file
+
+ private static Dictionary AnimatedTextureCache { get; } = 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;
+ }
+ }
+}
+#pragma warning restore CS0618
+#pragma warning restore CS0168
\ No newline at end of file