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

@@ -9,10 +9,16 @@ public abstract class GameRuleSystem : EntitySystem
[Dependency] protected GameTicker GameTicker = default!;
/// <summary>
/// Whether this GameRule is currently enabled or not.
/// Whether this GameRule is currently added or not.
/// Be sure to check this before doing anything rule-specific.
/// </summary>
public bool Enabled { get; protected set; } = false;
public bool RuleAdded { get; protected set; }
/// <summary>
/// Whether this game rule has been started after being added.
/// You probably want to check this before doing any update loop stuff.
/// </summary>
public bool RuleStarted { get; protected set; }
/// <summary>
/// When the GameRule prototype with this ID is added, this system will be enabled.
@@ -20,6 +26,12 @@ public abstract class GameRuleSystem : EntitySystem
/// </summary>
public new abstract string Prototype { get; }
/// <summary>
/// Holds the current configuration after the event has been added.
/// This should not be getting accessed before the event is enabled, as usual.
/// </summary>
public GameRuleConfiguration Configuration = default!;
public override void Initialize()
{
base.Initialize();
@@ -35,7 +47,10 @@ public abstract class GameRuleSystem : EntitySystem
if (ev.Rule.Configuration.Id != Prototype)
return;
Enabled = true;
Configuration = ev.Rule.Configuration;
RuleAdded = true;
Added();
}
private void OnGameRuleStarted(GameRuleStartedEvent ev)
@@ -43,7 +58,9 @@ public abstract class GameRuleSystem : EntitySystem
if (ev.Rule.Configuration.Id != Prototype)
return;
Started(ev.Rule.Configuration);
RuleStarted = true;
Started();
}
private void OnGameRuleEnded(GameRuleEndedEvent ev)
@@ -51,17 +68,27 @@ public abstract class GameRuleSystem : EntitySystem
if (ev.Rule.Configuration.Id != Prototype)
return;
Enabled = false;
Ended(ev.Rule.Configuration);
RuleAdded = false;
RuleStarted = false;
Ended();
}
/// <summary>
/// Called when the game rule has been started..
/// Called when the game rule has been added.
/// You should avoid using this in favor of started--they are not the same thing.
/// </summary>
public abstract void Started(GameRuleConfiguration configuration);
/// <remarks>
/// This is virtual because it doesn't actually have to be used, and most of the time shouldn't be.
/// </remarks>
public virtual void Added() { }
/// <summary>
/// Called when the game rule has ended..
/// Called when the game rule has been started.
/// </summary>
public abstract void Ended(GameRuleConfiguration configuration);
public abstract void Started();
/// <summary>
/// Called when the game rule has ended.
/// </summary>
public abstract void Ended();
}