Use pattern matching
This commit is contained in:
committed by
atlimit8
parent
aed2b8afae
commit
2677e9c013
@@ -223,8 +223,7 @@ namespace OpenRA.Graphics
|
|||||||
ShadowAmbient, ShadowDiffuse, shadowPalette.TextureMidIndex, normals.TextureMidIndex);
|
ShadowAmbient, ShadowDiffuse, shadowPalette.TextureMidIndex, normals.TextureMidIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}));
|
||||||
));
|
|
||||||
|
|
||||||
var screenLightVector = Util.MatrixVectorMultiply(invShadowTransform, ZVector);
|
var screenLightVector = Util.MatrixVectorMultiply(invShadowTransform, ZVector);
|
||||||
screenLightVector = Util.MatrixVectorMultiply(cameraTransform, screenLightVector);
|
screenLightVector = Util.MatrixVectorMultiply(cameraTransform, screenLightVector);
|
||||||
|
|||||||
@@ -177,8 +177,7 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
foreach (var e in World.Effects)
|
foreach (var e in World.Effects)
|
||||||
{
|
{
|
||||||
var ea = e as IEffectAboveShroud;
|
if (!(e is IEffectAboveShroud ea))
|
||||||
if (ea == null)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
foreach (var renderable in ea.RenderAboveShroud(this))
|
foreach (var renderable in ea.RenderAboveShroud(this))
|
||||||
@@ -219,8 +218,7 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
foreach (var e in World.Effects)
|
foreach (var e in World.Effects)
|
||||||
{
|
{
|
||||||
var ea = e as IEffectAnnotation;
|
if (!(e is IEffectAnnotation ea))
|
||||||
if (ea == null)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
foreach (var renderAnnotation in ea.RenderAnnotation(this))
|
foreach (var renderAnnotation in ea.RenderAnnotation(this))
|
||||||
|
|||||||
@@ -87,8 +87,7 @@ namespace OpenRA
|
|||||||
var ret = new MiniYaml(Type);
|
var ret = new MiniYaml(Type);
|
||||||
foreach (var o in initDict.Value)
|
foreach (var o in initDict.Value)
|
||||||
{
|
{
|
||||||
var init = o as ActorInit;
|
if (!(o is ActorInit init) || o is ISuppressInitExport)
|
||||||
if (init == null || o is ISuppressInitExport)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (initFilter != null && !initFilter(init))
|
if (initFilter != null && !initFilter(init))
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ namespace OpenRA.Primitives
|
|||||||
public static bool operator !=(BitSet<T> me, BitSet<T> other) { return !(me == other); }
|
public static bool operator !=(BitSet<T> me, BitSet<T> other) { return !(me == other); }
|
||||||
|
|
||||||
public bool Equals(BitSet<T> other) { return other == this; }
|
public bool Equals(BitSet<T> other) { return other == this; }
|
||||||
public override bool Equals(object obj) { return obj is BitSet<T> && Equals((BitSet<T>)obj); }
|
public override bool Equals(object obj) { return obj is BitSet<T> bitSet && Equals(bitSet); }
|
||||||
public override int GetHashCode() { return bits.GetHashCode(); }
|
public override int GetHashCode() { return bits.GetHashCode(); }
|
||||||
|
|
||||||
public bool IsEmpty => bits == 0;
|
public bool IsEmpty => bits == 0;
|
||||||
|
|||||||
@@ -86,8 +86,7 @@ namespace OpenRA.Scripting
|
|||||||
{
|
{
|
||||||
foreach (var arg in clrArgs)
|
foreach (var arg in clrArgs)
|
||||||
{
|
{
|
||||||
var table = arg as LuaValue[];
|
if (!(arg is LuaValue[] table))
|
||||||
if (table == null)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
foreach (var value in table)
|
foreach (var value in table)
|
||||||
|
|||||||
@@ -104,8 +104,8 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
{
|
{
|
||||||
case "BeginMinefield":
|
case "BeginMinefield":
|
||||||
var start = self.World.Map.CellContaining(target.CenterPosition);
|
var start = self.World.Map.CellContaining(target.CenterPosition);
|
||||||
if (self.World.OrderGenerator is MinefieldOrderGenerator)
|
if (self.World.OrderGenerator is MinefieldOrderGenerator generator)
|
||||||
((MinefieldOrderGenerator)self.World.OrderGenerator).AddMinelayer(self);
|
generator.AddMinelayer(self);
|
||||||
else
|
else
|
||||||
self.World.OrderGenerator = new MinefieldOrderGenerator(self, start, queued);
|
self.World.OrderGenerator = new MinefieldOrderGenerator(self, start, queued);
|
||||||
|
|
||||||
@@ -145,6 +145,8 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
// A different minelayer might have started laying the field without this minelayer knowing the start
|
// A different minelayer might have started laying the field without this minelayer knowing the start
|
||||||
minefieldStart = order.ExtraLocation;
|
minefieldStart = order.ExtraLocation;
|
||||||
|
|
||||||
|
#pragma warning disable IDE0019 // Use pattern matching
|
||||||
|
|
||||||
var movement = self.Trait<IPositionable>();
|
var movement = self.Trait<IPositionable>();
|
||||||
var mobile = movement as Mobile;
|
var mobile = movement as Mobile;
|
||||||
|
|
||||||
@@ -153,6 +155,8 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
&& movement.CanEnterCell(c, null, BlockedByActor.Immovable) && (mobile != null && mobile.CanStayInCell(c)))
|
&& movement.CanEnterCell(c, null, BlockedByActor.Immovable) && (mobile != null && mobile.CanStayInCell(c)))
|
||||||
.OrderBy(c => (c - minefieldStart).LengthSquared).ToList();
|
.OrderBy(c => (c - minefieldStart).LengthSquared).ToList();
|
||||||
|
|
||||||
|
#pragma warning restore IDE0019 // Use pattern matching
|
||||||
|
|
||||||
self.QueueActivity(order.Queued, new LayMines(self, minefield));
|
self.QueueActivity(order.Queued, new LayMines(self, minefield));
|
||||||
self.ShowTargetLines();
|
self.ShowTargetLines();
|
||||||
}
|
}
|
||||||
@@ -305,6 +309,8 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
var minefield = GetMinefieldCells(minefieldStart, lastMousePos,
|
var minefield = GetMinefieldCells(minefieldStart, lastMousePos,
|
||||||
minelayers.Max(m => m.Info.TraitInfo<MinelayerInfo>().MinefieldDepth));
|
minelayers.Max(m => m.Info.TraitInfo<MinelayerInfo>().MinefieldDepth));
|
||||||
|
|
||||||
|
#pragma warning disable IDE0019 // Use pattern matching
|
||||||
|
|
||||||
var movement = minelayer.Trait<IPositionable>();
|
var movement = minelayer.Trait<IPositionable>();
|
||||||
var mobile = movement as Mobile;
|
var mobile = movement as Mobile;
|
||||||
var pal = wr.Palette(TileSet.TerrainPaletteInternalName);
|
var pal = wr.Palette(TileSet.TerrainPaletteInternalName);
|
||||||
@@ -335,6 +341,8 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
}
|
}
|
||||||
|
|
||||||
yield return new SpriteRenderable(tile, world.Map.CenterOfCell(c), WVec.Zero, -511, pal, 1f, alpha, float3.Ones, TintModifiers.IgnoreWorldTint, true);
|
yield return new SpriteRenderable(tile, world.Map.CenterOfCell(c), WVec.Zero, -511, pal, 1f, alpha, float3.Ones, TintModifiers.IgnoreWorldTint, true);
|
||||||
|
|
||||||
|
#pragma warning restore IDE0019 // Use pattern matching
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -309,8 +309,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
{
|
{
|
||||||
foreach (var actor in self.World.ActorMap.GetActorsAt(cell))
|
foreach (var actor in self.World.ActorMap.GetActorsAt(cell))
|
||||||
{
|
{
|
||||||
var move = actor.OccupiesSpace as Mobile;
|
if (!(actor.OccupiesSpace is Mobile move) || !move.IsTraitEnabled() || !move.IsLeaving())
|
||||||
if (move == null || !move.IsTraitEnabled() || !move.IsLeaving())
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -155,8 +155,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// PERF: Mobile implements IPositionable, so we can use 'as' to save a trait look-up here.
|
// PERF: Mobile implements IPositionable, so we can use 'as' to save a trait look-up here.
|
||||||
var mobile = positionable as Mobile;
|
if (positionable is Mobile mobile && !mobile.CanInteractWithGroundLayer(self))
|
||||||
if (mobile != null && !mobile.CanInteractWithGroundLayer(self))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -55,8 +55,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
{
|
{
|
||||||
foreach (var sequence in kv.Value.Sequences(image))
|
foreach (var sequence in kv.Value.Sequences(image))
|
||||||
{
|
{
|
||||||
var s = kv.Value.GetSequence(image, sequence) as FileNotFoundSequence;
|
if (!(kv.Value.GetSequence(image, sequence) is FileNotFoundSequence s))
|
||||||
if (s == null)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Console.WriteLine("\tSequence `{0}.{1}` references sprite `{2}` that does not exist.", image, sequence, s.Filename);
|
Console.WriteLine("\tSequence `{0}.{1}` references sprite `{2}` that does not exist.", image, sequence, s.Filename);
|
||||||
|
|||||||
@@ -260,9 +260,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
foreach (var o in options)
|
foreach (var o in options)
|
||||||
{
|
{
|
||||||
if (o is EditorActorCheckbox)
|
if (o is EditorActorCheckbox co)
|
||||||
{
|
{
|
||||||
var co = (EditorActorCheckbox)o;
|
|
||||||
var checkboxContainer = checkboxOptionTemplate.Clone();
|
var checkboxContainer = checkboxOptionTemplate.Clone();
|
||||||
checkboxContainer.Bounds.Y = initContainer.Bounds.Height;
|
checkboxContainer.Bounds.Y = initContainer.Bounds.Height;
|
||||||
initContainer.Bounds.Height += checkboxContainer.Bounds.Height;
|
initContainer.Bounds.Height += checkboxContainer.Bounds.Height;
|
||||||
@@ -283,9 +282,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
initContainer.AddChild(checkboxContainer);
|
initContainer.AddChild(checkboxContainer);
|
||||||
}
|
}
|
||||||
else if (o is EditorActorSlider)
|
else if (o is EditorActorSlider so)
|
||||||
{
|
{
|
||||||
var so = (EditorActorSlider)o;
|
|
||||||
var sliderContainer = sliderOptionTemplate.Clone();
|
var sliderContainer = sliderOptionTemplate.Clone();
|
||||||
sliderContainer.Bounds.Y = initContainer.Bounds.Height;
|
sliderContainer.Bounds.Y = initContainer.Bounds.Height;
|
||||||
initContainer.Bounds.Height += sliderContainer.Bounds.Height;
|
initContainer.Bounds.Height += sliderContainer.Bounds.Height;
|
||||||
@@ -319,9 +317,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
initContainer.AddChild(sliderContainer);
|
initContainer.AddChild(sliderContainer);
|
||||||
}
|
}
|
||||||
else if (o is EditorActorDropdown)
|
else if (o is EditorActorDropdown ddo)
|
||||||
{
|
{
|
||||||
var ddo = (EditorActorDropdown)o;
|
|
||||||
var dropdownContainer = dropdownOptionTemplate.Clone();
|
var dropdownContainer = dropdownOptionTemplate.Clone();
|
||||||
dropdownContainer.Bounds.Y = initContainer.Bounds.Height;
|
dropdownContainer.Bounds.Y = initContainer.Bounds.Height;
|
||||||
initContainer.Bounds.Height += dropdownContainer.Bounds.Height;
|
initContainer.Bounds.Height += dropdownContainer.Bounds.Height;
|
||||||
|
|||||||
@@ -92,8 +92,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
foreach (var kv in modData.MapCache.MapLocations)
|
foreach (var kv in modData.MapCache.MapLocations)
|
||||||
{
|
{
|
||||||
var folder = kv.Key as Folder;
|
if (!(kv.Key is Folder folder))
|
||||||
if (folder == null)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -226,8 +226,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
games[games.IndexOf(oldPath)] = newPath;
|
games[games.IndexOf(oldPath)] = newPath;
|
||||||
foreach (var c in gameList.Children)
|
foreach (var c in gameList.Children)
|
||||||
{
|
{
|
||||||
var item = c as ScrollItemWidget;
|
if (!(c is ScrollItemWidget item) || item.ItemKey != oldPath)
|
||||||
if (item == null || item.ItemKey != oldPath)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
item.ItemKey = newPath;
|
item.ItemKey = newPath;
|
||||||
|
|||||||
@@ -133,8 +133,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
// Select the first active tab
|
// Select the first active tab
|
||||||
foreach (var b in typesContainer.Children)
|
foreach (var b in typesContainer.Children)
|
||||||
{
|
{
|
||||||
var button = b as ProductionTypeButtonWidget;
|
if (!(b is ProductionTypeButtonWidget button) || button.IsDisabled())
|
||||||
if (button == null || button.IsDisabled())
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
button.OnClick();
|
button.OnClick();
|
||||||
|
|||||||
@@ -207,74 +207,74 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
switch (i.Key)
|
switch (i.Key)
|
||||||
{
|
{
|
||||||
case "copy":
|
case "copy":
|
||||||
{
|
|
||||||
var sourceDir = Path.Combine(path, i.Value.Value);
|
|
||||||
foreach (var node in i.Value.Nodes)
|
|
||||||
{
|
{
|
||||||
var sourcePath = Path.Combine(sourceDir, node.Value.Value);
|
var sourceDir = Path.Combine(path, i.Value.Value);
|
||||||
var targetPath = Platform.ResolvePath(node.Key);
|
foreach (var node in i.Value.Nodes)
|
||||||
if (File.Exists(targetPath))
|
|
||||||
{
|
{
|
||||||
Log.Write("install", "Ignoring installed file " + targetPath);
|
var sourcePath = Path.Combine(sourceDir, node.Value.Value);
|
||||||
continue;
|
var targetPath = Platform.ResolvePath(node.Key);
|
||||||
|
if (File.Exists(targetPath))
|
||||||
|
{
|
||||||
|
Log.Write("install", "Ignoring installed file " + targetPath);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.Write("install", $"Copying {sourcePath} -> {targetPath}");
|
||||||
|
extracted.Add(targetPath);
|
||||||
|
Directory.CreateDirectory(Path.GetDirectoryName(targetPath));
|
||||||
|
|
||||||
|
using (var source = File.OpenRead(sourcePath))
|
||||||
|
using (var target = File.OpenWrite(targetPath))
|
||||||
|
{
|
||||||
|
var displayFilename = Path.GetFileName(targetPath);
|
||||||
|
var length = source.Length;
|
||||||
|
|
||||||
|
Action<long> onProgress = null;
|
||||||
|
if (length < ShowPercentageThreshold)
|
||||||
|
message = "Copying " + displayFilename;
|
||||||
|
else
|
||||||
|
onProgress = b => message = $"Copying {displayFilename} ({100 * b / length}%)";
|
||||||
|
|
||||||
|
CopyStream(source, target, length, onProgress);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.Write("install", $"Copying {sourcePath} -> {targetPath}");
|
break;
|
||||||
extracted.Add(targetPath);
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(targetPath));
|
|
||||||
|
|
||||||
using (var source = File.OpenRead(sourcePath))
|
|
||||||
using (var target = File.OpenWrite(targetPath))
|
|
||||||
{
|
|
||||||
var displayFilename = Path.GetFileName(targetPath);
|
|
||||||
var length = source.Length;
|
|
||||||
|
|
||||||
Action<long> onProgress = null;
|
|
||||||
if (length < ShowPercentageThreshold)
|
|
||||||
message = "Copying " + displayFilename;
|
|
||||||
else
|
|
||||||
onProgress = b => message = $"Copying {displayFilename} ({100 * b / length}%)";
|
|
||||||
|
|
||||||
CopyStream(source, target, length, onProgress);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "extract-raw":
|
case "extract-raw":
|
||||||
{
|
{
|
||||||
ExtractFromPackage(ExtractionType.Raw, path, i.Value, extracted, m => message = m);
|
ExtractFromPackage(ExtractionType.Raw, path, i.Value, extracted, m => message = m);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case "extract-blast":
|
case "extract-blast":
|
||||||
{
|
{
|
||||||
ExtractFromPackage(ExtractionType.Blast, path, i.Value, extracted, m => message = m);
|
ExtractFromPackage(ExtractionType.Blast, path, i.Value, extracted, m => message = m);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case "extract-mscab":
|
case "extract-mscab":
|
||||||
{
|
{
|
||||||
ExtractFromMSCab(path, i.Value, extracted, m => message = m);
|
ExtractFromMSCab(path, i.Value, extracted, m => message = m);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case "extract-iscab":
|
case "extract-iscab":
|
||||||
{
|
{
|
||||||
ExtractFromISCab(path, i.Value, extracted, m => message = m);
|
ExtractFromISCab(path, i.Value, extracted, m => message = m);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case "delete":
|
case "delete":
|
||||||
{
|
{
|
||||||
// Yaml path may be specified relative to a named directory (e.g. ^SupportDir) or the detected disc path
|
// Yaml path may be specified relative to a named directory (e.g. ^SupportDir) or the detected disc path
|
||||||
var sourcePath = i.Value.Value.StartsWith("^") ? Platform.ResolvePath(i.Value.Value) : Path.Combine(path, i.Value.Value);
|
var sourcePath = i.Value.Value.StartsWith("^") ? Platform.ResolvePath(i.Value.Value) : Path.Combine(path, i.Value.Value);
|
||||||
|
|
||||||
Log.Write("debug", "Deleting {0}", sourcePath);
|
Log.Write("debug", "Deleting {0}", sourcePath);
|
||||||
File.Delete(sourcePath);
|
File.Delete(sourcePath);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Log.Write("debug", "Unknown installation command {0} - ignoring", i.Key);
|
Log.Write("debug", "Unknown installation command {0} - ignoring", i.Key);
|
||||||
@@ -479,8 +479,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
foreach (var prefix in source.RegistryPrefixes)
|
foreach (var prefix in source.RegistryPrefixes)
|
||||||
{
|
{
|
||||||
var path = Microsoft.Win32.Registry.GetValue(prefix + source.RegistryKey, source.RegistryValue, null) as string;
|
if (!(Microsoft.Win32.Registry.GetValue(prefix + source.RegistryKey, source.RegistryValue, null) is string path))
|
||||||
if (path == null)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (source.Type == ModContent.SourceType.RegistryDirectoryFromFile)
|
if (source.Type == ModContent.SourceType.RegistryDirectoryFromFile)
|
||||||
@@ -530,7 +529,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (CryptoUtil.SHA1Hash(fileStream) != kv.Value.Value)
|
else if (CryptoUtil.SHA1Hash(fileStream) != kv.Value.Value)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,8 +89,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
row.Bounds.Y = optionsContainer.Bounds.Height;
|
row.Bounds.Y = optionsContainer.Bounds.Height;
|
||||||
optionsContainer.Bounds.Height += row.Bounds.Height;
|
optionsContainer.Bounds.Height += row.Bounds.Height;
|
||||||
foreach (var child in row.Children)
|
foreach (var child in row.Children)
|
||||||
if (child is CheckboxWidget)
|
if (child is CheckboxWidget childCheckbox)
|
||||||
checkboxColumns.Enqueue((CheckboxWidget)child);
|
checkboxColumns.Enqueue(childCheckbox);
|
||||||
|
|
||||||
optionsContainer.AddChild(row);
|
optionsContainer.AddChild(row);
|
||||||
}
|
}
|
||||||
@@ -118,8 +118,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
row.Bounds.Y = optionsContainer.Bounds.Height;
|
row.Bounds.Y = optionsContainer.Bounds.Height;
|
||||||
optionsContainer.Bounds.Height += row.Bounds.Height;
|
optionsContainer.Bounds.Height += row.Bounds.Height;
|
||||||
foreach (var child in row.Children)
|
foreach (var child in row.Children)
|
||||||
if (child is DropDownButtonWidget)
|
if (child is DropDownButtonWidget dropDown)
|
||||||
dropdownColumns.Enqueue((DropDownButtonWidget)child);
|
dropdownColumns.Enqueue(dropDown);
|
||||||
|
|
||||||
optionsContainer.AddChild(row);
|
optionsContainer.AddChild(row);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user