diff --git a/OpenRA.Game/Support/Log.cs b/OpenRA.Game/Support/Log.cs index b8e254f0d9..2031163b61 100644 --- a/OpenRA.Game/Support/Log.cs +++ b/OpenRA.Game/Support/Log.cs @@ -171,6 +171,11 @@ namespace OpenRA ChannelWriter.TryWrite(new ChannelData(channelName, value)); } + public static void Write(string channelName, Exception e) + { + ChannelWriter.TryWrite(new ChannelData(channelName, $"{e.Message}{Environment.NewLine}{e.StackTrace}")); + } + public static void Write(string channelName, string format, params object[] args) { ChannelWriter.TryWrite(new ChannelData(channelName, format.F(args))); diff --git a/OpenRA.Mods.Common/Traits/World/TimeLimitManager.cs b/OpenRA.Mods.Common/Traits/World/TimeLimitManager.cs index 146e5bd819..c4dd6e691d 100644 --- a/OpenRA.Mods.Common/Traits/World/TimeLimitManager.cs +++ b/OpenRA.Mods.Common/Traits/World/TimeLimitManager.cs @@ -160,7 +160,7 @@ namespace OpenRA.Mods.Common.Traits { TextNotificationsManager.AddSystemLine(Notification.F(m, m > 1 ? "s" : null)); - var faction = self.World.LocalPlayer == null ? null : self.World.LocalPlayer.Faction.InternalName; + var faction = self.World.LocalPlayer?.Faction.InternalName; Game.Sound.PlayNotification(self.World.Map.Rules, self.World.LocalPlayer, "Speech", info.TimeLimitWarnings[m], faction); } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs index 2d4e4d4ef6..78e343e493 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs @@ -97,7 +97,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var spriteWidget = panel.GetOrNull("SPRITE"); if (spriteWidget != null) { - spriteWidget.GetSprite = () => currentSprites != null ? currentSprites[currentFrame] : null; + spriteWidget.GetSprite = () => currentSprites?[currentFrame]; currentPalette = spriteWidget.Palette; spriteScale = spriteWidget.Scale; spriteWidget.GetPalette = () => currentPalette; @@ -394,7 +394,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (string.IsNullOrWhiteSpace(filter)) return true; - if (filename.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0) + if (filename.Contains(filter, StringComparison.OrdinalIgnoreCase)) return true; return false; @@ -524,11 +524,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic else return false; } - catch (Exception ex) + catch (Exception exception) { isLoadError = true; Log.AddChannel("assetbrowser", "assetbrowser.log"); - Log.Write("assetbrowser", "Error reading {0}:{3} {1}{3}{2}", filename, ex.Message, ex.StackTrace, Environment.NewLine); + Log.Write("assetbrowser", $"Error reading {filename}"); + Log.Write("assetbrowser", exception); return false; } diff --git a/OpenRA.Mods.Common/Widgets/Logic/CreditsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/CreditsLogic.cs index 625754875d..b849dc3a3f 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/CreditsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/CreditsLogic.cs @@ -90,7 +90,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic } } - IEnumerable ParseLines(Stream file) + static IEnumerable ParseLines(Stream file) { return file.ReadAllLines().Select(l => l.Replace("\t", " ").Replace("*", "\u2022")).ToList(); } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs index 261ed15e0c..1b17238a76 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs @@ -190,15 +190,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic map.Save(package); - Console.WriteLine("Saved current map at {0}", combinedPath); + Console.WriteLine($"Saved current map at {combinedPath}"); Ui.CloseWindow(); onSave(map.Uid); } catch (Exception e) { - Log.Write("debug", "Failed to save map at {0}: {1}", combinedPath, e.Message); - Log.Write("debug", "{0}", e.StackTrace); + Log.Write("debug", $"Failed to save map at {combinedPath}"); + Log.Write("debug", e); ConfirmationDialogs.ButtonPrompt( title: "Failed to save map", diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/DebugMenuLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/DebugMenuLogic.cs index d6495cf38d..bc9faf1bfa 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/DebugMenuLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/DebugMenuLogic.cs @@ -153,7 +153,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic } } - public void Order(World world, string order) + public static void Order(World world, string order) { world.IssueOrder(new Order(order, world.LocalPlayer.PlayerActor, false)); } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoObjectivesLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoObjectivesLogic.cs index 97dfbf829d..cc8b55c719 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoObjectivesLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoObjectivesLogic.cs @@ -58,7 +58,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic mo.ObjectiveAdded += redrawObjectives; } - void PopulateObjectivesList(MissionObjectives mo, ScrollPanelWidget parent, ContainerWidget template) + static void PopulateObjectivesList(MissionObjectives mo, ScrollPanelWidget parent, ContainerWidget template) { parent.RemoveChildren(); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverStatsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverStatsLogic.cs index 6cfe1e9497..92ca68c7bd 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverStatsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverStatsLogic.cs @@ -469,7 +469,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic return template; } - void SetupPlayerColor(Player player, ScrollItemWidget template, ColorBlockWidget colorBlockWidget, GradientColorBlockWidget gradientColorBlockWidget) + static void SetupPlayerColor(Player player, ScrollItemWidget template, ColorBlockWidget colorBlockWidget, GradientColorBlockWidget gradientColorBlockWidget) { var color = Color.FromArgb(128, player.Color.R, player.Color.G, player.Color.B); var hoverColor = Color.FromArgb(192, player.Color.R, player.Color.G, player.Color.B); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs index 6a12ccd9b2..e83517f806 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs @@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var requiresFormat = requiresLabel.Text; ActorInfo lastActor = null; - Hotkey lastHotkey = Hotkey.Invalid; + var lastHotkey = Hotkey.Invalid; var lastPowerState = pm?.PowerState ?? PowerState.Normal; var descLabelY = descLabel.Bounds.Y; var descLabelPadding = descLabel.Bounds.Height; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/SupportPowerTooltipLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/SupportPowerTooltipLogic.cs index a95c069cc9..6feab45814 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/SupportPowerTooltipLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/SupportPowerTooltipLogic.cs @@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var timeOffset = timeLabel.Bounds.X; SupportPowerInstance lastPower = null; - Hotkey lastHotkey = Hotkey.Invalid; + var lastHotkey = Hotkey.Invalid; var lastRemainingSeconds = 0; tooltipContainer.BeforeRender = () => diff --git a/OpenRA.Mods.Common/Widgets/Logic/Installation/InstallFromDiscLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Installation/InstallFromDiscLogic.cs index a5ba2e5b74..59581b5620 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Installation/InstallFromDiscLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Installation/InstallFromDiscLogic.cs @@ -137,7 +137,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var path = FindSourcePath(kv.Value, volumes); if (path != null) { - Log.Write("install", "Using installer `{0}: {1}` of type `{2}`:", kv.Key, kv.Value.Title, kv.Value.Type); + Log.Write("install", $"Using installer `{kv.Key}: {kv.Value.Title}` of type `{kv.Value.Type}`:"); var packages = content.Packages.Values .Where(p => p.Sources.Contains(kv.Key) && !p.IsInstalled()) @@ -271,13 +271,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic // 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); - Log.Write("debug", "Deleting {0}", sourcePath); + Log.Write("debug", $"Deleting {sourcePath}"); File.Delete(sourcePath); break; } default: - Log.Write("debug", "Unknown installation command {0} - ignoring", i.Key); + Log.Write("debug", $"Unknown installation command {i.Key} - ignoring"); break; } } @@ -499,7 +499,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic return null; } - bool IsValidSourcePath(string path, ModContent.ModSource source) + static bool IsValidSourcePath(string path, ModContent.ModSource source) { try { diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs index 52f7f36730..1b8fc11a3a 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs @@ -212,7 +212,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic slotsButton.IsVisible = () => panel != PanelType.Servers; slotsButton.IsDisabled = () => configurationDisabled() || panel != PanelType.Players || (orderManager.LobbyInfo.Slots.Values.All(s => !s.AllowBots) && - orderManager.LobbyInfo.Slots.Count(s => !s.Value.LockTeam && orderManager.LobbyInfo.ClientInSlot(s.Key) != null) == 0); + !orderManager.LobbyInfo.Slots.Any(s => !s.Value.LockTeam && orderManager.LobbyInfo.ClientInSlot(s.Key) != null)); slotsButton.OnMouseDown = _ => { @@ -269,7 +269,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { Title = $"{d} Teams", IsSelected = () => false, - OnClick = () => orderManager.IssueOrder(Order.Command($"assignteams {d.ToString()}")) + OnClick = () => orderManager.IssueOrder(Order.Command($"assignteams {d}")) }).ToList(); if (orderManager.LobbyInfo.Slots.Any(s => s.Value.AllowBots)) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs index fad5751a65..163db23b5c 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs @@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { "Slot", new List { - new SlotDropDownOption("Open", "slot_open " + slot.PlayerReference, () => (!slot.Closed && client == null)), + new SlotDropDownOption("Open", "slot_open " + slot.PlayerReference, () => !slot.Closed && client == null), new SlotDropDownOption("Closed", "slot_close " + slot.PlayerReference, () => slot.Closed) } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/SpawnSelectorTooltipLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/SpawnSelectorTooltipLogic.cs index 5d2f78842a..28b2621777 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/SpawnSelectorTooltipLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/SpawnSelectorTooltipLogic.cs @@ -20,7 +20,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic [ObjectCreator.UseCtor] public SpawnSelectorTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, MapPreviewWidget preview, bool showUnoccupiedSpawnpoints) { - bool showTooltip = true; + var showTooltip = true; widget.IsVisible = () => preview.TooltipSpawnIndex != -1 && showTooltip; var label = widget.Get("LABEL"); var flag = widget.Get("FLAG"); diff --git a/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs index 13d3e165ae..a7d4244b79 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs @@ -346,7 +346,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic }); } - void LoadMapIntoEditor(string uid) + static void LoadMapIntoEditor(string uid) { Game.LoadEditor(uid); diff --git a/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs index bba6279855..a1f51c852b 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs @@ -126,7 +126,7 @@ 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.Keys.Contains(initialTab) && tabMaps[initialTab].Length > 0) + if (initialMap == null && tabMaps.ContainsKey(initialTab) && tabMaps[initialTab].Length > 0) { selectedUid = Game.ModData.MapCache.ChooseInitialMap(tabMaps[initialTab].Select(mp => mp.Uid).First(), Game.CosmeticRandom); @@ -178,8 +178,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { foreach (var category in map.Categories) { - var count = 0; - categoryDict.TryGetValue(category, out count); + categoryDict.TryGetValue(category, out var count); categoryDict[category] = count + 1; } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/PlayerProfileLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/PlayerProfileLogic.cs index bde099feae..b4a29ef839 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/PlayerProfileLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/PlayerProfileLogic.cs @@ -211,9 +211,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic { var badges = Ui.LoadWidget("PLAYER_PROFILE_BADGES_INSERT", badgeContainer, new WidgetArgs() { - { "worldRenderer", worldRenderer }, - { "profile", profile }, - { "negotiateWidth", negotiateWidth } + { nameof(worldRenderer), worldRenderer }, + { nameof(profile), profile }, + { nameof(negotiateWidth), negotiateWidth } }); if (badges.Bounds.Height > 0) @@ -236,7 +236,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic } catch (Exception e) { - Log.Write("debug", "Failed to parse player data result with exception: {0}", e); + Log.Write("debug", "Failed to parse player data result with exception"); + Log.Write("debug", e); } finally { diff --git a/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs index 9141c6a130..3ce823fa0f 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs @@ -445,7 +445,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic }; var deleteAllButton = panel.Get("MNG_DELALL_BUTTON"); - deleteAllButton.IsDisabled = () => replayState.Count(kvp => kvp.Value.Visible) == 0; + deleteAllButton.IsDisabled = () => !replayState.Any(kvp => kvp.Value.Visible); deleteAllButton.OnClick = () => { var list = replayState.Where(kvp => kvp.Value.Visible).Select(kvp => kvp.Key).ToList(); @@ -511,7 +511,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic replayState.Remove(replay); } - bool EvaluateReplayVisibility(ReplayMetadata replay) + static bool EvaluateReplayVisibility(ReplayMetadata replay) { // Game type if ((filter.Type == GameType.Multiplayer && replay.GameInfo.IsSinglePlayer) || (filter.Type == GameType.Singleplayer && !replay.GameInfo.IsSinglePlayer)) @@ -675,7 +675,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic } catch (Exception e) { - Log.Write("debug", "Exception while parsing replay: {0}", e); + Log.Write("debug", $"Exception while parsing replay: {replay}"); + Log.Write("debug", e); SelectReplay(null); } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/ServerListLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ServerListLogic.cs index f0401ec93d..b806552550 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/ServerListLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/ServerListLogic.cs @@ -320,7 +320,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic RefreshServerList(); } - string PlayersLabel(GameServer game) + static string PlayersLabel(GameServer game) { return $"{(game.Players > 0 ? game.Players.ToString() : "No")} Player{(game.Players != 1 ? "s" : "")}{(game.Bots > 0 ? $", {game.Bots} Bot{(game.Bots != 1 ? "s" : "")}" : "")}{(game.Spectators > 0 ? $", {game.Spectators} Spectator{(game.Spectators != 1 ? "s" : "")}" : "")}"; } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Settings/InputSettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Settings/InputSettingsLogic.cs index ed8fe95106..14a225fc88 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Settings/InputSettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Settings/InputSettingsLogic.cs @@ -184,7 +184,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, options.Keys, setupItem); } - void MakeMouseFocusSettingsLive() + static void MakeMouseFocusSettingsLive() { var gameSettings = Game.Settings.Game;