add: Agent, ProxyMethod, LoadingScene

This commit is contained in:
h z
2025-02-11 15:07:41 +00:00
parent aea9059e16
commit f7da4ee8bb
9 changed files with 105 additions and 7 deletions

View File

@@ -8,12 +8,12 @@
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
<PackageId>Polonium</PackageId>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.167-d</Version>
<Version>0.1.0</Version>
<Authors>Hangman</Authors>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="GodotSharp" Version="4.4.0-beta.3" />
<PackageReference Include="Polonium.Tasks" Version="0.0.92-d" />
<PackageReference Include="Polonium.Tasks" Version="0.1.0" />
</ItemGroup>
<Target Name="GenerateProxyNodes" BeforeTargets="BeforeBuild">
<GenerateProxyNodesTask

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

@@ -0,0 +1,38 @@
namespace Polonium.Agents;
public abstract class Agent
{
public string Name { get; init; }
public Agent(string name)
{
Name = name;
PoloniumRegistry.Instance.Agents[name] = this;
}
}
public abstract class Agent<TAgent, TAgentDecisionMaker, TAgentKnowledge> : Agent
where TAgent : Agent<TAgent, TAgentDecisionMaker, TAgentKnowledge>
where TAgentDecisionMaker : AgentDecisionMaker<TAgent, TAgentDecisionMaker, TAgentKnowledge>, new()
where TAgentKnowledge : AgentKnowledge<TAgent, TAgentDecisionMaker, TAgentKnowledge>, new()
{
private static int ComputerCount = 0;
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;
}
}

View File

@@ -0,0 +1,28 @@
namespace Polonium.Agents;
public abstract class AgentDecisionMaker<TAgent, TAgentDecisionMaker, TAgentKnowledge>
where TAgent : Agent<TAgent, TAgentDecisionMaker, TAgentKnowledge>
where TAgentDecisionMaker : AgentDecisionMaker<TAgent, TAgentDecisionMaker, TAgentKnowledge>, new()
where TAgentKnowledge : AgentKnowledge<TAgent, TAgentDecisionMaker, TAgentKnowledge>, new()
{
public enum DecisionMakerType
{
None = 0,
Player = 1,
Computer = 2,
Global = 3,
}
public DecisionMakerType Type { get; init; }
public AgentDecisionMaker()
{
Type = DecisionMakerType.Computer;
}
public AgentDecisionMaker(DecisionMakerType type)
{
Type = type;
}
}

View File

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

View File

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

View File

@@ -1,4 +1,5 @@
using Godot;
using Polonium.Agents;
using Polonium.Resources;
using Polonium.Scenes;
@@ -16,4 +17,5 @@ public class PoloniumRegistry
{
DirAccess.MakeDirAbsolute("user://saves");
}
public Dictionary<string, Agent> Agents { get; set; } = new();
}

View File

@@ -1,9 +1,8 @@
using Godot;
using Polonium.DataStructures;
using Polonium.Managers;
namespace Polonium.Scenes;
public abstract partial class LoadingScene<T> : Scene
where T : ProgressInfo
{

View File

@@ -6,7 +6,7 @@ namespace Polonium.Scenes;
public partial class RootScene : Node2D
{
private Scene CurrentScene { get; set; }
public void SwitchScene(Scene scene)
{
if (CurrentScene != null)
@@ -20,4 +20,15 @@ public partial class RootScene : Node2D
PoloniumRegistry.Instance.RootScene = this;
base._Ready();
}
[ProxyMethod]
public virtual void Enter()
{
}
public override void _EnterTree()
{
Enter();
base._EnterTree();
}
}

View File

@@ -1,8 +1,9 @@
using Godot;
using Polonium.Attributes;
namespace Polonium.Scenes;
public abstract partial class Scene : Node2D
[ProxyNode]
public partial class Scene : Node2D
{
}