From ae81bc11569067d26de68fa8591ce474b8fedddc Mon Sep 17 00:00:00 2001 From: Whatstone Date: Mon, 14 Oct 2024 19:34:13 -0400 Subject: [PATCH] SectorServices: spawn in nullspace --- .../_NF/SectorServices/SectorServiceSystem.cs | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/Content.Server/_NF/SectorServices/SectorServiceSystem.cs b/Content.Server/_NF/SectorServices/SectorServiceSystem.cs index 8f1df78d0c8..147170ba60f 100644 --- a/Content.Server/_NF/SectorServices/SectorServiceSystem.cs +++ b/Content.Server/_NF/SectorServices/SectorServiceSystem.cs @@ -1,5 +1,7 @@ +using Content.Server.GameTicking; using Content.Shared._NF.SectorServices.Prototypes; using JetBrains.Annotations; +using Robust.Shared.Map.Components; using Robust.Shared.Prototypes; @@ -12,8 +14,9 @@ namespace Content.Server._NF.SectorServices; [PublicAPI] public sealed class SectorServiceSystem : EntitySystem { - [Robust.Shared.IoC.Dependency] private readonly IPrototypeManager _prototypeManager = default!; - [Robust.Shared.IoC.Dependency] private readonly IEntityManager _entityManager = default!; + [Dependency] private readonly IPrototypeManager _prototypeManager = default!; + [Dependency] private readonly IEntityManager _entityManager = default!; + [Dependency] private readonly GameTicker _gameTicker = default!; [ViewVariables(VVAccess.ReadOnly)] private EntityUid _entity = EntityUid.Invalid; // The station entity that's storing our services. @@ -22,16 +25,18 @@ public override void Initialize() { base.Initialize(); - SubscribeLocalEvent(OnComponentStartup); - SubscribeLocalEvent(OnComponentShutdown); + //SubscribeLocalEvent(OnComponentStartup); + //SubscribeLocalEvent(OnComponentShutdown); + SubscribeLocalEvent(OnMapInit); + SubscribeLocalEvent(OnMapRemove); } - private void OnComponentStartup(EntityUid uid, StationSectorServiceHostComponent component, ComponentStartup args) + private void OnMapInit(EntityUid uid, MapComponent map, ComponentInit args) { - Log.Debug($"OnComponentStartup! Entity: {uid} internal: {_entity}"); - if (_entity == EntityUid.Invalid) + Log.Debug($"OnMapInit! Entity: {uid} internal: {_entity}"); + if (map.MapId == _gameTicker.DefaultMap) { - _entity = uid; + _entity = Spawn(); foreach (var servicePrototype in _prototypeManager.EnumeratePrototypes()) { @@ -41,16 +46,12 @@ private void OnComponentStartup(EntityUid uid, StationSectorServiceHostComponent } } - private void OnComponentShutdown(EntityUid uid, StationSectorServiceHostComponent component, ComponentShutdown args) + private void OnMapRemove(EntityUid uid, MapComponent map, ComponentRemove args) { - Log.Debug($"OnComponentShutdown! Entity: {_entity}"); - if (_entity != EntityUid.Invalid) + Log.Debug($"OnMapRemove! Entity: {_entity}"); + if (map.MapId == _gameTicker.DefaultMap) { - foreach (var servicePrototype in _prototypeManager.EnumeratePrototypes()) - { - Log.Debug($"Removing component for service {servicePrototype.ID}"); - _entityManager.RemoveComponents(_entity, servicePrototype.Components); - } + Del(_entity); _entity = EntityUid.Invalid; } }