Files
RobustToolbox/Robust.Shared/GameObjects/IMapInit.cs
T
mirrorcultandGitHub 25881ce343 MapInit ECS event (#1813)
* MapInit ECS event

* allocs
2021-06-08 22:33:21 +02:00

39 lines
1.1 KiB
C#

using Robust.Shared.Utility;
namespace Robust.Shared.GameObjects
{
/// <summary>
/// Defines a component that has "map initialization" behavior.
/// Basically irreversible behavior that moves the map from "map editor" to playable,
/// like spawning preset objects.
/// </summary>
public interface IMapInit
{
void MapInit();
}
/// <summary>
/// Raised directed on an entity when the map is initialized.
/// </summary>
public class MapInitEvent : EntityEventArgs
{
}
public static class MapInitExt
{
private static readonly MapInitEvent MapInit = new MapInitEvent();
public static void RunMapInit(this IEntity entity)
{
DebugTools.Assert(entity.LifeStage == EntityLifeStage.Initialized);
entity.LifeStage = EntityLifeStage.MapInitialized;
entity.EntityManager.EventBus.RaiseLocalEvent(entity.Uid, MapInit, false);
foreach (var init in entity.GetAllComponents<IMapInit>())
{
init.MapInit();
}
}
}
}