2025-04-27 11:13:52 +02:00
|
|
|
using Content.Shared.EntityTable;
|
|
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
|
|
|
|
|
namespace Content.Shared.ComponentTable;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Applies an entity prototype to an entity on map init. Taken from entities inside an EntityTableSelector.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class SharedComponentTableSystem : EntitySystem
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly EntityTableSystem _entTable = default!;
|
|
|
|
|
[Dependency] private readonly IPrototypeManager _proto = default!;
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<ComponentTableComponent, MapInitEvent>(OnTableInit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnTableInit(Entity<ComponentTableComponent> ent, ref MapInitEvent args)
|
|
|
|
|
{
|
|
|
|
|
var spawns = _entTable.GetSpawns(ent.Comp.Table);
|
|
|
|
|
|
|
|
|
|
foreach (var entity in spawns)
|
|
|
|
|
{
|
2025-09-09 18:17:56 +02:00
|
|
|
if (_proto.Resolve(entity, out var entProto))
|
2025-04-27 11:13:52 +02:00
|
|
|
{
|
|
|
|
|
EntityManager.AddComponents(ent, entProto.Components);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|