Replace terniary null checks with coalescing.
This commit is contained in:
@@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
var variant = resource.Sequences.FirstOrDefault();
|
||||
var sequence = rules.Sequences.GetSequence("resources", variant);
|
||||
var frame = sequence.Frames != null ? sequence.Frames.Last() : resource.MaxDensity - 1;
|
||||
var frame = sequence.Frames?.Last() ?? resource.MaxDensity - 1;
|
||||
layerPreview.GetSprite = () => sequence.GetSprite(frame);
|
||||
|
||||
layerPreview.Bounds.Width = tileSize.Width;
|
||||
|
||||
@@ -118,7 +118,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
if (selectedDirectory == null)
|
||||
selectedDirectory = writableDirectories.OrderByDescending(kv => kv.Classification).First();
|
||||
|
||||
directoryDropdown.GetText = () => selectedDirectory == null ? "" : selectedDirectory.DisplayName;
|
||||
directoryDropdown.GetText = () => selectedDirectory?.DisplayName ?? "";
|
||||
directoryDropdown.OnClick = () =>
|
||||
directoryDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, writableDirectories, setupItem);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
return;
|
||||
|
||||
var tooltip = armyUnit.TooltipInfo;
|
||||
var name = tooltip != null ? tooltip.Name : armyUnit.ActorInfo.Name;
|
||||
var name = tooltip?.Name ?? armyUnit.ActorInfo.Name;
|
||||
var buildable = armyUnit.BuildableInfo;
|
||||
|
||||
nameLabel.Text = name;
|
||||
|
||||
@@ -67,9 +67,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
var teams = world.Players.Where(p => !p.NonCombatant && p.Playable)
|
||||
.Select(p => (Player: p, PlayerStatistics: p.PlayerActor.TraitOrDefault<PlayerStatistics>()))
|
||||
.OrderByDescending(p => p.PlayerStatistics != null ? p.PlayerStatistics.Experience : 0)
|
||||
.OrderByDescending(p => p.PlayerStatistics?.Experience ?? 0)
|
||||
.GroupBy(p => (world.LobbyInfo.ClientWithIndex(p.Player.ClientIndex) ?? new Session.Client()).Team)
|
||||
.OrderByDescending(g => g.Sum(gg => gg.PlayerStatistics != null ? gg.PlayerStatistics.Experience : 0));
|
||||
.OrderByDescending(g => g.Sum(gg => gg.PlayerStatistics?.Experience ?? 0));
|
||||
|
||||
foreach (var t in teams)
|
||||
{
|
||||
@@ -111,7 +111,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
}
|
||||
|
||||
var scoreCache = new CachedTransform<int, string>(s => s.ToString());
|
||||
item.Get<LabelWidget>("SCORE").GetText = () => scoreCache.Update(p.PlayerStatistics != null ? p.PlayerStatistics.Experience : 0);
|
||||
item.Get<LabelWidget>("SCORE").GetText = () => scoreCache.Update(p.PlayerStatistics?.Experience ?? 0);
|
||||
|
||||
playerPanel.AddChild(item);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
if (status == null && shouldShowStatus())
|
||||
return statusText();
|
||||
|
||||
var timeLimit = tlm != null ? tlm.TimeLimit : 0;
|
||||
var timeLimit = tlm?.TimeLimit ?? 0;
|
||||
var displayTick = timeLimit > 0 ? timeLimit - world.WorldTick : world.WorldTick;
|
||||
return WidgetUtils.FormatTime(Math.Max(0, displayTick), timestep);
|
||||
};
|
||||
|
||||
@@ -119,7 +119,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var moi = world.Map.Rules.Actors["player"].TraitInfoOrDefault<MissionObjectivesInfo>();
|
||||
if (moi != null)
|
||||
{
|
||||
var faction = world.LocalPlayer == null ? null : world.LocalPlayer.Faction.InternalName;
|
||||
var faction = world.LocalPlayer?.Faction.InternalName;
|
||||
Game.Sound.PlayNotification(world.Map.Rules, null, "Speech", moi.LeaveNotification, faction);
|
||||
}
|
||||
}
|
||||
@@ -127,7 +127,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
leaving = true;
|
||||
|
||||
var iop = world.WorldActor.TraitsImplementing<IObjectivesPanel>().FirstOrDefault();
|
||||
var exitDelay = iop != null ? iop.ExitDelay : 0;
|
||||
var exitDelay = iop?.ExitDelay ?? 0;
|
||||
if (mpe != null)
|
||||
{
|
||||
Game.RunAfterDelay(exitDelay, () =>
|
||||
@@ -208,7 +208,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
return;
|
||||
|
||||
var iop = world.WorldActor.TraitsImplementing<IObjectivesPanel>().FirstOrDefault();
|
||||
var exitDelay = iop != null ? iop.ExitDelay : 0;
|
||||
var exitDelay = iop?.ExitDelay ?? 0;
|
||||
|
||||
Action onRestart = () =>
|
||||
{
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
if (world.LocalPlayer.WinState != WinState.Undefined && !loadingObserverWidgets)
|
||||
{
|
||||
loadingObserverWidgets = true;
|
||||
Game.RunAfterDelay(objectives != null ? objectives.GameOverDelay : 0, () =>
|
||||
Game.RunAfterDelay(objectives?.GameOverDelay ?? 0, () =>
|
||||
{
|
||||
if (!Game.IsCurrentWorld(world))
|
||||
return;
|
||||
|
||||
@@ -49,26 +49,24 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
ActorInfo lastActor = null;
|
||||
Hotkey lastHotkey = Hotkey.Invalid;
|
||||
var lastPowerState = pm == null ? PowerState.Normal : pm.PowerState;
|
||||
var lastPowerState = pm?.PowerState ?? PowerState.Normal;
|
||||
var descLabelY = descLabel.Bounds.Y;
|
||||
var descLabelPadding = descLabel.Bounds.Height;
|
||||
|
||||
tooltipContainer.BeforeRender = () =>
|
||||
{
|
||||
var tooltipIcon = getTooltipIcon();
|
||||
if (tooltipIcon == null)
|
||||
return;
|
||||
|
||||
var actor = tooltipIcon.Actor;
|
||||
var actor = tooltipIcon?.Actor;
|
||||
if (actor == null)
|
||||
return;
|
||||
|
||||
var hotkey = tooltipIcon.Hotkey != null ? tooltipIcon.Hotkey.GetValue() : Hotkey.Invalid;
|
||||
var hotkey = tooltipIcon.Hotkey?.GetValue() ?? Hotkey.Invalid;
|
||||
if (actor == lastActor && hotkey == lastHotkey && (pm == null || pm.PowerState == lastPowerState))
|
||||
return;
|
||||
|
||||
var tooltip = actor.TraitInfos<TooltipInfo>().FirstOrDefault(info => info.EnabledByDefault);
|
||||
var name = tooltip != null ? tooltip.Name : actor.Name;
|
||||
var name = tooltip?.Name ?? actor.Name;
|
||||
var buildable = actor.TraitInfo<BuildableInfo>();
|
||||
|
||||
var cost = 0;
|
||||
@@ -125,7 +123,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
powerSize = font.Measure(powerLabel.Text);
|
||||
}
|
||||
|
||||
var buildTime = tooltipIcon.ProductionQueue == null ? 0 : tooltipIcon.ProductionQueue.GetBuildTime(actor, buildable);
|
||||
var buildTime = tooltipIcon.ProductionQueue?.GetBuildTime(actor, buildable) ?? 0;
|
||||
var timeModifier = pm != null && pm.PowerState != PowerState.Normal ? tooltipIcon.ProductionQueue.Info.LowPowerModifier : 100;
|
||||
|
||||
timeLabel.Text = formatBuildTime.Update((buildTime * timeModifier) / 100);
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
// to efficiently work when the label is going to change, requiring a panel relayout
|
||||
var remainingSeconds = (int)Math.Ceiling(sp.RemainingTicks * world.Timestep / 1000f);
|
||||
|
||||
var hotkey = icon.Hotkey != null ? icon.Hotkey.GetValue() : Hotkey.Invalid;
|
||||
var hotkey = icon.Hotkey?.GetValue() ?? Hotkey.Invalid;
|
||||
if (sp == lastPower && hotkey == lastHotkey && lastRemainingSeconds == remainingSeconds)
|
||||
return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user