Visualized regions for NavMapControl (#31910)
* Atmospheric alerts computer * Moved components, restricted access to them * Minor tweaks * The screen will now turn off when the computer is not powered * Bug fix * Adjusted label * Updated to latest master version * Initial commit * Tidy up * Add firelocks to the nav map * Add nav map regions to atmos alerts computer * Added support for multiple region overlay sets per grid * Fixed issue where console values were not updating correctly * Fixing merge conflict * Fixing merge conflicts * Finished all major features * Removed station map regions (to be re-added in a separate PR) * Improved clarity * Adjusted the color saturation of the regions displayed on the atmos alerts computer
This commit is contained in:
@@ -3,10 +3,9 @@ using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Content.Shared.Tag;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Shared.Pinpointer;
|
||||
|
||||
@@ -16,7 +15,7 @@ public abstract class SharedNavMapSystem : EntitySystem
|
||||
public const int Directions = 4; // Not directly tied to number of atmos directions
|
||||
|
||||
public const int ChunkSize = 8;
|
||||
public const int ArraySize = ChunkSize* ChunkSize;
|
||||
public const int ArraySize = ChunkSize * ChunkSize;
|
||||
|
||||
public const int AllDirMask = (1 << Directions) - 1;
|
||||
public const int AirlockMask = AllDirMask << (int) NavMapChunkType.Airlock;
|
||||
@@ -24,6 +23,7 @@ public abstract class SharedNavMapSystem : EntitySystem
|
||||
public const int FloorMask = AllDirMask << (int) NavMapChunkType.Floor;
|
||||
|
||||
[Robust.Shared.IoC.Dependency] private readonly TagSystem _tagSystem = default!;
|
||||
[Robust.Shared.IoC.Dependency] private readonly INetManager _net = default!;
|
||||
|
||||
private static readonly ProtoId<TagPrototype>[] WallTags = {"Wall", "Window"};
|
||||
private EntityQuery<NavMapDoorComponent> _doorQuery;
|
||||
@@ -57,7 +57,7 @@ public abstract class SharedNavMapSystem : EntitySystem
|
||||
public NavMapChunkType GetEntityType(EntityUid uid)
|
||||
{
|
||||
if (_doorQuery.HasComp(uid))
|
||||
return NavMapChunkType.Airlock;
|
||||
return NavMapChunkType.Airlock;
|
||||
|
||||
if (_tagSystem.HasAnyTag(uid, WallTags))
|
||||
return NavMapChunkType.Wall;
|
||||
@@ -81,6 +81,57 @@ public abstract class SharedNavMapSystem : EntitySystem
|
||||
return true;
|
||||
}
|
||||
|
||||
public void AddOrUpdateNavMapRegion(EntityUid uid, NavMapComponent component, NetEntity regionOwner, NavMapRegionProperties regionProperties)
|
||||
{
|
||||
// Check if a new region has been added or an existing one has been altered
|
||||
var isDirty = !component.RegionProperties.TryGetValue(regionOwner, out var oldProperties) || oldProperties != regionProperties;
|
||||
|
||||
if (isDirty)
|
||||
{
|
||||
component.RegionProperties[regionOwner] = regionProperties;
|
||||
|
||||
if (_net.IsServer)
|
||||
Dirty(uid, component);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveNavMapRegion(EntityUid uid, NavMapComponent component, NetEntity regionOwner)
|
||||
{
|
||||
bool regionOwnerRemoved = component.RegionProperties.Remove(regionOwner) | component.RegionOverlays.Remove(regionOwner);
|
||||
|
||||
if (regionOwnerRemoved)
|
||||
{
|
||||
if (component.RegionOwnerToChunkTable.TryGetValue(regionOwner, out var affectedChunks))
|
||||
{
|
||||
foreach (var affectedChunk in affectedChunks)
|
||||
{
|
||||
if (component.ChunkToRegionOwnerTable.TryGetValue(affectedChunk, out var regionOwners))
|
||||
regionOwners.Remove(regionOwner);
|
||||
}
|
||||
|
||||
component.RegionOwnerToChunkTable.Remove(regionOwner);
|
||||
}
|
||||
|
||||
if (_net.IsServer)
|
||||
Dirty(uid, component);
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<NetEntity, NavMapRegionOverlay> GetNavMapRegionOverlays(EntityUid uid, NavMapComponent component, Enum uiKey)
|
||||
{
|
||||
var regionOverlays = new Dictionary<NetEntity, NavMapRegionOverlay>();
|
||||
|
||||
foreach (var (regionOwner, regionOverlay) in component.RegionOverlays)
|
||||
{
|
||||
if (!regionOverlay.UiKey.Equals(uiKey))
|
||||
continue;
|
||||
|
||||
regionOverlays.Add(regionOwner, regionOverlay);
|
||||
}
|
||||
|
||||
return regionOverlays;
|
||||
}
|
||||
|
||||
#region: Event handling
|
||||
|
||||
private void OnGetState(EntityUid uid, NavMapComponent component, ref ComponentGetState args)
|
||||
@@ -97,7 +148,7 @@ public abstract class SharedNavMapSystem : EntitySystem
|
||||
chunks.Add(origin, chunk.TileData);
|
||||
}
|
||||
|
||||
args.State = new NavMapState(chunks, component.Beacons);
|
||||
args.State = new NavMapState(chunks, component.Beacons, component.RegionProperties);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -110,7 +161,7 @@ public abstract class SharedNavMapSystem : EntitySystem
|
||||
chunks.Add(origin, chunk.TileData);
|
||||
}
|
||||
|
||||
args.State = new NavMapDeltaState(chunks, component.Beacons, new(component.Chunks.Keys));
|
||||
args.State = new NavMapDeltaState(chunks, component.Beacons, component.RegionProperties, new(component.Chunks.Keys));
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -120,22 +171,26 @@ public abstract class SharedNavMapSystem : EntitySystem
|
||||
[Serializable, NetSerializable]
|
||||
protected sealed class NavMapState(
|
||||
Dictionary<Vector2i, int[]> chunks,
|
||||
Dictionary<NetEntity, NavMapBeacon> beacons)
|
||||
Dictionary<NetEntity, NavMapBeacon> beacons,
|
||||
Dictionary<NetEntity, NavMapRegionProperties> regions)
|
||||
: ComponentState
|
||||
{
|
||||
public Dictionary<Vector2i, int[]> Chunks = chunks;
|
||||
public Dictionary<NetEntity, NavMapBeacon> Beacons = beacons;
|
||||
public Dictionary<NetEntity, NavMapRegionProperties> Regions = regions;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
protected sealed class NavMapDeltaState(
|
||||
Dictionary<Vector2i, int[]> modifiedChunks,
|
||||
Dictionary<NetEntity, NavMapBeacon> beacons,
|
||||
Dictionary<NetEntity, NavMapRegionProperties> regions,
|
||||
HashSet<Vector2i> allChunks)
|
||||
: ComponentState, IComponentDeltaState<NavMapState>
|
||||
{
|
||||
public Dictionary<Vector2i, int[]> ModifiedChunks = modifiedChunks;
|
||||
public Dictionary<NetEntity, NavMapBeacon> Beacons = beacons;
|
||||
public Dictionary<NetEntity, NavMapRegionProperties> Regions = regions;
|
||||
public HashSet<Vector2i> AllChunks = allChunks;
|
||||
|
||||
public void ApplyToFullState(NavMapState state)
|
||||
@@ -159,11 +214,18 @@ public abstract class SharedNavMapSystem : EntitySystem
|
||||
{
|
||||
state.Beacons.Add(nuid, beacon);
|
||||
}
|
||||
|
||||
state.Regions.Clear();
|
||||
foreach (var (nuid, region) in Regions)
|
||||
{
|
||||
state.Regions.Add(nuid, region);
|
||||
}
|
||||
}
|
||||
|
||||
public NavMapState CreateNewFullState(NavMapState state)
|
||||
{
|
||||
var chunks = new Dictionary<Vector2i, int[]>(state.Chunks.Count);
|
||||
|
||||
foreach (var (index, data) in state.Chunks)
|
||||
{
|
||||
if (!AllChunks!.Contains(index))
|
||||
@@ -177,12 +239,25 @@ public abstract class SharedNavMapSystem : EntitySystem
|
||||
Array.Copy(newData, data, ArraySize);
|
||||
}
|
||||
|
||||
return new NavMapState(chunks, new(Beacons));
|
||||
return new NavMapState(chunks, new(Beacons), new(Regions));
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public record struct NavMapBeacon(NetEntity NetEnt, Color Color, string Text, Vector2 Position);
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public record struct NavMapRegionProperties(NetEntity Owner, Enum UiKey, HashSet<Vector2i> Seeds)
|
||||
{
|
||||
// Server defined color for the region
|
||||
public Color Color = Color.White;
|
||||
|
||||
// The maximum number of tiles that can be assigned to this region
|
||||
public int MaxArea = 625;
|
||||
|
||||
// The maximum distance this region can propagate from its seeds
|
||||
public int MaxRadius = 25;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user