Event refactor (#9589)

* Station event refactor

* Remove clientside `IStationEventManager`

we can just use prototypes

* Basic API idea

* Cruft

* first attempt at epicness

* okay yeah this shit is really clean

* sort out minor stuff

* Convert `BreakerFlip`

* `BureaucraticError` + general cleanup

* `DiseaseOutbreak`

* `FalseAlarm`

* `GasLeak`

* `KudzuGrowth`

* `MeteorSwarm`

* `MouseMigration`

* misc errors

* `PowerGridCheck`

* `RandomSentience`

* `VentClog`

* `VentCritters`

* `ZombieOutbreak`

* Rewrite basic event scheduler

* Minor fixes and logging

* ooooops

* errors + fix

* linter

* completions, `RuleStarted` property, update loop fixes

* Tweaks

* Fix #9462

* Basic scheduler update fix, and fixes #8174

* Add test

* UI cleanup

* really this was just for testing
This commit is contained in:
Kara
2022-07-10 18:48:41 -07:00
committed by GitHub
parent f28cdaaa7c
commit b9a0894d7c
55 changed files with 1095 additions and 1582 deletions

View File

@@ -0,0 +1,54 @@
using System.Linq;
using System.Threading.Tasks;
using Content.Server.GameTicking;
using Content.Server.GameTicking.Rules;
using NUnit.Framework;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
namespace Content.IntegrationTests.Tests.GameRules;
/// <summary>
/// Tests that all game rules can be added/started/ended at the same time without exceptions.
/// </summary>
[TestFixture]
public sealed class StartEndGameRulesTest
{
[Test]
public async Task Test()
{
await using var pairTracker = await PoolManager.GetServerClient();
var server = pairTracker.Pair.Server;
await server.WaitAssertion(() =>
{
var gameTicker = EntitySystem.Get<GameTicker>();
var protoMan = IoCManager.Resolve<IPrototypeManager>();
var rules = protoMan.EnumeratePrototypes<GameRulePrototype>().ToArray();
// Start all rules
foreach (var rule in rules)
{
gameTicker.StartGameRule(rule);
}
Assert.That(gameTicker.AddedGameRules.Count == rules.Length);
});
// Wait three ticks for any random update loops that might happen
await server.WaitRunTicks(3);
await server.WaitAssertion(() =>
{
var gameTicker = EntitySystem.Get<GameTicker>();
// End all rules
gameTicker.ClearGameRules();
Assert.That(!gameTicker.AddedGameRules.Any());
});
await pairTracker.CleanReturnAsync();
}
}

View File

@@ -1,49 +0,0 @@
using System.Threading.Tasks;
using Content.Server.StationEvents;
using Content.Shared.GameTicking;
using NUnit.Framework;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Timing;
namespace Content.IntegrationTests.Tests.StationEvents
{
[TestFixture]
public sealed class StationEventsSystemTest
{
[Test]
public async Task Test()
{
await using var pairTracker = await PoolManager.GetServerClient();
var server = pairTracker.Pair.Server;
await server.WaitAssertion(() =>
{
// Idle each event
var stationEventsSystem = EntitySystem.Get<StationEventSystem>();
var dummyFrameTime = (float) IoCManager.Resolve<IGameTiming>().TickPeriod.TotalSeconds;
foreach (var stationEvent in stationEventsSystem.StationEvents)
{
stationEvent.Announce();
stationEvent.Update(dummyFrameTime);
stationEvent.Startup();
stationEvent.Update(dummyFrameTime);
stationEvent.Running = false;
stationEvent.Shutdown();
// Due to timings some events might startup twice when in reality they wouldn't.
Assert.That(stationEvent.Occurrences > 0);
}
stationEventsSystem.Reset(new RoundRestartCleanupEvent());
foreach (var stationEvent in stationEventsSystem.StationEvents)
{
Assert.That(stationEvent.Occurrences, Is.EqualTo(0));
}
});
await pairTracker.CleanReturnAsync();
}
}
}