Replace terniary null checks with coalescing.
This commit is contained in:
@@ -65,7 +65,7 @@ namespace OpenRA
|
||||
public CPos Location => OccupiesSpace.TopLeft;
|
||||
public WPos CenterPosition => OccupiesSpace.CenterPosition;
|
||||
|
||||
public WRot Orientation => facing != null ? facing.Orientation : WRot.None;
|
||||
public WRot Orientation => facing?.Orientation ?? WRot.None;
|
||||
|
||||
/// <summary>Value used to represent an invalid token.</summary>
|
||||
public static readonly int InvalidConditionToken = -1;
|
||||
|
||||
@@ -206,7 +206,7 @@ namespace OpenRA
|
||||
public static void RestartGame()
|
||||
{
|
||||
var replay = OrderManager.Connection as ReplayConnection;
|
||||
var replayName = replay != null ? replay.Filename : null;
|
||||
var replayName = replay?.Filename;
|
||||
var lobbyInfo = OrderManager.LobbyInfo;
|
||||
|
||||
// Reseed the RNG so this isn't an exact repeat of the last game
|
||||
|
||||
@@ -112,7 +112,7 @@ namespace OpenRA.Graphics
|
||||
int CurrentSequenceTickOrDefault()
|
||||
{
|
||||
const int DefaultTick = 40; // 25 fps == 40 ms
|
||||
return CurrentSequence != null ? CurrentSequence.Tick : DefaultTick;
|
||||
return CurrentSequence?.Tick ?? DefaultTick;
|
||||
}
|
||||
|
||||
void PlaySequence(string sequenceName)
|
||||
|
||||
@@ -38,16 +38,16 @@ namespace OpenRA.Graphics
|
||||
public IRenderable[] Render(Actor self, WorldRenderer wr, PaletteReference pal)
|
||||
{
|
||||
var center = self.CenterPosition;
|
||||
var offset = OffsetFunc != null ? OffsetFunc() : WVec.Zero;
|
||||
var offset = OffsetFunc?.Invoke() ?? WVec.Zero;
|
||||
|
||||
var z = (ZOffset != null) ? ZOffset(center + offset) : 0;
|
||||
var z = ZOffset?.Invoke(center + offset) ?? 0;
|
||||
return Animation.Render(center, offset, z, pal);
|
||||
}
|
||||
|
||||
public Rectangle ScreenBounds(Actor self, WorldRenderer wr)
|
||||
{
|
||||
var center = self.CenterPosition;
|
||||
var offset = OffsetFunc != null ? OffsetFunc() : WVec.Zero;
|
||||
var offset = OffsetFunc?.Invoke() ?? WVec.Zero;
|
||||
|
||||
return Animation.ScreenBounds(wr, center, offset);
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace OpenRA
|
||||
public MapVisibility Visibility;
|
||||
|
||||
Lazy<Ruleset> rules;
|
||||
public Ruleset Rules => rules != null ? rules.Value : null;
|
||||
public Ruleset Rules => rules?.Value;
|
||||
public bool InvalidCustomRules { get; private set; }
|
||||
public bool DefinesUnsafeCustomRules { get; private set; }
|
||||
public bool RulesLoaded { get; private set; }
|
||||
|
||||
@@ -452,7 +452,7 @@ namespace OpenRA
|
||||
existingDict.TryGetValue(key, out var existingNode);
|
||||
overrideDict.TryGetValue(key, out var overrideNode);
|
||||
|
||||
var loc = overrideNode == null ? default(MiniYamlNode.SourceLocation) : overrideNode.Location;
|
||||
var loc = overrideNode?.Location ?? default;
|
||||
var comment = (overrideNode ?? existingNode).Comment;
|
||||
var merged = (existingNode == null || overrideNode == null) ? overrideNode ?? existingNode :
|
||||
new MiniYamlNode(key, MergePartial(existingNode.Value, overrideNode.Value), comment, loc);
|
||||
|
||||
@@ -103,9 +103,9 @@ namespace OpenRA
|
||||
|
||||
return new PlayerBadge(
|
||||
labelNode.Value.Value,
|
||||
icon24Node != null ? icon24Node.Value.Value : null,
|
||||
icon48Node != null ? icon48Node.Value.Value : null,
|
||||
icon72Node != null ? icon72Node.Value.Value : null);
|
||||
icon24Node?.Value.Value,
|
||||
icon48Node?.Value.Value,
|
||||
icon72Node?.Value.Value);
|
||||
}
|
||||
|
||||
public Sprite GetIcon(PlayerBadge badge)
|
||||
|
||||
@@ -323,9 +323,9 @@ namespace OpenRA
|
||||
}
|
||||
}
|
||||
|
||||
public float MusicSeekPosition => music != null ? music.SeekPosition : 0;
|
||||
public float MusicSeekPosition => music?.SeekPosition ?? 0;
|
||||
|
||||
public float VideoSeekPosition => video != null ? video.SeekPosition : 0;
|
||||
public float VideoSeekPosition => video?.SeekPosition ?? 0;
|
||||
|
||||
// Returns true if played successfully
|
||||
public bool PlayPredefined(SoundType soundType, Ruleset ruleset, Player p, Actor voicedActor, string type, string definition, string variant,
|
||||
@@ -340,11 +340,11 @@ namespace OpenRA
|
||||
if (ruleset.Voices == null || ruleset.Notifications == null)
|
||||
return false;
|
||||
|
||||
var rules = (voicedActor != null) ? ruleset.Voices[type] : ruleset.Notifications[type];
|
||||
var rules = voicedActor != null ? ruleset.Voices[type] : ruleset.Notifications[type];
|
||||
if (rules == null)
|
||||
return false;
|
||||
|
||||
var id = voicedActor != null ? voicedActor.ActorID : 0;
|
||||
var id = voicedActor?.ActorID ?? 0;
|
||||
|
||||
SoundPool pool;
|
||||
var suffix = rules.DefaultVariant;
|
||||
|
||||
@@ -592,7 +592,7 @@ namespace OpenRA.Support
|
||||
Token lastToken = null;
|
||||
for (var i = 0; ;)
|
||||
{
|
||||
var token = Token.GetNext(Expression, ref i, lastToken != null ? lastToken.Type : TokenType.Invalid);
|
||||
var token = Token.GetNext(Expression, ref i, lastToken?.Type ?? TokenType.Invalid);
|
||||
if (token == null)
|
||||
{
|
||||
// Sanity check parsed tree
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace OpenRA
|
||||
LoadWidget(args, widget, c);
|
||||
|
||||
var logicNode = node.Value.Nodes.FirstOrDefault(n => n.Key == "Logic");
|
||||
var logic = logicNode == null ? null : logicNode.Value.ToDictionary();
|
||||
var logic = logicNode?.Value.ToDictionary();
|
||||
args.Add("logicArgs", logic);
|
||||
|
||||
widget.PostInit(args);
|
||||
|
||||
Reference in New Issue
Block a user