Use out var syntax

This commit is contained in:
teinarss
2020-08-16 10:49:33 +02:00
committed by Paul Chote
parent d52e4793fe
commit 27f1a7ab27
193 changed files with 395 additions and 826 deletions

View File

@@ -560,8 +560,7 @@ namespace OpenRA
/// <returns>The invalid token ID.</returns>
public int RevokeCondition(int token)
{
string condition;
if (!conditionTokens.TryGetValue(token, out condition))
if (!conditionTokens.TryGetValue(token, out var condition))
throw new InvalidOperationException("Attempting to revoke condition with invalid token {0} for {1}.".F(token, this));
conditionTokens.Remove(token);
@@ -594,8 +593,7 @@ namespace OpenRA
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
{
Actor a, b;
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
if (!left.TryGetClrValue(out Actor a) || !right.TryGetClrValue(out Actor b))
return false;
return a == b;

View File

@@ -89,9 +89,7 @@ namespace OpenRA
public LuaValue Add(LuaRuntime runtime, LuaValue left, LuaValue right)
{
CPos a;
CVec b;
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
if (!left.TryGetClrValue(out CPos a) || !right.TryGetClrValue(out CVec b))
throw new LuaException("Attempted to call CPos.Add(CPos, CVec) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
return new LuaCustomClrObject(a + b);
@@ -99,21 +97,18 @@ namespace OpenRA
public LuaValue Subtract(LuaRuntime runtime, LuaValue left, LuaValue right)
{
CPos a;
var rightType = right.WrappedClrType();
if (!left.TryGetClrValue(out a))
if (!left.TryGetClrValue(out CPos a))
throw new LuaException("Attempted to call CPos.Subtract(CPos, (CPos|CVec)) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, rightType.Name));
if (rightType == typeof(CPos))
{
CPos b;
right.TryGetClrValue(out b);
right.TryGetClrValue(out CPos b);
return new LuaCustomClrObject(a - b);
}
else if (rightType == typeof(CVec))
{
CVec b;
right.TryGetClrValue(out b);
right.TryGetClrValue(out CVec b);
return new LuaCustomClrObject(a - b);
}
@@ -122,8 +117,7 @@ namespace OpenRA
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
{
CPos a, b;
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
if (!left.TryGetClrValue(out CPos a) || !right.TryGetClrValue(out CPos b))
return false;
return a == b;

View File

@@ -75,8 +75,7 @@ namespace OpenRA
public LuaValue Add(LuaRuntime runtime, LuaValue left, LuaValue right)
{
CVec a, b;
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
if (!left.TryGetClrValue(out CVec a) || !right.TryGetClrValue(out CVec b))
throw new LuaException("Attempted to call CVec.Add(CVec, CVec) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
return new LuaCustomClrObject(a + b);
@@ -84,8 +83,7 @@ namespace OpenRA
public LuaValue Subtract(LuaRuntime runtime, LuaValue left, LuaValue right)
{
CVec a, b;
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
if (!left.TryGetClrValue(out CVec a) || !right.TryGetClrValue(out CVec b))
throw new LuaException("Attempted to call CVec.Subtract(CVec, CVec) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
return new LuaCustomClrObject(a - b);
@@ -98,8 +96,7 @@ namespace OpenRA
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
{
CVec a, b;
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
if (!left.TryGetClrValue(out CVec a) || !right.TryGetClrValue(out CVec b))
return false;
return a == b;

View File

@@ -125,8 +125,7 @@ namespace OpenRA
public static V GetOrAdd<K, V>(this Dictionary<K, V> d, K k, Func<K, V> createFn)
{
V ret;
if (!d.TryGetValue(k, out ret))
if (!d.TryGetValue(k, out var ret))
d.Add(k, ret = createFn(k));
return ret;
}
@@ -353,8 +352,7 @@ namespace OpenRA
public static int IntegerDivisionRoundingAwayFromZero(int dividend, int divisor)
{
int remainder;
var quotient = Math.DivRem(dividend, divisor, out remainder);
var quotient = Math.DivRem(dividend, divisor, out var remainder);
if (remainder == 0)
return quotient;
return quotient + (Math.Sign(dividend) == Math.Sign(divisor) ? 1 : -1);
@@ -405,8 +403,7 @@ namespace OpenRA
// Check for a key conflict:
if (d.ContainsKey(key))
{
List<string> dupKeyMessages;
if (!dupKeys.TryGetValue(key, out dupKeyMessages))
if (!dupKeys.TryGetValue(key, out var dupKeyMessages))
{
// Log the initial conflicting value already inserted:
dupKeyMessages = new List<string>();

View File

@@ -121,8 +121,7 @@ namespace OpenRA
{
ret = null;
MiniYaml yaml;
if (!md.TryGetValue(yamlName, out yaml))
if (!md.TryGetValue(yamlName, out var yaml))
return false;
ret = GetValue(field.Name, field.FieldType, yaml, field);
@@ -185,37 +184,32 @@ namespace OpenRA
if (fieldType == typeof(int))
{
int res;
if (Exts.TryParseIntegerInvariant(value, out res))
if (Exts.TryParseIntegerInvariant(value, out var res))
return res;
return InvalidValueAction(value, fieldType, fieldName);
}
else if (fieldType == typeof(ushort))
{
ushort res;
if (ushort.TryParse(value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out res))
if (ushort.TryParse(value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out var res))
return res;
return InvalidValueAction(value, fieldType, fieldName);
}
if (fieldType == typeof(long))
{
long res;
if (long.TryParse(value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out res))
if (long.TryParse(value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out var res))
return res;
return InvalidValueAction(value, fieldType, fieldName);
}
else if (fieldType == typeof(float))
{
float res;
if (value != null && float.TryParse(value.Replace("%", ""), NumberStyles.Float, NumberFormatInfo.InvariantInfo, out res))
if (value != null && float.TryParse(value.Replace("%", ""), NumberStyles.Float, NumberFormatInfo.InvariantInfo, out var res))
return res * (value.Contains('%') ? 0.01f : 1f);
return InvalidValueAction(value, fieldType, fieldName);
}
else if (fieldType == typeof(decimal))
{
decimal res;
if (value != null && decimal.TryParse(value.Replace("%", ""), NumberStyles.Float, NumberFormatInfo.InvariantInfo, out res))
if (value != null && decimal.TryParse(value.Replace("%", ""), NumberStyles.Float, NumberFormatInfo.InvariantInfo, out var res))
return res * (value.Contains('%') ? 0.01m : 1m);
return InvalidValueAction(value, fieldType, fieldName);
}
@@ -227,16 +221,14 @@ namespace OpenRA
}
else if (fieldType == typeof(Color))
{
Color color;
if (value != null && Color.TryParse(value, out color))
if (value != null && Color.TryParse(value, out var color))
return color;
return InvalidValueAction(value, fieldType, fieldName);
}
else if (fieldType == typeof(Hotkey))
{
Hotkey res;
if (Hotkey.TryParse(value, out res))
if (Hotkey.TryParse(value, out var res))
return res;
return InvalidValueAction(value, fieldType, fieldName);
@@ -247,8 +239,7 @@ namespace OpenRA
}
else if (fieldType == typeof(WDist))
{
WDist res;
if (WDist.TryParse(value, out res))
if (WDist.TryParse(value, out var res))
return res;
return InvalidValueAction(value, fieldType, fieldName);
@@ -260,8 +251,7 @@ namespace OpenRA
var parts = value.Split(',');
if (parts.Length == 3)
{
WDist rx, ry, rz;
if (WDist.TryParse(parts[0], out rx) && WDist.TryParse(parts[1], out ry) && WDist.TryParse(parts[2], out rz))
if (WDist.TryParse(parts[0], out var rx) && WDist.TryParse(parts[1], out var ry) && WDist.TryParse(parts[2], out var rz))
return new WVec(rx, ry, rz);
}
}
@@ -281,8 +271,7 @@ namespace OpenRA
for (var i = 0; i < vecs.Length; ++i)
{
WDist rx, ry, rz;
if (WDist.TryParse(parts[3 * i], out rx) && WDist.TryParse(parts[3 * i + 1], out ry) && WDist.TryParse(parts[3 * i + 2], out rz))
if (WDist.TryParse(parts[3 * i], out var rx) && WDist.TryParse(parts[3 * i + 1], out var ry) && WDist.TryParse(parts[3 * i + 2], out var rz))
vecs[i] = new WVec(rx, ry, rz);
}
@@ -298,8 +287,7 @@ namespace OpenRA
var parts = value.Split(',');
if (parts.Length == 3)
{
WDist rx, ry, rz;
if (WDist.TryParse(parts[0], out rx) && WDist.TryParse(parts[1], out ry) && WDist.TryParse(parts[2], out rz))
if (WDist.TryParse(parts[0], out var rx) && WDist.TryParse(parts[1], out var ry) && WDist.TryParse(parts[2], out var rz))
return new WPos(rx, ry, rz);
}
}
@@ -308,8 +296,7 @@ namespace OpenRA
}
else if (fieldType == typeof(WAngle))
{
int res;
if (Exts.TryParseIntegerInvariant(value, out res))
if (Exts.TryParseIntegerInvariant(value, out var res))
return new WAngle(res);
return InvalidValueAction(value, fieldType, fieldName);
}
@@ -320,8 +307,7 @@ namespace OpenRA
var parts = value.Split(',');
if (parts.Length == 3)
{
int rr, rp, ry;
if (Exts.TryParseIntegerInvariant(parts[0], out rr) && Exts.TryParseIntegerInvariant(parts[1], out rp) && Exts.TryParseIntegerInvariant(parts[2], out ry))
if (Exts.TryParseIntegerInvariant(parts[0], out var rr) && Exts.TryParseIntegerInvariant(parts[1], out var rp) && Exts.TryParseIntegerInvariant(parts[2], out var ry))
return new WRot(new WAngle(rr), new WAngle(rp), new WAngle(ry));
}
}
@@ -360,8 +346,7 @@ namespace OpenRA
var vecs = new CVec[parts.Length / 2];
for (var i = 0; i < vecs.Length; i++)
{
int rx, ry;
if (int.TryParse(parts[2 * i], out rx) && int.TryParse(parts[2 * i + 1], out ry))
if (int.TryParse(parts[2 * i], out var rx) && int.TryParse(parts[2 * i + 1], out var ry))
vecs[i] = new CVec(rx, ry);
}
@@ -415,8 +400,7 @@ namespace OpenRA
}
else if (fieldType == typeof(bool))
{
bool result;
if (bool.TryParse(value.ToLowerInvariant(), out result))
if (bool.TryParse(value.ToLowerInvariant(), out var result))
return result;
return InvalidValueAction(value, fieldType, fieldName);
@@ -509,8 +493,7 @@ namespace OpenRA
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
float xx = 0;
float yy = 0;
float res;
if (float.TryParse(parts[0].Replace("%", ""), NumberStyles.Float, NumberFormatInfo.InvariantInfo, out res))
if (float.TryParse(parts[0].Replace("%", ""), NumberStyles.Float, NumberFormatInfo.InvariantInfo, out var res))
xx = res * (parts[0].Contains('%') ? 0.01f : 1f);
if (float.TryParse(parts[1].Replace("%", ""), NumberStyles.Float, NumberFormatInfo.InvariantInfo, out res))
yy = res * (parts[1].Contains('%') ? 0.01f : 1f);
@@ -524,13 +507,11 @@ namespace OpenRA
if (value != null)
{
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
float x = 0;
float y = 0;
float z = 0;
float.TryParse(parts[0], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out x);
float.TryParse(parts[1], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out y);
float.TryParse(parts[0], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out var x);
float.TryParse(parts[1], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out var y);
// z component is optional for compatibility with older float2 definitions
float z = 0;
if (parts.Length > 2)
float.TryParse(parts[2], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out z);
@@ -575,8 +556,7 @@ namespace OpenRA
}
else if (fieldType == typeof(DateTime))
{
DateTime dt;
if (DateTime.TryParseExact(value, "yyyy-MM-dd HH-mm-ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out dt))
if (DateTime.TryParseExact(value, "yyyy-MM-dd HH-mm-ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var dt))
return dt;
return InvalidValueAction(value, fieldType, fieldName);
}
@@ -726,8 +706,7 @@ namespace OpenRA
if (translations == null)
return key;
string value;
if (!translations.TryGetValue(key, out value))
if (!translations.TryGetValue(key, out var value))
return key;
return value;

View File

@@ -67,15 +67,12 @@ namespace OpenRA.FileSystem
return new Folder(resolvedPath);
// Children of another package require special handling
IReadOnlyPackage parent;
string subPath = null;
if (TryGetPackageContaining(filename, out parent, out subPath))
if (TryGetPackageContaining(filename, out var parent, out var subPath))
return parent.OpenPackage(subPath, this);
// Try and open it normally
IReadOnlyPackage package;
var stream = Open(filename);
if (TryParsePackage(stream, filename, out package))
if (TryParsePackage(stream, filename, out var package))
return package;
// No package loaders took ownership of the stream, so clean it up
@@ -97,8 +94,7 @@ namespace OpenRA.FileSystem
{
name = name.Substring(1);
Manifest mod;
if (!installedMods.TryGetValue(name, out mod))
if (!installedMods.TryGetValue(name, out var mod))
throw new InvalidOperationException("Could not load mod '{0}'. Available mods: {1}".F(name, installedMods.Keys.JoinWith(", ")));
package = mod.Package;
@@ -122,8 +118,7 @@ namespace OpenRA.FileSystem
public void Mount(IReadOnlyPackage package, string explicitName = null)
{
var mountCount = 0;
if (mountedPackages.TryGetValue(package, out mountCount))
if (mountedPackages.TryGetValue(package, out var mountCount))
{
// Package is already mounted
// Increment the mount count and bump up the file loading priority
@@ -149,8 +144,7 @@ namespace OpenRA.FileSystem
public bool Unmount(IReadOnlyPackage package)
{
var mountCount = 0;
if (!mountedPackages.TryGetValue(package, out mountCount))
if (!mountedPackages.TryGetValue(package, out var mountCount))
return false;
if (--mountCount <= 0)
@@ -211,8 +205,7 @@ namespace OpenRA.FileSystem
public Stream Open(string filename)
{
Stream s;
if (!TryOpen(filename, out s))
if (!TryOpen(filename, out var s))
throw new FileNotFoundException("File not found: {0}".F(filename), filename);
return s;
@@ -238,8 +231,7 @@ namespace OpenRA.FileSystem
var explicitSplit = filename.IndexOf('|');
if (explicitSplit > 0)
{
IReadOnlyPackage explicitPackage;
if (explicitMounts.TryGetValue(filename.Substring(0, explicitSplit), out explicitPackage))
if (explicitMounts.TryGetValue(filename.Substring(0, explicitSplit), out var explicitPackage))
{
s = explicitPackage.GetStream(filename.Substring(explicitSplit + 1));
if (s != null)
@@ -274,12 +266,9 @@ namespace OpenRA.FileSystem
{
var explicitSplit = filename.IndexOf('|');
if (explicitSplit > 0)
{
IReadOnlyPackage explicitPackage;
if (explicitMounts.TryGetValue(filename.Substring(0, explicitSplit), out explicitPackage))
if (explicitMounts.TryGetValue(filename.Substring(0, explicitSplit), out var explicitPackage))
if (explicitPackage.Contains(filename.Substring(explicitSplit + 1)))
return true;
}
return fileIndex.ContainsKey(filename);
}
@@ -293,8 +282,7 @@ namespace OpenRA.FileSystem
if (explicitSplit < 0)
return false;
IReadOnlyPackage explicitPackage;
if (!explicitMounts.TryGetValue(filename.Substring(0, explicitSplit), out explicitPackage))
if (!explicitMounts.TryGetValue(filename.Substring(0, explicitSplit), out var explicitPackage))
return false;
if (installedMods[modID].Package == explicitPackage)
@@ -321,8 +309,7 @@ namespace OpenRA.FileSystem
if (parentPath.StartsWith("$", StringComparison.Ordinal))
{
Manifest mod;
if (!installedMods.TryGetValue(parentPath.Substring(1), out mod))
if (!installedMods.TryGetValue(parentPath.Substring(1), out var mod))
return null;
if (!(mod.Package is Folder))

View File

@@ -58,17 +58,15 @@ namespace OpenRA.FileSystem
return new Folder(resolvedPath);
// Zip files loaded from Folders (and *only* from Folders) can be read-write
IReadWritePackage readWritePackage;
if (ZipFileLoader.TryParseReadWritePackage(resolvedPath, out readWritePackage))
if (ZipFileLoader.TryParseReadWritePackage(resolvedPath, out var readWritePackage))
return readWritePackage;
// Other package types can be loaded normally
IReadOnlyPackage package;
var s = GetStream(filename);
if (s == null)
return null;
if (context.TryParsePackage(s, filename, out package))
if (context.TryParsePackage(s, filename, out var package))
return package;
s.Dispose();

View File

@@ -81,12 +81,11 @@ namespace OpenRA.FileSystem
return new ZipFolder(this, filename);
// Other package types can be loaded normally
IReadOnlyPackage package;
var s = GetStream(filename);
if (s == null)
return null;
if (context.TryParsePackage(s, filename, out package))
if (context.TryParsePackage(s, filename, out var package))
return package;
s.Dispose();

View File

@@ -355,8 +355,7 @@ namespace OpenRA
ExternalMods = new ExternalMods();
Manifest currentMod;
if (modID != null && Mods.TryGetValue(modID, out currentMod))
if (modID != null && Mods.TryGetValue(modID, out var currentMod))
{
var launchPath = args.GetValue("Engine.LaunchPath", Assembly.GetEntryAssembly().Location);
@@ -367,8 +366,7 @@ namespace OpenRA
ExternalMods.Register(Mods[modID], launchPath, ModRegistration.User);
ExternalMod activeMod;
if (ExternalMods.TryGetValue(ExternalMod.MakeKey(Mods[modID]), out activeMod))
if (ExternalMods.TryGetValue(ExternalMod.MakeKey(Mods[modID]), out var activeMod))
ExternalMods.ClearInvalidRegistrations(activeMod, ModRegistration.User);
}

View File

@@ -133,9 +133,7 @@ namespace OpenRA
/// <summary>Gets the player information for the specified runtime player instance.</summary>
public Player GetPlayer(OpenRA.Player runtimePlayer)
{
Player player;
playersByRuntime.TryGetValue(runtimePlayer, out player);
playersByRuntime.TryGetValue(runtimePlayer, out var player);
return player;
}

View File

@@ -41,8 +41,7 @@ namespace OpenRA.GameRules
public void Load(IReadOnlyFileSystem fileSystem)
{
Stream stream;
if (!fileSystem.TryOpen(Filename, out stream))
if (!fileSystem.TryOpen(Filename, out var stream))
return;
try
@@ -50,8 +49,7 @@ namespace OpenRA.GameRules
Exists = true;
foreach (var loader in Game.ModData.SoundLoaders)
{
ISoundFormat soundFormat;
if (loader.TryParseSound(stream, out soundFormat))
if (loader.TryParseSound(stream, out var soundFormat))
{
Length = (int)soundFormat.LengthInSeconds;
soundFormat.Dispose();

View File

@@ -137,8 +137,7 @@ namespace OpenRA.GameRules
static object LoadProjectile(MiniYaml yaml)
{
MiniYaml proj;
if (!yaml.ToDictionary().TryGetValue("Projectile", out proj))
if (!yaml.ToDictionary().TryGetValue("Projectile", out var proj))
return null;
var ret = Game.CreateObject<IProjectileInfo>(proj.Value + "Info");
FieldLoader.Load(ret, proj);

View File

@@ -160,8 +160,7 @@ namespace OpenRA.Graphics
return null;
}
Rectangle mi;
if (!collection.Regions.TryGetValue(imageName, out mi))
if (!collection.Regions.TryGetValue(imageName, out var mi))
return null;
// Cache the sprite

View File

@@ -47,15 +47,13 @@ namespace OpenRA.Graphics
if (d.ContainsKey("X"))
{
int x;
Exts.TryParseIntegerInvariant(d["X"].Value, out x);
Exts.TryParseIntegerInvariant(d["X"].Value, out var x);
Hotspot = Hotspot.WithX(x);
}
if (d.ContainsKey("Y"))
{
int y;
Exts.TryParseIntegerInvariant(d["Y"].Value, out y);
Exts.TryParseIntegerInvariant(d["Y"].Value, out var y);
Hotspot = Hotspot.WithY(y);
}
}

View File

@@ -38,19 +38,16 @@ namespace OpenRA.Graphics
public IPalette GetPalette(string name)
{
MutablePalette mutable;
if (modifiablePalettes.TryGetValue(name, out mutable))
if (modifiablePalettes.TryGetValue(name, out var mutable))
return mutable.AsReadOnly();
ImmutablePalette immutable;
if (palettes.TryGetValue(name, out immutable))
if (palettes.TryGetValue(name, out var immutable))
return immutable;
throw new InvalidOperationException("Palette `{0}` does not exist".F(name));
}
public int GetPaletteIndex(string name)
{
int ret;
if (!indices.TryGetValue(name, out ret))
if (!indices.TryGetValue(name, out var ret))
throw new InvalidOperationException("Palette `{0}` does not exist".F(name));
return ret;
}

View File

@@ -160,10 +160,8 @@ namespace OpenRA.Graphics
}
// Shadows are rendered at twice the resolution to reduce artifacts
Size spriteSize, shadowSpriteSize;
int2 spriteOffset, shadowSpriteOffset;
CalculateSpriteGeometry(tl, br, 1, out spriteSize, out spriteOffset);
CalculateSpriteGeometry(stl, sbr, 2, out shadowSpriteSize, out shadowSpriteOffset);
CalculateSpriteGeometry(tl, br, 1, out var spriteSize, out var spriteOffset);
CalculateSpriteGeometry(stl, sbr, 2, out var shadowSpriteSize, out var shadowSpriteOffset);
if (sheetBuilderForFrame == null)
sheetBuilderForFrame = new SheetBuilder(SheetType.BGRA, AllocateSheet);

View File

@@ -53,8 +53,7 @@ namespace OpenRA.Graphics
public Color GetRemappedColor(Color original, int index)
{
Color c;
return remapColors.TryGetValue(index, out c)
return remapColors.TryGetValue(index, out var c)
? c : original;
}
}

View File

@@ -70,12 +70,10 @@ namespace OpenRA.Graphics
public ISpriteSequence GetSequence(string unitName, string sequenceName)
{
UnitSequences unitSeq;
if (!sequences.Value.TryGetValue(unitName, out unitSeq))
if (!sequences.Value.TryGetValue(unitName, out var unitSeq))
throw new InvalidOperationException("Unit `{0}` does not have any sequences defined.".F(unitName));
ISpriteSequence seq;
if (!unitSeq.Value.TryGetValue(sequenceName, out seq))
if (!unitSeq.Value.TryGetValue(sequenceName, out var seq))
throw new InvalidOperationException("Unit `{0}` does not have a sequence named `{1}`".F(unitName, sequenceName));
return seq;
@@ -88,8 +86,7 @@ namespace OpenRA.Graphics
public bool HasSequence(string unitName, string sequenceName)
{
UnitSequences unitSeq;
if (!sequences.Value.TryGetValue(unitName, out unitSeq))
if (!sequences.Value.TryGetValue(unitName, out var unitSeq))
throw new InvalidOperationException("Unit `{0}` does not have any sequences defined.".F(unitName));
return unitSeq.Value.ContainsKey(sequenceName);
@@ -97,8 +94,7 @@ namespace OpenRA.Graphics
public IEnumerable<string> Sequences(string unitName)
{
UnitSequences unitSeq;
if (!sequences.Value.TryGetValue(unitName, out unitSeq))
if (!sequences.Value.TryGetValue(unitName, out var unitSeq))
throw new InvalidOperationException("Unit `{0}` does not have any sequences defined.".F(unitName));
return unitSeq.Value.Keys;
@@ -115,8 +111,7 @@ namespace OpenRA.Graphics
var key = node.Value.ToLines(node.Key).JoinWith("|");
UnitSequences t;
if (sequenceCache.TryGetValue(key, out t))
if (sequenceCache.TryGetValue(key, out var t))
items.Add(node.Key, t);
else
{

View File

@@ -76,8 +76,7 @@ namespace OpenRA.Graphics
var allSprites = sprites.GetOrAdd(filename);
var sprite = allSprites.FirstOrDefault();
ISpriteFrame[] unloaded;
if (!unloadedFrames.TryGetValue(filename, out unloaded))
if (!unloadedFrames.TryGetValue(filename, out var unloaded))
unloaded = null;
// This is the first time that the file has been requested
@@ -85,8 +84,7 @@ namespace OpenRA.Graphics
// the loaded cache (initially empty)
if (sprite == null)
{
TypeDictionary fileMetadata = null;
unloaded = FrameLoader.GetFrames(fileSystem, filename, loaders, out fileMetadata);
unloaded = FrameLoader.GetFrames(fileSystem, filename, loaders, out var fileMetadata);
unloadedFrames[filename] = unloaded;
metadata[filename] = fileMetadata;
@@ -125,8 +123,7 @@ namespace OpenRA.Graphics
/// </summary>
public TypeDictionary FrameMetadata(string filename)
{
TypeDictionary fileMetadata;
if (!metadata.TryGetValue(filename, out fileMetadata))
if (!metadata.TryGetValue(filename, out var fileMetadata))
{
FrameLoader.GetFrames(fileSystem, filename, loaders, out fileMetadata);
metadata[filename] = fileMetadata;
@@ -142,8 +139,7 @@ namespace OpenRA.Graphics
public FrameCache(IReadOnlyFileSystem fileSystem, ISpriteLoader[] loaders)
{
TypeDictionary metadata;
frames = new Cache<string, ISpriteFrame[]>(filename => FrameLoader.GetFrames(fileSystem, filename, loaders, out metadata));
frames = new Cache<string, ISpriteFrame[]>(filename => FrameLoader.GetFrames(fileSystem, filename, loaders, out var metadata));
}
public ISpriteFrame[] this[string filename] { get { return frames[filename]; } }
@@ -165,11 +161,10 @@ namespace OpenRA.Graphics
public static ISpriteFrame[] GetFrames(Stream stream, ISpriteLoader[] loaders, out TypeDictionary metadata)
{
ISpriteFrame[] frames;
metadata = null;
foreach (var loader in loaders)
if (loader.TryParseSprite(stream, out frames, out metadata))
if (loader.TryParseSprite(stream, out var frames, out metadata))
return frames;
return null;

View File

@@ -118,8 +118,7 @@ namespace OpenRA.Graphics
public Sprite TileSprite(TerrainTile r, int? variant = null)
{
TheaterTemplate template;
if (!templates.TryGetValue(r.Type, out template))
if (!templates.TryGetValue(r.Type, out var template))
return missingTile;
if (r.Index >= template.Stride)

View File

@@ -50,8 +50,7 @@ namespace OpenRA
return () => keys[name];
// Try and parse as a hardcoded definition
Hotkey key;
if (!Hotkey.TryParse(name, out key))
if (!Hotkey.TryParse(name, out var key))
key = Hotkey.Invalid;
return () => key;
@@ -59,8 +58,7 @@ namespace OpenRA
public void Set(string name, Hotkey value)
{
HotkeyDefinition definition;
if (!definitions.TryGetValue(name, out definition))
if (!definitions.TryGetValue(name, out var definition))
return;
keys[name] = value;

View File

@@ -32,11 +32,9 @@ namespace OpenRA
var parts = s.Split(' ');
Keycode key;
if (!Enum<Keycode>.TryParse(parts[0], true, out key))
if (!Enum<Keycode>.TryParse(parts[0], true, out var key))
{
int c;
if (!int.TryParse(parts[0], out c))
if (!int.TryParse(parts[0], out var c))
return false;
key = (Keycode)c;
}

View File

@@ -498,8 +498,7 @@ namespace OpenRA
public static string DisplayString(Keycode k)
{
string ret;
if (!KeyNames.TryGetValue(k, out ret))
if (!KeyNames.TryGetValue(k, out var ret))
return k.ToString();
return ret;

View File

@@ -96,8 +96,7 @@ namespace OpenRA
// TODO: Use fieldloader
MapFolders = YamlDictionary(yaml, "MapFolders");
MiniYaml packages;
if (yaml.TryGetValue("Packages", out packages))
if (yaml.TryGetValue("Packages", out var packages))
Packages = packages.ToDictionary(x => x.Value).AsReadOnly();
Rules = YamlList(yaml, "Rules");
@@ -217,9 +216,8 @@ namespace OpenRA
/// </summary>
public T Get<T>(ObjectCreator oc) where T : IGlobalModData
{
MiniYaml data;
var t = typeof(T);
if (!yaml.TryGetValue(t.Name, out data))
if (!yaml.TryGetValue(t.Name, out var data))
{
// Lazily create the default values if not explicitly defined.
return (T)oc.CreateBasic(t);

View File

@@ -185,14 +185,13 @@ namespace OpenRA
public virtual void Initialize(Dictionary<string, object> values)
{
object value;
foreach (var field in GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
{
var sa = field.GetCustomAttributes<FieldLoader.SerializeAttribute>(false).DefaultIfEmpty(FieldLoader.SerializeAttribute.Default).First();
if (!sa.Serialize)
continue;
if (values.TryGetValue(field.Name, out value))
if (values.TryGetValue(field.Name, out var value))
field.SetValue(this, value);
}
}

View File

@@ -131,8 +131,7 @@ namespace OpenRA
// Enumerate map directories
foreach (var kv in modData.Manifest.MapFolders)
{
MapClassification packageClassification;
if (!Enum.TryParse(kv.Value, out packageClassification))
if (!Enum.TryParse(kv.Value, out MapClassification packageClassification))
continue;
if (!classification.HasFlag(packageClassification))

View File

@@ -233,8 +233,7 @@ namespace OpenRA
newData.GridType = gridType;
newData.Class = classification;
MiniYaml temp;
if (yaml.TryGetValue("MapFormat", out temp))
if (yaml.TryGetValue("MapFormat", out var temp))
{
var format = FieldLoader.GetValue<int>("MapFormat", temp.Value);
if (format != Map.SupportedMapFormat)
@@ -269,8 +268,7 @@ namespace OpenRA
try
{
// Actor definitions may change if the map format changes
MiniYaml actorDefinitions;
if (yaml.TryGetValue("Actors", out actorDefinitions))
if (yaml.TryGetValue("Actors", out var actorDefinitions))
{
var spawns = new List<CPos>();
foreach (var kv in actorDefinitions.Nodes.Where(d => d.Value.Value == "mpspawn"))
@@ -293,8 +291,7 @@ namespace OpenRA
try
{
// Player definitions may change if the map format changes
MiniYaml playerDefinitions;
if (yaml.TryGetValue("Players", out playerDefinitions))
if (yaml.TryGetValue("Players", out var playerDefinitions))
{
newData.Players = new MapPlayers(playerDefinitions.Nodes);
newData.PlayerCount = newData.Players.Players.Count(x => x.Value.Playable);
@@ -331,8 +328,7 @@ namespace OpenRA
MiniYaml LoadRuleSection(Dictionary<string, MiniYaml> yaml, string section)
{
MiniYaml node;
if (!yaml.TryGetValue(section, out node))
if (!yaml.TryGetValue(section, out var node))
return null;
return node;

View File

@@ -72,8 +72,7 @@ namespace OpenRA
tileInfo = new TerrainTileInfo[Size.X * Size.Y];
foreach (var node in nodes)
{
int key;
if (!int.TryParse(node.Key, out key) || key < 0 || key >= tileInfo.Length)
if (!int.TryParse(node.Key, out var key) || key < 0 || key >= tileInfo.Length)
throw new InvalidDataException("Invalid tile key '{0}' on template '{1}' of tileset '{2}'.".F(node.Key, Id, tileSet.Id));
tileInfo[key] = LoadTileInfo(tileSet, node.Value);
@@ -86,8 +85,7 @@ namespace OpenRA
var i = 0;
foreach (var node in nodes)
{
int key;
if (!int.TryParse(node.Key, out key) || key != i++)
if (!int.TryParse(node.Key, out var key) || key != i++)
throw new InvalidDataException("Invalid tile key '{0}' on template '{1}' of tileset '{2}'.".F(node.Key, Id, tileSet.Id));
tileInfo[key] = LoadTileInfo(tileSet, node.Value);
@@ -216,8 +214,7 @@ namespace OpenRA
public byte GetTerrainIndex(string type)
{
byte index;
if (terrainIndexByType.TryGetValue(type, out index))
if (terrainIndexByType.TryGetValue(type, out var index))
return index;
throw new InvalidDataException("Tileset '{0}' lacks terrain type '{1}'".F(Id, type));
@@ -225,8 +222,7 @@ namespace OpenRA
public byte GetTerrainIndex(TerrainTile r)
{
TerrainTemplateInfo tpl;
if (!Templates.TryGetValue(r.Type, out tpl))
if (!Templates.TryGetValue(r.Type, out var tpl))
return defaultWalkableTerrainIndex;
if (tpl.Contains(r.Index))
@@ -241,8 +237,7 @@ namespace OpenRA
public TerrainTileInfo GetTileInfo(TerrainTile r)
{
TerrainTemplateInfo tpl;
if (!Templates.TryGetValue(r.Type, out tpl))
if (!Templates.TryGetValue(r.Type, out var tpl))
return null;
return tpl.Contains(r.Index) ? tpl[r.Index] : null;

View File

@@ -339,8 +339,7 @@ namespace OpenRA
{
if (n.Key == "Inherits" || n.Key.StartsWith("Inherits@", StringComparison.Ordinal))
{
MiniYaml parent;
if (!tree.TryGetValue(n.Value.Value, out parent))
if (!tree.TryGetValue(n.Value.Value, out var parent))
throw new YamlException(
"{0}: Parent type `{1}` not found".F(n.Location, n.Value.Value));
@@ -428,9 +427,8 @@ namespace OpenRA
foreach (var key in allKeys)
{
MiniYamlNode existingNode, overrideNode;
existingDict.TryGetValue(key, out existingNode);
overrideDict.TryGetValue(key, out overrideNode);
existingDict.TryGetValue(key, out var existingNode);
overrideDict.TryGetValue(key, out var overrideNode);
var loc = overrideNode == null ? default(MiniYamlNode.SourceLocation) : overrideNode.Location;
var comment = (overrideNode ?? existingNode).Comment;

View File

@@ -167,28 +167,22 @@ namespace OpenRA.Network
// Games advertised using the old API calculated the play time locally
if (State == 2 && PlayTime < 0)
{
DateTime startTime;
if (DateTime.TryParse(Started, out startTime))
if (DateTime.TryParse(Started, out var startTime))
PlayTime = (int)(DateTime.UtcNow - startTime).TotalSeconds;
}
ExternalMod external;
var externalKey = ExternalMod.MakeKey(Mod, Version);
if (Game.ExternalMods.TryGetValue(externalKey, out external) && external.Version == Version)
if (Game.ExternalMods.TryGetValue(externalKey, out var external) && external.Version == Version)
IsCompatible = true;
// Games advertised using the old API used local mod metadata
if (string.IsNullOrEmpty(ModTitle))
{
Manifest mod;
if (external != null && external.Version == Version)
{
// Use external mod registration to populate the section header
ModTitle = external.Title;
}
else if (Game.Mods.TryGetValue(Mod, out mod))
else if (Game.Mods.TryGetValue(Mod, out var mod))
{
// Use internal mod data to populate the section header, but
// on-connect switching must use the external mod plumbing.

View File

@@ -107,8 +107,7 @@ namespace OpenRA
{
case TargetType.Actor:
{
Actor targetActor;
if (world != null && TryGetActorFromUInt(world, r.ReadUInt32(), out targetActor))
if (world != null && TryGetActorFromUInt(world, r.ReadUInt32(), out var targetActor))
target = Target.FromActor(targetActor);
break;
}
@@ -118,8 +117,7 @@ namespace OpenRA
var playerActorID = r.ReadUInt32();
var frozenActorID = r.ReadUInt32();
Actor playerActor;
if (world == null || !TryGetActorFromUInt(world, playerActorID, out playerActor))
if (world == null || !TryGetActorFromUInt(world, playerActorID, out var playerActor))
break;
if (playerActor.Owner.FrozenActorLayer == null)

View File

@@ -149,8 +149,7 @@ namespace OpenRA.Network
void CheckSync(byte[] packet)
{
var frame = BitConverter.ToInt32(packet, 0);
byte[] existingSync;
if (syncForFrame.TryGetValue(frame, out existingSync))
if (syncForFrame.TryGetValue(frame, out var existingSync))
{
if (packet.Length != existingSync.Length)
OutOfSync(frame);

View File

@@ -250,8 +250,7 @@ namespace OpenRA.Network
public bool OptionOrDefault(string id, bool def)
{
LobbyOptionState option;
if (LobbyOptions.TryGetValue(id, out option))
if (LobbyOptions.TryGetValue(id, out var option))
return option.IsEnabled;
return def;
@@ -259,8 +258,7 @@ namespace OpenRA.Network
public string OptionOrDefault(string id, string def)
{
LobbyOptionState option;
if (LobbyOptions.TryGetValue(id, out option))
if (LobbyOptions.TryGetValue(id, out var option))
return option.Value;
return def;

View File

@@ -190,9 +190,8 @@ namespace OpenRA.Network
var request = HandshakeRequest.Deserialize(order.TargetString);
var externalKey = ExternalMod.MakeKey(request.Mod, request.Version);
ExternalMod external;
if ((request.Mod != mod.Id || request.Version != mod.Metadata.Version)
&& Game.ExternalMods.TryGetValue(externalKey, out external))
if ((request.Mod != mod.Id || request.Version != mod.Metadata.Version) &&
Game.ExternalMods.TryGetValue(externalKey, out var external))
{
// The ConnectionFailedLogic will prompt the user to switch mods
orderManager.ServerExternalMod = external;

View File

@@ -48,8 +48,7 @@ namespace OpenRA
// We can't check the internal name of the assembly, so we'll work off the data instead
var hash = CryptoUtil.SHA1Hash(File.ReadAllBytes(resolvedPath));
Assembly assembly;
if (!ResolvedAssemblies.TryGetValue(hash, out assembly))
if (!ResolvedAssemblies.TryGetValue(hash, out var assembly))
{
assembly = Assembly.LoadFile(resolvedPath);
ResolvedAssemblies.Add(hash, assembly);

View File

@@ -253,8 +253,7 @@ namespace OpenRA
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
{
Player a, b;
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
if (!left.TryGetClrValue(out Player a) || !right.TryGetClrValue(out Player b))
return false;
return a == b;

View File

@@ -47,14 +47,9 @@ namespace OpenRA.Primitives
BitSetIndex bits = 0;
lock (Bits)
{
foreach (var value in values)
{
BitSetIndex valueBit;
if (Bits.TryGetValue(value, out valueBit))
if (Bits.TryGetValue(value, out var valueBit))
bits |= valueBit;
}
}
return bits;
}

View File

@@ -124,10 +124,10 @@ namespace OpenRA.Primitives
if (value.Length != 6 && value.Length != 8)
return false;
byte red, green, blue, alpha = 255;
if (!byte.TryParse(value.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out red)
|| !byte.TryParse(value.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out green)
|| !byte.TryParse(value.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out blue))
byte alpha = 255;
if (!byte.TryParse(value.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var red)
|| !byte.TryParse(value.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var green)
|| !byte.TryParse(value.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var blue))
return false;
if (value.Length == 8

View File

@@ -50,14 +50,9 @@ namespace OpenRA.Primitives
long bits = 0;
lock (Bits)
{
foreach (var value in values)
{
long valueBit;
if (Bits.TryGetValue(value, out valueBit))
if (Bits.TryGetValue(value, out var valueBit))
bits |= valueBit;
}
}
return bits;
}

View File

@@ -120,8 +120,7 @@ namespace OpenRA.Primitives
/// <param name="count">The length of the segment.</param>
public static Stream CreateWithoutOwningStream(Stream stream, long offset, int count)
{
Stream parentStream;
var nestedOffset = offset + GetOverallNestedOffset(stream, out parentStream);
var nestedOffset = offset + GetOverallNestedOffset(stream, out var parentStream);
// Special case FileStream - instead of creating an in-memory copy,
// just reference the portion of the on-disk file that we need to save memory.

View File

@@ -52,8 +52,7 @@ namespace OpenRA.Primitives
public bool Remove(T item)
{
Rectangle bounds;
if (!itemBounds.TryGetValue(item, out bounds))
if (!itemBounds.TryGetValue(item, out var bounds))
return false;
MutateBins(item, bounds, removeItem);
@@ -91,8 +90,7 @@ namespace OpenRA.Primitives
void MutateBins(T actor, Rectangle bounds, Action<Dictionary<T, Rectangle>, T, Rectangle> action)
{
int minRow, maxRow, minCol, maxCol;
BoundsToBinRowsAndCols(bounds, out minRow, out maxRow, out minCol, out maxCol);
BoundsToBinRowsAndCols(bounds, out var minRow, out var maxRow, out var minCol, out var maxCol);
for (var row = minRow; row < maxRow; row++)
for (var col = minCol; col < maxCol; col++)
@@ -110,8 +108,7 @@ namespace OpenRA.Primitives
public IEnumerable<T> InBox(Rectangle box)
{
int minRow, maxRow, minCol, maxCol;
BoundsToBinRowsAndCols(box, out minRow, out maxRow, out minCol, out maxCol);
BoundsToBinRowsAndCols(box, out var minRow, out var maxRow, out var minCol, out var maxCol);
// We want to return any items intersecting the box.
// If the box covers multiple bins, we must handle items that are contained in multiple bins and avoid

View File

@@ -61,8 +61,7 @@ namespace OpenRA.Primitives
object Get(Type t, bool throwsIfMissing)
{
List<object> ret;
if (!data.TryGetValue(t, out ret))
if (!data.TryGetValue(t, out var ret))
{
if (throwsIfMissing)
throw new InvalidOperationException("TypeDictionary does not contain instance of type `{0}`".F(t));
@@ -76,8 +75,7 @@ namespace OpenRA.Primitives
public IEnumerable<T> WithInterface<T>()
{
List<object> objs;
if (data.TryGetValue(typeof(T), out objs))
if (data.TryGetValue(typeof(T), out var objs))
return objs.Cast<T>();
return new T[0];
}
@@ -94,8 +92,7 @@ namespace OpenRA.Primitives
void InnerRemove(Type t, object val)
{
List<object> objs;
if (!data.TryGetValue(t, out objs))
if (!data.TryGetValue(t, out var objs))
return;
objs.Remove(val);
if (objs.Count == 0)

View File

@@ -28,8 +28,7 @@ namespace OpenRA.Scripting
public static string LuaDocString(this Type t)
{
string ret;
if (!LuaTypeNameReplacements.TryGetValue(t.Name, out ret))
if (!LuaTypeNameReplacements.TryGetValue(t.Name, out var ret))
ret = t.Name;
return ret;
}

View File

@@ -111,8 +111,7 @@ namespace OpenRA.Scripting
if (IsSetProperty)
{
var pi = (PropertyInfo)Member;
object clrValue;
if (!value.TryGetClrValue(pi.PropertyType, out clrValue))
if (!value.TryGetClrValue(pi.PropertyType, out var clrValue))
throw new LuaException("Unable to convert '{0}' to Clr type '{1}'".F(value.WrappedClrType().Name, pi.PropertyType));
pi.SetValue(Target, clrValue, null);

View File

@@ -51,8 +51,7 @@ namespace OpenRA.Scripting
get
{
var name = keyValue.ToString();
ScriptMemberWrapper wrapper;
if (!members.TryGetValue(name, out wrapper))
if (!members.TryGetValue(name, out var wrapper))
throw new LuaException(MemberNotFoundError(name));
return wrapper.Get(runtime);
@@ -61,8 +60,7 @@ namespace OpenRA.Scripting
set
{
var name = keyValue.ToString();
ScriptMemberWrapper wrapper;
if (!members.TryGetValue(name, out wrapper))
if (!members.TryGetValue(name, out var wrapper))
throw new LuaException(MemberNotFoundError(name));
wrapper.Set(runtime, value);

View File

@@ -18,8 +18,7 @@ namespace OpenRA.Scripting
{
public static Type WrappedClrType(this LuaValue value)
{
object inner;
if (value.TryGetClrObject(out inner))
if (value.TryGetClrObject(out var inner))
return inner.GetType();
return value.GetType();
@@ -27,16 +26,13 @@ namespace OpenRA.Scripting
public static bool TryGetClrValue<T>(this LuaValue value, out T clrObject)
{
object temp;
var ret = value.TryGetClrValue(typeof(T), out temp);
var ret = value.TryGetClrValue(typeof(T), out object temp);
clrObject = ret ? (T)temp : default(T);
return ret;
}
public static bool TryGetClrValue(this LuaValue value, Type t, out object clrObject)
{
object temp;
// Is t a nullable?
// If yes, get the underlying type
var nullable = Nullable.GetUnderlyingType(t);
@@ -44,7 +40,7 @@ namespace OpenRA.Scripting
t = nullable;
// Value wraps a CLR object
if (value.TryGetClrObject(out temp))
if (value.TryGetClrObject(out var temp))
{
if (temp.GetType() == t)
{

View File

@@ -99,8 +99,7 @@ namespace OpenRA.Server
// Non-blocking sends are free to send only part of the data
while (start < length)
{
SocketError error;
var sent = s.Send(data, start, length - start, SocketFlags.None, out error);
var sent = s.Send(data, start, length - start, SocketFlags.None, out var error);
if (error == SocketError.WouldBlock)
{
Log.Write("server", "Non-blocking send of {0} bytes failed. Falling back to blocking send.", length - start);
@@ -716,8 +715,7 @@ namespace OpenRA.Server
break;
case "Pong":
{
long pingSent;
if (!OpenRA.Exts.TryParseInt64Invariant(o.TargetString, out pingSent))
if (!OpenRA.Exts.TryParseInt64Invariant(o.TargetString, out var pingSent))
{
Log.Write("server", "Invalid order pong payload: {0}", o.TargetString);
break;

View File

@@ -295,8 +295,7 @@ namespace OpenRA
yamlCache = MiniYaml.FromFile(settingsFile, false);
foreach (var yamlSection in yamlCache)
{
object settingsSection;
if (yamlSection.Key != null && Sections.TryGetValue(yamlSection.Key, out settingsSection))
if (yamlSection.Key != null && Sections.TryGetValue(yamlSection.Key, out var settingsSection))
LoadSectionYaml(yamlSection.Value, settingsSection);
}

View File

@@ -66,11 +66,10 @@ namespace OpenRA
using (var stream = fileSystem.Open(filename))
{
ISoundFormat soundFormat;
foreach (var loader in loaders)
{
stream.Position = 0;
if (loader.TryParseSound(stream, out soundFormat))
if (loader.TryParseSound(stream, out var soundFormat))
{
var source = loadFormat(soundFormat);
soundFormat.Dispose();

View File

@@ -668,8 +668,7 @@ namespace OpenRA.Support
static int ParseSymbol(string symbol, IReadOnlyDictionary<string, int> symbols)
{
int value;
symbols.TryGetValue(symbol, out value);
symbols.TryGetValue(symbol, out var value);
return value;
}

View File

@@ -310,8 +310,7 @@ namespace OpenRA.Traits
public FrozenActor FromID(uint id)
{
FrozenActor fa;
if (!frozenActorsById.TryGetValue(id, out fa))
if (!frozenActorsById.TryGetValue(id, out var fa))
return null;
return fa;

View File

@@ -253,8 +253,7 @@ namespace OpenRA.Traits
public void RemoveSource(object key)
{
ShroudSource state;
if (!sources.TryGetValue(key, out state))
if (!sources.TryGetValue(key, out var state))
return;
foreach (var puv in state.ProjectedCells)

View File

@@ -221,19 +221,16 @@ namespace OpenRA
public LuaValue Add(LuaRuntime runtime, LuaValue left, LuaValue right)
{
WAngle a, b;
int c;
if (!left.TryGetClrValue(out a))
if (!left.TryGetClrValue(out WAngle a))
throw new LuaException("Attempted to call WAngle.Add(WAngle, WAngle) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
if (right.TryGetClrValue(out c))
if (right.TryGetClrValue(out int c))
{
Game.Debug("Support for facing calculations mixing Angle with integers is deprecated. Make sure all facing calculations use Angle");
return new LuaCustomClrObject(a + FromFacing(c));
}
if (right.TryGetClrValue(out b))
if (right.TryGetClrValue(out WAngle b))
return new LuaCustomClrObject(a + b);
throw new LuaException("Attempted to call WAngle.Add(WAngle, WAngle) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
@@ -241,19 +238,16 @@ namespace OpenRA
public LuaValue Subtract(LuaRuntime runtime, LuaValue left, LuaValue right)
{
WAngle a, b;
int c;
if (!left.TryGetClrValue(out a))
if (!left.TryGetClrValue(out WAngle a))
throw new LuaException("Attempted to call WAngle.Subtract(WAngle, WAngle) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
if (right.TryGetClrValue(out c))
if (right.TryGetClrValue(out int c))
{
Game.Debug("Support for facing calculations mixing Angle with integers is deprecated. Make sure all facing calculations use Angle");
return new LuaCustomClrObject(a - FromFacing(c));
}
if (right.TryGetClrValue(out b))
if (right.TryGetClrValue(out WAngle b))
return new LuaCustomClrObject(a - b);
throw new LuaException("Attempted to call WAngle.Subtract(WAngle, WAngle) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
@@ -261,8 +255,7 @@ namespace OpenRA
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
{
WAngle a, b;
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
if (!left.TryGetClrValue(out WAngle a) || !right.TryGetClrValue(out WAngle b))
return false;
return a == b;

View File

@@ -114,9 +114,7 @@ namespace OpenRA
#region Scripting interface
public LuaValue Add(LuaRuntime runtime, LuaValue left, LuaValue right)
{
WDist a;
WDist b;
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
if (!left.TryGetClrValue(out WDist a) || !right.TryGetClrValue(out WDist b))
throw new LuaException("Attempted to call WDist.Add(WDist, WDist) with invalid arguments.");
return new LuaCustomClrObject(a + b);
@@ -124,9 +122,7 @@ namespace OpenRA
public LuaValue Subtract(LuaRuntime runtime, LuaValue left, LuaValue right)
{
WDist a;
WDist b;
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
if (!left.TryGetClrValue(out WDist a) || !right.TryGetClrValue(out WDist b))
throw new LuaException("Attempted to call WDist.Subtract(WDist, WDist) with invalid arguments.");
return new LuaCustomClrObject(a - b);
@@ -134,9 +130,7 @@ namespace OpenRA
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
{
WDist a;
WDist b;
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
if (!left.TryGetClrValue(out WDist a) || !right.TryGetClrValue(out WDist b))
throw new LuaException("Attempted to call WDist.Equals(WDist, WDist) with invalid arguments.");
return a == b;

View File

@@ -82,9 +82,7 @@ namespace OpenRA
public LuaValue Add(LuaRuntime runtime, LuaValue left, LuaValue right)
{
WPos a;
WVec b;
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
if (!left.TryGetClrValue(out WPos a) || !right.TryGetClrValue(out WVec b))
throw new LuaException("Attempted to call WPos.Add(WPos, WVec) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
return new LuaCustomClrObject(a + b);
@@ -92,21 +90,18 @@ namespace OpenRA
public LuaValue Subtract(LuaRuntime runtime, LuaValue left, LuaValue right)
{
WPos a;
var rightType = right.WrappedClrType();
if (!left.TryGetClrValue(out a))
if (!left.TryGetClrValue(out WPos a))
throw new LuaException("Attempted to call WPos.Subtract(WPos, (WPos|WVec)) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, rightType.Name));
if (rightType == typeof(WPos))
{
WPos b;
right.TryGetClrValue(out b);
right.TryGetClrValue(out WPos b);
return new LuaCustomClrObject(a - b);
}
else if (rightType == typeof(WVec))
{
WVec b;
right.TryGetClrValue(out b);
right.TryGetClrValue(out WVec b);
return new LuaCustomClrObject(a - b);
}
@@ -115,8 +110,7 @@ namespace OpenRA
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
{
WPos a, b;
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
if (!left.TryGetClrValue(out WPos a) || !right.TryGetClrValue(out WPos b))
return false;
return a == b;

View File

@@ -158,8 +158,7 @@ namespace OpenRA
public Int32Matrix4x4 AsMatrix()
{
Int32Matrix4x4 mtx;
AsMatrix(out mtx);
AsMatrix(out var mtx);
return mtx;
}

View File

@@ -46,8 +46,7 @@ namespace OpenRA
public WVec Rotate(WRot rot)
{
Int32Matrix4x4 mtx;
rot.AsMatrix(out mtx);
rot.AsMatrix(out var mtx);
return Rotate(ref mtx);
}
@@ -111,8 +110,7 @@ namespace OpenRA
public LuaValue Add(LuaRuntime runtime, LuaValue left, LuaValue right)
{
WVec a, b;
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
if (!left.TryGetClrValue(out WVec a) || !right.TryGetClrValue(out WVec b))
throw new LuaException("Attempted to call WVec.Add(WVec, WVec) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
return new LuaCustomClrObject(a + b);
@@ -120,8 +118,7 @@ namespace OpenRA
public LuaValue Subtract(LuaRuntime runtime, LuaValue left, LuaValue right)
{
WVec a, b;
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
if (!left.TryGetClrValue(out WVec a) || !right.TryGetClrValue(out WVec b))
throw new LuaException("Attempted to call WVec.Subtract(WVec, WVec) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
return new LuaCustomClrObject(a - b);
@@ -134,8 +131,7 @@ namespace OpenRA
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
{
WVec a, b;
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
if (!left.TryGetClrValue(out WVec a) || !right.TryGetClrValue(out WVec b))
return false;
return a == b;

View File

@@ -35,8 +35,7 @@ namespace OpenRA.Widgets
public static bool TryGet<T>(string key, out T result)
{
string s;
if (!data.TryGetValue(key, out s))
if (!data.TryGetValue(key, out var s))
{
result = default(T);
return false;

View File

@@ -37,8 +37,7 @@ namespace OpenRA
public Widget LoadWidget(WidgetArgs args, Widget parent, string w)
{
MiniYamlNode ret;
if (!widgets.TryGetValue(w, out ret))
if (!widgets.TryGetValue(w, out var ret))
throw new InvalidDataException("Cannot find widget with Id `{0}`".F(w));
return LoadWidget(args, parent, ret);

View File

@@ -486,8 +486,7 @@ namespace OpenRA
public Actor GetActorById(uint actorId)
{
Actor a;
if (actors.TryGetValue(actorId, out a))
if (actors.TryGetValue(actorId, out var a))
return a;
return null;
}

View File

@@ -80,8 +80,7 @@ namespace OpenRA.Mods.Cnc.Activities
if (IsCanceling)
return true;
bool targetIsHiddenActor;
target = target.Recalculate(self.Owner, out targetIsHiddenActor);
target = target.Recalculate(self.Owner, out var targetIsHiddenActor);
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
{
lastVisibleTarget = Target.FromTargetPositions(target);

View File

@@ -98,8 +98,7 @@ namespace OpenRA.Mods.Cnc.AudioLoaders
this.stream = stream;
CheckVocHeader(stream);
int sampleRate;
Preload(stream, out blocks, out totalSamples, out sampleRate);
Preload(stream, out blocks, out totalSamples, out var sampleRate);
SampleRate = sampleRate;
Rewind();
}

View File

@@ -48,10 +48,7 @@ namespace OpenRA.Mods.Cnc.FileSystem
List<PackageEntry> entries;
if (isEncrypted)
{
long unused;
entries = ParseHeader(DecryptHeader(s, 4, out dataStart), 0, out unused);
}
entries = ParseHeader(DecryptHeader(s, 4, out dataStart), 0, out var unused);
else
entries = ParseHeader(s, isCncMix ? 0 : 4, out dataStart);
@@ -93,9 +90,8 @@ namespace OpenRA.Mods.Cnc.FileSystem
{
var classicHash = PackageEntry.HashFilename(filename, PackageHashType.Classic);
var crcHash = PackageEntry.HashFilename(filename, PackageHashType.CRC32);
PackageEntry e;
if (entries.TryGetValue(classicHash, out e))
if (entries.TryGetValue(classicHash, out var e))
classicIndex.Add(filename, e);
if (entries.TryGetValue(crcHash, out e))
@@ -187,8 +183,7 @@ namespace OpenRA.Mods.Cnc.FileSystem
public Stream GetStream(string filename)
{
PackageEntry e;
if (!index.TryGetValue(filename, out e))
if (!index.TryGetValue(filename, out var e))
return null;
return GetContent(e);
@@ -210,12 +205,11 @@ namespace OpenRA.Mods.Cnc.FileSystem
public IReadOnlyPackage OpenPackage(string filename, FS context)
{
IReadOnlyPackage package;
var childStream = GetStream(filename);
if (childStream == null)
return null;
if (context.TryParsePackage(childStream, filename, out package))
if (context.TryParsePackage(childStream, filename, out var package))
return package;
childStream.Dispose();
@@ -237,9 +231,8 @@ namespace OpenRA.Mods.Cnc.FileSystem
}
// Load the global mix database
Stream mixDatabase;
var allPossibleFilenames = new HashSet<string>();
if (context.TryOpen("global mix database.dat", out mixDatabase))
if (context.TryOpen("global mix database.dat", out var mixDatabase))
using (var db = new XccGlobalDatabase(mixDatabase))
foreach (var e in db.Entries)
allPossibleFilenames.Add(e);

View File

@@ -49,8 +49,7 @@ namespace OpenRA.Mods.Cnc.FileSystem
public override string ToString()
{
string filename;
if (names.TryGetValue(Hash, out filename))
if (names.TryGetValue(Hash, out var filename))
return "{0} - offset 0x{1:x8} - length 0x{2:x8}".F(filename, Offset, Length);
else
return "0x{0:x8} - offset 0x{1:x8} - length 0x{2:x8}".F(Hash, Offset, Length);

View File

@@ -66,8 +66,7 @@ namespace OpenRA.Mods.Cnc.FileSystem
public Stream GetStream(string filename)
{
Entry entry;
if (!index.TryGetValue(filename, out entry))
if (!index.TryGetValue(filename, out var entry))
return null;
return SegmentStream.CreateWithoutOwningStream(stream, entry.Offset, (int)entry.Length);

View File

@@ -25,8 +25,7 @@ namespace OpenRA.Mods.Cnc.Graphics
: base(modData)
{
var metadata = modData.Manifest.Get<SpriteSequenceFormat>().Metadata;
MiniYaml yaml;
if (metadata.TryGetValue("DefaultSpriteExtension", out yaml))
if (metadata.TryGetValue("DefaultSpriteExtension", out var yaml))
DefaultSpriteExtension = yaml.Value;
if (metadata.TryGetValue("TilesetExtensions", out yaml))
@@ -51,8 +50,7 @@ namespace OpenRA.Mods.Cnc.Graphics
{
var tsId = tileSet.Id;
MiniYaml yaml;
if (d.TryGetValue("TilesetOverrides", out yaml))
if (d.TryGetValue("TilesetOverrides", out var yaml))
{
var tsNode = yaml.Nodes.FirstOrDefault(n => n.Key == tsId);
if (tsNode != null)
@@ -70,8 +68,7 @@ namespace OpenRA.Mods.Cnc.Graphics
if (LoadField(d, "UseTilesetCode", false))
{
string code;
if (loader.TilesetCodes.TryGetValue(ResolveTilesetId(tileSet, d), out code))
if (loader.TilesetCodes.TryGetValue(ResolveTilesetId(tileSet, d), out var code))
spriteName = spriteName.Substring(0, 1) + code + spriteName.Substring(2, spriteName.Length - 2);
}
@@ -79,8 +76,7 @@ namespace OpenRA.Mods.Cnc.Graphics
{
var useTilesetExtension = LoadField(d, "UseTilesetExtension", false);
string tilesetExtension;
if (useTilesetExtension && loader.TilesetExtensions.TryGetValue(ResolveTilesetId(tileSet, d), out tilesetExtension))
if (useTilesetExtension && loader.TilesetExtensions.TryGetValue(ResolveTilesetId(tileSet, d), out var tilesetExtension))
return spriteName + tilesetExtension;
return spriteName + loader.DefaultSpriteExtension;

View File

@@ -235,8 +235,7 @@ namespace OpenRA.Mods.Cnc.Traits
if (disguisedAsToken != Actor.InvalidConditionToken)
disguisedAsToken = self.RevokeCondition(disguisedAsToken);
string disguisedAsCondition;
if (info.DisguisedAsConditions.TryGetValue(AsActor.Name, out disguisedAsCondition))
if (info.DisguisedAsConditions.TryGetValue(AsActor.Name, out var disguisedAsCondition))
disguisedAsToken = self.GrantCondition(disguisedAsCondition);
}
}

View File

@@ -53,8 +53,7 @@ namespace OpenRA.Mods.Cnc.Traits
{
var damageSubTicks = (int)(damage.Value * 100L * Info.DamageMultiplier / Info.DamageDivisor);
SupportPowerInstance spi;
if (spm.Powers.TryGetValue(Info.OrderName, out spi))
if (spm.Powers.TryGetValue(Info.OrderName, out var spi))
{
var dspi = spi as GrantPrerequisiteChargeDrainPower.DischargeableSupportPowerInstance;
if (dspi != null)

View File

@@ -36,10 +36,8 @@ namespace OpenRA.Mods.Cnc.Traits
public void RulesetLoaded(Ruleset rules, ActorInfo ai)
{
WeaponInfo weaponInfo;
var weaponToLower = Weapon.ToLowerInvariant();
if (!rules.Weapons.TryGetValue(weaponToLower, out weaponInfo))
if (!rules.Weapons.TryGetValue(weaponToLower, out var weaponInfo))
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(weaponToLower));
WeaponInfo = weaponInfo;

View File

@@ -65,15 +65,13 @@ namespace OpenRA.Mods.Cnc.Traits
public void RulesetLoaded(Ruleset rules, ActorInfo ai)
{
WeaponInfo thumpDamageWeapon;
WeaponInfo detonationWeapon;
var thumpDamageWeaponToLower = (ThumpDamageWeapon ?? string.Empty).ToLowerInvariant();
var detonationWeaponToLower = (DetonationWeapon ?? string.Empty).ToLowerInvariant();
if (!rules.Weapons.TryGetValue(thumpDamageWeaponToLower, out thumpDamageWeapon))
if (!rules.Weapons.TryGetValue(thumpDamageWeaponToLower, out var thumpDamageWeapon))
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(thumpDamageWeaponToLower));
if (!rules.Weapons.TryGetValue(detonationWeaponToLower, out detonationWeapon))
if (!rules.Weapons.TryGetValue(detonationWeaponToLower, out var detonationWeapon))
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(detonationWeaponToLower));
ThumpDamageWeaponInfo = thumpDamageWeapon;

View File

@@ -66,9 +66,8 @@ namespace OpenRA.Mods.Cnc.Traits
public override void RulesetLoaded(Ruleset rules, ActorInfo ai)
{
WeaponInfo weapon;
var weaponToLower = (Weapon ?? string.Empty).ToLowerInvariant();
if (!rules.Weapons.TryGetValue(weaponToLower, out weapon))
if (!rules.Weapons.TryGetValue(weaponToLower, out var weapon))
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(weaponToLower));
WeaponInfo = weapon;

View File

@@ -52,9 +52,8 @@ namespace OpenRA.Mods.Cnc.Traits
public override object Create(ActorInitializer init) { return new IonCannonPower(init.Self, this); }
public override void RulesetLoaded(Ruleset rules, ActorInfo ai)
{
WeaponInfo weapon;
var weaponToLower = (Weapon ?? string.Empty).ToLowerInvariant();
if (!rules.Weapons.TryGetValue(weaponToLower, out weapon))
if (!rules.Weapons.TryGetValue(weaponToLower, out var weapon))
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(weaponToLower));
WeaponInfo = weapon;

View File

@@ -404,8 +404,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
if (overlayType == 0xFF)
continue;
string actorType;
if (OverlayToActor.TryGetValue(overlayType, out actorType))
if (OverlayToActor.TryGetValue(overlayType, out var actorType))
{
if (string.IsNullOrEmpty(actorType))
continue;
@@ -416,19 +415,13 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
// Only import the top-left cell of multi-celled overlays
var aboveType = overlayPack[overlayIndex[cell - new CVec(1, 0)]];
if (shape.Width > 1 && aboveType != 0xFF)
{
string a;
if (OverlayToActor.TryGetValue(aboveType, out a) && a == actorType)
if (OverlayToActor.TryGetValue(aboveType, out var a) && a == actorType)
continue;
}
var leftType = overlayPack[overlayIndex[cell - new CVec(0, 1)]];
if (shape.Height > 1 && leftType != 0xFF)
{
string a;
if (OverlayToActor.TryGetValue(leftType, out a) && a == actorType)
if (OverlayToActor.TryGetValue(leftType, out var a) && a == actorType)
continue;
}
}
var ar = new ActorReference(actorType)
@@ -437,8 +430,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
new OwnerInit("Neutral")
};
DamageState damageState;
if (OverlayToHealth.TryGetValue(overlayType, out damageState))
if (OverlayToHealth.TryGetValue(overlayType, out var damageState))
{
var health = 100;
if (damageState == DamageState.Critical)
@@ -484,8 +476,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
var dy = rx + ry - fullSize.X - 1;
var cell = new MPos(dx / 2, dy).ToCPos(map);
int wpindex;
var ar = new ActorReference((!int.TryParse(kv.Key, out wpindex) || wpindex > 7) ? "waypoint" : "mpspawn");
var ar = new ActorReference((!int.TryParse(kv.Key, out var wpindex) || wpindex > 7) ? "waypoint" : "mpspawn");
ar.Add(new LocationInit(cell));
ar.Add(new OwnerInit("Neutral"));
@@ -598,8 +589,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
foreach (var node in lightingTypes)
{
float val;
if (node.Value != null && parsed.TryGetValue(node.Key, out val) && ((node.Key == "Level" && val != 0) || (node.Key != "Level" && val != 1.0f)))
if (node.Value != null && parsed.TryGetValue(node.Key, out var val) && ((node.Key == "Level" && val != 0) || (node.Key != "Level" && val != 1.0f)))
lightingNodes.Add(new MiniYamlNode(node.Value, FieldSaver.FormatValue(val)));
}

View File

@@ -265,9 +265,8 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
else
Console.WriteLine("\t\tFacings: 8");
int length, stride;
int.TryParse(splitting[2], out stride);
int.TryParse(splitting[1], out length);
int.TryParse(splitting[2], out var stride);
int.TryParse(splitting[1], out var length);
if (stride != 0 && stride != length)
Console.WriteLine("\t\tStride: " + stride);
}

View File

@@ -164,8 +164,7 @@ namespace OpenRA.Mods.Common.Activities
return false;
}
bool targetIsHiddenActor;
target = target.Recalculate(self.Owner, out targetIsHiddenActor);
target = target.Recalculate(self.Owner, out var targetIsHiddenActor);
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
lastVisibleTarget = Target.FromTargetPositions(target);

View File

@@ -90,8 +90,7 @@ namespace OpenRA.Mods.Common.Activities
if (attackAircraft.IsTraitPaused)
return false;
bool targetIsHiddenActor;
target = target.Recalculate(self.Owner, out targetIsHiddenActor);
target = target.Recalculate(self.Owner, out var targetIsHiddenActor);
attackAircraft.SetRequestedTarget(self, target, forceAttack);
hasTicked = true;
@@ -239,8 +238,7 @@ namespace OpenRA.Mods.Common.Activities
// Cancel the run if the target become invalid (e.g. killed) while visible
var targetWasVisibleActor = targetIsVisibleActor;
bool targetIsHiddenActor;
target = target.Recalculate(self.Owner, out targetIsHiddenActor);
target = target.Recalculate(self.Owner, out var targetIsHiddenActor);
targetIsVisibleActor = target.Type == TargetType.Actor && !targetIsHiddenActor;
if (targetWasVisibleActor && !target.IsValidFor(self))
@@ -284,8 +282,7 @@ namespace OpenRA.Mods.Common.Activities
// Strafe attacks target the ground below the original target
// Update the position if we seen the target move; keep the previous one if it dies or disappears
bool targetIsHiddenActor;
target = target.Recalculate(self.Owner, out targetIsHiddenActor);
target = target.Recalculate(self.Owner, out var targetIsHiddenActor);
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
attackAircraft.SetRequestedTarget(self, Target.FromTargetPositions(target), true);

View File

@@ -55,8 +55,7 @@ namespace OpenRA.Mods.Common.Activities
if (IsCanceling)
return true;
bool targetIsHiddenActor;
target = target.Recalculate(self.Owner, out targetIsHiddenActor);
target = target.Recalculate(self.Owner, out var targetIsHiddenActor);
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
lastVisibleTarget = Target.FromTargetPositions(target);

View File

@@ -96,8 +96,7 @@ namespace OpenRA.Mods.Common.Activities
return false;
}
bool targetIsHiddenActor;
target = RecalculateTarget(self, out targetIsHiddenActor);
target = RecalculateTarget(self, out var targetIsHiddenActor);
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
{

View File

@@ -46,8 +46,7 @@ namespace OpenRA.Mods.Common.Activities
// StartCapture returns false when a capture delay is enabled
// We wait until it returns true before allowing entering the target
Captures captures;
if (!manager.StartCapture(self, enterActor, enterCaptureManager, out captures))
if (!manager.StartCapture(self, enterActor, enterCaptureManager, out var captures))
return false;
if (!captures.Info.ConsumedByCapture)

View File

@@ -62,8 +62,7 @@ namespace OpenRA.Mods.Common.Activities
public override bool Tick(Actor self)
{
// Update our view of the target
bool targetIsHiddenActor;
target = target.Recalculate(self.Owner, out targetIsHiddenActor);
target = target.Recalculate(self.Owner, out var targetIsHiddenActor);
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
lastVisibleTarget = Target.FromTargetPositions(target);

View File

@@ -51,8 +51,7 @@ namespace OpenRA.Mods.Common.Activities
if (IsCanceling)
return true;
bool targetIsHiddenActor;
target = target.Recalculate(self.Owner, out targetIsHiddenActor);
target = target.Recalculate(self.Owner, out var targetIsHiddenActor);
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
lastVisibleTarget = Target.FromTargetPositions(target);

View File

@@ -88,9 +88,8 @@ namespace OpenRA.Mods.Common.Activities
public override bool Tick(Actor self)
{
bool targetIsHiddenActor;
var oldTargetLocation = lastVisibleTargetLocation;
target = target.Recalculate(self.Owner, out targetIsHiddenActor);
target = target.Recalculate(self.Owner, out var targetIsHiddenActor);
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
{
lastVisibleTarget = Target.FromTargetPositions(target);

View File

@@ -57,10 +57,7 @@ namespace OpenRA.Mods.Common
public bool IsValid(Color askedColor, out Color forbiddenColor, IEnumerable<Color> terrainColors, IEnumerable<Color> playerColors, HashSet<string> errorMessages = null)
{
// Validate color against HSV
float h, s, v;
int a;
askedColor.ToAhsv(out a, out h, out s, out v);
askedColor.ToAhsv(out var a, out var h, out var s, out var v);
if (s < HsvSaturationRange[0] || s > HsvSaturationRange[1] || v < HsvValueRange[0] || v > HsvValueRange[1])
{
if (errorMessages != null)
@@ -95,9 +92,8 @@ namespace OpenRA.Mods.Common
{
if (TeamColorPresets.Any())
{
Color forbidden;
foreach (var c in TeamColorPresets.Shuffle(random))
if (IsValid(c, out forbidden, terrainColors, playerColors))
if (IsValid(c, out var forbidden, terrainColors, playerColors))
return c;
}
@@ -107,7 +103,6 @@ namespace OpenRA.Mods.Common
public Color RandomValidColor(MersenneTwister random, IEnumerable<Color> terrainColors, IEnumerable<Color> playerColors)
{
Color color;
Color forbidden;
do
{
var h = random.Next(255) / 255f;
@@ -115,7 +110,7 @@ namespace OpenRA.Mods.Common
var v = float2.Lerp(HsvValueRange[0], HsvValueRange[1], random.NextFloat());
color = Color.FromAhsv(h, s, v);
}
while (!IsValid(color, out forbidden, terrainColors, playerColors));
while (!IsValid(color, out var forbidden, terrainColors, playerColors));
return color;
}
@@ -124,8 +119,7 @@ namespace OpenRA.Mods.Common
{
var errorMessages = new HashSet<string>();
Color forbiddenColor;
if (IsValid(askedColor, out forbiddenColor, terrainColors, playerColors, errorMessages))
if (IsValid(askedColor, out var forbiddenColor, terrainColors, playerColors, errorMessages))
return askedColor;
// Vector between the 2 colors

View File

@@ -147,8 +147,7 @@ namespace OpenRA.Mods.Common.Commands
var orderString = toAll ? "DevGiveCashAll" : "DevGiveCash";
var giveCashOrder = new Order(orderString, world.LocalPlayer.PlayerActor, false);
int cash;
int.TryParse(arg, out cash);
int.TryParse(arg, out var cash);
giveCashOrder.ExtraData = (uint)cash;
world.IssueOrder(giveCashOrder);

View File

@@ -45,8 +45,7 @@ namespace OpenRA.Mods.Common.Commands
foreach (var key in console.Commands.Keys)
{
string description;
if (!helpDescriptions.TryGetValue(key, out description))
if (!helpDescriptions.TryGetValue(key, out var description))
description = "no description available.";
Game.Debug("{0}: {1}", key, description);

View File

@@ -62,8 +62,7 @@ namespace OpenRA.Mods.Common.FileFormats
return null;
var sectionName = m.Groups[1].Value.ToLowerInvariant();
IniSection ret;
if (!sections.TryGetValue(sectionName, out ret))
if (!sections.TryGetValue(sectionName, out var ret))
sections.Add(sectionName, ret = new IniSection(sectionName));
return ret;
}
@@ -102,8 +101,7 @@ namespace OpenRA.Mods.Common.FileFormats
public IniSection GetSection(string s, bool allowFail)
{
IniSection section;
if (sections.TryGetValue(s.ToLowerInvariant(), out section))
if (sections.TryGetValue(s.ToLowerInvariant(), out var section))
return section;
if (allowFail)
@@ -136,8 +134,7 @@ namespace OpenRA.Mods.Common.FileFormats
public string GetValue(string key, string defaultValue)
{
string s;
return values.TryGetValue(key, out s) ? s : defaultValue;
return values.TryGetValue(key, out var s) ? s : defaultValue;
}
public IEnumerator<KeyValuePair<string, string>> GetEnumerator()

View File

@@ -394,8 +394,7 @@ namespace OpenRA.Mods.Common.FileFormats
public void ExtractFile(string filename, Stream output, Action<int> onProgress = null)
{
FileDescriptor file;
if (!index.TryGetValue(filename, out file))
if (!index.TryGetValue(filename, out var file))
throw new FileNotFoundException(filename);
ExtractFile(file, output, onProgress);

View File

@@ -109,8 +109,7 @@ namespace OpenRA.Mods.Common.FileSystem
public Stream GetStream(string filename)
{
Entry e;
if (!index.TryGetValue(filename, out e))
if (!index.TryGetValue(filename, out var e))
return null;
s.Seek(dataStart + e.Offset, SeekOrigin.Begin);

View File

@@ -53,10 +53,9 @@ namespace OpenRA.Mods.Common.Graphics
var sequences = new Dictionary<string, ISpriteSequence>();
var nodes = node.Value.ToDictionary();
MiniYaml defaults;
try
{
if (nodes.TryGetValue("Defaults", out defaults))
if (nodes.TryGetValue("Defaults", out var defaults))
{
nodes.Remove("Defaults");
foreach (var n in nodes)
@@ -123,8 +122,7 @@ namespace OpenRA.Mods.Common.Graphics
protected static T LoadField<T>(Dictionary<string, MiniYaml> d, string key, T fallback)
{
MiniYaml value;
if (d.TryGetValue(key, out value))
if (d.TryGetValue(key, out var value))
return FieldLoader.GetValue<T>(key, value.Value);
return fallback;
@@ -174,8 +172,7 @@ namespace OpenRA.Mods.Common.Graphics
Func<int, IEnumerable<int>> getUsedFrames = frameCount =>
{
MiniYaml length;
if (d.TryGetValue("Length", out length) && length.Value == "*")
if (d.TryGetValue("Length", out var length) && length.Value == "*")
Length = Frames != null ? Frames.Length : frameCount - Start;
else
Length = LoadField(d, "Length", 1);
@@ -244,8 +241,7 @@ namespace OpenRA.Mods.Common.Graphics
return usedFrames;
};
MiniYaml combine;
if (d.TryGetValue("Combine", out combine))
if (d.TryGetValue("Combine", out var combine))
{
var combined = Enumerable.Empty<Sprite>();
foreach (var sub in combine.Nodes)
@@ -262,8 +258,7 @@ namespace OpenRA.Mods.Common.Graphics
Func<int, IEnumerable<int>> subGetUsedFrames = subFrameCount =>
{
MiniYaml subLengthYaml;
if (sd.TryGetValue("Length", out subLengthYaml) && subLengthYaml.Value == "*")
if (sd.TryGetValue("Length", out var subLengthYaml) && subLengthYaml.Value == "*")
subLength = subFrames != null ? subFrames.Length : subFrameCount - subStart;
else
subLength = LoadField(sd, "Length", 1);

View File

@@ -25,8 +25,7 @@ namespace OpenRA.Mods.Common.Graphics
: base(modData)
{
var metadata = modData.Manifest.Get<SpriteSequenceFormat>().Metadata;
MiniYaml yaml;
if (metadata.TryGetValue("DefaultSpriteExtension", out yaml))
if (metadata.TryGetValue("DefaultSpriteExtension", out var yaml))
DefaultSpriteExtension = yaml.Value;
if (metadata.TryGetValue("TilesetExtensions", out yaml))
@@ -51,8 +50,7 @@ namespace OpenRA.Mods.Common.Graphics
{
var tsId = tileSet.Id;
MiniYaml yaml;
if (d.TryGetValue("TilesetOverrides", out yaml))
if (d.TryGetValue("TilesetOverrides", out var yaml))
{
var tsNode = yaml.Nodes.FirstOrDefault(n => n.Key == tsId);
if (tsNode != null)
@@ -70,8 +68,7 @@ namespace OpenRA.Mods.Common.Graphics
if (LoadField(d, "UseTilesetCode", false))
{
string code;
if (loader.TilesetCodes.TryGetValue(ResolveTilesetId(tileSet, d), out code))
if (loader.TilesetCodes.TryGetValue(ResolveTilesetId(tileSet, d), out var code))
spriteName = spriteName.Substring(0, 1) + code + spriteName.Substring(2, spriteName.Length - 2);
}
@@ -79,8 +76,7 @@ namespace OpenRA.Mods.Common.Graphics
{
var useTilesetExtension = LoadField(d, "UseTilesetExtension", false);
string tilesetExtension;
if (useTilesetExtension && loader.TilesetExtensions.TryGetValue(ResolveTilesetId(tileSet, d), out tilesetExtension))
if (useTilesetExtension && loader.TilesetExtensions.TryGetValue(ResolveTilesetId(tileSet, d), out var tilesetExtension))
return spriteName + tilesetExtension;
return spriteName + loader.DefaultSpriteExtension;

View File

@@ -89,9 +89,8 @@ namespace OpenRA.Mods.Common.Lint
var type = modData.ObjectCreator.FindType(widgetType + "Widget");
var keyNames = checkMethods.SelectMany(m => (IEnumerable<string>)type.GetMethod(m).Invoke(null, new object[] { node, emitError, emitWarning }));
Hotkey unused;
foreach (var name in keyNames)
if (!namedKeys.Contains(name) && !Hotkey.TryParse(name, out unused))
if (!namedKeys.Contains(name) && !Hotkey.TryParse(name, out var unused))
emitError("{0} refers to a Key named `{1}` that does not exist".F(node.Location, name));
}

View File

@@ -43,9 +43,8 @@ namespace OpenRA.Mods.Common.Lint
if (string.IsNullOrEmpty(notification))
continue;
SoundInfo soundInfo;
if (string.IsNullOrEmpty(type) || !rules.Notifications.TryGetValue(type.ToLowerInvariant(), out soundInfo) ||
!soundInfo.Notifications.ContainsKey(notification))
if (string.IsNullOrEmpty(type) || !rules.Notifications.TryGetValue(type.ToLowerInvariant(), out var soundInfo) ||
!soundInfo.Notifications.ContainsKey(notification))
emitError("Undefined notification reference {0}.{1} detected at {2} for {3}".F(
type ?? "(null)", notification, traitInfo.GetType().Name, actorInfo.Key));
}

View File

@@ -95,8 +95,7 @@ namespace OpenRA.Mods.Common.Lint
if (!playerNames.Contains(ownerName))
emitError("Actor {0} is owned by unknown player {1}.".F(kv.Key, ownerName));
RequiresSpecificOwnersInfo info;
if (actorsWithRequiredOwner.TryGetValue(kv.Value.Value, out info))
if (actorsWithRequiredOwner.TryGetValue(kv.Value.Value, out var info))
if (!info.ValidOwnerNames.Contains(ownerName))
emitError("Actor {0} owner {1} is not one of ValidOwnerNames: {2}".F(kv.Key, ownerName, info.ValidOwnerNames.JoinWith(", ")));
}

View File

@@ -49,8 +49,7 @@ namespace OpenRA.Mods.Common.LoadScreens
public override void StartGame(Arguments args)
{
var modId = args.GetValue("Content.Mod", null);
Manifest selectedMod;
if (modId == null || !Game.Mods.TryGetValue(modId, out selectedMod))
if (modId == null || !Game.Mods.TryGetValue(modId, out var selectedMod))
throw new InvalidOperationException("Invalid or missing Content.Mod argument.");
var content = selectedMod.Get<ModContent>(Game.ModData.ObjectCreator);

View File

@@ -52,8 +52,7 @@ namespace OpenRA.Mods.Common.Pathfinder
public List<CPos> Retrieve(string key)
{
CachedPath cached;
if (cachedPaths.TryGetValue(key, out cached))
if (cachedPaths.TryGetValue(key, out var cached))
{
if (IsExpired(cached))
{

View File

@@ -218,9 +218,7 @@ namespace OpenRA.Mods.Common.Projectiles
}
// Check for blocking actors
WPos blockedPos;
if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, tailPos, headPos,
info.Width, out blockedPos))
if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, tailPos, headPos, info.Width, out var blockedPos))
{
headPos = blockedPos;
target = headPos;

View File

@@ -205,9 +205,7 @@ namespace OpenRA.Mods.Common.Projectiles
// Check for walls or other blocking obstacles
var shouldExplode = false;
WPos blockedPos;
if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, lastPos, pos, info.Width,
out blockedPos))
if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, lastPos, pos, info.Width, out var blockedPos))
{
pos = blockedPos;
shouldExplode = true;

View File

@@ -67,7 +67,6 @@ namespace OpenRA.Mods.Common.Projectiles
public void Tick(World world)
{
// Check for blocking actors
WPos blockedPos;
if (info.Blockable)
{
// If GuidedTarget has become invalid due to getting killed the same tick,
@@ -77,7 +76,7 @@ namespace OpenRA.Mods.Common.Projectiles
target = Target.FromPos(args.PassiveTarget);
if (BlocksProjectiles.AnyBlockingActorsBetween(world, args.Source, target.CenterPosition,
info.Width, out blockedPos))
info.Width, out var blockedPos))
target = Target.FromPos(blockedPos);
}

View File

@@ -158,9 +158,7 @@ namespace OpenRA.Mods.Common.Projectiles
target = args.Weapon.TargetActorCenter ? args.GuidedTarget.CenterPosition : args.GuidedTarget.Positions.PositionClosestTo(source);
// Check for blocking actors
WPos blockedPos;
if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, source, target,
info.Width, out blockedPos))
if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, source, target, info.Width, out var blockedPos))
{
target = blockedPos;
}

View File

@@ -849,9 +849,7 @@ namespace OpenRA.Mods.Common.Projectiles
// Check for walls or other blocking obstacles
var shouldExplode = false;
WPos blockedPos;
if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, lastPos, pos, info.Width,
out blockedPos))
if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, lastPos, pos, info.Width, out var blockedPos))
{
pos = blockedPos;
shouldExplode = true;

Some files were not shown because too many files have changed in this diff Show More