using System; using Robust.Shared.Map; using Robust.Shared.Prototypes; using Robust.Shared.Players; using Robust.Shared.Serialization; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Robust.Shared.GameObjects { /// /// Represents a world map inside the ECS system. /// public interface IMapComponent : IComponent { MapId WorldMap { get; } void ClearMapId(); } /// public class MapComponent : Component, IMapComponent { [ViewVariables(VVAccess.ReadOnly)] [DataField("index")] private MapId _mapIndex = MapId.Nullspace; /// public override string Name => "Map"; /// public override uint? NetID => NetIDs.MAP_MAP; /// public MapId WorldMap { get => _mapIndex; internal set => _mapIndex = value; } /// public void ClearMapId() { _mapIndex = MapId.Nullspace; } /// /// public override ComponentState GetComponentState(ICommonSession player) { return new MapComponentState(_mapIndex); } /// 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); } } /// /// Serialized state of a . /// [Serializable, NetSerializable] internal class MapComponentState : ComponentState { public MapId MapId { get; } public MapComponentState(MapId mapId) : base(NetIDs.MAP_MAP) { MapId = mapId; } } }