Compare commits

..

16 Commits

Author SHA1 Message Date
a95de5aa59 improve: dynamic textureset 2025-02-18 14:28:26 +00:00
f9a6dbe55b add: sdk 2025-02-18 11:41:05 +00:00
604b7dd6d8 refactor: redesign project structures 2025-02-17 02:49:21 +00:00
f290b52fa3 refactor: redesign project structure 2025-02-16 22:36:38 +00:00
5a981c91ee draft: texture button 2025-02-15 08:25:01 +00:00
0d75ed106d refactor: move global classes def into package 2025-02-14 13:31:11 +00:00
ca7e3c68a5 add: dissolve scene / nuget feed source 2025-02-12 23:37:50 +00:00
2323211a65 add: Agent Actions 2025-02-12 14:09:56 +00:00
f7da4ee8bb add: Agent, ProxyMethod, LoadingScene 2025-02-11 15:07:41 +00:00
aea9059e16 add: Script Templates for global classes 2025-02-11 01:10:40 +00:00
ac1c93d1e5 fix: change Global class Namespace 2025-02-10 16:03:22 +00:00
3c1035bdfe fix: Enable tasks to generate proxy nodes 2025-02-10 15:20:57 +00:00
0a8b275176 add: LoadingScene, ProxyNode 2025-02-09 01:07:12 +00:00
15c667c3c4 add: Template for Save and config 2025-02-07 02:29:37 +00:00
1f2ba38f65 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	Polonium.csproj
2025-02-06 01:34:07 +00:00
022b64bc2c improve: rename project 2025-02-06 01:33:12 +00:00
40 changed files with 873 additions and 63 deletions

13
.idea/.idea.Polonium/.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,13 @@
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/.idea.Hangman.SDK.iml
/modules.xml
/projectSettingsUpdater.xml
/contentModel.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

7
.idea/.idea.Polonium/.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$/../Polonium.Generators" vcs="Git" />
</component>
</project>

8
NuGet.config Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="hangman-lab" value="https://git.hangman-lab.top/api/packages/hzhang/nuget/index.json"/>
<add key="Local" value="/NuGetFeed"/>
</packageSources>
</configuration>

View File

@@ -0,0 +1,7 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PoloniumTemplateTargetPath>$(ProjectDir)script_templates/</PoloniumTemplateTargetPath>
<PoloniumTemplateManifest>$(ProjectDir)embedded/templates.polonium.manifest</PoloniumTemplateManifest>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,69 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<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="PoloniumPrepare" BeforeTargets="PoloniumClean">
<Message Text="Executing EnsureFolders target" Importance="High"/>
<Message Text="$(ProjectDir)" Importance="High"/>
<MakeDir Directories="$(ProjectDir)Assets" Condition="!Exists('$(ProjectDir)Assets')"/>
<MakeDir Directories="$(ProjectDir)Concepts" Condition="!Exists('$(ProjectDir)Concepts')"/>
<MakeDir Directories="$(ProjectDir)Registries" Condition="!Exists('$(ProjectDir)Registries')"/>
<MakeDir Directories="$(ProjectDir)Data" Condition="!Exists('$(ProjectDir)Data')"/>
<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')"/>
</Target>
<Target Name="PoloniumClean" DependsOnTargets="PoloniumPrepare" BeforeTargets="PoloniumRegenerate">
<ReadLinesFromFile
File="$(PoloniumTemplateManifest)"
Condition="Exists('$(PoloniumTemplateManifest)')"
>
<Output TaskParameter="Lines" ItemName="PreviousTemplateFiles"/>
</ReadLinesFromFile>
<Delete Files="@(PreviousTemplateFiles)" Condition="@(PreviousTemplateFiles) != ''" />
<RemoveDir Directories="$(ProjectDir)embedded" Condition="Exists('$(ProjectDir)embedded')"/>
</Target>
<Target Name="PoloniumRegenerate" DependsOnTargets="PoloniumClean" BeforeTargets="CoreCompile">
<MakeDir Directories="$(ProjectDir)" Condition="!Exists('$(ProjectDir)embedded')"/>
<ItemGroup>
<EmbeddedFiles Include="$(MSBuildThisFileDirectory)embedded/**/*.*"/>
</ItemGroup>
<Copy
SourceFiles="@(EmbeddedFiles)"
DestinationFolder="$(ProjectDir)embedded/%(RecursiveDir)"
/>
<ItemGroup>
<PoloniumTemplateFiles Include="$(MSBuildThisFileDirectory)embedded/polonium_templates/**/*.*" />
</ItemGroup>
<Copy
SourceFiles="@(PoloniumTemplateFiles)"
DestinationFiles="@(PoloniumTemplateFiles->'$(PoloniumTemplateTargetPath)%(RecursiveDir)%(FileName)%(Extension)')"
>
<Output TaskParameter="CopiedFiles" ItemName="CopiedTemplates" />
</Copy>
<WriteLinesToFile
File="$(PoloniumTemplateManifest)"
Lines="@(CopiedTemplates)"
Overwrite="true"
Encoding="UTF-8"
/>
<GenerateTextureSetTask
RootPath="$(ProjectDir)Resources/ButtonTextureSet/"
OutputPath="$(ProjectDir)embedded/"
/>
</Target>
</Project>

View File

@@ -1,2 +0,0 @@
#!/bin/bash
dotnet nuget push "$(ls -t ../../.godot/mono/temp/bin/Debug/Polonium.*.nupkg | head -n 1)" --source hangman-lab

View File

@@ -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

View 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;
}

View 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

View 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

View 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

View 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

62
Polonium.csproj Normal file
View File

@@ -0,0 +1,62 @@
<Project Sdk="Godot.NET.Sdk/4.4.0-beta.3">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
<PackageId>Polonium</PackageId>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.1.1-x</Version>
<Authors>Hangman</Authors>
<DisableImplicitRestore>true</DisableImplicitRestore>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Polonium.Tasks" Version="0.1.1-x" />
</ItemGroup>
<Target Name="Prepare" BeforeTargets="BeforeBuild">
<RemoveDir Directories="$(ProjectDir)Package/embedded/polonium_templates" Condition="Exists('$(ProjectDir)Package/polonium_templates')"/>
<MakeDir Directories="$(ProjectDir)Package/embedded/polonium_templates"/>
<GenerateProxyNodesTask
SourceDirectory="$(ProjectDir)Package/embedded/GlobalClasses"
TemplateDirectory="$(ProjectDir)Package/embedded/polonium_templates"
AttributeName="ProxyNode"
/>
</Target>
<ItemGroup>
<None Include="NuGet.config" />
<None Include="Package/build/$(AssemblyName).targets" Pack="true" PackagePath="build" />
<None Include="Package/build/$(AssemblyName).props" Pack="true" PackagePath="build" />
<None Include="Package/embedded/**/*.*" Pack="true" PackagePath="build/embedded" />
<None Include="publish" />
<None Include="build" />
<Compile Remove="Package/**/*.*"/>
</ItemGroup>
<Target Name="CleanPreviousPackages" BeforeTargets="Build">
<Message Text="Cleaning Previous Packages -------------------------" Importance="high" />
<Message Text="Cleaning --------------------------------------------" Importance="high" />
<ItemGroup>
<ExistingPackages Include="$(OutputPath)*.nupkg" />
</ItemGroup>
<Delete Files="@(ExistingPackages)" ContinueOnError="true" />
</Target>
<Target Name="CopyPackageToLocalFeed" AfterTargets="Pack">
<Message Text="Executing Copy Task ----------------------" Importance="high" />
<Message Text="OutputPath: $(OutputPath)" Importance="high" />
<ItemGroup>
<NuGetPackages Include="$(OutputPath)*.nupkg" />
</ItemGroup>
<Message Text="Printing pkgs--------------------" Importance="high" />
<Message Text="Pkgs: @(NuGetPackages)" Importance="high" />
<Copy SourceFiles="@(NuGetPackages)" DestinationFolder="/NuGetFeed" />
</Target>
<Target Name="RestoreNoCache" BeforeTargets="Build">
<Message Text="Restoring packages with no chache" Importance="high" />
<Exec Command="dotnet restore --no-cache" />
</Target>
</Project>

View File

@@ -2,10 +2,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Polonium", "Polonium.csproj", "{5BA39DF8-7098-4348-A670-B3F34269F48F}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Polonium", "Polonium.csproj", "{5BA39DF8-7098-4348-A670-B3F34269F48F}"
EndProject 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
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@@ -14,15 +10,15 @@ Global
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5BA39DF8-7098-4348-A670-B3F34269F48F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {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}.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.ActiveCfg = Debug|Any CPU
{41B784D2-841C-44D6-90F3-9219BC264B19}.Debug|Any CPU.Build.0 = 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.ActiveCfg = Release|Any CPU
{41B784D2-841C-44D6-90F3-9219BC264B19}.Release|Any CPU.Build.0 = 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.ActiveCfg = Debug|Any CPU
{3BADB215-214B-41C1-B94E-89AF4A972F30}.Debug|Any CPU.Build.0 = 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 {5F0664A8-563F-408A-9EB6-05B2F25F5DC5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3BADB215-214B-41C1-B94E-89AF4A972F30}.Release|Any CPU.Build.0 = Release|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
{5F0664A8-563F-408A-9EB6-05B2F25F5DC5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

View File

@@ -0,0 +1,9 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ADynamicResolver_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fb71753e8d7f5410a90c2ccab6d9fac7bd1be00_003F9b_003F0c3b144f_003FDynamicResolver_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGlobalRegistry_002Eg_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F2655819e4eaf2a7f63a82a59653d80b82de731_003FGlobalRegistry_002Eg_002Ecs_002Fz_003A4_002D3/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGlobalRegistry_002Eg_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F3cc424ce28293e197699c4e55c1b4a24aac9bd75_003FGlobalRegistry_002Eg_002Ecs_002Fz_003A3_002D2/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGlobalRegistry_002Eg_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F6f3e482ddee84872fa4917a75473b425c3154e_003FGlobalRegistry_002Eg_002Ecs_002Fz_003A5_002D4/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGlobalRegistry_002Eg_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fe6fa4548b681609c78398e67b195bc2a6e96a5e_003FGlobalRegistry_002Eg_002Ecs_002Fz_003A2_002D1/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AMethodBaseInvoker_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fb71753e8d7f5410a90c2ccab6d9fac7bd1be00_003Fb6_003Fb10878e7_003FMethodBaseInvoker_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=Polonium_002EGenerators_002FResources/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/ResxEditorPersonal/Initialized/@EntryValue">True</s:Boolean></wpf:ResourceDictionary>

17
build Executable file
View File

@@ -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

2
publish Normal file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
dotnet nuget push "$(ls -t ./.godot/mono/temp/bin/Debug/Polonium.*.nupkg | head -n 1)" --source hangman-lab

51
src/Agents/Agent.cs Normal file
View File

@@ -0,0 +1,51 @@
namespace Polonium.Agents;
public abstract class Agent
{
protected static int ComputerCount = 0;
public string Name { get; init; }
public Agent(string name)
{
Name = name;
PoloniumRegistry.Instance.Agents[name] = this;
}
public int Level { get; private set; }
public abstract int MaxLevel { get; }
public virtual void LevelUp()
{
if(Level < MaxLevel)
Level++;
}
}
public abstract class Agent<TAgent, TAgentDecisionMaker, TAgentKnowledge, TAgentAction> : Agent
where TAgent : Agent<TAgent, TAgentDecisionMaker, TAgentKnowledge, TAgentAction>, new()
where TAgentDecisionMaker : AgentDecisionMaker<TAgent, TAgentDecisionMaker, TAgentKnowledge, TAgentAction>, new()
where TAgentKnowledge : AgentKnowledge<TAgent, TAgentDecisionMaker, TAgentKnowledge, TAgentAction>, new()
where TAgentAction : AgentAction<TAgent, TAgentDecisionMaker, TAgentKnowledge, TAgentAction>, new()
{
public Dictionary<string, TAgentAction> Actions { get; } = new();
public TAgentDecisionMaker DecisionMaker { get; init; }
public TAgentKnowledge Knowledge { get; init; }
public Agent() : base($"Computer {ComputerCount++}")
{
DecisionMaker = new TAgentDecisionMaker();
Knowledge = new TAgentKnowledge();
}
public Agent(string name, TAgentDecisionMaker decisionMaker, TAgentKnowledge knowledge) : base(name)
{
DecisionMaker = decisionMaker;
Knowledge = knowledge;
}
}

60
src/Agents/AgentAction.cs Normal file
View File

@@ -0,0 +1,60 @@
using Polonium.Interfaces;
namespace Polonium.Agents;
public abstract class AgentAction
{
}
public abstract class AgentAction<TAgent, TAgentDecisionMaker, TAgentKnowledge, TAgentAction> : AgentAction, ITimeConsumer
where TAgent : Agent<TAgent, TAgentDecisionMaker, TAgentKnowledge, TAgentAction>, new()
where TAgentDecisionMaker : AgentDecisionMaker<TAgent, TAgentDecisionMaker, TAgentKnowledge, TAgentAction>, new()
where TAgentKnowledge : AgentKnowledge<TAgent, TAgentDecisionMaker, TAgentKnowledge, TAgentAction>, new()
where TAgentAction : AgentAction<TAgent, TAgentDecisionMaker, TAgentKnowledge, TAgentAction>, new()
{
public int Level { get; private set; }
public abstract int MaxLevel { get; }
public virtual void LevelUp()
{
if(Level < MaxLevel)
Level++;
}
public AgentAction(double coolDown)
{
CoolDown = coolDown;
PoloniumRegistry.Instance.TimeConsumers.Add(this);
}
public abstract class ActionParameter
{
}
public virtual bool Execute(ActionParameter parameter)
{
if (Disabled || CoolDown > 0)
return false;
CoolDownTime = CoolDown;
return true;
}
private double CoolDownTime { get; set; }
public bool Disabled { get; set; }
private double CoolDown { get; }
public void Process(double delta)
{
if (Disabled || CoolDownTime <= 0)
return;
CoolDownTime -= delta;
if (CoolDownTime <= 0)
CoolDownTime = 0;
}
}

View File

@@ -0,0 +1,17 @@
namespace Polonium.Agents;
public abstract class AgentDecisionMaker<TAgent, TAgentDecisionMaker, TAgentKnowledge, TAgentAction>(DecisionMakerType type)
where TAgent : Agent<TAgent, TAgentDecisionMaker, TAgentKnowledge, TAgentAction>, new()
where TAgentDecisionMaker : AgentDecisionMaker<TAgent, TAgentDecisionMaker, TAgentKnowledge, TAgentAction>, new()
where TAgentKnowledge : AgentKnowledge<TAgent, TAgentDecisionMaker, TAgentKnowledge, TAgentAction>, new()
where TAgentAction : AgentAction<TAgent, TAgentDecisionMaker, TAgentKnowledge, TAgentAction>, new()
{
public DecisionMakerType Type { get; init; } = type;
public AgentDecisionMaker() : this(DecisionMakerType.Computer)
{
}
}

View File

@@ -0,0 +1,18 @@
namespace Polonium.Agents;
public abstract class AgentKnowledge
{
}
public abstract class AgentKnowledge<TAgent, TAgentDecisionMaker, TAgentKnowledge, TAgentAction> : AgentKnowledge
where TAgent : Agent<TAgent, TAgentDecisionMaker, TAgentKnowledge, TAgentAction>, new()
where TAgentDecisionMaker : AgentDecisionMaker<TAgent, TAgentDecisionMaker, TAgentKnowledge, TAgentAction>, new()
where TAgentKnowledge : AgentKnowledge<TAgent, TAgentDecisionMaker, TAgentKnowledge, TAgentAction>, new()
where TAgentAction : AgentAction<TAgent, TAgentDecisionMaker, TAgentKnowledge, TAgentAction>, new()
{
public AgentKnowledge()
{
}
public abstract void Update(TAgentKnowledge newKnowledge);
}

View File

@@ -0,0 +1,9 @@
namespace Polonium.Agents;
public enum DecisionMakerType
{
None = 0,
Player = 1,
Computer = 2,
Global = 3,
}

View File

@@ -0,0 +1,6 @@
namespace Polonium.Attributes;
[AttributeUsage(AttributeTargets.Method)]
public class ProxyMethod : Attribute
{
}

View File

@@ -0,0 +1,6 @@
namespace Polonium.Attributes;
[AttributeUsage(AttributeTargets.Class)]
public class ProxyNode : Attribute
{
}

View File

@@ -0,0 +1,6 @@
namespace Polonium.Attributes;
[AttributeUsage(AttributeTargets.Property)]
public class ProxyProperty : Attribute
{
}

View File

@@ -0,0 +1,6 @@
namespace Polonium.Attributes;
[AttributeUsage(AttributeTargets.Class)]
public class RegistryEntity : Attribute
{
}

View File

@@ -0,0 +1,9 @@
namespace Polonium.DataStructures;
public abstract class ProgressInfo
{
public int CurrentTaskIndex { get; set; }
public int TotalTasks { get; set; }
public abstract float Progress { get; }
public string Message { get; set; }
}

View File

@@ -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<Texture2D>($"{path}.png");
else if(DirAccess.DirExistsAbsolute($"{path}.at_dir"))
res = Utils.LoadAnimatedTextureFromDirectory($"{path}.at_dir");
return res;
}
}

View File

@@ -0,0 +1,8 @@
namespace Polonium.Interfaces;
public interface IGlobalRegistry
{
public bool Paused { get; set; }
public void Start();
public void Prepare();
}

View File

@@ -0,0 +1,6 @@
namespace Polonium.Interfaces;
public interface ITimeConsumer
{
public void Process(double time);
}

View File

@@ -0,0 +1,29 @@
using Polonium.DataStructures;
namespace Polonium.Managers;
public abstract class LoaderManager<T>
where T : ProgressInfo
{
public bool Started { get; private set; } = false;
public bool Finished { get; protected set; } = false;
public void Start()
{
if(Started)
throw new InvalidOperationException("Loader is already started");
Started = true;
Thread load = new Thread(LoadTask);
load.Start();
}
public abstract T QueryProgress();
public abstract void Load();
public void LoadTask()
{
Load();
Finished = true;
}
}

25
src/PoloniumRegistry.cs Normal file
View File

@@ -0,0 +1,25 @@
using Godot;
using Polonium.Agents;
using Polonium.Interfaces;
using Polonium.Resources;
namespace Polonium;
public class PoloniumRegistry
{
public static IGlobalRegistry GlobalRegistry { get; set; }
private static PoloniumRegistry InternalInstance { get; set; }
public static PoloniumRegistry Instance => InternalInstance ??= new PoloniumRegistry();
public Config Config { get; set; }
public Save Save { get; set; }
public static void Prepare()
{
DirAccess.MakeDirAbsolute("user://saves");
}
public Dictionary<string, Agent> Agents { get; set; } = new();
public HashSet<ITimeConsumer> TimeConsumers { get; set; } = new();
}

16
src/Resources/Config.cs Normal file
View File

@@ -0,0 +1,16 @@
using Godot;
namespace Polonium.Resources;
public partial class Config: Resource
{
public void Save() => ResourceSaver.Save(this, "user://Config.tres");
public static void Load<T>()
where T : Config, new()
{
PoloniumRegistry.Instance.Config = ResourceLoader.Load<T>("user://Config.tres") ?? new T();
}
}

49
src/Resources/Save.cs Normal file
View File

@@ -0,0 +1,49 @@
using Godot;
namespace Polonium.Resources;
public abstract partial class Save : Resource
{
[Export]
public string Name { get; set; }
public abstract class Preview
{
}
public void SaveToUser() => ResourceSaver.Save(this, $"user://saves/{Name}.tres");
public static void LoadFromUser<T>(string name)
where T : Save, new()
{
T res = ResourceLoader.Load<T>($"user://saves/{name}.tres");
if (res is null)
{
res = new T();
res.Name = name;
}
PoloniumRegistry.Instance.Save = res;
}
public void Load() => PoloniumRegistry.Instance.Save = this;
public static IEnumerable<T> ListSaves<T>()
where T : Save
{
DirAccess dir = DirAccess.Open("user://saves");
if(dir is null)
{
DirAccess.MakeDirRecursiveAbsolute("user://saves");
yield break;
}
foreach (string save in dir.GetFiles())
{
if(!save.EndsWith(".tres"))
continue;
yield return ResourceLoader.Load<T>($"user://saves/{save}");
}
}
}

View File

@@ -1,25 +0,0 @@
using Godot;
namespace Polonium.Scenes;
public abstract partial class CameraScene : Scene
{
private Camera2D Camera { get; set; }
protected abstract float MaxZoom { get; }
protected abstract float MinZoom { get; }
protected abstract float ZoomRate { get; }
private float Zoom
{
get => Camera.Zoom.X;
set => Camera.Zoom = value * Vector2.One;
}
public override void _Ready()
{
Camera = GetNode<Camera2D>("Camera");
base._Ready();
}
protected void ZoomIn() => Mathf.Max(Zoom * (1 + ZoomRate), MaxZoom);
protected void ZoomOut() => Mathf.Min(Zoom * (1 - ZoomRate), MinZoom);
protected void ZoomAt(Vector2 pos) => Camera.Position = pos;
}

View File

@@ -1,19 +0,0 @@
using Godot;
namespace Polonium.Scenes;
public abstract partial class RootScene : Node2D
{
private Polonium.Scenes.Scene CurrentScene { get; set; }
public void SwitchScene(Polonium.Scenes.Scene scene)
{
if (CurrentScene != null)
RemoveChild(CurrentScene);
AddChild(scene);
CurrentScene = scene;
}
}

View File

@@ -1,8 +0,0 @@
using Godot;
namespace Polonium.Scenes;
public abstract partial class Scene : Node2D
{
}

View File

@@ -1,4 +1,7 @@
#pragma warning disable CS0618
#pragma warning disable CS0168
using System.Reflection; using System.Reflection;
using Godot;
namespace Polonium; namespace Polonium;
@@ -15,4 +18,32 @@ public static class Utils
return e.Types.Where(t => t != null); return e.Types.Where(t => t != null);
} }
} }
private static Dictionary<StringName, AnimatedTexture> 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<Texture2D>(fname));
}
}
return AnimatedTextureCache[path];
}
catch (Exception e)
{
return null;
}
}
} }
#pragma warning restore CS0618
#pragma warning restore CS0168