From 4521dc37f54fd4a2b2ed5270ad0397851668eb9d Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Fri, 4 Nov 2022 10:12:36 +1100 Subject: [PATCH] Remove IMap / IMapGrid comps (#3434) --- Resources/Locale/en-US/commands.ftl | 6 ++ .../GameObjects/ClientComponentFactory.cs | 2 - .../GameObjects/EntitySystems/MapSystem.cs | 2 +- .../Graphics/Clyde/Clyde.LightRendering.cs | 5 +- .../Graphics/Lighting/ILightManager.cs | 4 - .../GameObjects/EntitySystems/MapSystem.cs | 2 +- .../GameObjects/ServerComponentFactory.cs | 2 - Robust.Server/Placement/PlacementManager.cs | 2 +- Robust.Shared/Containers/BaseContainer.cs | 3 +- .../Components/Map/MapComponent.cs | 74 ++----------------- .../Components/Map/MapGridComponent.cs | 18 +---- .../Transform/TransformComponent.cs | 4 +- .../Systems/SharedMapSystem.Light.cs | 44 +++++++++++ .../GameObjects/Systems/SharedMapSystem.cs | 41 +++++++++- .../SharedTransformSystem.Component.cs | 16 ++-- .../Systems/SharedTransformSystem.cs | 2 +- .../Map/Commands/AmbientLightCommand.cs | 54 ++++++++++++++ .../Map/Components/MapLightComponent.cs | 23 ++++++ Robust.Shared/Map/IMapManager.cs | 2 +- Robust.Shared/Map/IMapManagerInternal.cs | 2 - .../Map/MapManager.GridCollection.cs | 24 ++---- Robust.Shared/Map/MapManager.MapCollection.cs | 4 +- Robust.Shared/Map/MapManager.Pause.cs | 12 +-- Robust.Shared/Map/MapManager.cs | 4 +- Robust.Shared/Map/NetworkedMapManager.cs | 2 +- .../Physics/Systems/SharedBroadphaseSystem.cs | 2 +- Robust.UnitTesting/RobustUnitTest.cs | 10 +++ .../Server/RobustServerSimulation.cs | 2 + .../Shared/Map/MapManager_Tests.cs | 6 +- 29 files changed, 229 insertions(+), 145 deletions(-) create mode 100644 Robust.Shared/GameObjects/Systems/SharedMapSystem.Light.cs create mode 100644 Robust.Shared/Map/Commands/AmbientLightCommand.cs create mode 100644 Robust.Shared/Map/Components/MapLightComponent.cs diff --git a/Resources/Locale/en-US/commands.ftl b/Resources/Locale/en-US/commands.ftl index cb0aa5a49b..950af18f8f 100644 --- a/Resources/Locale/en-US/commands.ftl +++ b/Resources/Locale/en-US/commands.ftl @@ -8,6 +8,7 @@ cmd-parse-failure-integer = {$arg} is not a valid integer. cmd-parse-failure-float = {$arg} is not a valid float. cmd-parse-failure-bool = {$arg} is not a valid bool. cmd-parse-failure-uid = {$arg} is not a valid entity UID. +cmd-parse-failure-mapid = {$arg} is not a valid MapId. cmd-parse-failure-entity-exist = UID {$arg} does not correspond to an existing entity. @@ -128,6 +129,11 @@ cmd-monitor-minus-all-hint = Hides all monitors cmd-monitor-plus-all-hint = Shows all monitors +## 'setambientlight' command +cmd-set-ambient-light-desc = Allows you to set the ambient light for the specified map, in SRGB. +cmd-set-ambient-light-help = setambientlight [mapid] [r g b a] +cmd-set-ambient-light-parse = Unable to parse args as a byte values for a color. + ## Mapping commands cmd-savemap-desc = Serializes a map to disk. Will not save a post-init map unless forced. diff --git a/Robust.Client/GameObjects/ClientComponentFactory.cs b/Robust.Client/GameObjects/ClientComponentFactory.cs index f63ef0e06c..0249279fe6 100644 --- a/Robust.Client/GameObjects/ClientComponentFactory.cs +++ b/Robust.Client/GameObjects/ClientComponentFactory.cs @@ -16,8 +16,6 @@ namespace Robust.Client.GameObjects RegisterClass(); RegisterClass(); - RegisterClass(); - RegisterClass(); RegisterClass(); RegisterClass(); RegisterClass(); diff --git a/Robust.Client/GameObjects/EntitySystems/MapSystem.cs b/Robust.Client/GameObjects/EntitySystems/MapSystem.cs index e480e73936..55929dcc67 100644 --- a/Robust.Client/GameObjects/EntitySystems/MapSystem.cs +++ b/Robust.Client/GameObjects/EntitySystems/MapSystem.cs @@ -3,7 +3,7 @@ using Robust.Shared.GameObjects; namespace Robust.Client.GameObjects { - internal sealed class MapSystem : SharedMapSystem + public sealed class MapSystem : SharedMapSystem { protected override void OnMapAdd(EntityUid uid, MapComponent component, ComponentAdd args) { diff --git a/Robust.Client/Graphics/Clyde/Clyde.LightRendering.cs b/Robust.Client/Graphics/Clyde/Clyde.LightRendering.cs index 14dc1836b3..9677dc59d5 100644 --- a/Robust.Client/Graphics/Clyde/Clyde.LightRendering.cs +++ b/Robust.Client/Graphics/Clyde/Clyde.LightRendering.cs @@ -9,6 +9,7 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Map; +using Robust.Shared.Map.Components; using Robust.Shared.Maths; using static Robust.Client.GameObjects.ClientOccluderComponent; using OGLTextureWrapMode = OpenToolkit.Graphics.OpenGL.TextureWrapMode; @@ -338,7 +339,7 @@ namespace Robust.Client.Graphics.Clyde // If this map has lighting disabled, return var mapUid = _mapManager.GetMapEntityId(mapId); - if (!_entityManager.GetComponent(mapUid).LightingEnabled) + if (!_entityManager.GetComponent(mapUid).LightingEnabled) { return; } @@ -396,7 +397,7 @@ namespace Robust.Client.Graphics.Clyde BindRenderTargetImmediate(RtToLoaded(viewport.LightRenderTarget)); CheckGlError(); - GLClearColor(_lightManager.AmbientLightColor); + GLClearColor(_entityManager.GetComponentOrNull(mapUid)?.AmbientLightColor ?? MapLightComponent.DefaultColor); GL.ClearStencil(0xFF); GL.StencilMask(0xFF); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.StencilBufferBit); diff --git a/Robust.Client/Graphics/Lighting/ILightManager.cs b/Robust.Client/Graphics/Lighting/ILightManager.cs index 785cdf6706..3204c4689c 100644 --- a/Robust.Client/Graphics/Lighting/ILightManager.cs +++ b/Robust.Client/Graphics/Lighting/ILightManager.cs @@ -24,9 +24,5 @@ namespace Robust.Client.Graphics /// This is useful to prevent players messing with lighting setup when they shouldn't. /// bool LockConsoleAccess { get; set; } - /// - /// Ambient light. This is in linear-light, i.e. when providing a fixed colour, you must use Color.FromSrgb(Color.Black)! - /// - Color AmbientLightColor { get; set; } } } diff --git a/Robust.Server/GameObjects/EntitySystems/MapSystem.cs b/Robust.Server/GameObjects/EntitySystems/MapSystem.cs index 5326d90abd..70e532c40b 100644 --- a/Robust.Server/GameObjects/EntitySystems/MapSystem.cs +++ b/Robust.Server/GameObjects/EntitySystems/MapSystem.cs @@ -9,7 +9,7 @@ using Robust.Shared.Map; namespace Robust.Server.GameObjects { - internal sealed class MapSystem : SharedMapSystem + public sealed class MapSystem : SharedMapSystem { private bool _deleteEmptyGrids; diff --git a/Robust.Server/GameObjects/ServerComponentFactory.cs b/Robust.Server/GameObjects/ServerComponentFactory.cs index c0dfefef12..11b9c3a3a3 100644 --- a/Robust.Server/GameObjects/ServerComponentFactory.cs +++ b/Robust.Server/GameObjects/ServerComponentFactory.cs @@ -17,8 +17,6 @@ namespace Robust.Server.GameObjects RegisterClass(); RegisterClass(); - RegisterClass(); - RegisterClass(); RegisterClass(); RegisterClass(); RegisterClass(); diff --git a/Robust.Server/Placement/PlacementManager.cs b/Robust.Server/Placement/PlacementManager.cs index 685ab3e5df..ffa8becb56 100644 --- a/Robust.Server/Placement/PlacementManager.cs +++ b/Robust.Server/Placement/PlacementManager.cs @@ -168,7 +168,7 @@ namespace Robust.Server.Placement foreach (EntityUid entity in EntitySystem.Get().GetEntitiesIntersecting(start.GetMapId(_entityManager), new Box2(start.Position, start.Position + rectSize))) { - if (_entityManager.Deleted(entity) || _entityManager.HasComponent(entity) || _entityManager.HasComponent(entity)) + if (_entityManager.Deleted(entity) || _entityManager.HasComponent(entity) || _entityManager.HasComponent(entity)) continue; _entityManager.DeleteEntity(entity); } diff --git a/Robust.Shared/Containers/BaseContainer.cs b/Robust.Shared/Containers/BaseContainer.cs index 0bf8ef75e3..1120dc94fd 100644 --- a/Robust.Shared/Containers/BaseContainer.cs +++ b/Robust.Shared/Containers/BaseContainer.cs @@ -197,7 +197,7 @@ namespace Robust.Shared.Containers IoCManager.Resolve(ref entMan); // no, you can't put maps or grids into containers - if (entMan.HasComponent(toinsert) || entMan.HasComponent(toinsert)) + if (entMan.HasComponent(toinsert) || entMan.HasComponent(toinsert)) return false; var xformSystem = entMan.EntitySysManager.GetEntitySystem(); @@ -261,6 +261,7 @@ namespace Robust.Shared.Containers // Unset flag (before parent change events are raised). meta.Flags &= ~MetaDataFlags.InContainer; + // Implementation specific remove logic InternalRemove(toRemove, entMan); diff --git a/Robust.Shared/GameObjects/Components/Map/MapComponent.cs b/Robust.Shared/GameObjects/Components/Map/MapComponent.cs index c0c2e6203a..2530630654 100644 --- a/Robust.Shared/GameObjects/Components/Map/MapComponent.cs +++ b/Robust.Shared/GameObjects/Components/Map/MapComponent.cs @@ -1,6 +1,5 @@ using System; using Robust.Shared.GameStates; -using Robust.Shared.IoC; using Robust.Shared.Map; using Robust.Shared.Serialization; using Robust.Shared.Serialization.Manager.Attributes; @@ -8,24 +7,10 @@ using Robust.Shared.ViewVariables; namespace Robust.Shared.GameObjects { - /// - /// Represents a world map inside the ECS system. - /// - public interface IMapComponent : IComponent - { - bool LightingEnabled { get; set; } - MapId WorldMap { get; } - bool MapPaused { get; internal set; } - bool MapPreInit { get; internal set; } - } - - /// - [ComponentReference(typeof(IMapComponent))] + [RegisterComponent] [NetworkedComponent] - public sealed class MapComponent : Component, IMapComponent + public sealed class MapComponent : Component { - [Dependency] private readonly IEntityManager _entMan = default!; - [ViewVariables(VVAccess.ReadOnly)] [DataField("index")] private MapId _mapIndex = MapId.Nullspace; @@ -34,7 +19,6 @@ namespace Robust.Shared.GameObjects [DataField(("lightingEnabled"))] public bool LightingEnabled { get; set; } = true; - /// public MapId WorldMap { get => _mapIndex; @@ -42,64 +26,20 @@ namespace Robust.Shared.GameObjects } [ViewVariables(VVAccess.ReadOnly)] - internal bool MapPaused { get; set; } = false; - - /// - bool IMapComponent.MapPaused - { - get => this.MapPaused; - set => this.MapPaused = value; - } + public bool MapPaused { get; set; } = false; [ViewVariables(VVAccess.ReadOnly)] - internal bool MapPreInit { get; set; } = false; - - /// - bool IMapComponent.MapPreInit - { - get => this.MapPreInit; - set => this.MapPreInit = value; - } - - /// - protected override void OnRemove() - { - base.OnRemove(); - - var mapMan = IoCManager.Resolve(); - mapMan.TrueDeleteMap(_mapIndex); - } - - /// - public override ComponentState GetComponentState() - { - return new MapComponentState(_mapIndex, LightingEnabled); - } - - /// - public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) - { - base.HandleComponentState(curState, nextState); - - if (curState is not MapComponentState state) - return; - - _mapIndex = state.MapId; - LightingEnabled = state.LightingEnabled; - var xformQuery = _entMan.GetEntityQuery(); - - xformQuery.GetComponent(Owner).ChangeMapId(_mapIndex, xformQuery); - } + public bool MapPreInit { get; set; } = false; } /// /// Serialized state of a . /// [Serializable, NetSerializable] - internal sealed class MapComponentState : ComponentState + public sealed class MapComponentState : ComponentState { - public MapId MapId { get; } - public bool LightingEnabled { get; } + public MapId MapId; + public bool LightingEnabled; public MapComponentState(MapId mapId, bool lightingEnabled) { diff --git a/Robust.Shared/GameObjects/Components/Map/MapGridComponent.cs b/Robust.Shared/GameObjects/Components/Map/MapGridComponent.cs index 2b69acbd41..cf1fa3272d 100644 --- a/Robust.Shared/GameObjects/Components/Map/MapGridComponent.cs +++ b/Robust.Shared/GameObjects/Components/Map/MapGridComponent.cs @@ -12,18 +12,9 @@ using Robust.Shared.ViewVariables; namespace Robust.Shared.GameObjects { - /// - /// Represents a map grid inside the ECS system. - /// - public interface IMapGridComponent : IComponent - { - IMapGrid Grid { get; } - } - - /// - [ComponentReference(typeof(IMapGridComponent))] + [RegisterComponent] [NetworkedComponent] - internal sealed class MapGridComponent : Component, IMapGridComponent + public sealed class MapGridComponent : Component { [Dependency] private readonly IMapManagerInternal _mapManager = default!; [Dependency] private readonly IEntityManager _entMan = default!; @@ -40,7 +31,6 @@ namespace Robust.Shared.GameObjects [DataField("chunkSize")] private ushort _chunkSize = 16; - /// [ViewVariables] public IMapGrid Grid { @@ -85,7 +75,7 @@ namespace Robust.Shared.GameObjects _chunkSize = state.ChunkSize; } - public MapGrid AllocMapGrid(ushort chunkSize, ushort tileSize) + internal MapGrid AllocMapGrid(ushort chunkSize, ushort tileSize) { DebugTools.Assert(LifeStage == ComponentLifeStage.Added); @@ -98,7 +88,7 @@ namespace Robust.Shared.GameObjects return grid; } - public static void ApplyMapGridState(NetworkedMapManager networkedMapManager, IMapGridComponent gridComp, GameStateMapData.ChunkDatum[] chunkUpdates) + internal static void ApplyMapGridState(NetworkedMapManager networkedMapManager, MapGridComponent gridComp, GameStateMapData.ChunkDatum[] chunkUpdates) { var grid = (MapGrid)gridComp.Grid; networkedMapManager.SuppressOnTileChanged = true; diff --git a/Robust.Shared/GameObjects/Components/Transform/TransformComponent.cs b/Robust.Shared/GameObjects/Components/Transform/TransformComponent.cs index a87eeaf9f1..ff5a7d8f31 100644 --- a/Robust.Shared/GameObjects/Components/Transform/TransformComponent.cs +++ b/Robust.Shared/GameObjects/Components/Transform/TransformComponent.cs @@ -448,12 +448,12 @@ namespace Robust.Shared.GameObjects internal EntityUid? FindGridEntityId(EntityQuery xformQuery) { - if (_entMan.HasComponent(Owner)) + if (_entMan.HasComponent(Owner)) { return null; } - if (_entMan.HasComponent(Owner)) + if (_entMan.HasComponent(Owner)) { return Owner; } diff --git a/Robust.Shared/GameObjects/Systems/SharedMapSystem.Light.cs b/Robust.Shared/GameObjects/Systems/SharedMapSystem.Light.cs new file mode 100644 index 0000000000..9cd9bcf453 --- /dev/null +++ b/Robust.Shared/GameObjects/Systems/SharedMapSystem.Light.cs @@ -0,0 +1,44 @@ +using System; +using Robust.Shared.GameStates; +using Robust.Shared.Map; +using Robust.Shared.Map.Components; +using Robust.Shared.Maths; +using Robust.Shared.Serialization; + +namespace Robust.Shared.GameObjects; + +public abstract partial class SharedMapSystem +{ + public void SetAmbientLight(MapId mapId, Color color) + { + var mapComp = EnsureComp(MapManager.GetMapEntityId(mapId)); + + if (mapComp.AmbientLightColor.Equals(color)) + return; + + mapComp.AmbientLightColor = color; + Dirty(mapComp); + } + + private void OnMapLightGetState(EntityUid uid, MapLightComponent component, ref ComponentGetState args) + { + args.State = new MapLightComponentState() + { + AmbientLightColor = component.AmbientLightColor, + }; + } + + private void OnMapLightHandleState(EntityUid uid, MapLightComponent component, ref ComponentHandleState args) + { + if (args.Current is not MapLightComponentState state) + return; + + component.AmbientLightColor = state.AmbientLightColor; + } + + [Serializable, NetSerializable] + private sealed class MapLightComponentState : ComponentState + { + public Color AmbientLightColor; + } +} diff --git a/Robust.Shared/GameObjects/Systems/SharedMapSystem.cs b/Robust.Shared/GameObjects/Systems/SharedMapSystem.cs index 99fdd48966..c3712fe96b 100644 --- a/Robust.Shared/GameObjects/Systems/SharedMapSystem.cs +++ b/Robust.Shared/GameObjects/Systems/SharedMapSystem.cs @@ -3,13 +3,15 @@ using Robust.Shared.IoC; using Robust.Shared.Map; using Robust.Shared.Maths; using System.Collections.Generic; +using Robust.Shared.GameStates; +using Robust.Shared.Map.Components; namespace Robust.Shared.GameObjects { [UsedImplicitly] - internal abstract class SharedMapSystem : EntitySystem + public abstract partial class SharedMapSystem : EntitySystem { - [Dependency] protected readonly IMapManagerInternal MapManager = default!; + [Dependency] protected readonly IMapManager MapManager = default!; public override void Initialize() { @@ -18,11 +20,33 @@ namespace Robust.Shared.GameObjects SubscribeLocalEvent(OnMapAdd); SubscribeLocalEvent(OnMapInit); SubscribeLocalEvent(OnMapRemoved); + SubscribeLocalEvent(OnMapHandleState); + SubscribeLocalEvent(OnMapGetState); SubscribeLocalEvent(OnGridAdd); SubscribeLocalEvent(OnGridInit); SubscribeLocalEvent(OnGridStartup); SubscribeLocalEvent(OnGridRemove); + + SubscribeLocalEvent(OnMapLightGetState); + SubscribeLocalEvent(OnMapLightHandleState); + } + + private void OnMapHandleState(EntityUid uid, MapComponent component, ref ComponentHandleState args) + { + if (args.Current is not MapComponentState state) + return; + + component.WorldMap = state.MapId; + component.LightingEnabled = state.LightingEnabled; + var xformQuery = GetEntityQuery(); + + xformQuery.GetComponent(uid).ChangeMapId(state.MapId, xformQuery); + } + + private void OnMapGetState(EntityUid uid, MapComponent component, ref ComponentGetState args) + { + args.State = new MapComponentState(component.WorldMap, component.LightingEnabled); } protected abstract void OnMapAdd(EntityUid uid, MapComponent component, ComponentAdd args); @@ -35,6 +59,10 @@ namespace Robust.Shared.GameObjects private void OnMapRemoved(EntityUid uid, MapComponent component, ComponentShutdown args) { + var iMap = (IMapManagerInternal)MapManager; + + iMap.TrueDeleteMap(component.WorldMap); + var msg = new MapChangedEvent(component.WorldMap, false); RaiseLocalEvent(uid, msg, true); } @@ -61,7 +89,14 @@ namespace Robust.Shared.GameObjects private void OnGridRemove(EntityUid uid, MapGridComponent component, ComponentShutdown args) { RaiseLocalEvent(uid, new GridRemovalEvent(uid), true); - MapManager.OnComponentRemoved(component); + + if (uid == EntityUid.Invalid) + return; + + if (!MapManager.GridExists(uid)) + return; + + MapManager.DeleteGrid(uid); } } diff --git a/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs b/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs index d4c36bf0de..4bf051c940 100644 --- a/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs +++ b/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs @@ -110,7 +110,7 @@ public abstract partial class SharedTransformSystem if (xform.LifeStage < ComponentLifeStage.Initialized) return; - if (TryComp(xform.GridUid, out IMapGridComponent? grid)) + if (TryComp(xform.GridUid, out MapGridComponent? grid)) { var tileIndices = grid.Grid.TileIndicesFor(xform.Coordinates); grid.Grid.RemoveFromSnapGridCell(tileIndices, xform.Owner); @@ -179,7 +179,7 @@ public abstract partial class SharedTransformSystem { // Children MAY be initialized here before their parents are. // We do this whole dance to handle this recursively, - // setting _mapIdInitialized along the way to avoid going to the IMapComponent every iteration. + // setting _mapIdInitialized along the way to avoid going to the MapComponent every iteration. static MapId FindMapIdAndSet(TransformComponent xform, IEntityManager entMan, EntityQuery xformQuery) { if (xform._mapIdInitialized) @@ -194,7 +194,7 @@ public abstract partial class SharedTransformSystem else { // second level node, terminates recursion up the branch of the tree - if (entMan.TryGetComponent(xform.Owner, out IMapComponent? mapComp)) + if (entMan.TryGetComponent(xform.Owner, out MapComponent? mapComp)) { value = mapComp.WorldMap; } @@ -250,7 +250,7 @@ public abstract partial class SharedTransformSystem IMapGrid? grid; // First try find grid via parent: - if (component.GridUid == component.ParentUid && TryComp(component.ParentUid, out IMapGridComponent? gridComp)) + if (component.GridUid == component.ParentUid && TryComp(component.ParentUid, out MapGridComponent? gridComp)) { grid = gridComp.Grid; } @@ -574,7 +574,7 @@ public abstract partial class SharedTransformSystem || xform.ParentUid != newParentId) { // remove from any old grid lookups - if (xform.Anchored && TryComp(xform.ParentUid, out IMapGridComponent? grid)) + if (xform.Anchored && TryComp(xform.ParentUid, out MapGridComponent? grid)) { var tileIndices = grid.Grid.TileIndicesFor(xform.Coordinates); grid.Grid.RemoveFromSnapGridCell(tileIndices, xform.Owner); @@ -592,7 +592,7 @@ public abstract partial class SharedTransformSystem // or by the following AnchorStateChangedEvent if (xform._anchored && xform.Initialized) { - if (xform.ParentUid == xform.GridUid && TryComp(xform.GridUid, out IMapGridComponent? newGrid)) + if (xform.ParentUid == xform.GridUid && TryComp(xform.GridUid, out MapGridComponent? newGrid)) { var tileIndices = newGrid.Grid.TileIndicesFor(xform.Coordinates); newGrid.Grid.AddToSnapGridCell(tileIndices, xform.Owner); @@ -614,7 +614,7 @@ public abstract partial class SharedTransformSystem var ev = new AnchorStateChangedEvent(xform); RaiseLocalEvent(xform.Owner, ref ev, true); } - + xform._prevPosition = newState.LocalPosition; xform._prevRotation = newState.Rotation; xform._noLocalRotation = newState.NoLocalRotation; @@ -972,7 +972,7 @@ public abstract partial class SharedTransformSystem if (xform.Anchored && metaQuery.TryGetComponent(xform.GridUid, out var meta) && meta.EntityLifeStage <= EntityLifeStage.MapInitialized) { - var grid = Comp(xform.GridUid.Value); + var grid = Comp(xform.GridUid.Value); var tileIndices = grid.Grid.TileIndicesFor(xform.Coordinates); grid.Grid.RemoveFromSnapGridCell(tileIndices, xform.Owner); xform._anchored = false; diff --git a/Robust.Shared/GameObjects/Systems/SharedTransformSystem.cs b/Robust.Shared/GameObjects/Systems/SharedTransformSystem.cs index d106600aff..488d02588e 100644 --- a/Robust.Shared/GameObjects/Systems/SharedTransformSystem.cs +++ b/Robust.Shared/GameObjects/Systems/SharedTransformSystem.cs @@ -104,7 +104,7 @@ namespace Robust.Shared.GameObjects public void DeferMoveEvent(ref MoveEvent moveEvent) { - if (EntityManager.HasComponent(moveEvent.Sender)) + if (EntityManager.HasComponent(moveEvent.Sender)) _gridMoves.Enqueue(moveEvent); else _otherMoves.Enqueue(moveEvent); diff --git a/Robust.Shared/Map/Commands/AmbientLightCommand.cs b/Robust.Shared/Map/Commands/AmbientLightCommand.cs new file mode 100644 index 0000000000..576cdbb668 --- /dev/null +++ b/Robust.Shared/Map/Commands/AmbientLightCommand.cs @@ -0,0 +1,54 @@ +using Robust.Shared.Console; +using Robust.Shared.GameObjects; +using Robust.Shared.IoC; +using Robust.Shared.Localization; +using Robust.Shared.Maths; + +namespace Robust.Shared.Map.Commands; + +/// +/// Sets the ambient light for a particular map +/// +public sealed class AmbientLightCommand : IConsoleCommand +{ + public string Command => $"setambientlight"; + public string Description => Loc.GetString("cmd-set-ambient-light-desc"); + public string Help => Loc.GetString("cmd-set-ambient-light-help"); + public void Execute(IConsoleShell shell, string argStr, string[] args) + { + if (args.Length != 5) + { + shell.WriteError(Loc.GetString("cmd-invalid-arg-number-error")); + return; + } + + var mapManager = IoCManager.Resolve(); + + if (!int.TryParse(args[0], out var mapInt)) + { + shell.WriteError(Loc.GetString("cmd-parse-failure-integer")); + return; + } + + var mapId = new MapId(mapInt); + + if (!mapManager.MapExists(mapId)) + { + shell.WriteError(Loc.GetString("cmd-parse-failure-mapid")); + return; + } + + if (!byte.TryParse(args[1], out var r) || + !byte.TryParse(args[2], out var g) || + !byte.TryParse(args[3], out var b) || + !byte.TryParse(args[4], out var a)) + { + shell.WriteError(Loc.GetString("cmd-set-ambient-light-parse")); + return; + } + + var color = Color.FromSrgb(new Color(r, g, b, a)); + var mapSystem = IoCManager.Resolve().GetEntitySystem(); + mapSystem.SetAmbientLight(mapId, color); + } +} diff --git a/Robust.Shared/Map/Components/MapLightComponent.cs b/Robust.Shared/Map/Components/MapLightComponent.cs new file mode 100644 index 0000000000..14b878538e --- /dev/null +++ b/Robust.Shared/Map/Components/MapLightComponent.cs @@ -0,0 +1,23 @@ +using Robust.Shared.GameObjects; +using Robust.Shared.GameStates; +using Robust.Shared.Maths; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.ViewVariables; + +namespace Robust.Shared.Map.Components; + +/// +/// Controls per-map lighting values. +/// +[RegisterComponent, NetworkedComponent] +public sealed class MapLightComponent : Component +{ + public static readonly Color DefaultColor = Color.FromSrgb(Color.Black); + + /// + /// Ambient light. This is in linear-light, i.e. when providing a fixed colour, you must use Color.FromSrgb(Color.Black)! + /// + [ViewVariables(VVAccess.ReadWrite)] + [DataField("ambientLightColor")] + public Color AmbientLightColor { get; set; } = Color.FromSrgb(Color.Black); +} diff --git a/Robust.Shared/Map/IMapManager.cs b/Robust.Shared/Map/IMapManager.cs index 06c9bbd0c9..4d46318760 100644 --- a/Robust.Shared/Map/IMapManager.cs +++ b/Robust.Shared/Map/IMapManager.cs @@ -188,7 +188,7 @@ namespace Robust.Shared.Map [Obsolete("Whatever this is used for, it is a terrible idea. Create a new map and get it's MapId.")] MapId NextMapId(); - IMapGridComponent GetGridComp(EntityUid euid); + MapGridComponent GetGridComp(EntityUid euid); // // Pausing functions diff --git a/Robust.Shared/Map/IMapManagerInternal.cs b/Robust.Shared/Map/IMapManagerInternal.cs index 8697c88ffe..f962fc61aa 100644 --- a/Robust.Shared/Map/IMapManagerInternal.cs +++ b/Robust.Shared/Map/IMapManagerInternal.cs @@ -13,8 +13,6 @@ namespace Robust.Shared.Map IGameTiming GameTiming { get; } IEntityManager EntityManager { get; } - void OnComponentRemoved(MapGridComponent comp); - void ChunkRemoved(EntityUid gridId, MapChunk chunk); /// diff --git a/Robust.Shared/Map/MapManager.GridCollection.cs b/Robust.Shared/Map/MapManager.GridCollection.cs index 6d5caad287..b403c5ef56 100644 --- a/Robust.Shared/Map/MapManager.GridCollection.cs +++ b/Robust.Shared/Map/MapManager.GridCollection.cs @@ -65,9 +65,9 @@ internal partial class MapManager public virtual void ChunkRemoved(EntityUid gridId, MapChunk chunk) { } - public IMapGridComponent GetGridComp(EntityUid euid) + public MapGridComponent GetGridComp(EntityUid euid) { - return EntityManager.GetComponent(euid); + return EntityManager.GetComponent(euid); } /// @@ -121,12 +121,12 @@ internal partial class MapManager public bool IsGrid(EntityUid uid) { - return EntityManager.HasComponent(uid); + return EntityManager.HasComponent(uid); } public bool TryGetGrid([NotNullWhen(true)] EntityUid? euid, [MaybeNullWhen(false)] out IMapGrid grid) { - if (EntityManager.TryGetComponent(euid, out IMapGridComponent? comp)) + if (EntityManager.TryGetComponent(euid, out MapGridComponent? comp)) { grid = comp.Grid; return true; @@ -138,14 +138,14 @@ internal partial class MapManager public bool GridExists([NotNullWhen(true)] EntityUid? euid) { - return EntityManager.HasComponent(euid); + return EntityManager.HasComponent(euid); } public IEnumerable GetAllMapGrids(MapId mapId) { var xformQuery = EntityManager.GetEntityQuery(); - return EntityManager.EntityQuery(true) + return EntityManager.EntityQuery(true) .Where(c => xformQuery.GetComponent(c.Grid.GridEntityId).MapID == mapId) .Select(c => c.Grid); } @@ -214,18 +214,6 @@ internal partial class MapManager /// public bool SuppressOnTileChanged { get; set; } - public void OnComponentRemoved(MapGridComponent comp) - { - var gridIndex = comp.Owner; - if (gridIndex == EntityUid.Invalid) - return; - - if (!GridExists(gridIndex)) - return; - - DeleteGrid(gridIndex); - } - /// /// Raises the OnTileChanged event. /// diff --git a/Robust.Shared/Map/MapManager.MapCollection.cs b/Robust.Shared/Map/MapManager.MapCollection.cs index adb0d0b2e9..28234e3faa 100644 --- a/Robust.Shared/Map/MapManager.MapCollection.cs +++ b/Robust.Shared/Map/MapManager.MapCollection.cs @@ -211,7 +211,7 @@ internal partial class MapManager /// public bool IsMap(EntityUid uid) { - return EntityManager.HasComponent(uid); + return EntityManager.HasComponent(uid); } /// @@ -246,7 +246,7 @@ internal partial class MapManager { var mapComps = EntityManager.EntityQuery(true); - IMapComponent? result = null; + MapComponent? result = null; foreach (var mapComp in mapComps) { if (mapComp.WorldMap != actualId) diff --git a/Robust.Shared/Map/MapManager.Pause.cs b/Robust.Shared/Map/MapManager.Pause.cs index 5b9c61816f..79bd1a3f25 100644 --- a/Robust.Shared/Map/MapManager.Pause.cs +++ b/Robust.Shared/Map/MapManager.Pause.cs @@ -58,7 +58,7 @@ namespace Robust.Shared.Map throw new ArgumentException("That map is already initialized."); var mapEnt = GetMapEntityId(mapId); - var mapComp = EntityManager.GetComponent(mapEnt); + var mapComp = EntityManager.GetComponent(mapEnt); var xformQuery = EntityManager.GetEntityQuery(); var metaQuery = EntityManager.GetEntityQuery(); var metaSystem = EntityManager.EntitySysManager.GetEntitySystem(); @@ -100,7 +100,7 @@ namespace Robust.Shared.Map return; var mapEuid = GetMapEntityId(mapId); - var mapComp = EntityManager.GetComponent(mapEuid); + var mapComp = EntityManager.GetComponent(mapEuid); mapComp.MapPaused = true; } @@ -114,7 +114,7 @@ namespace Robust.Shared.Map if (mapEuid == EntityUid.Invalid) return false; - var mapComp = EntityManager.GetComponent(mapEuid); + var mapComp = EntityManager.GetComponent(mapEuid); return mapComp.MapPaused; } @@ -124,7 +124,7 @@ namespace Robust.Shared.Map return; var mapEuid = GetMapEntityId(mapId); - var mapComp = EntityManager.GetComponent(mapEuid); + var mapComp = EntityManager.GetComponent(mapEuid); mapComp.MapPaused = false; } @@ -134,7 +134,7 @@ namespace Robust.Shared.Map return; var mapEuid = GetMapEntityId(mapId); - var mapComp = EntityManager.GetComponent(mapEuid); + var mapComp = EntityManager.GetComponent(mapEuid); mapComp.MapPreInit = true; } @@ -148,7 +148,7 @@ namespace Robust.Shared.Map if (mapEuid == EntityUid.Invalid) return false; - var mapComp = EntityManager.GetComponent(mapEuid); + var mapComp = EntityManager.GetComponent(mapEuid); return mapComp.MapPreInit; } diff --git a/Robust.Shared/Map/MapManager.cs b/Robust.Shared/Map/MapManager.cs index a568e2b237..94b0d547ae 100644 --- a/Robust.Shared/Map/MapManager.cs +++ b/Robust.Shared/Map/MapManager.cs @@ -52,7 +52,7 @@ internal partial class MapManager : IMapManagerInternal, IEntityEventSubscriber #endif Logger.DebugS("map", "Stopping..."); - foreach (var mapComp in EntityManager.EntityQuery()) + foreach (var mapComp in EntityManager.EntityQuery()) { EntityManager.DeleteEntity(mapComp.Owner); } @@ -72,7 +72,7 @@ internal partial class MapManager : IMapManagerInternal, IEntityEventSubscriber // Don't just call Shutdown / Startup because we don't want to touch the subscriptions on gridtrees // Restart can be called any time during a game, whereas shutdown / startup are typically called upon connection. - foreach (var mapComp in EntityManager.EntityQuery()) + foreach (var mapComp in EntityManager.EntityQuery()) { EntityManager.DeleteEntity(mapComp.Owner); } diff --git a/Robust.Shared/Map/NetworkedMapManager.cs b/Robust.Shared/Map/NetworkedMapManager.cs index 0f18871479..b62df1d615 100644 --- a/Robust.Shared/Map/NetworkedMapManager.cs +++ b/Robust.Shared/Map/NetworkedMapManager.cs @@ -192,7 +192,7 @@ internal sealed class NetworkedMapManager : MapManager, INetworkedMapManager var xformComp = EntityManager.GetComponent(gridId); ApplyTransformState(xformComp, gridDatum); - var gridComp = EntityManager.GetComponent(gridId); + var gridComp = EntityManager.GetComponent(gridId); MapGridComponent.ApplyMapGridState(this, gridComp, gridDatum.ChunkData); } } diff --git a/Robust.Shared/Physics/Systems/SharedBroadphaseSystem.cs b/Robust.Shared/Physics/Systems/SharedBroadphaseSystem.cs index 0240fb396d..68cf316086 100644 --- a/Robust.Shared/Physics/Systems/SharedBroadphaseSystem.cs +++ b/Robust.Shared/Physics/Systems/SharedBroadphaseSystem.cs @@ -458,7 +458,7 @@ namespace Robust.Shared.Physics.Systems { if (xform.MapID != mapId) continue; - if (!EntityManager.TryGetComponent(broadphase.Owner, out IMapGridComponent? mapGrid)) + if (!EntityManager.TryGetComponent(broadphase.Owner, out MapGridComponent? mapGrid)) { yield return broadphase; continue; diff --git a/Robust.UnitTesting/RobustUnitTest.cs b/Robust.UnitTesting/RobustUnitTest.cs index 0dc00a2cd7..137223f710 100644 --- a/Robust.UnitTesting/RobustUnitTest.cs +++ b/Robust.UnitTesting/RobustUnitTest.cs @@ -117,6 +117,16 @@ namespace Robust.UnitTesting // Required components for the engine to work var compFactory = IoCManager.Resolve(); + if (!compFactory.AllRegisteredTypes.Contains(typeof(MapComponent))) + { + compFactory.RegisterClass(); + } + + if (!compFactory.AllRegisteredTypes.Contains(typeof(MapGridComponent))) + { + compFactory.RegisterClass(); + } + if (!compFactory.AllRegisteredTypes.Contains(typeof(MetaDataComponent))) { compFactory.RegisterClass(); diff --git a/Robust.UnitTesting/Server/RobustServerSimulation.cs b/Robust.UnitTesting/Server/RobustServerSimulation.cs index e8c8409e82..e0fe36d4f7 100644 --- a/Robust.UnitTesting/Server/RobustServerSimulation.cs +++ b/Robust.UnitTesting/Server/RobustServerSimulation.cs @@ -23,6 +23,7 @@ using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Log; using Robust.Shared.Map; +using Robust.Shared.Map.Components; using Robust.Shared.Network; using Robust.Shared.Physics; using Robust.Shared.Physics.Collision; @@ -246,6 +247,7 @@ namespace Robust.UnitTesting.Server compFactory.RegisterClass(); compFactory.RegisterClass(); compFactory.RegisterClass(); + compFactory.RegisterClass(); compFactory.RegisterClass(); compFactory.RegisterClass(); compFactory.RegisterClass(); diff --git a/Robust.UnitTesting/Shared/Map/MapManager_Tests.cs b/Robust.UnitTesting/Shared/Map/MapManager_Tests.cs index a3f49e7791..f2afc98a12 100644 --- a/Robust.UnitTesting/Shared/Map/MapManager_Tests.cs +++ b/Robust.UnitTesting/Shared/Map/MapManager_Tests.cs @@ -70,7 +70,7 @@ namespace Robust.UnitTesting.Shared.Map } /// - /// When using SetMapEntity, the existing entities on the map are removed, and the new map entity gets a IMapComponent. + /// When using SetMapEntity, the existing entities on the map are removed, and the new map entity gets a MapComponent. /// [Test] public void SetMapEntity_WithExistingEntity_ExistingEntityDeleted() @@ -92,9 +92,9 @@ namespace Robust.UnitTesting.Shared.Map // Assert Assert.That(entMan.Deleted(oldMapEntity)); - Assert.That(entMan.HasComponent(newMapEntity)); + Assert.That(entMan.HasComponent(newMapEntity)); - var mapComp = entMan.GetComponent(newMapEntity); + var mapComp = entMan.GetComponent(newMapEntity); Assert.That(mapComp.WorldMap == mapID); }