Use out var syntax
This commit is contained in:
@@ -272,10 +272,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
// Select the first visible
|
||||
var firstVisible = assetVisByName.FirstOrDefault(kvp => kvp.Value);
|
||||
IReadOnlyPackage package;
|
||||
string filename;
|
||||
|
||||
if (firstVisible.Key != null && modData.DefaultFileSystem.TryGetPackageContaining(firstVisible.Key, out package, out filename))
|
||||
if (firstVisible.Key != null && modData.DefaultFileSystem.TryGetPackageContaining(firstVisible.Key, out var package, out var filename))
|
||||
LoadAsset(package, filename);
|
||||
}
|
||||
|
||||
@@ -290,8 +288,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
item.IsVisible = () =>
|
||||
{
|
||||
bool visible;
|
||||
if (assetVisByName.TryGetValue(filepath, out visible))
|
||||
if (assetVisByName.TryGetValue(filepath, out var visible))
|
||||
return visible;
|
||||
|
||||
visible = FilterAsset(filepath);
|
||||
|
||||
@@ -27,8 +27,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
public ColorPickerLogic(Widget widget, ModData modData, World world, Color initialColor, string initialFaction, Action<Color> onChange,
|
||||
Dictionary<string, MiniYaml> logicArgs)
|
||||
{
|
||||
string actorType;
|
||||
if (initialFaction == null || !ChromeMetrics.TryGet("ColorPickerActorType-" + initialFaction, out actorType))
|
||||
if (initialFaction == null || !ChromeMetrics.TryGet("ColorPickerActorType-" + initialFaction, out string actorType))
|
||||
actorType = ChromeMetrics.Get<string>("ColorPickerActorType");
|
||||
|
||||
var preview = widget.GetOrNull<ActorPreviewWidget>("PREVIEW");
|
||||
@@ -103,8 +102,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var palettePresetRows = 2;
|
||||
var paletteCustomRows = 1;
|
||||
|
||||
MiniYaml yaml;
|
||||
if (logicArgs.TryGetValue("PaletteColumns", out yaml))
|
||||
if (logicArgs.TryGetValue("PaletteColumns", out var yaml))
|
||||
if (!int.TryParse(yaml.Value, out paletteCols))
|
||||
throw new YamlException("Invalid value for PaletteColumns: {0}".F(yaml.Value));
|
||||
if (logicArgs.TryGetValue("PalettePresetRows", out yaml))
|
||||
@@ -189,9 +187,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
static float HueFromColor(Color c)
|
||||
{
|
||||
float h, s, v;
|
||||
int a;
|
||||
c.ToAhsv(out a, out h, out s, out v);
|
||||
c.ToAhsv(out var a, out var h, out var s, out var v);
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
@@ -106,8 +106,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
actorIDErrorLabel.GetText = () => actorIDStatus == ActorIDStatus.Duplicate ?
|
||||
"Duplicate Actor ID" : "Enter an Actor ID";
|
||||
|
||||
MiniYaml yaml;
|
||||
if (logicArgs.TryGetValue("EditPanelPadding", out yaml))
|
||||
if (logicArgs.TryGetValue("EditPanelPadding", out var yaml))
|
||||
editPanelPadding = FieldLoader.GetValue<int>("EditPanelPadding", yaml.Value);
|
||||
|
||||
okButton.IsDisabled = () => !IsValid() || !editActorPreview.IsDirty;
|
||||
|
||||
@@ -45,9 +45,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
panel.Get<ButtonWidget>("CREATE_BUTTON").OnClick = () =>
|
||||
{
|
||||
int width, height;
|
||||
int.TryParse(widthTextField.Text, out width);
|
||||
int.TryParse(heightTextField.Text, out height);
|
||||
int.TryParse(widthTextField.Text, out var width);
|
||||
int.TryParse(heightTextField.Text, out var height);
|
||||
|
||||
// Require at least a 2x2 playable area so that the
|
||||
// ground is visible through the edge shroud
|
||||
|
||||
@@ -19,8 +19,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
[ObjectCreator.UseCtor]
|
||||
public AddFactionSuffixLogic(Widget widget, World world)
|
||||
{
|
||||
string faction;
|
||||
if (!ChromeMetrics.TryGet("FactionSuffix-" + world.LocalPlayer.Faction.InternalName, out faction))
|
||||
if (!ChromeMetrics.TryGet("FactionSuffix-" + world.LocalPlayer.Faction.InternalName, out string faction))
|
||||
faction = world.LocalPlayer.Faction.InternalName;
|
||||
var suffix = "-" + faction;
|
||||
|
||||
|
||||
@@ -36,8 +36,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic.Ingame
|
||||
selection = world.Selection;
|
||||
this.world = world;
|
||||
|
||||
MiniYaml yaml;
|
||||
if (logicArgs.TryGetValue("ClickSound", out yaml))
|
||||
if (logicArgs.TryGetValue("ClickSound", out var yaml))
|
||||
clickSound = yaml.Value;
|
||||
}
|
||||
|
||||
|
||||
@@ -209,8 +209,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
});
|
||||
}
|
||||
|
||||
MiniYaml yaml;
|
||||
if (logicArgs.TryGetValue("ChatLineSound", out yaml))
|
||||
if (logicArgs.TryGetValue("ChatLineSound", out var yaml))
|
||||
chatLineSound = yaml.Value;
|
||||
}
|
||||
|
||||
|
||||
@@ -74,20 +74,17 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
buttonContainer.RemoveChild(buttonTemplate);
|
||||
buttonContainer.IsVisible = () => !hideMenu;
|
||||
|
||||
MiniYaml buttonStrideNode;
|
||||
if (logicArgs.TryGetValue("ButtonStride", out buttonStrideNode))
|
||||
if (logicArgs.TryGetValue("ButtonStride", out var buttonStrideNode))
|
||||
buttonStride = FieldLoader.GetValue<int2>("ButtonStride", buttonStrideNode.Value);
|
||||
|
||||
var scriptContext = world.WorldActor.TraitOrDefault<LuaScript>();
|
||||
hasError = scriptContext != null && scriptContext.FatalErrorOccurred;
|
||||
|
||||
MiniYaml buttonsNode;
|
||||
if (logicArgs.TryGetValue("Buttons", out buttonsNode))
|
||||
if (logicArgs.TryGetValue("Buttons", out var buttonsNode))
|
||||
{
|
||||
Action createHandler;
|
||||
var buttonIds = FieldLoader.GetValue<string[]>("Buttons", buttonsNode.Value);
|
||||
foreach (var button in buttonIds)
|
||||
if (buttonHandlers.TryGetValue(button, out createHandler))
|
||||
if (buttonHandlers.TryGetValue(button, out var createHandler))
|
||||
createHandler();
|
||||
}
|
||||
|
||||
|
||||
@@ -35,8 +35,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
worldRoot = Ui.Root.Get("WORLD_ROOT");
|
||||
menuRoot = Ui.Root.Get("MENU_ROOT");
|
||||
|
||||
MiniYaml yaml;
|
||||
|
||||
// System buttons
|
||||
var options = widget.GetOrNull<MenuButtonWidget>("OPTIONS_BUTTON");
|
||||
if (options != null)
|
||||
@@ -85,7 +83,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
});
|
||||
}
|
||||
|
||||
if (logicArgs.TryGetValue("ClickSound", out yaml))
|
||||
if (logicArgs.TryGetValue("ClickSound", out var yaml))
|
||||
clickSound = yaml.Value;
|
||||
}
|
||||
|
||||
|
||||
@@ -76,8 +76,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
this.world = world;
|
||||
|
||||
MiniYaml yaml;
|
||||
if (logicArgs.TryGetValue("CombinedViewKey", out yaml))
|
||||
if (logicArgs.TryGetValue("CombinedViewKey", out var yaml))
|
||||
combinedViewKey = modData.Hotkeys[yaml.Value];
|
||||
|
||||
if (logicArgs.TryGetValue("WorldViewKey", out yaml))
|
||||
|
||||
@@ -165,8 +165,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
static string ActorName(Ruleset rules, string a)
|
||||
{
|
||||
ActorInfo ai;
|
||||
if (rules.Actors.TryGetValue(a.ToLowerInvariant(), out ai))
|
||||
if (rules.Actors.TryGetValue(a.ToLowerInvariant(), out var ai))
|
||||
{
|
||||
var actorTooltip = ai.TraitInfos<TooltipInfo>().FirstOrDefault(info => info.EnabledByDefault);
|
||||
if (actorTooltip != null)
|
||||
|
||||
@@ -450,8 +450,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
if (skirmishMode)
|
||||
addBotOnMapLoad = true;
|
||||
|
||||
MiniYaml yaml;
|
||||
if (logicArgs.TryGetValue("ChatLineSound", out yaml))
|
||||
if (logicArgs.TryGetValue("ChatLineSound", out var yaml))
|
||||
chatLineSound = yaml.Value;
|
||||
}
|
||||
|
||||
|
||||
@@ -138,8 +138,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
var getOptionLabel = new CachedTransform<string, string>(id =>
|
||||
{
|
||||
string value;
|
||||
if (id == null || !option.Values.TryGetValue(id, out value))
|
||||
if (id == null || !option.Values.TryGetValue(id, out var value))
|
||||
return "Not Available";
|
||||
|
||||
return value;
|
||||
|
||||
@@ -215,8 +215,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
void EnumerateMaps(MapClassification tab, ScrollItemWidget template)
|
||||
{
|
||||
int playerCountFilter;
|
||||
if (!int.TryParse(mapFilter, out playerCountFilter))
|
||||
if (!int.TryParse(mapFilter, out var playerCountFilter))
|
||||
playerCountFilter = -1;
|
||||
|
||||
var maps = tabMaps[tab]
|
||||
|
||||
@@ -26,9 +26,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
musicPlaylist = world.WorldActor.Trait<MusicPlaylist>();
|
||||
|
||||
MiniYaml yaml;
|
||||
var stopKey = new HotkeyReference();
|
||||
if (logicArgs.TryGetValue("StopMusicKey", out yaml))
|
||||
if (logicArgs.TryGetValue("StopMusicKey", out var yaml))
|
||||
stopKey = modData.Hotkeys[yaml.Value];
|
||||
|
||||
var pauseKey = new HotkeyReference();
|
||||
|
||||
@@ -177,8 +177,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
void CreateAndJoin()
|
||||
{
|
||||
var name = Settings.SanitizedServerName(panel.Get<TextFieldWidget>("SERVER_NAME").Text);
|
||||
int listenPort;
|
||||
if (!Exts.TryParseIntegerInvariant(panel.Get<TextFieldWidget>("LISTEN_PORT").Text, out listenPort))
|
||||
if (!Exts.TryParseIntegerInvariant(panel.Get<TextFieldWidget>("LISTEN_PORT").Text, out var listenPort))
|
||||
listenPort = 1234;
|
||||
|
||||
var passwordField = panel.GetOrNull<PasswordFieldWidget>("PASSWORD");
|
||||
|
||||
@@ -370,9 +370,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
return () =>
|
||||
{
|
||||
int x, y;
|
||||
Exts.TryParseIntegerInvariant(windowWidth.Text, out x);
|
||||
Exts.TryParseIntegerInvariant(windowHeight.Text, out y);
|
||||
Exts.TryParseIntegerInvariant(windowWidth.Text, out var x);
|
||||
Exts.TryParseIntegerInvariant(windowHeight.Text, out var y);
|
||||
ds.WindowedSize = new int2(x, y);
|
||||
nameTextfield.YieldKeyboardFocus();
|
||||
};
|
||||
@@ -590,8 +589,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
Func<bool> returnTrue = () => true;
|
||||
Action doNothing = () => { };
|
||||
|
||||
MiniYaml hotkeyGroups;
|
||||
if (logicArgs.TryGetValue("HotkeyGroups", out hotkeyGroups))
|
||||
if (logicArgs.TryGetValue("HotkeyGroups", out var hotkeyGroups))
|
||||
{
|
||||
InitHotkeyRemapDialog(panel);
|
||||
|
||||
|
||||
@@ -18,10 +18,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
protected SingleHotkeyBaseLogic(Widget widget, ModData modData, string argName, string parentName, Dictionary<string, MiniYaml> logicArgs)
|
||||
{
|
||||
MiniYaml yaml;
|
||||
|
||||
var namedKey = new HotkeyReference();
|
||||
if (logicArgs.TryGetValue(argName, out yaml))
|
||||
if (logicArgs.TryGetValue(argName, out var yaml))
|
||||
namedKey = modData.Hotkeys[yaml.Value];
|
||||
|
||||
var keyhandler = widget.Get<LogicKeyListenerWidget>(parentName);
|
||||
|
||||
Reference in New Issue
Block a user