refactor: redesign project structure
This commit is contained in:
6
Package/build/Polonium.props
Normal file
6
Package/build/Polonium.props
Normal file
@@ -0,0 +1,6 @@
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<PoloniumTemplateTargetPath>$(ProjectDir)script_templates/</PoloniumTemplateTargetPath>
|
||||
<PoloniumTemplateManifest>$(ProjectDir)embedded/templates.polonium.manifest</PoloniumTemplateManifest>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -1,12 +1,20 @@
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<PoloniumTemplateTargetPath>$(ProjectDir)script_templates/</PoloniumTemplateTargetPath>
|
||||
<PoloniumTemplateManifest>$(PoloniumTemplateTargetPath).polonium.manifest</PoloniumTemplateManifest>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Label="Scene">
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Polonium.Generators" Version="0.1.1-x" />
|
||||
<PackageReference Include="Polonium.Tasks" Version="0.1.1-x"/>
|
||||
<Folder Include="Concepts"/>
|
||||
<Folder Include="Assets"/>
|
||||
<Folder Include="Registries"/>
|
||||
<Folder Include="Data"/>
|
||||
<Folder Include="Resources"/>
|
||||
<None Include="script_templates/**/*.*"/>
|
||||
<Compile Remove="script_templates/**/*.*"/>
|
||||
<Compile Remove="embedded/polonium_templates/**/*.cs"/>
|
||||
<AdditionalFiles Include="Assets/**/*.tscn"/>
|
||||
</ItemGroup>
|
||||
<Target Name="EnsureFolders" BeforeTargets="BeforeBuild">
|
||||
|
||||
<Target Name="PoloniumPrepare" BeforeTargets="PoloniumClean">
|
||||
<Message Text="Executing EnsureFolders target" Importance="High"/>
|
||||
<Message Text="$(ProjectDir)" Importance="High"/>
|
||||
<MakeDir Directories="$(ProjectDir)Assets" Condition="!Exists('$(ProjectDir)Assets')"/>
|
||||
@@ -16,27 +24,9 @@
|
||||
<MakeDir Directories="$(ProjectDir)Resources" Condition="!Exists('$(ProjectDir)Resources')"/>
|
||||
<MakeDir Directories="$(ProjectDir)Resources/ButtonTextureSet" Condition="!Exists('$(ProjectDir)Resources/ButtonTextureSet')"/>
|
||||
<MakeDir Directories="$(ProjectDir)script_templates" Condition="!Exists('$(ProjectDir)script_templates')"/>
|
||||
<MakeDir Directories="$(ProjectDir).polonium" Condition="!Exists('$(ProjectDir).polonium')"/>
|
||||
<MakeDir Directories="$(ProjectDir).polonium/Patches" Condition="!Exists('$(ProjectDir).polonium/Patches')" />
|
||||
<Exec
|
||||
Command='rmdir "$(ProjectDir)GlobalClasses"'
|
||||
Condition="'$(OS)'=='Windows_NT' and Exists('$(ProjectDir)GlobalClasses')"
|
||||
/>
|
||||
<Exec
|
||||
Command='mklink /D "$(ProjectDir)GlobalClasses" "$(MSBuildThisFileDirectory)GlobalClasses"'
|
||||
Condition="'$(OS)'=='Windows_NT' and !Exists('$(ProjectDir)GlobalClasses')"
|
||||
/>
|
||||
<Exec
|
||||
Command='rm -rf "$(ProjectDir)GlobalClasses"'
|
||||
Condition="'$(OS)'!='Windows_NT' and Exists('$(ProjectDir)GlobalClasses')"
|
||||
/>
|
||||
<Exec
|
||||
Command='ln -s "$(MSBuildThisFileDirectory)GlobalClasses" "$(ProjectDir)GlobalClasses"'
|
||||
Condition="'$(OS)'!='Windows_NT' and !Exists('$(ProjectDir)GlobalClasses')"
|
||||
/>
|
||||
</Target>
|
||||
|
||||
<Target Name="CleanPoloniumTemplates" BeforeTargets="CopyPoloniumTemplates">
|
||||
|
||||
<Target Name="PoloniumClean" DependsOnTargets="PoloniumPrepare" BeforeTargets="PoloniumRegenerate">
|
||||
<ReadLinesFromFile
|
||||
File="$(PoloniumTemplateManifest)"
|
||||
Condition="Exists('$(PoloniumTemplateManifest)')"
|
||||
@@ -44,16 +34,22 @@
|
||||
<Output TaskParameter="Lines" ItemName="PreviousTemplateFiles"/>
|
||||
</ReadLinesFromFile>
|
||||
<Delete Files="@(PreviousTemplateFiles)" Condition="@(PreviousTemplateFiles) != ''" />
|
||||
<Delete
|
||||
Files="$(PoloniumTemplateManifest)"
|
||||
Condition="Exists('$(PoloniumTemplateManifest)')"
|
||||
/>
|
||||
<RemoveDir Directories="$(ProjectDir)embedded" Condition="Exists('$(ProjectDir)embedded')"/>
|
||||
</Target>
|
||||
<Target Name="CopyPoloniumTemplates" DependsOnTargets="CleanPoloniumTemplates" AfterTargets="Build">
|
||||
|
||||
|
||||
<Target Name="PoloniumRegenerate" DependsOnTargets="PoloniumClean" BeforeTargets="CoreCompile">
|
||||
<MakeDir Directories="$(ProjectDir)" Condition="!Exists('$(ProjectDir)embedded')"/>
|
||||
<ItemGroup>
|
||||
<PoloniumTemplateFiles Include="$(MSBuildThisFileDirectory)polonium_templates/**/*.*"/>
|
||||
<EmbeddedFiles Include="$(MSBuildThisFileDirectory)embedded/**/*.*"/>
|
||||
</ItemGroup>
|
||||
<Copy
|
||||
SourceFiles="@(EmbeddedFiles)"
|
||||
DestinationFolder="$(ProjectDir)embedded/%(RecursiveDir)"
|
||||
/>
|
||||
<ItemGroup>
|
||||
<PoloniumTemplateFiles Include="$(MSBuildThisFileDirectory)embedded/polonium_templates/**/*.*"/>
|
||||
</ItemGroup>
|
||||
<Message Text="Executing Copy Task" Importance="high"/>
|
||||
<Copy
|
||||
SourceFiles="@(PoloniumTemplateFiles)"
|
||||
DestinationFiles="@(PoloniumTemplateFiles->'$(PoloniumTemplateTargetPath)%(RecursiveDir)%(FileName)%(Extension)')"
|
||||
@@ -66,29 +62,11 @@
|
||||
Overwrite="true"
|
||||
Encoding="UTF-8"
|
||||
/>
|
||||
</Target>
|
||||
<Target Name="CleanPoloniumFiles" BeforeTargets="GenerateTextureSetManifest">
|
||||
<ItemGroup>
|
||||
<PoloniumFiles Include="$(ProjectDir).polonium/**/*.*"/>
|
||||
</ItemGroup>
|
||||
<Delete Files="@(PoloniumFiles)"/>
|
||||
</Target>
|
||||
<Target Name="GenerateTextureSetManifest" DependsOnTargets="CleanPoloniumFiles" BeforeTargets="BeforeBuild">
|
||||
<ScanTextureSetFolderTask
|
||||
<GenerateTextureSetTask
|
||||
RootPath="$(ProjectDir)Resources/ButtonTextureSet/"
|
||||
OutputPath="$(ProjectDir).polonium/"
|
||||
OutputPath="$(ProjectDir)embedded/"
|
||||
/>
|
||||
</Target>
|
||||
<ItemGroup>
|
||||
<Folder Include="Concepts"/>
|
||||
<Folder Include="Assets"/>
|
||||
<Folder Include="Registries"/>
|
||||
<Folder Include="Data"/>
|
||||
<Folder Include="Resources"/>
|
||||
<None Include="script_templates/**/*.*"/>
|
||||
<Compile Remove="script_templates/**/*.*"/>
|
||||
<PackageReference Include="Polonium.Generators" Version="0.1.1-x" />
|
||||
<PackageReference Include="Polonium.Tasks" Version="0.1.1-x"/>
|
||||
<AdditionalFiles Include=".polonium/**/*.*"/>
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
#pragma warning disable IDE0130
|
||||
using Godot;
|
||||
using Polonium.Attributes;
|
||||
using Polonium.DataStructures;
|
||||
using System.Collections.Generic;
|
||||
// ReSharper disable once CheckNamespace
|
||||
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()
|
||||
{
|
||||
}
|
||||
}
|
||||
#pragma warning restore IDE0130
|
||||
38
Package/embedded/GlobalClasses/Nodes/Scenes/CameraScene.cs
Normal file
38
Package/embedded/GlobalClasses/Nodes/Scenes/CameraScene.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Godot;
|
||||
using Polonium.Attributes;
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace GlobalClasses;
|
||||
[ProxyNode]
|
||||
[GlobalClass]
|
||||
[Tool]
|
||||
public partial class CameraScene : Scene
|
||||
{
|
||||
private Camera2D Camera { get; set; }
|
||||
|
||||
public float MaxZoom { get; set; }
|
||||
|
||||
public float MinZoom { get; set; }
|
||||
|
||||
public float ZoomRate { get; set; }
|
||||
|
||||
private float Zoom
|
||||
{
|
||||
get => Camera.Zoom.X;
|
||||
set => Camera.Zoom = value * Vector2.One;
|
||||
}
|
||||
|
||||
[ProxyMethod]
|
||||
public virtual void __Ready()
|
||||
{
|
||||
}
|
||||
|
||||
public sealed override void _Ready()
|
||||
{
|
||||
Camera = GetNode<Camera2D>("Camera");
|
||||
__Ready();
|
||||
base._Ready();
|
||||
}
|
||||
protected void ZoomIn() => Zoom = Mathf.Max(Zoom * (1 + ZoomRate), MaxZoom);
|
||||
protected void ZoomOut() => Zoom = Mathf.Min(Zoom * (1 - ZoomRate), MinZoom);
|
||||
protected void ZoomAt(Vector2 pos) => Camera.Position = pos;
|
||||
}
|
||||
45
Package/embedded/GlobalClasses/Nodes/Scenes/DissolveScene.cs
Normal file
45
Package/embedded/GlobalClasses/Nodes/Scenes/DissolveScene.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
#pragma warning disable IDE0130
|
||||
using Godot;
|
||||
using Polonium.Attributes;
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace GlobalClasses;
|
||||
[ProxyNode]
|
||||
[GlobalClass]
|
||||
[Tool]
|
||||
public partial class DissolveScene : Scene
|
||||
{
|
||||
[Export]
|
||||
public Scene NextScene { get; set; }
|
||||
private bool Finished { get; set; } = false;
|
||||
private bool Terminated { get; set; } = false;
|
||||
|
||||
public sealed override void _Process(double delta)
|
||||
{
|
||||
if(Finished && !Terminated)
|
||||
{
|
||||
Terminated = true;
|
||||
GlobalRegistry.RootScene.SwitchScene(NextScene);
|
||||
return;
|
||||
}
|
||||
|
||||
__Process(delta);
|
||||
base._Process(delta);
|
||||
}
|
||||
[ProxyMethod]
|
||||
public virtual void __Enter()
|
||||
{
|
||||
}
|
||||
[ProxyMethod]
|
||||
public virtual void __Process(double delta)
|
||||
{
|
||||
}
|
||||
|
||||
public sealed override void _EnterTree()
|
||||
{
|
||||
Finished = false;
|
||||
Terminated = false;
|
||||
__Enter();
|
||||
base._EnterTree();
|
||||
}
|
||||
}
|
||||
#pragma warning restore IDE0130
|
||||
63
Package/embedded/GlobalClasses/Nodes/Scenes/RootScene.cs
Normal file
63
Package/embedded/GlobalClasses/Nodes/Scenes/RootScene.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
#pragma warning disable IDE0130
|
||||
using Godot;
|
||||
using Polonium.Attributes;
|
||||
using Polonium.Interfaces;
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace GlobalClasses;
|
||||
[ProxyNode]
|
||||
[GlobalClass]
|
||||
[Tool]
|
||||
[RegistryEntity]
|
||||
public partial class RootScene : Scene
|
||||
{
|
||||
private Scene CurrentScene { get; set; }
|
||||
|
||||
public void SwitchScene(Scene scene)
|
||||
{
|
||||
if (CurrentScene != null)
|
||||
RemoveChild(CurrentScene);
|
||||
AddChild(scene);
|
||||
CurrentScene = scene;
|
||||
}
|
||||
|
||||
[ProxyMethod]
|
||||
public virtual void __Enter()
|
||||
{
|
||||
}
|
||||
|
||||
[ProxyMethod]
|
||||
public virtual void __Ready()
|
||||
{
|
||||
}
|
||||
|
||||
[ProxyMethod]
|
||||
public virtual void __Process(double delta)
|
||||
{
|
||||
}
|
||||
|
||||
public sealed override void _EnterTree()
|
||||
{
|
||||
GlobalRegistry.Prepare();
|
||||
GlobalRegistry.Start();
|
||||
__Enter();
|
||||
base._EnterTree();
|
||||
}
|
||||
|
||||
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
|
||||
13
Package/embedded/GlobalClasses/Nodes/Scenes/Scene.cs
Normal file
13
Package/embedded/GlobalClasses/Nodes/Scenes/Scene.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma warning disable IDE0130
|
||||
using Godot;
|
||||
using Polonium.Attributes;
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace GlobalClasses;
|
||||
[ProxyNode]
|
||||
[GlobalClass]
|
||||
[Tool]
|
||||
public partial class Scene : Node2D
|
||||
{
|
||||
|
||||
}
|
||||
#pragma warning restore IDE0130
|
||||
57
Package/embedded/Patches/GlobalRegistry.p.cs
Normal file
57
Package/embedded/Patches/GlobalRegistry.p.cs
Normal file
@@ -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<Type> 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<T> where T : Node
|
||||
{
|
||||
private static readonly Queue<T> Pool = new();
|
||||
// ReSharper disable once StaticMemberInGenericType
|
||||
// ReSharper disable once UnusedAutoPropertyAccessor.Global
|
||||
public static PackedScene Scene { get; set; }
|
||||
private static T Instance => Scene.Instantiate<T>();
|
||||
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<ITimeConsumer> 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
|
||||
Reference in New Issue
Block a user