Component ECS (#17991)

This commit is contained in:
metalgearsloth
2023-07-13 20:20:46 +10:00
committed by GitHub
parent 0c93be1dcd
commit fbf1d476f2
13 changed files with 108 additions and 114 deletions

View File

@@ -3,6 +3,7 @@ using Content.Server.Alert;
using Content.Shared.Alert;
using NUnit.Framework;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager;
@@ -33,6 +34,7 @@ namespace Content.Tests.Shared.Alert
// but wanted to keep it anyway to see what's possible w.r.t. testing components
// in a unit test
var entManager = IoCManager.Resolve<IEntityManager>();
IoCManager.Resolve<ISerializationManager>().Initialize();
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
prototypeManager.Initialize();
@@ -41,7 +43,7 @@ namespace Content.Tests.Shared.Alert
prototypeManager.LoadFromStream(new StringReader(PROTOTYPES));
prototypeManager.ResolveResults();
var entSys = IoCManager.Resolve<IEntitySystemManager>();
var entSys = entManager.EntitySysManager;
entSys.LoadExtraSystemType<ServerAlertsSystem>();
var alertsComponent = new AlertsComponent();
@@ -51,18 +53,27 @@ namespace Content.Tests.Shared.Alert
Assert.That(EntitySystem.Get<AlertsSystem>().TryGet(AlertType.HighPressure, out var highpressure));
EntitySystem.Get<AlertsSystem>().ShowAlert(alertsComponent.Owner, AlertType.LowPressure, null, null);
var alertState = alertsComponent.GetComponentState() as AlertsComponentState;
var getty = new ComponentGetState();
entManager.EventBus.RaiseComponentEvent(alertsComponent, getty);
var alertState = (AlertsComponentState) getty.State!;
Assert.NotNull(alertState);
Assert.That(alertState.Alerts.Count, Is.EqualTo(1));
Assert.That(alertState.Alerts.ContainsKey(lowpressure.AlertKey));
EntitySystem.Get<AlertsSystem>().ShowAlert(alertsComponent.Owner, AlertType.HighPressure, null, null);
alertState = alertsComponent.GetComponentState() as AlertsComponentState;
// Lazy
entManager.EventBus.RaiseComponentEvent(alertsComponent, getty);
alertState = (AlertsComponentState) getty.State!;
Assert.That(alertState.Alerts.Count, Is.EqualTo(1));
Assert.That(alertState.Alerts.ContainsKey(highpressure.AlertKey));
EntitySystem.Get<AlertsSystem>().ClearAlertCategory(alertsComponent.Owner, AlertCategory.Pressure);
alertState = alertsComponent.GetComponentState() as AlertsComponentState;
entManager.EventBus.RaiseComponentEvent(alertsComponent, getty);
alertState = (AlertsComponentState) getty.State!;
Assert.That(alertState.Alerts.Count, Is.EqualTo(0));
}
}