Use out var syntax
This commit is contained in:
@@ -52,16 +52,14 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
using (kv.Value)
|
||||
{
|
||||
var key = kv.Key.ToString();
|
||||
Type type;
|
||||
if (!args.TryGetValue(key, out type))
|
||||
if (!args.TryGetValue(key, out var type))
|
||||
throw new LuaException("Unknown initializer type '{0}.{1}'".F(initInstance[0], key));
|
||||
|
||||
object clrValue;
|
||||
var isActorReference = type == typeof(ActorInitActorReference);
|
||||
if (isActorReference)
|
||||
type = kv.Value is LuaString ? typeof(string) : typeof(Actor);
|
||||
|
||||
if (!kv.Value.TryGetClrValue(type, out clrValue))
|
||||
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()));
|
||||
|
||||
if (isActorReference)
|
||||
@@ -79,8 +77,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
var facingInit = init as FacingInit;
|
||||
if (facingInit != null)
|
||||
{
|
||||
int facing;
|
||||
if (value.TryGetClrValue(out facing))
|
||||
if (value.TryGetClrValue(out int facing))
|
||||
{
|
||||
facingInit.Initialize(WAngle.FromFacing(facing));
|
||||
Game.Debug("Initializing Facing with integers is deprecated. Use Angle instead.");
|
||||
@@ -97,8 +94,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
var valueType = parameterType.IsEnum ? Enum.GetUnderlyingType(parameterType) : parameterType;
|
||||
|
||||
// Try and coerce the table value to the required type
|
||||
object clrValue;
|
||||
if (!value.TryGetClrValue(valueType, out clrValue))
|
||||
if (!value.TryGetClrValue(valueType, out var clrValue))
|
||||
continue;
|
||||
|
||||
initializer.Invoke(init, new[] { clrValue });
|
||||
@@ -139,8 +135,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
"An optional second value can be used to exactly specify the producing queue type.")]
|
||||
public int BuildTime(string type, string queue = null)
|
||||
{
|
||||
ActorInfo ai;
|
||||
if (!Context.World.Map.Rules.Actors.TryGetValue(type, out ai))
|
||||
if (!Context.World.Map.Rules.Actors.TryGetValue(type, out var ai))
|
||||
throw new LuaException("Unknown actor type '{0}'".F(type));
|
||||
|
||||
var bi = ai.TraitInfoOrDefault<BuildableInfo>();
|
||||
@@ -187,8 +182,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
[Desc("Returns the cruise altitude of the requested unit type (zero if it is ground-based).")]
|
||||
public int CruiseAltitude(string type)
|
||||
{
|
||||
ActorInfo ai;
|
||||
if (!Context.World.Map.Rules.Actors.TryGetValue(type, out ai))
|
||||
if (!Context.World.Map.Rules.Actors.TryGetValue(type, out var ai))
|
||||
throw new LuaException("Unknown actor type '{0}'".F(type));
|
||||
|
||||
var pi = ai.TraitInfoOrDefault<ICruiseAltitudeInfo>();
|
||||
@@ -197,8 +191,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
|
||||
public int Cost(string type)
|
||||
{
|
||||
ActorInfo ai;
|
||||
if (!Context.World.Map.Rules.Actors.TryGetValue(type, out ai))
|
||||
if (!Context.World.Map.Rules.Actors.TryGetValue(type, out var ai))
|
||||
throw new LuaException("Unknown actor type '{0}'".F(type));
|
||||
|
||||
var vi = ai.TraitInfoOrDefault<ValuedInfo>();
|
||||
|
||||
@@ -45,8 +45,7 @@ namespace OpenRA.Mods.Common.Scripting.Global
|
||||
[Desc("Create a new color with the specified red/green/blue/[alpha] hex string (rrggbb[aa]).")]
|
||||
public Color FromHex(string value)
|
||||
{
|
||||
Color color;
|
||||
if (Color.TryParse(value, out color))
|
||||
if (Color.TryParse(value, out var color))
|
||||
return color;
|
||||
|
||||
throw new LuaException("Invalid rrggbb[aa] hex string.");
|
||||
|
||||
@@ -128,9 +128,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
"the map file (or nil, if the actor is dead or not found).")]
|
||||
public Actor NamedActor(string actorName)
|
||||
{
|
||||
Actor ret;
|
||||
|
||||
if (!sma.Actors.TryGetValue(actorName, out ret))
|
||||
if (!sma.Actors.TryGetValue(actorName, out var ret))
|
||||
return null;
|
||||
|
||||
if (ret.Disposed)
|
||||
|
||||
@@ -35,8 +35,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
|
||||
Actor CreateActor(Player owner, string actorType, bool addToWorld, CPos? entryLocation = null, CPos? nextLocation = null)
|
||||
{
|
||||
ActorInfo ai;
|
||||
if (!Context.World.Map.Rules.Actors.TryGetValue(actorType, out ai))
|
||||
if (!Context.World.Map.Rules.Actors.TryGetValue(actorType, out var ai))
|
||||
throw new LuaException("Unknown actor type '{0}'".F(actorType));
|
||||
|
||||
var initDict = new TypeDictionary();
|
||||
|
||||
@@ -183,8 +183,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
if (autotarget == null)
|
||||
return;
|
||||
|
||||
UnitStance stance;
|
||||
if (!Enum<UnitStance>.TryParse(value, true, out stance))
|
||||
if (!Enum<UnitStance>.TryParse(value, true, out var stance))
|
||||
throw new LuaException("Unknown stance type '{0}'".F(value));
|
||||
|
||||
autotarget.PredictedStance = stance;
|
||||
|
||||
@@ -77,8 +77,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
{
|
||||
var result = new List<Actor>();
|
||||
|
||||
ActorInfo ai;
|
||||
if (!Context.World.Map.Rules.Actors.TryGetValue(type, out ai))
|
||||
if (!Context.World.Map.Rules.Actors.TryGetValue(type, out var ai))
|
||||
throw new LuaException("Unknown actor type '{0}'".F(type));
|
||||
|
||||
result.AddRange(Player.World.Actors
|
||||
|
||||
@@ -38,8 +38,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
"If 'Buildable.BuildAtProductionType' is not set either, a random exit will be selected.")]
|
||||
public void Produce(string actorType, string factionVariant = null, string productionType = null)
|
||||
{
|
||||
ActorInfo actorInfo;
|
||||
if (!Self.World.Map.Rules.Actors.TryGetValue(actorType, out actorInfo))
|
||||
if (!Self.World.Map.Rules.Actors.TryGetValue(actorType, out var actorInfo))
|
||||
throw new LuaException("Unknown actor type '{0}'".F(actorType));
|
||||
|
||||
var bi = actorInfo.TraitInfo<BuildableInfo>();
|
||||
|
||||
Reference in New Issue
Block a user