Use single dictionary call in Shroud.AddSource, Shroud.RemoveSource.

This commit is contained in:
RoosterDragon
2023-11-04 15:48:08 +00:00
committed by Gustas
parent 0c2d060d43
commit 8e80117eb8

View File

@@ -274,11 +274,9 @@ namespace OpenRA.Traits
public void AddSource(object key, SourceType type, PPos[] projectedCells)
{
if (sources.ContainsKey(key))
if (!sources.TryAdd(key, new ShroudSource(type, projectedCells)))
throw new InvalidOperationException("Attempting to add duplicate shroud source");
sources[key] = new ShroudSource(type, projectedCells);
foreach (var puv in projectedCells)
{
// Force cells outside the visible bounds invisible
@@ -309,7 +307,7 @@ namespace OpenRA.Traits
public void RemoveSource(object key)
{
if (!sources.TryGetValue(key, out var state))
if (!sources.Remove(key, out var state))
return;
foreach (var puv in state.ProjectedCells)
@@ -334,8 +332,6 @@ namespace OpenRA.Traits
}
}
}
sources.Remove(key);
}
public void ExploreProjectedCells(IEnumerable<PPos> cells)