Refactor stations to properly use entity prototypes. (stationsv3) (#16570)

* Update StationSpawningSystem.cs

Web-edit to allow feeding in an existing entity.

* Update StationSpawningSystem.cs

value type moment

* Update StationSpawningSystem.cs

* Oh goddamnit this is a refactor now.

* awawawa

* aaaaaaaaaaa

* ee

* forgot records.

* no records? no records.

* What's in a name?

* Sloth forcing me to do the refactor properly smh.

* e

* optional evac in test.

* tests pls work

* awa

---------

Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com>
This commit is contained in:
Moony
2023-05-19 15:45:09 -05:00
committed by GitHub
parent 0d9b9e113e
commit e92a8fedab
77 changed files with 1176 additions and 987 deletions

View File

@@ -73,7 +73,7 @@ public sealed partial class EmergencyShuttleSystem : EntitySystem
// Don't immediately invoke as roundstart will just handle it.
_configManager.OnValueChanged(CCVars.EmergencyShuttleEnabled, SetEmergencyShuttleEnabled);
SubscribeLocalEvent<RoundStartingEvent>(OnRoundStart);
SubscribeLocalEvent<StationDataComponent, ComponentStartup>(OnStationStartup);
SubscribeLocalEvent<StationEmergencyShuttleComponent, ComponentStartup>(OnStationStartup);
SubscribeNetworkEvent<EmergencyShuttleRequestPositionMessage>(OnShuttleRequestPosition);
InitializeEmergencyConsole();
}
@@ -115,19 +115,22 @@ public sealed partial class EmergencyShuttleSystem : EntitySystem
return;
var player = args.SenderSession.AttachedEntity;
if (player is null)
return;
if (player == null ||
!TryComp<StationDataComponent>(_station.GetOwningStation(player.Value), out var stationData) ||
!HasComp<ShuttleComponent>(stationData.EmergencyShuttle))
var station = _station.GetOwningStation(player.Value);
if (!TryComp<StationEmergencyShuttleComponent>(station, out var stationShuttle) ||
!HasComp<ShuttleComponent>(stationShuttle.EmergencyShuttle))
{
return;
}
var targetGrid = _station.GetLargestGrid(stationData);
var targetGrid = _station.GetLargestGrid(Comp<StationDataComponent>(station.Value));
if (targetGrid == null)
return;
var config = _dock.GetDockingConfig(stationData.EmergencyShuttle.Value, targetGrid.Value, DockTag);
var config = _dock.GetDockingConfig(stationShuttle.EmergencyShuttle.Value, targetGrid.Value, DockTag);
if (config == null)
return;
@@ -143,14 +146,14 @@ public sealed partial class EmergencyShuttleSystem : EntitySystem
/// </summary>
public void CallEmergencyShuttle(EntityUid? stationUid)
{
if (!TryComp<StationDataComponent>(stationUid, out var stationData) ||
!TryComp<TransformComponent>(stationData.EmergencyShuttle, out var xform) ||
!TryComp<ShuttleComponent>(stationData.EmergencyShuttle, out var shuttle))
if (!TryComp<StationEmergencyShuttleComponent>(stationUid, out var stationShuttle) ||
!TryComp<TransformComponent>(stationShuttle.EmergencyShuttle, out var xform) ||
!TryComp<ShuttleComponent>(stationShuttle.EmergencyShuttle, out var shuttle))
{
return;
}
var targetGrid = _station.GetLargestGrid(stationData);
var targetGrid = _station.GetLargestGrid(Comp<StationDataComponent>(stationUid.Value));
// UHH GOOD LUCK
if (targetGrid == null)
@@ -164,11 +167,11 @@ public sealed partial class EmergencyShuttleSystem : EntitySystem
var xformQuery = GetEntityQuery<TransformComponent>();
if (_shuttle.TryFTLDock(stationData.EmergencyShuttle.Value, shuttle, targetGrid.Value, DockTag))
if (_shuttle.TryFTLDock(stationShuttle.EmergencyShuttle.Value, shuttle, targetGrid.Value, DockTag))
{
if (TryComp<TransformComponent>(targetGrid.Value, out var targetXform))
{
var angle = _dock.GetAngle(stationData.EmergencyShuttle.Value, xform, targetGrid.Value, targetXform, xformQuery);
var angle = _dock.GetAngle(stationShuttle.EmergencyShuttle.Value, xform, targetGrid.Value, targetXform, xformQuery);
_chatSystem.DispatchStationAnnouncement(stationUid.Value, Loc.GetString("emergency-shuttle-docked", ("time", $"{_consoleAccumulator:0}"), ("direction", angle.GetDir())), playDefaultSound: false);
}
@@ -180,7 +183,7 @@ public sealed partial class EmergencyShuttleSystem : EntitySystem
{
if (TryComp<TransformComponent>(targetGrid.Value, out var targetXform))
{
var angle = _dock.GetAngle(stationData.EmergencyShuttle.Value, xform, targetGrid.Value, targetXform, xformQuery);
var angle = _dock.GetAngle(stationShuttle.EmergencyShuttle.Value, xform, targetGrid.Value, targetXform, xformQuery);
_chatSystem.DispatchStationAnnouncement(stationUid.Value, Loc.GetString("emergency-shuttle-nearby", ("direction", angle.GetDir())), playDefaultSound: false);
}
@@ -190,7 +193,7 @@ public sealed partial class EmergencyShuttleSystem : EntitySystem
}
}
private void OnStationStartup(EntityUid uid, StationDataComponent component, ComponentStartup args)
private void OnStationStartup(EntityUid uid, StationEmergencyShuttleComponent component, ComponentStartup args)
{
AddEmergencyShuttle(component);
}
@@ -254,24 +257,23 @@ public sealed partial class EmergencyShuttleSystem : EntitySystem
_sawmill.Info("No CentCom map found, skipping setup.");
}
foreach (var comp in EntityQuery<StationDataComponent>(true))
foreach (var comp in EntityQuery<StationEmergencyShuttleComponent>(true))
{
AddEmergencyShuttle(comp);
}
}
private void AddEmergencyShuttle(StationDataComponent component)
private void AddEmergencyShuttle(StationEmergencyShuttleComponent component)
{
if (!_emergencyShuttleEnabled
|| CentComMap == null
|| component.EmergencyShuttle != null
|| component.StationConfig == null)
|| component.EmergencyShuttle != null)
{
return;
}
// Load escape shuttle
var shuttlePath = component.StationConfig.EmergencyShuttlePath;
var shuttlePath = component.EmergencyShuttlePath;
var shuttle = _map.LoadGrid(CentComMap.Value, shuttlePath.ToString(), new MapLoadOptions()
{
// Should be far enough... right? I'm too lazy to bounds check CentCom rn.