ActorReference takes MiniYaml as input instead of a Dict.

As the InitDict is lazy, this removes the possibility for a mutable collection to be used but the values not to be consumed until later, which would be confusing. As all existing callers actually create a throw-away dictionary from MiniYaml, this is an easy switch.
This commit is contained in:
RoosterDragon
2025-12-22 18:42:13 +00:00
committed by Gustas Kažukauskas
parent a546ca2f92
commit 827f4682a5
12 changed files with 14 additions and 14 deletions

View File

@@ -30,15 +30,15 @@ namespace OpenRA
internal TypeDictionary InitDict => initDict.Value;
public ActorReference(string type)
: this(type, new Dictionary<string, MiniYaml>()) { }
: this(type, new MiniYaml("")) { }
public ActorReference(string type, Dictionary<string, MiniYaml> inits)
public ActorReference(string type, MiniYaml inits)
{
Type = type;
initDict = Exts.Lazy(() =>
{
var dict = new TypeDictionary();
foreach (var i in inits)
foreach (var i in inits.Nodes)
{
var init = LoadInit(i.Key, i.Value);
if (init is ISingleInstanceInit && dict.Contains(init.GetType()))

View File

@@ -756,7 +756,7 @@ namespace OpenRA
var positions = new List<(MPos Uv, Color Color)>();
foreach (var actor in actors)
{
var s = new ActorReference(actor.Value.Value, actor.Value.ToDictionary());
var s = new ActorReference(actor.Value.Value, actor.Value);
var ai = Rules.Actors[actor.Value.Value];
var impsis = ai.TraitInfos<IMapPreviewSignatureInfo>();

View File

@@ -429,7 +429,7 @@ namespace OpenRA
var spawns = new List<CPos>();
foreach (var kv in actorDefinitions.Nodes.Where(d => d.Value.Value == "mpspawn"))
{
var s = new ActorReference(kv.Value.Value, kv.Value.ToDictionary());
var s = new ActorReference(kv.Value.Value, kv.Value);
spawns.Add(s.Get<LocationInit>().Value);
}

View File

@@ -65,7 +65,7 @@ namespace OpenRA.Mods.Cnc.Traits
if (!VeinholeActors.Contains(type))
continue;
var actorReference = new ActorReference(type, kv.Value.ToDictionary());
var actorReference = new ActorReference(type, kv.Value);
var location = actorReference.Get<LocationInit>();
var veinholeInfo = map.Rules.Actors[actorReference.Type];
foreach (var cell in veinholeInfo.TraitInfo<IOccupySpaceInfo>().OccupiedCells(veinholeInfo, location.Value))

View File

@@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.Lint
foreach (var kv in map.ActorDefinitions)
{
var actorReference = new ActorReference(kv.Value.Value, kv.Value.ToDictionary());
var actorReference = new ActorReference(kv.Value.Value, kv.Value);
var ownerInit = actorReference.GetOrDefault<OwnerInit>();
if (ownerInit == null)
emitError($"Actor `{kv.Key}` is not owned by any player.");

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Lint
var spawns = new List<CPos>();
foreach (var kv in map.ActorDefinitions.Where(d => d.Value.Value == "mpspawn"))
{
var s = new ActorReference(kv.Value.Value, kv.Value.ToDictionary());
var s = new ActorReference(kv.Value.Value, kv.Value);
spawns.Add(s.Get<LocationInit>().Value);
}

View File

@@ -97,7 +97,7 @@ namespace OpenRA.Mods.Common.Traits
{
var kv = world.Map.ActorDefinitions.ElementAt(i);
names[i] = kv.Key;
references.Add(new ActorReference(kv.Value.Value, kv.Value.ToDictionary()));
references.Add(new ActorReference(kv.Value.Value, kv.Value));
}
AddRange(CollectionsMarshal.AsSpan(references), names);

View File

@@ -131,7 +131,7 @@ namespace OpenRA.Mods.Common.Traits
var spawns = new List<CPos>();
foreach (var n in self.World.Map.ActorDefinitions)
if (n.Value.Value == "mpspawn")
spawns.Add(new ActorReference(n.Key, n.Value.ToDictionary()).GetValue<LocationInit, CPos>());
spawns.Add(new ActorReference(n.Key, n.Value).GetValue<LocationInit, CPos>());
spawnLocations = spawns.ToArray();

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Traits
foreach (var kv in world.Map.ActorDefinitions)
{
var actorReference = new ActorReference(kv.Value.Value, kv.Value.ToDictionary());
var actorReference = new ActorReference(kv.Value.Value, kv.Value);
// If an actor's doesn't have a valid owner transfer ownership to neutral
var ownerInit = actorReference.Get<OwnerInit>();

View File

@@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
foreach (var kv in map.ActorDefinitions)
{
var actor = new ActorReference(kv.Value.Value, kv.Value.ToDictionary());
var actor = new ActorReference(kv.Value.Value, kv.Value);
var locationInit = actor.GetOrDefault<LocationInit>();
if (locationInit == null)
continue;

View File

@@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common.Widgets
{
var spawnPoints = map.ActorDefinitions
.Where(d => d.Value.Value == "mpspawn")
.Select(kv => new ActorReference(kv.Value.Value, kv.Value.ToDictionary()).Get<LocationInit>().Value);
.Select(kv => new ActorReference(kv.Value.Value, kv.Value).Get<LocationInit>().Value);
Update(spawnPoints, map.Bounds, map.Grid.Type, new Png(map.Package.GetStream("map.png")));
}

View File

@@ -295,7 +295,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
.ToDictionary(player => player.Name);
foreach (var kv in generatedMap.ActorDefinitions)
{
var actorReference = new ActorReference(kv.Value.Value, kv.Value.ToDictionary());
var actorReference = new ActorReference(kv.Value.Value, kv.Value);
var ownerInit = actorReference.Get<OwnerInit>();
if (!players.TryGetValue(ownerInit.InternalName, out var owner))
throw new MapGenerationException("Generator produced mismatching player and actor definitions.");