Use ECS prototype-reload events (#22613)

* Use ECS prototype-reload events

* better constructors

* Maybe this fixes tests?
This commit is contained in:
Leon Friedrich
2023-12-22 09:13:45 -05:00
committed by GitHub
parent 053c1e877f
commit b6bd82caa6
23 changed files with 135 additions and 242 deletions

View File

@@ -30,6 +30,7 @@ public sealed class SpreaderSystem : EntitySystem
/// <summary>
/// Remaining number of updates per grid & prototype.
/// </summary>
// TODO PERFORMANCE Assign each prototype to an index and convert dictionary to array
private Dictionary<EntityUid, Dictionary<string, int>> _gridUpdates = new();
public const float SpreadCooldownSeconds = 1;
@@ -42,24 +43,16 @@ public sealed class SpreaderSystem : EntitySystem
{
SubscribeLocalEvent<AirtightChanged>(OnAirtightChanged);
SubscribeLocalEvent<GridInitializeEvent>(OnGridInit);
SubscribeLocalEvent<PrototypesReloadedEventArgs>(OnPrototypeReload);
SubscribeLocalEvent<EdgeSpreaderComponent, EntityTerminatingEvent>(OnTerminating);
SetupPrototypes();
_prototype.PrototypesReloaded += OnPrototypeReload;
}
public override void Shutdown()
{
base.Shutdown();
_prototype.PrototypesReloaded -= OnPrototypeReload;
}
private void OnPrototypeReload(PrototypesReloadedEventArgs obj)
{
if (!obj.ByType.ContainsKey(typeof(EdgeSpreaderPrototype)))
return;
SetupPrototypes();
if (obj.WasModified<EdgeSpreaderPrototype>())
SetupPrototypes();
}
private void SetupPrototypes()