mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-02 01:57:07 +02:00
87 lines
2.2 KiB
C#
87 lines
2.2 KiB
C#
using System;
|
|
using Robust.Shared.GameObjects.Components.Transform;
|
|
using Robust.Shared.Interfaces.GameObjects;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Serialization;
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
namespace Robust.Shared.GameObjects.Components.Map
|
|
{
|
|
/// <summary>
|
|
/// Represents a world map inside the ECS system.
|
|
/// </summary>
|
|
public interface IMapComponent : IComponent
|
|
{
|
|
MapId WorldMap { get; }
|
|
void ClearMapId();
|
|
}
|
|
|
|
/// <inheritdoc cref="IMapComponent"/>
|
|
public class MapComponent : Component, IMapComponent
|
|
{
|
|
[ViewVariables(VVAccess.ReadOnly)]
|
|
private MapId _mapIndex;
|
|
|
|
/// <inheritdoc />
|
|
public override string Name => "Map";
|
|
|
|
/// <inheritdoc />
|
|
public override uint? NetID => NetIDs.MAP_MAP;
|
|
|
|
/// <inheritdoc />
|
|
public MapId WorldMap
|
|
{
|
|
get => _mapIndex;
|
|
internal set => _mapIndex = value;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public void ClearMapId()
|
|
{
|
|
_mapIndex = MapId.Nullspace;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override ComponentState GetComponentState()
|
|
{
|
|
return new MapComponentState(_mapIndex);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
|
{
|
|
base.HandleComponentState(curState, nextState);
|
|
|
|
if (!(curState is MapComponentState state))
|
|
return;
|
|
|
|
_mapIndex = state.MapId;
|
|
|
|
((TransformComponent) Owner.Transform).ChangeMapId(_mapIndex);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override void ExposeData(ObjectSerializer serializer)
|
|
{
|
|
base.ExposeData(serializer);
|
|
|
|
serializer.DataField(ref _mapIndex, "index", MapId.Nullspace);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Serialized state of a <see cref="MapGridComponentState"/>.
|
|
/// </summary>
|
|
[Serializable, NetSerializable]
|
|
internal class MapComponentState : ComponentState
|
|
{
|
|
public MapId MapId { get; }
|
|
public override uint NetID => NetIDs.MAP_MAP;
|
|
|
|
public MapComponentState(MapId mapId)
|
|
{
|
|
MapId = mapId;
|
|
}
|
|
}
|
|
}
|