Use null propagation
This commit is contained in:
@@ -162,6 +162,9 @@ dotnet_diagnostic.IDE0029.severity = warning
|
|||||||
# Use coalesce expression (nullable types).
|
# Use coalesce expression (nullable types).
|
||||||
dotnet_diagnostic.IDE0030.severity = warning
|
dotnet_diagnostic.IDE0030.severity = warning
|
||||||
|
|
||||||
|
# Use null propagation.
|
||||||
|
dotnet_diagnostic.IDE0031.severity = warning
|
||||||
|
|
||||||
# Use explicitly provided tuple name.
|
# Use explicitly provided tuple name.
|
||||||
dotnet_diagnostic.IDE0033.severity = warning
|
dotnet_diagnostic.IDE0033.severity = warning
|
||||||
|
|
||||||
|
|||||||
@@ -100,9 +100,7 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
static void LoadCollection(string name, MiniYaml yaml)
|
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));
|
collections.Add(name, FieldLoader.Load<Collection>(yaml));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -111,8 +111,7 @@ namespace OpenRA.Graphics
|
|||||||
var template = kv.Value;
|
var template = kv.Value;
|
||||||
for (var i = 0; i < template.Sprites.Length; i++)
|
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
|
// Calculate the padding to position the frame within sequenceBounds
|
||||||
var paddingTL = -(template.Bounds.Location - template.Sprites[i].Offset.XY.ToInt2());
|
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.
|
// 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 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 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) ??
|
return inits.LastOrDefault(i => i.InstanceName == info.InstanceName) ??
|
||||||
inits.LastOrDefault(i => string.IsNullOrEmpty(i.InstanceName));
|
inits.LastOrDefault(i => string.IsNullOrEmpty(i.InstanceName));
|
||||||
|
|
||||||
@@ -159,9 +159,9 @@ namespace OpenRA
|
|||||||
|
|
||||||
public virtual void Initialize(T value)
|
public virtual void Initialize(T value)
|
||||||
{
|
{
|
||||||
var field = typeof(ValueActorInit<T>).GetField(nameof(value), BindingFlags.NonPublic | BindingFlags.Instance);
|
typeof(ValueActorInit<T>)
|
||||||
if (field != null)
|
.GetField(nameof(value), BindingFlags.NonPublic | BindingFlags.Instance)
|
||||||
field.SetValue(this, value);
|
?.SetValue(this, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override MiniYaml Save()
|
public override MiniYaml Save()
|
||||||
@@ -246,16 +246,16 @@ namespace OpenRA
|
|||||||
|
|
||||||
public void Initialize(MiniYaml yaml)
|
public void Initialize(MiniYaml yaml)
|
||||||
{
|
{
|
||||||
var field = typeof(OwnerInit).GetField(nameof(InternalName), BindingFlags.Public | BindingFlags.Instance);
|
typeof(OwnerInit)
|
||||||
if (field != null)
|
.GetField(nameof(InternalName), BindingFlags.Public | BindingFlags.Instance)
|
||||||
field.SetValue(this, yaml.Value);
|
?.SetValue(this, yaml.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Initialize(Player player)
|
public void Initialize(Player player)
|
||||||
{
|
{
|
||||||
var field = typeof(OwnerInit).GetField(nameof(value), BindingFlags.NonPublic | BindingFlags.Instance);
|
typeof(OwnerInit)
|
||||||
if (field != null)
|
.GetField(nameof(value), BindingFlags.NonPublic | BindingFlags.Instance)
|
||||||
field.SetValue(this, player);
|
?.SetValue(this, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override MiniYaml Save()
|
public override MiniYaml Save()
|
||||||
|
|||||||
@@ -37,11 +37,8 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
{
|
{
|
||||||
if (self.World.Map.DistanceAboveTerrain(self.CenterPosition).Length <= 0)
|
if (self.World.Map.DistanceAboveTerrain(self.CenterPosition).Length <= 0)
|
||||||
{
|
{
|
||||||
if (info.ExplosionWeapon != null)
|
// Use .FromPos since this actor is killed. Cannot use Target.FromActor
|
||||||
{
|
info.ExplosionWeapon?.Impact(Target.FromPos(self.CenterPosition), self);
|
||||||
// Use .FromPos since this actor is killed. Cannot use Target.FromActor
|
|
||||||
info.ExplosionWeapon.Impact(Target.FromPos(self.CenterPosition), self);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.Kill(self);
|
self.Kill(self);
|
||||||
Cancel(self);
|
Cancel(self);
|
||||||
|
|||||||
@@ -74,8 +74,8 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
if (enterLegacyHut != null)
|
if (enterLegacyHut != null)
|
||||||
enterLegacyHut.Repair(self);
|
enterLegacyHut.Repair(self);
|
||||||
else if (enterHut != null)
|
else
|
||||||
enterHut.Repair(self);
|
enterHut?.Repair(self);
|
||||||
|
|
||||||
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", speechNotification, self.Owner.Faction.InternalName);
|
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", speechNotification, self.Owner.Faction.InternalName);
|
||||||
TextNotificationsManager.AddTransientLine(textNotification, self.Owner);
|
TextNotificationsManager.AddTransientLine(textNotification, self.Owner);
|
||||||
|
|||||||
@@ -53,9 +53,9 @@ namespace OpenRA.Mods.Common
|
|||||||
|
|
||||||
public void Initialize(int value)
|
public void Initialize(int value)
|
||||||
{
|
{
|
||||||
var field = GetType().GetField(nameof(value), BindingFlags.NonPublic | BindingFlags.Instance);
|
GetType()
|
||||||
if (field != null)
|
.GetField(nameof(value), BindingFlags.NonPublic | BindingFlags.Instance)
|
||||||
field.SetValue(this, value);
|
?.SetValue(this, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override MiniYaml Save()
|
public override MiniYaml Save()
|
||||||
|
|||||||
@@ -74,8 +74,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
self.World.Add(playerBeacon);
|
self.World.Add(playerBeacon);
|
||||||
|
|
||||||
if (self.Owner.IsAlliedWith(self.World.RenderPlayer))
|
if (self.Owner.IsAlliedWith(self.World.RenderPlayer))
|
||||||
Game.Sound.PlayNotification(self.World.Map.Rules, null, info.NotificationType, info.Notification,
|
Game.Sound.PlayNotification(self.World.Map.Rules, null, info.NotificationType, info.Notification, self.World.RenderPlayer?.Faction.InternalName);
|
||||||
self.World.RenderPlayer != null ? self.World.RenderPlayer.Faction.InternalName : null);
|
|
||||||
|
|
||||||
if (radarPings != null)
|
if (radarPings != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
if (!world.IsLoadingGameSave)
|
if (!world.IsLoadingGameSave)
|
||||||
{
|
{
|
||||||
Game.Sound.PlayNotification(world.Map.Rules, null, "Speech", info.Notification, world.RenderPlayer == null ? null : world.RenderPlayer.Faction.InternalName);
|
Game.Sound.PlayNotification(world.Map.Rules, null, "Speech", info.Notification, world.RenderPlayer?.Faction.InternalName);
|
||||||
TextNotificationsManager.AddTransientLine(info.TextNotification, null);
|
TextNotificationsManager.AddTransientLine(info.TextNotification, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
if (!world.IsReplay)
|
if (!world.IsReplay)
|
||||||
{
|
{
|
||||||
Game.Sound.PlayNotification(world.Map.Rules, null, "Speech", info.LoadedNotification, world.RenderPlayer == null ? null : world.RenderPlayer.Faction.InternalName);
|
Game.Sound.PlayNotification(world.Map.Rules, null, "Speech", info.LoadedNotification, world.RenderPlayer?.Faction.InternalName);
|
||||||
TextNotificationsManager.AddTransientLine(info.LoadedTextNotification, null);
|
TextNotificationsManager.AddTransientLine(info.LoadedTextNotification, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
if (!world.IsReplay)
|
if (!world.IsReplay)
|
||||||
{
|
{
|
||||||
Game.Sound.PlayNotification(world.Map.Rules, null, "Speech", info.SavedNotification, world.RenderPlayer == null ? null : world.RenderPlayer.Faction.InternalName);
|
Game.Sound.PlayNotification(world.Map.Rules, null, "Speech", info.SavedNotification, world.RenderPlayer?.Faction.InternalName);
|
||||||
TextNotificationsManager.AddTransientLine(info.SavedTextNotification, null);
|
TextNotificationsManager.AddTransientLine(info.SavedTextNotification, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,8 +117,7 @@ namespace OpenRA.Mods.Common.UpdateRules
|
|||||||
if (namedType != null && namedType.IsSubclassOf(typeof(UpdateRule)))
|
if (namedType != null && namedType.IsSubclassOf(typeof(UpdateRule)))
|
||||||
return new[] { (UpdateRule)objectCreator.CreateBasic(namedType) };
|
return new[] { (UpdateRule)objectCreator.CreateBasic(namedType) };
|
||||||
|
|
||||||
var namedPath = Paths.FirstOrDefault(p => p.source == source);
|
return Paths.FirstOrDefault(p => p.source == source)?.Rules(chain);
|
||||||
return namedPath != null ? namedPath.Rules(chain) : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<string> KnownPaths { get { return Paths.Select(p => p.source); } }
|
public static IEnumerable<string> KnownPaths { get { return Paths.Select(p => p.source); } }
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
paletteWidget.Value.CurrentQueue = value;
|
paletteWidget.Value.CurrentQueue = value;
|
||||||
queueGroup = value != null ? value.Info.Group : null;
|
queueGroup = value?.Info.Group;
|
||||||
|
|
||||||
// TODO: Scroll tabs so selected queue is visible
|
// TODO: Scroll tabs so selected queue is visible
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
{
|
{
|
||||||
currentPlayer = player;
|
currentPlayer = player;
|
||||||
|
|
||||||
var newShroud = player != null ? player.Shroud : null;
|
var newShroud = player?.Shroud;
|
||||||
|
|
||||||
if (newShroud != shroud)
|
if (newShroud != shroud)
|
||||||
{
|
{
|
||||||
@@ -146,8 +146,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
shroud = newShroud;
|
shroud = newShroud;
|
||||||
}
|
}
|
||||||
|
|
||||||
var newPlayerRadarTerrain =
|
var newPlayerRadarTerrain = currentPlayer?.PlayerActor.TraitOrDefault<PlayerRadarTerrain>();
|
||||||
currentPlayer != null ? currentPlayer.PlayerActor.TraitOrDefault<PlayerRadarTerrain>() : null;
|
|
||||||
|
|
||||||
if (forceUpdate || newPlayerRadarTerrain != playerRadarTerrain)
|
if (forceUpdate || newPlayerRadarTerrain != playerRadarTerrain)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user