Use null propagation
This commit is contained in:
@@ -100,9 +100,7 @@ namespace OpenRA.Graphics
|
||||
|
||||
static void LoadCollection(string name, MiniYaml yaml)
|
||||
{
|
||||
if (Game.ModData.LoadScreen != null)
|
||||
Game.ModData.LoadScreen.Display();
|
||||
|
||||
Game.ModData.LoadScreen?.Display();
|
||||
collections.Add(name, FieldLoader.Load<Collection>(yaml));
|
||||
}
|
||||
|
||||
|
||||
@@ -111,8 +111,7 @@ namespace OpenRA.Graphics
|
||||
var template = kv.Value;
|
||||
for (var i = 0; i < template.Sprites.Length; i++)
|
||||
{
|
||||
if (template.Cursors[i] != null)
|
||||
template.Cursors[i].Dispose();
|
||||
template.Cursors[i]?.Dispose();
|
||||
|
||||
// Calculate the padding to position the frame within sequenceBounds
|
||||
var paddingTL = -(template.Bounds.Location - template.Sprites[i].Offset.XY.ToInt2());
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace OpenRA
|
||||
// Traits tagged with an instance name prefer inits with the same name.
|
||||
// If a more specific init is not available, fall back to an unnamed init.
|
||||
// If duplicate inits are defined, take the last to match standard yaml override expectations
|
||||
if (info != null && !string.IsNullOrEmpty(info.InstanceName))
|
||||
if (!string.IsNullOrEmpty(info?.InstanceName))
|
||||
return inits.LastOrDefault(i => i.InstanceName == info.InstanceName) ??
|
||||
inits.LastOrDefault(i => string.IsNullOrEmpty(i.InstanceName));
|
||||
|
||||
@@ -159,9 +159,9 @@ namespace OpenRA
|
||||
|
||||
public virtual void Initialize(T value)
|
||||
{
|
||||
var field = typeof(ValueActorInit<T>).GetField(nameof(value), BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
if (field != null)
|
||||
field.SetValue(this, value);
|
||||
typeof(ValueActorInit<T>)
|
||||
.GetField(nameof(value), BindingFlags.NonPublic | BindingFlags.Instance)
|
||||
?.SetValue(this, value);
|
||||
}
|
||||
|
||||
public override MiniYaml Save()
|
||||
@@ -246,16 +246,16 @@ namespace OpenRA
|
||||
|
||||
public void Initialize(MiniYaml yaml)
|
||||
{
|
||||
var field = typeof(OwnerInit).GetField(nameof(InternalName), BindingFlags.Public | BindingFlags.Instance);
|
||||
if (field != null)
|
||||
field.SetValue(this, yaml.Value);
|
||||
typeof(OwnerInit)
|
||||
.GetField(nameof(InternalName), BindingFlags.Public | BindingFlags.Instance)
|
||||
?.SetValue(this, yaml.Value);
|
||||
}
|
||||
|
||||
public void Initialize(Player player)
|
||||
{
|
||||
var field = typeof(OwnerInit).GetField(nameof(value), BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
if (field != null)
|
||||
field.SetValue(this, player);
|
||||
typeof(OwnerInit)
|
||||
.GetField(nameof(value), BindingFlags.NonPublic | BindingFlags.Instance)
|
||||
?.SetValue(this, player);
|
||||
}
|
||||
|
||||
public override MiniYaml Save()
|
||||
|
||||
Reference in New Issue
Block a user