From 6f2dea38494f6305ee252a78c4d9c44d12ea5d49 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 11 Oct 2026 11:37:07 +0200 Subject: [PATCH] Entity.VisibilitySources is a read-only view: SetSignature and the decay loop are the only writers The dictionary is private; the public member is an IReadOnlyDictionary over it, so a write around SetSignature is a compile error, not a grep. Readers (Thruster, tests) use only the read members. Builds; the test project at this commit still compiles (no reader writes). Co-Authored-By: Claude Opus 5.5 --- Assets/Scripts/ServerShared/Entity.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Assets/Scripts/ServerShared/Entity.cs b/Assets/Scripts/ServerShared/Entity.cs index bfb771ff7..bf30ee927 100644 --- a/Assets/Scripts/ServerShared/Entity.cs +++ b/Assets/Scripts/ServerShared/Entity.cs @@ -85,12 +85,14 @@ public abstract class Entity // public Dictionary Personality = new Dictionary(); public readonly Dictionary Messages = new Dictionary(); - public readonly Dictionary VisibilitySources = new Dictionary(); + private readonly Dictionary _visibilitySources = new Dictionary(); + // A read-only view: the only writes are SetSignature and the decay loop in Update, both below. + public IReadOnlyDictionary VisibilitySources => _visibilitySources; // The one writer of VisibilitySources (the decay loop in Update is the one decayer). Every light signature // names its channel and the item that produced it (null for the hull). public void SetSignature(object source, SignatureChannel channel, float strength, EquippedItem item) => - VisibilitySources[source] = new Signature(channel, strength, item); + _visibilitySources[source] = new Signature(channel, strength, item); public readonly ReactiveDictionary EntityInfoGathered = new ReactiveDictionary(); public (List weapons, List items)[] WeaponGroups; @@ -1428,11 +1430,11 @@ public abstract class Entity var localSecurityLevel = Zone.GetSecurityLevel(Position.xz); if (CurrentSecurityLevel.Value != localSecurityLevel) CurrentSecurityLevel.Value = localSecurityLevel; - foreach (var v in VisibilitySources.Keys.ToArray()) + foreach (var v in _visibilitySources.Keys.ToArray()) { - VisibilitySources[v] = VisibilitySources[v].WithStrength(decay(VisibilitySources[v].Strength, ItemManager.GameplaySettings.VisibilityDecay, delta)); + _visibilitySources[v] = _visibilitySources[v].WithStrength(decay(_visibilitySources[v].Strength, ItemManager.GameplaySettings.VisibilityDecay, delta)); - if (VisibilitySources[v].Strength < 0.1f) VisibilitySources.Remove(v); + if (_visibilitySources[v].Strength < 0.1f) _visibilitySources.Remove(v); } UpdateTemperature(delta);