refactor: Yaml serialization moved from Core to own project
This commit is contained in:
@@ -1,35 +1,3 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Syntriax.Engine.Core.Serialization;
|
||||
|
||||
public record class EntityReference(string? Id = null);
|
||||
|
||||
public class EntityRegistry
|
||||
{
|
||||
public event EntityRegisteredEventHandler? OnEntityRegistered = null!;
|
||||
|
||||
private readonly Dictionary<string, Action<IEntity>?> assignCallbacks = [];
|
||||
private readonly Dictionary<string, IEntity> registeredEntities = [];
|
||||
public IReadOnlyDictionary<string, IEntity> RegisteredEntities => registeredEntities;
|
||||
|
||||
public void Add(IEntity entity)
|
||||
{
|
||||
if (registeredEntities.TryAdd(entity.Id, entity))
|
||||
OnEntityRegistered?.InvokeSafe(this, entity);
|
||||
}
|
||||
|
||||
public void QueueAssign(string id, Action<IEntity> setMethod)
|
||||
{
|
||||
assignCallbacks.TryAdd(id, null);
|
||||
assignCallbacks[id] = assignCallbacks[id] + setMethod;
|
||||
}
|
||||
|
||||
public void AssignAll()
|
||||
{
|
||||
foreach ((string id, Action<IEntity>? action) in assignCallbacks)
|
||||
action?.InvokeSafe(registeredEntities[id]);
|
||||
}
|
||||
|
||||
public delegate void EntityRegisteredEventHandler(EntityRegistry sender, IEntity entity);
|
||||
}
|
||||
|
Reference in New Issue
Block a user