Change classes that use FieldLoader to use read-only collections.

This commit is contained in:
RoosterDragon
2025-11-08 12:40:56 +00:00
committed by Paul Chote
parent 797c71e500
commit 649e7e8c28
308 changed files with 1233 additions and 901 deletions

View File

@@ -11,6 +11,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using OpenRA.Traits;
@@ -42,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits
[NotificationReference("Speech")]
[Desc("Notifications to play when the delivery actor is on its way. Last notification is played when the actors to deliver are spawned on the map.")]
public readonly string[] DeliveryProgressNotifications = [];
public readonly ImmutableArray<string> DeliveryProgressNotifications = [];
public override object Create(ActorInitializer init) { return new BulkProductionQueue(init, this); }
}

View File

@@ -11,6 +11,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using OpenRA.Primitives;
using OpenRA.Traits;
@@ -30,10 +31,10 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Every time another production building of the same queue is",
"constructed, the build times of all actors in the queue",
"modified by a percentage of the original time.")]
public readonly int[] BuildingCountBuildTimeMultipliers = [100, 86, 75, 67, 60, 55, 50];
public readonly ImmutableArray<int> BuildingCountBuildTimeMultipliers = [100, 86, 75, 67, 60, 55, 50];
[Desc("Build time modifier multiplied by the number of parallel production for producing different actors at the same time.")]
public readonly int[] ParallelPenaltyBuildTimeMultipliers = [100, 116, 133, 150, 166, 183, 200, 216, 233, 250];
public readonly ImmutableArray<int> ParallelPenaltyBuildTimeMultipliers = [100, 116, 133, 150, 166, 183, 200, 216, 233, 250];
public override object Create(ActorInitializer init) { return new ClassicParallelProductionQueue(init, this); }
}

View File

@@ -11,6 +11,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using OpenRA.Primitives;
using OpenRA.Traits;
@@ -29,7 +30,7 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Every time another production building of the same queue is",
"constructed, the build times of all actors in the queue",
"decreased by a percentage of the original time.")]
public readonly int[] BuildTimeSpeedReduction = [100, 86, 75, 67, 60, 55, 50];
public readonly ImmutableArray<int> BuildTimeSpeedReduction = [100, 86, 75, 67, 60, 55, 50];
public override object Create(ActorInitializer init) { return new ClassicProductionQueue(init, this); }
}

View File

@@ -10,6 +10,7 @@
#endregion
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using OpenRA.Traits;
@@ -34,12 +35,12 @@ namespace OpenRA.Mods.Common.Traits
techTree = self.Trait<TechTree>();
}
static string MakeKey(string[] prerequisites)
static string MakeKey(ImmutableArray<string> prerequisites)
{
return "condition_" + string.Join("_", prerequisites.Order());
}
public void Register(Actor actor, GrantConditionOnPrerequisite u, string[] prerequisites)
public void Register(Actor actor, GrantConditionOnPrerequisite u, ImmutableArray<string> prerequisites)
{
var key = MakeKey(prerequisites);
if (!upgradables.TryGetValue(key, out var list))
@@ -54,7 +55,7 @@ namespace OpenRA.Mods.Common.Traits
u.PrerequisitesUpdated(actor, techTree.HasPrerequisites(prerequisites));
}
public void Unregister(Actor actor, GrantConditionOnPrerequisite u, string[] prerequisites)
public void Unregister(Actor actor, GrantConditionOnPrerequisite u, ImmutableArray<string> prerequisites)
{
var key = MakeKey(prerequisites);
var list = upgradables[key];

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System.Collections.Frozen;
using System.Collections.Generic;
using OpenRA.Traits;
@@ -45,7 +46,7 @@ namespace OpenRA.Mods.Common.Traits
[FieldLoader.Require]
[Desc("Prerequisites to grant when this checkbox is enabled.")]
public readonly HashSet<string> Prerequisites = [];
public readonly FrozenSet<string> Prerequisites = FrozenSet<string>.Empty;
IEnumerable<string> ITechTreePrerequisiteInfo.Prerequisites(ActorInfo info) { return Prerequisites; }
@@ -61,7 +62,7 @@ namespace OpenRA.Mods.Common.Traits
public class LobbyPrerequisiteCheckbox : INotifyCreated, ITechTreePrerequisite
{
readonly LobbyPrerequisiteCheckboxInfo info;
HashSet<string> prerequisites = [];
FrozenSet<string> prerequisites = FrozenSet<string>.Empty;
public LobbyPrerequisiteCheckbox(LobbyPrerequisiteCheckboxInfo info)
{

View File

@@ -10,7 +10,9 @@
#endregion
using System;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Globalization;
using System.Linq;
using OpenRA.Traits;
@@ -27,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly string DefaultCashDropdownDescription = "The amount of cash that players start with";
[Desc("Starting cash options that are available in the lobby options.")]
public readonly int[] SelectableCash = [2500, 5000, 10000, 20000];
public readonly ImmutableArray<int> SelectableCash = [2500, 5000, 10000, 20000];
[Desc("Default starting cash option: should be one of the SelectableCash options.")]
public readonly int DefaultCash = 5000;
@@ -59,7 +61,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly string CashTickDownNotification = null;
[Desc("Monetary value of each resource type.", "Dictionary of [resource type]: [value per unit].")]
public readonly Dictionary<string, int> ResourceValues = [];
public readonly FrozenDictionary<string, int> ResourceValues = FrozenDictionary<string, int>.Empty;
IEnumerable<LobbyOption> ILobbyOptions.LobbyOptions(MapPreview map)
{

View File

@@ -10,6 +10,7 @@
#endregion
using System;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Primitives;
@@ -33,7 +34,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly string Group = null;
[Desc("Only enable this queue for certain factions.")]
public readonly HashSet<string> Factions = [];
public readonly FrozenSet<string> Factions = FrozenSet<string>.Empty;
[Desc("Should the prerequisite remain enabled if the owner changes?")]
public readonly bool Sticky = true;

View File

@@ -9,7 +9,9 @@
*/
#endregion
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using OpenRA.Traits;
@@ -21,10 +23,10 @@ namespace OpenRA.Mods.Common.Traits
public readonly string Prerequisite = null;
[Desc("Only grant this prerequisite when you have these prerequisites.")]
public readonly string[] RequiresPrerequisites = [];
public readonly ImmutableArray<string> RequiresPrerequisites = [];
[Desc("Only grant this prerequisite for certain factions.")]
public readonly HashSet<string> Factions = [];
public readonly FrozenSet<string> Factions = FrozenSet<string>.Empty;
[Desc("Should it recheck everything when it is captured?")]
public readonly bool ResetOnOwnerChange = false;

View File

@@ -10,6 +10,7 @@
#endregion
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using OpenRA.Traits;
@@ -26,7 +27,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly string Name;
[Desc("Prerequisites to grant when this tech level is active.")]
public readonly string[] Prerequisites = [];
public readonly ImmutableArray<string> Prerequisites = [];
IEnumerable<string> ITechTreePrerequisiteInfo.Prerequisites(ActorInfo info) { return Prerequisites; }

View File

@@ -10,6 +10,7 @@
#endregion
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using OpenRA.Traits;
@@ -47,7 +48,7 @@ namespace OpenRA.Mods.Common.Traits
w.Update(ownedPrerequisites);
}
public void Add(string key, string[] prerequisites, int limit, ITechTreeElement tte)
public void Add(string key, ImmutableArray<string> prerequisites, int limit, ITechTreeElement tte)
{
watchers.Add(new Watcher(key, prerequisites, limit, tte));
}
@@ -119,13 +120,13 @@ namespace OpenRA.Mods.Common.Traits
public ITechTreeElement RegisteredBy { get; }
// Strings may be either actor type, or "alternate name" key
readonly string[] prerequisites;
readonly ImmutableArray<string> prerequisites;
bool hasPrerequisites;
readonly int limit;
bool hidden;
bool initialized = false;
public Watcher(string key, string[] prerequisites, int limit, ITechTreeElement watcher)
public Watcher(string key, ImmutableArray<string> prerequisites, int limit, ITechTreeElement watcher)
{
Key = key;
this.prerequisites = prerequisites;