Files
RobustToolbox/Robust.Shared/GameObjects/Systems/SharedMapSystem.cs
T
metalgearslothandGitHub d72185933a Add support for grid chunk removals (#1941)
* Add support for grid chunk removals

Also allows grids to be removed when they have no more chunks remaining.

* No more crashing pog

* Slightly better

* Minor optimisations and fix bounds

* Avoid creating new chunks for anchoring

* chucky

* comment

* Tests

* Remove some logs

* Remove another log

* Review
2021-08-23 16:00:07 +10:00

66 lines
2.0 KiB
C#

using JetBrains.Annotations;
using Robust.Shared.IoC;
using Robust.Shared.Map;
namespace Robust.Shared.GameObjects
{
[UsedImplicitly]
internal abstract class SharedMapSystem : EntitySystem
{
[Dependency] protected readonly IMapManagerInternal MapManager = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<MapGridComponent, ComponentRemove>(RemoveHandler);
SubscribeLocalEvent<MapGridComponent, ComponentInit>(HandleGridInitialize);
SubscribeLocalEvent<MapGridComponent, ComponentStartup>(HandleGridStartup);
}
private void HandleGridStartup(EntityUid uid, MapGridComponent component, ComponentStartup args)
{
var msg = new GridStartupEvent(uid, component.GridIndex);
EntityManager.EventBus.RaiseLocalEvent(uid, msg);
}
private void RemoveHandler(EntityUid uid, MapGridComponent component, ComponentRemove args)
{
MapManager.OnComponentRemoved(component);
}
private void HandleGridInitialize(EntityUid uid, MapGridComponent component, ComponentInit args)
{
var msg = new GridInitializeEvent(uid, component.GridIndex);
EntityManager.EventBus.RaiseLocalEvent(uid, msg);
}
}
public sealed class GridStartupEvent : EntityEventArgs
{
public EntityUid EntityUid { get; }
public GridId GridId { get; }
public GridStartupEvent(EntityUid uid, GridId gridId)
{
EntityUid = uid;
GridId = gridId;
}
}
/// <summary>
/// Raised whenever a grid is being initialized.
/// </summary>
public sealed class GridInitializeEvent : EntityEventArgs
{
public EntityUid EntityUid { get; }
public GridId GridId { get; }
public GridInitializeEvent(EntityUid uid, GridId gridId)
{
EntityUid = uid;
GridId = gridId;
}
}
}