fish-station/Content.Shared/_Starlight/StarlightEntitySystem.Singleton.cs
Vigers Ray b52f640b5a
Порт стрельбы со старлайна (#2640)
Co-authored-by: KaiserMaus <kaiser.ratte@gmail.com>
2025-08-08 22:25:02 +03:00

31 lines
975 B
C#

using Content.Shared.GameTicking;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
namespace Content.Server.Administration.Systems;
public sealed partial class StarlightEntitySystem : EntitySystem
{
private readonly Dictionary<EntProtoId, EntityUid> _entities = [];
private void OnRoundRestartCleanup(RoundRestartCleanupEvent ev) => _entities.Clear();
public bool TryGetSingleton(EntProtoId surgeryOrStep, out EntityUid uid)
{
uid = EntityUid.Invalid;
if (!_prototypes.HasIndex(surgeryOrStep))
{
_sawmill.Error("Prototype '{PrototypeId}' is not registered. Cannot retrieve or spawn a singleton entity.", surgeryOrStep);
return false;
}
if (!_entities.TryGetValue(surgeryOrStep, out uid) || TerminatingOrDeleted(uid))
{
uid = Spawn(surgeryOrStep, MapCoordinates.Nullspace);
_entities[surgeryOrStep] = uid;
}
return true;
}
}