Replace F extension with string interpolation
This commit is contained in:
@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
var initInstance = initName.Split(ActorInfo.TraitInstanceSeparator);
|
||||
var initType = Game.ModData.ObjectCreator.FindType(initInstance[0] + "Init");
|
||||
if (initType == null)
|
||||
throw new LuaException("Unknown initializer type '{0}'".F(initInstance[0]));
|
||||
throw new LuaException($"Unknown initializer type '{initInstance[0]}'");
|
||||
|
||||
// Construct the ActorInit.
|
||||
var init = (ActorInit)FormatterServices.GetUninitializedObject(initType);
|
||||
@@ -51,14 +51,14 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
{
|
||||
var key = kv.Key.ToString();
|
||||
if (!args.TryGetValue(key, out var type))
|
||||
throw new LuaException("Unknown initializer type '{0}.{1}'".F(initInstance[0], key));
|
||||
throw new LuaException($"Unknown initializer type '{initInstance[0]}.{key}'");
|
||||
|
||||
var isActorReference = type == typeof(ActorInitActorReference);
|
||||
if (isActorReference)
|
||||
type = kv.Value is LuaString ? typeof(string) : typeof(Actor);
|
||||
|
||||
if (!kv.Value.TryGetClrValue(type, out var clrValue))
|
||||
throw new LuaException("Invalid data type for '{0}.{1}' (expected {2}, got {3})".F(initInstance[0], key, type.Name, kv.Value.WrappedClrType()));
|
||||
throw new LuaException($"Invalid data type for '{initInstance[0]}.{key}' (expected {type.Name}, got {kv.Value.WrappedClrType()})");
|
||||
|
||||
if (isActorReference)
|
||||
clrValue = type == typeof(string) ? new ActorInitActorReference((string)clrValue) : new ActorInitActorReference((Actor)clrValue);
|
||||
@@ -100,7 +100,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
}
|
||||
|
||||
var types = initializers.Select(y => y.GetParameters()[0].ParameterType.Name).JoinWith(", ");
|
||||
throw new LuaException("Invalid data type for '{0}' (expected one of {1})".F(initInstance[0], types));
|
||||
throw new LuaException($"Invalid data type for '{initInstance[0]}' (expected one of {types})");
|
||||
}
|
||||
|
||||
[Desc("Create a new actor. initTable specifies a list of key-value pairs that defines the initial parameters for the actor's traits.")]
|
||||
@@ -118,7 +118,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
|
||||
var owner = initDict.GetOrDefault<OwnerInit>();
|
||||
if (owner == null)
|
||||
throw new LuaException("Tried to create actor '{0}' with an invalid or no owner init!".F(type));
|
||||
throw new LuaException($"Tried to create actor '{type}' with an invalid or no owner init!");
|
||||
|
||||
// The actor must be added to the world at the end of the tick
|
||||
var a = Context.World.CreateActor(false, type, initDict);
|
||||
@@ -133,7 +133,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
public int BuildTime(string type, string queue = null)
|
||||
{
|
||||
if (!Context.World.Map.Rules.Actors.TryGetValue(type, out var ai))
|
||||
throw new LuaException("Unknown actor type '{0}'".F(type));
|
||||
throw new LuaException($"Unknown actor type '{type}'");
|
||||
|
||||
var bi = ai.TraitInfoOrDefault<BuildableInfo>();
|
||||
|
||||
@@ -157,7 +157,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
.Where(x => x.Type == queue)).FirstOrDefault();
|
||||
|
||||
if (pqueue == null)
|
||||
throw new LuaException("The specified queue '{0}' does not exist!".F(queue));
|
||||
throw new LuaException($"The specified queue '{queue}' does not exist!");
|
||||
|
||||
pbi = pqueue.BuildDurationModifier;
|
||||
}
|
||||
@@ -167,7 +167,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
.Where(x => bi.Queue.Contains(x.Type))).FirstOrDefault();
|
||||
|
||||
if (pqueue == null)
|
||||
throw new LuaException("No actors can produce actor '{0}'!".F(type));
|
||||
throw new LuaException($"No actors can produce actor '{type}'!");
|
||||
|
||||
pbi = pqueue.BuildDurationModifier;
|
||||
}
|
||||
@@ -180,7 +180,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
public int CruiseAltitude(string type)
|
||||
{
|
||||
if (!Context.World.Map.Rules.Actors.TryGetValue(type, out var ai))
|
||||
throw new LuaException("Unknown actor type '{0}'".F(type));
|
||||
throw new LuaException($"Unknown actor type '{type}'");
|
||||
|
||||
var pi = ai.TraitInfoOrDefault<ICruiseAltitudeInfo>();
|
||||
return pi != null ? pi.GetCruiseAltitude().Length : 0;
|
||||
@@ -189,11 +189,11 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
public int Cost(string type)
|
||||
{
|
||||
if (!Context.World.Map.Rules.Actors.TryGetValue(type, out var ai))
|
||||
throw new LuaException("Unknown actor type '{0}'".F(type));
|
||||
throw new LuaException($"Unknown actor type '{type}'");
|
||||
|
||||
var vi = ai.TraitInfoOrDefault<ValuedInfo>();
|
||||
if (vi == null)
|
||||
throw new LuaException("Actor type '{0}' does not have the Valued trait required to get the Cost.".F(type));
|
||||
throw new LuaException($"Actor type '{type}' does not have the Valued trait required to get the Cost.");
|
||||
|
||||
return vi.Cost;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
Actor CreateActor(Player owner, string actorType, bool addToWorld, CPos? entryLocation = null, CPos? nextLocation = null)
|
||||
{
|
||||
if (!Context.World.Map.Rules.Actors.TryGetValue(actorType, out var ai))
|
||||
throw new LuaException("Unknown actor type '{0}'".F(actorType));
|
||||
throw new LuaException($"Unknown actor type '{actorType}'");
|
||||
|
||||
var initDict = new TypeDictionary();
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
{
|
||||
var events = a.TraitOrDefault<ScriptTriggers>();
|
||||
if (events == null)
|
||||
throw new LuaException("Actor '{0}' requires the ScriptTriggers trait before attaching a trigger".F(a.Info.Name));
|
||||
throw new LuaException($"Actor '{a.Info.Name}' requires the ScriptTriggers trait before attaching a trigger");
|
||||
|
||||
return events;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
{
|
||||
var pool = ammoPools.FirstOrDefault(a => a.Info.Name == poolName);
|
||||
if (pool == null)
|
||||
throw new LuaException("Invalid ammopool name {0} queried on actor {1}.".F(poolName, self));
|
||||
throw new LuaException($"Invalid ammopool name {poolName} queried on actor {self}.");
|
||||
|
||||
return pool.CurrentAmmoCount;
|
||||
}
|
||||
@@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
{
|
||||
var pool = ammoPools.FirstOrDefault(a => a.Info.Name == poolName);
|
||||
if (pool == null)
|
||||
throw new LuaException("Invalid ammopool name {0} queried on actor {1}.".F(poolName, self));
|
||||
throw new LuaException($"Invalid ammopool name {poolName} queried on actor {self}.");
|
||||
|
||||
return pool.Info.Ammo;
|
||||
}
|
||||
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
{
|
||||
var pool = ammoPools.FirstOrDefault(a => a.Info.Name == poolName);
|
||||
if (pool == null)
|
||||
throw new LuaException("Invalid ammopool name {0} queried on actor {1}.".F(poolName, self));
|
||||
throw new LuaException($"Invalid ammopool name {poolName} queried on actor {self}.");
|
||||
|
||||
if (amount > 0)
|
||||
pool.GiveAmmo(self, amount);
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
{
|
||||
var targetManager = target.TraitOrDefault<CaptureManager>();
|
||||
if (targetManager == null || !targetManager.CanBeTargetedBy(target, Self, captureManager))
|
||||
throw new LuaException("Actor '{0}' cannot capture actor '{1}'!".F(Self, target));
|
||||
throw new LuaException($"Actor '{Self}' cannot capture actor '{target}'!");
|
||||
|
||||
// NB: Scripted actions get no visible targetlines.
|
||||
Self.QueueActivity(new CaptureActor(Self, Target.FromActor(target), null));
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
.FirstOrDefault(t => t.Info.Condition == condition && t.CanGrantCondition(Self, this));
|
||||
|
||||
if (external == null)
|
||||
throw new LuaException("Condition `{0}` has not been listed on an enabled ExternalCondition trait".F(condition));
|
||||
throw new LuaException($"Condition `{condition}` has not been listed on an enabled ExternalCondition trait");
|
||||
|
||||
return external.GrantCondition(Self, this, duration);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
{
|
||||
var targetGainsExperience = target.TraitOrDefault<GainsExperience>();
|
||||
if (targetGainsExperience == null)
|
||||
throw new LuaException("Actor '{0}' cannot gain experience!".F(target));
|
||||
throw new LuaException($"Actor '{target}' cannot gain experience!");
|
||||
|
||||
if (targetGainsExperience.Level == targetGainsExperience.MaxLevel)
|
||||
return;
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
throw new LuaException("Attempted to change the owner of actor '{0}' to nil value.".F(Self));
|
||||
throw new LuaException($"Attempted to change the owner of actor '{Self}' to nil value.");
|
||||
|
||||
if (Self.Owner != value)
|
||||
Self.ChangeOwner(value);
|
||||
@@ -121,7 +121,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
get
|
||||
{
|
||||
if (facing == null)
|
||||
throw new LuaException("Actor '{0}' doesn't define a facing".F(Self));
|
||||
throw new LuaException($"Actor '{Self}' doesn't define a facing");
|
||||
|
||||
return facing.Facing;
|
||||
}
|
||||
@@ -172,7 +172,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
return;
|
||||
|
||||
if (!Enum<UnitStance>.TryParse(value, true, out var stance))
|
||||
throw new LuaException("Unknown stance type '{0}'".F(value));
|
||||
throw new LuaException($"Unknown stance type '{value}'");
|
||||
|
||||
autotarget.PredictedStance = stance;
|
||||
autotarget.SetStance(Self, stance);
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
.FirstOrDefault(t => t.Info.Condition == condition && t.CanGrantCondition(Player.PlayerActor, this));
|
||||
|
||||
if (external == null)
|
||||
throw new LuaException("Condition `{0}` has not been listed on an enabled ExternalCondition trait".F(condition));
|
||||
throw new LuaException($"Condition `{condition}` has not been listed on an enabled ExternalCondition trait");
|
||||
|
||||
return external.GrantCondition(Player.PlayerActor, this, duration);
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
var result = new List<Actor>();
|
||||
|
||||
if (!Context.World.Map.Rules.Actors.TryGetValue(type, out var ai))
|
||||
throw new LuaException("Unknown actor type '{0}'".F(type));
|
||||
throw new LuaException($"Unknown actor type '{type}'");
|
||||
|
||||
result.AddRange(Player.World.Actors
|
||||
.Where(actor => actor.Owner == Player && !actor.IsDead && actor.IsInWorld && actor.Info.Name == ai.Name));
|
||||
@@ -106,7 +106,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
|
||||
foreach (var type in types)
|
||||
if (!Context.World.Map.Rules.Actors.ContainsKey(type))
|
||||
throw new LuaException("Unknown actor type '{0}'".F(type));
|
||||
throw new LuaException($"Unknown actor type '{type}'");
|
||||
|
||||
result.AddRange(Player.World.Actors
|
||||
.Where(actor => actor.Owner == Player && !actor.IsDead && actor.IsInWorld && types.Contains(actor.Info.Name)));
|
||||
@@ -119,7 +119,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
{
|
||||
var tt = Player.PlayerActor.TraitOrDefault<TechTree>();
|
||||
if (tt == null)
|
||||
throw new LuaException("Missing TechTree trait on player {0}!".F(Player));
|
||||
throw new LuaException($"Missing TechTree trait on player {Player}!");
|
||||
|
||||
return tt.HasPrerequisites(type);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
public void Produce(string actorType, string factionVariant = null, string productionType = null)
|
||||
{
|
||||
if (!Self.World.Map.Rules.Actors.TryGetValue(actorType, out var actorInfo))
|
||||
throw new LuaException("Unknown actor type '{0}'".F(actorType));
|
||||
throw new LuaException($"Unknown actor type '{actorType}'");
|
||||
|
||||
var bi = actorInfo.TraitInfo<BuildableInfo>();
|
||||
Self.QueueActivity(new WaitFor(() =>
|
||||
@@ -197,7 +197,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
var bi = ri.TraitInfoOrDefault<BuildableInfo>();
|
||||
|
||||
if (bi == null)
|
||||
throw new LuaException("Actor of type {0} cannot be produced".F(actorType));
|
||||
throw new LuaException($"Actor of type {actorType} cannot be produced");
|
||||
else
|
||||
return bi;
|
||||
}
|
||||
@@ -304,7 +304,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
var bi = ri.TraitInfoOrDefault<BuildableInfo>();
|
||||
|
||||
if (bi == null)
|
||||
throw new LuaException("Actor of type {0} cannot be produced".F(actorType));
|
||||
throw new LuaException($"Actor of type {actorType} cannot be produced");
|
||||
else
|
||||
return bi;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user