add: MessageBus
This commit is contained in:
@@ -1,27 +1,27 @@
|
||||
using Godot;
|
||||
using Polonium.Resources;
|
||||
using Polonium.MessageManager;
|
||||
|
||||
namespace Polonium.Agents;
|
||||
|
||||
public abstract partial class World : Node
|
||||
public abstract partial class World : MessageBus
|
||||
{
|
||||
protected WorldModel Model { get; set; }
|
||||
public HashSet<Agent> Agents { get; } = new();
|
||||
public Knowledge CommonKnowledge { get; set; }
|
||||
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Model = GetNode<WorldModel>("WorldModel");
|
||||
Model.WorldKnowledge.PostCode = "WorldKnowledge";
|
||||
Register(Model.WorldKnowledge);
|
||||
CommonKnowledge = GetNode<Knowledge>("CommonKnowledge");
|
||||
Model.CommonKnowledgeUpdated += CommonKnowledgeUpdated;
|
||||
Model.PrivateKnowledgeUpdated += ForwardPrivateKnowledgeUpdated;
|
||||
CommonKnowledge.PostCode = "CommonKnowledge";
|
||||
Register(CommonKnowledge);
|
||||
base._Ready();
|
||||
}
|
||||
|
||||
public void RegisterAgent(Agent agent)
|
||||
public void Register(Agent agent)
|
||||
{
|
||||
Agents.Add(agent);
|
||||
agent.ActionExecuted += Model.ActionExecuted;
|
||||
Register(agent.Knowledge);
|
||||
}
|
||||
|
||||
public virtual void Enter()
|
||||
@@ -34,12 +34,4 @@ public abstract partial class World : Node
|
||||
PoloniumRegistry.Instance.CurrentWorld = null;
|
||||
}
|
||||
|
||||
public void CommonKnowledgeUpdated(KnowledgePatch update) => update.Patch(CommonKnowledge);
|
||||
|
||||
public void ForwardPrivateKnowledgeUpdated(SignalHeader header, KnowledgePatch update)
|
||||
{
|
||||
foreach (Agent receiver in header.ResolveReceivers())
|
||||
receiver.UpdateKnowledge(update);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user