Fix CA1854
This commit is contained in:
@@ -32,8 +32,8 @@ namespace OpenRA.Mods.Common.LoadScreens
|
||||
{
|
||||
base.Init(modData, info);
|
||||
|
||||
if (info.ContainsKey("Text"))
|
||||
messages = info["Text"].Split(',');
|
||||
if (info.TryGetValue("Text", out var text))
|
||||
messages = text.Split(',');
|
||||
}
|
||||
|
||||
public override void DisplayInner(Renderer r, Sheet s, int density)
|
||||
|
||||
@@ -56,22 +56,21 @@ namespace OpenRA.Mods.Common.LoadScreens
|
||||
sheet = null;
|
||||
}
|
||||
|
||||
if (sheet == null && Info.ContainsKey("Image"))
|
||||
if (sheet == null && Info.TryGetValue("Image", out var image))
|
||||
{
|
||||
var key = "Image";
|
||||
density = 1;
|
||||
if (dpiScale > 2 && Info.ContainsKey("Image3x"))
|
||||
if (dpiScale > 2 && Info.TryGetValue("Image3x", out var image3))
|
||||
{
|
||||
key = "Image3x";
|
||||
image = image3;
|
||||
density = 3;
|
||||
}
|
||||
else if (dpiScale > 1 && Info.ContainsKey("Image2x"))
|
||||
else if (dpiScale > 1 && Info.TryGetValue("Image2x", out var image2))
|
||||
{
|
||||
key = "Image2x";
|
||||
image = image2;
|
||||
density = 2;
|
||||
}
|
||||
|
||||
using (var stream = ModData.DefaultFileSystem.Open(Platform.ResolvePath(Info[key])))
|
||||
using (var stream = ModData.DefaultFileSystem.Open(Platform.ResolvePath(image)))
|
||||
{
|
||||
sheet = new Sheet(SheetType.BGRA, stream);
|
||||
sheet.GetTexture().ScaleFilter = TextureScaleFilter.Linear;
|
||||
|
||||
@@ -225,8 +225,8 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
|
||||
var queue = GetBuildableInfo(unit.Info.Name).Queue.First();
|
||||
|
||||
if (productionHandlers.ContainsKey(queue))
|
||||
productionHandlers[queue](factory, unit);
|
||||
if (productionHandlers.TryGetValue(queue, out var productionHandler))
|
||||
productionHandler(factory, unit);
|
||||
}
|
||||
|
||||
var triggers = TriggerGlobal.GetScriptTriggers(player.PlayerActor);
|
||||
|
||||
@@ -115,29 +115,29 @@ namespace OpenRA.Mods.Common.SpriteLoaders
|
||||
var frameSize = new Size(png.Width, png.Height);
|
||||
var frameAmount = 1;
|
||||
|
||||
if (png.EmbeddedData.ContainsKey("FrameSize"))
|
||||
if (png.EmbeddedData.TryGetValue("FrameSize", out var value))
|
||||
{
|
||||
// If FrameSize exist, use it and...
|
||||
frameSize = FieldLoader.GetValue<Size>("FrameSize", png.EmbeddedData["FrameSize"]);
|
||||
frameSize = FieldLoader.GetValue<Size>("FrameSize", value);
|
||||
|
||||
// ... either use FrameAmount or calculate how many times FrameSize fits into the image.
|
||||
if (png.EmbeddedData.ContainsKey("FrameAmount"))
|
||||
frameAmount = FieldLoader.GetValue<int>("FrameAmount", png.EmbeddedData["FrameAmount"]);
|
||||
if (png.EmbeddedData.TryGetValue("FrameAmount", out value))
|
||||
frameAmount = FieldLoader.GetValue<int>("FrameAmount", value);
|
||||
else
|
||||
frameAmount = png.Width / frameSize.Width * (png.Height / frameSize.Height);
|
||||
}
|
||||
else if (png.EmbeddedData.ContainsKey("FrameAmount"))
|
||||
else if (png.EmbeddedData.TryGetValue("FrameAmount", out value))
|
||||
{
|
||||
// Otherwise, calculate the number of frames by splitting the image horizontally by FrameAmount.
|
||||
frameAmount = FieldLoader.GetValue<int>("FrameAmount", png.EmbeddedData["FrameAmount"]);
|
||||
frameAmount = FieldLoader.GetValue<int>("FrameAmount", value);
|
||||
frameSize = new Size(png.Width / frameAmount, png.Height);
|
||||
}
|
||||
|
||||
float2 offset;
|
||||
|
||||
// If Offset property exists, use its value. Otherwise assume the frame is centered.
|
||||
if (png.EmbeddedData.ContainsKey("Offset"))
|
||||
offset = FieldLoader.GetValue<float2>("Offset", png.EmbeddedData["Offset"]);
|
||||
if (png.EmbeddedData.TryGetValue("Offset", out value))
|
||||
offset = FieldLoader.GetValue<float2>("Offset", value);
|
||||
else
|
||||
offset = float2.Zero;
|
||||
|
||||
|
||||
@@ -322,8 +322,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
// Does this building have initial delay, if so have we passed it?
|
||||
if (baseBuilder.Info.BuildingDelays != null &&
|
||||
baseBuilder.Info.BuildingDelays.ContainsKey(name) &&
|
||||
baseBuilder.Info.BuildingDelays[name] > world.WorldTick)
|
||||
baseBuilder.Info.BuildingDelays.TryGetValue(name, out var delay) &&
|
||||
delay > world.WorldTick)
|
||||
continue;
|
||||
|
||||
// Can we build this structure?
|
||||
@@ -341,7 +341,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (count * 100 > frac.Value * playerBuildings.Length)
|
||||
continue;
|
||||
|
||||
if (baseBuilder.Info.BuildingLimits.ContainsKey(name) && baseBuilder.Info.BuildingLimits[name] <= count)
|
||||
if (baseBuilder.Info.BuildingLimits.TryGetValue(name, out var limit) && limit <= count)
|
||||
continue;
|
||||
|
||||
// If we're considering to build a naval structure, check whether there is enough water inside the base perimeter
|
||||
|
||||
@@ -79,9 +79,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
// If we have recently tried and failed to find a use location for a power, then do not try again until later
|
||||
var isDelayed = waitingPowers[sp] > 0;
|
||||
if (sp.Ready && !isDelayed && powerDecisions.ContainsKey(sp.Info.OrderName))
|
||||
if (sp.Ready && !isDelayed && powerDecisions.TryGetValue(sp.Info.OrderName, out var powerDecision))
|
||||
{
|
||||
var powerDecision = powerDecisions[sp.Info.OrderName];
|
||||
if (powerDecision == null)
|
||||
{
|
||||
AIUtils.BotDebug("{0} couldn't find powerDecision for {1}", player.PlayerName, sp.Info.OrderName);
|
||||
|
||||
@@ -121,13 +121,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return;
|
||||
|
||||
if (Info.UnitDelays != null &&
|
||||
Info.UnitDelays.ContainsKey(name) &&
|
||||
Info.UnitDelays[name] > world.WorldTick)
|
||||
Info.UnitDelays.TryGetValue(name, out var delay) &&
|
||||
delay > world.WorldTick)
|
||||
return;
|
||||
|
||||
if (Info.UnitLimits != null &&
|
||||
Info.UnitLimits.ContainsKey(name) &&
|
||||
world.Actors.Count(a => a.Owner == player && a.Info.Name == name) >= Info.UnitLimits[name])
|
||||
Info.UnitLimits.TryGetValue(name, out var limit) &&
|
||||
world.Actors.Count(a => a.Owner == player && a.Info.Name == name) >= limit)
|
||||
return;
|
||||
|
||||
bot.QueueOrder(Order.StartProduction(queue.Actor, name, 1));
|
||||
|
||||
@@ -102,8 +102,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
// order.OrderString is the key of the support power
|
||||
if (Powers.ContainsKey(order.OrderString))
|
||||
Powers[order.OrderString].Activate(order);
|
||||
if (Powers.TryGetValue(order.OrderString, out var sp))
|
||||
sp.Activate(order);
|
||||
}
|
||||
|
||||
static readonly SupportPowerInstance[] NoInstances = Array.Empty<SupportPowerInstance>();
|
||||
|
||||
@@ -91,8 +91,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (speed > 0)
|
||||
{
|
||||
var nodesDict = t.Value.ToDictionary();
|
||||
var cost = nodesDict.ContainsKey("PathingCost")
|
||||
? FieldLoader.GetValue<short>("cost", nodesDict["PathingCost"].Value)
|
||||
var cost = nodesDict.TryGetValue("PathingCost", out var entry)
|
||||
? FieldLoader.GetValue<short>("cost", entry.Value)
|
||||
: 10000 / speed;
|
||||
ret.Add(t.Key, new TerrainInfo(speed, (short)cost));
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
// Existing smudge; make it deeper
|
||||
// A null Sequence indicates a deleted smudge.
|
||||
var tile = dirty.ContainsKey(loc) && dirty[loc].Sequence != null ? dirty[loc] : tiles[loc];
|
||||
var tile = dirty.TryGetValue(loc, out var d) && d.Sequence != null ? d : tiles[loc];
|
||||
var maxDepth = smudges[tile.Type].Length;
|
||||
if (tile.Depth < maxDepth - 1)
|
||||
tile.Depth++;
|
||||
@@ -180,7 +180,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!world.Map.Contains(loc))
|
||||
return;
|
||||
|
||||
var tile = dirty.ContainsKey(loc) ? dirty[loc] : default;
|
||||
var tile = dirty.TryGetValue(loc, out var d) ? d : default;
|
||||
|
||||
// Setting Sequence to null to indicate a deleted smudge.
|
||||
tile.Sequence = null;
|
||||
|
||||
@@ -46,8 +46,8 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
this.world = world;
|
||||
|
||||
var highlightOnButtonPress = false;
|
||||
if (logicArgs.ContainsKey("HighlightOnButtonPress"))
|
||||
highlightOnButtonPress = FieldLoader.GetValue<bool>("HighlightOnButtonPress", logicArgs["HighlightOnButtonPress"].Value);
|
||||
if (logicArgs.TryGetValue("HighlightOnButtonPress", out var entry))
|
||||
highlightOnButtonPress = FieldLoader.GetValue<bool>("HighlightOnButtonPress", entry.Value);
|
||||
|
||||
var attackMoveButton = widget.GetOrNull<ButtonWidget>("ATTACK_MOVE");
|
||||
if (attackMoveButton != null)
|
||||
|
||||
@@ -264,7 +264,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
foreach (var packageInstallationNode in modSource.Install.Where(x => x.Key == "ContentPackage"))
|
||||
{
|
||||
var packageName = packageInstallationNode.Value.Nodes.SingleOrDefault(x => x.Key == "Name")?.Value.Value;
|
||||
if (!string.IsNullOrEmpty(packageName) && selectedPackages.ContainsKey(packageName) && selectedPackages[packageName])
|
||||
if (!string.IsNullOrEmpty(packageName) && selectedPackages.TryGetValue(packageName, out var required) && required)
|
||||
RunSourceActions(packageInstallationNode);
|
||||
}
|
||||
|
||||
|
||||
@@ -189,9 +189,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
SetupMapTab(MapClassification.User, filter, "USER_MAPS_TAB_BUTTON", "USER_MAPS_TAB", itemTemplate);
|
||||
SetupMapTab(MapClassification.System, filter, "SYSTEM_MAPS_TAB_BUTTON", "SYSTEM_MAPS_TAB", itemTemplate);
|
||||
|
||||
if (initialMap == null && tabMaps.ContainsKey(initialTab) && tabMaps[initialTab].Length > 0)
|
||||
if (initialMap == null && tabMaps.TryGetValue(initialTab, out var map) && map.Length > 0)
|
||||
{
|
||||
selectedUid = Game.ModData.MapCache.ChooseInitialMap(tabMaps[initialTab].Select(mp => mp.Uid).First(),
|
||||
selectedUid = Game.ModData.MapCache.ChooseInitialMap(map.Select(mp => mp.Uid).First(),
|
||||
Game.CosmeticRandom);
|
||||
currentTab = initialTab;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user