Replace terniary null checks with coalescing.

This commit is contained in:
Paul Chote
2021-03-07 21:22:00 +00:00
committed by teinarss
parent 2473b8763b
commit d52ba83f96
43 changed files with 72 additions and 73 deletions

View File

@@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Traits.Render
{
body = self.Trait<BodyOrientation>();
facing = self.TraitOrDefault<IFacing>();
cachedFacing = facing != null ? facing.Facing : WAngle.Zero;
cachedFacing = facing?.Facing ?? WAngle.Zero;
cachedPosition = self.CenterPosition;
base.Created(self);
@@ -126,14 +126,14 @@ namespace OpenRA.Mods.Common.Traits.Render
var pos = Info.Type == TrailType.CenterPosition ? spawnPosition + body.LocalToWorld(offsetRotation) :
self.World.Map.CenterOfCell(spawnCell);
var spawnFacing = Info.SpawnAtLastPosition ? cachedFacing : (facing != null ? facing.Facing : WAngle.Zero);
var spawnFacing = Info.SpawnAtLastPosition ? cachedFacing : facing?.Facing ?? WAngle.Zero;
if ((Info.TerrainTypes.Count == 0 || Info.TerrainTypes.Contains(type)) && !string.IsNullOrEmpty(Info.Image))
self.World.AddFrameEndTask(w => w.Add(new SpriteEffect(pos, spawnFacing, self.World, Info.Image,
Info.Sequences.Random(Game.CosmeticRandom), Info.Palette, Info.VisibleThroughFog)));
cachedPosition = self.CenterPosition;
cachedFacing = facing != null ? facing.Facing : WAngle.Zero;
cachedFacing = facing?.Facing ?? WAngle.Zero;
ticks = 0;
cachedInterval = isMoving ? Info.MovingInterval : Info.StationaryInterval;

View File

@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Traits.Render
public RenderDebugState(Actor self, RenderDebugStateInfo info)
{
var buildingInfo = self.Info.TraitInfoOrDefault<BuildingInfo>();
var yOffset = buildingInfo == null ? 1 : buildingInfo.Dimensions.Y;
var yOffset = buildingInfo?.Dimensions.Y ?? 1;
offset = new WVec(0, 512 * yOffset, 0);
this.self = self;

View File

@@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.Traits.Render
if (facings == -1)
{
var qbo = init.Actor.TraitInfoOrDefault<IQuantizeBodyOrientationInfo>();
facings = qbo != null ? qbo.QuantizedBodyFacings(init.Actor, sequenceProvider, faction) : 1;
facings = qbo?.QuantizedBodyFacings(init.Actor, sequenceProvider, faction) ?? 1;
}
}
@@ -127,7 +127,7 @@ namespace OpenRA.Mods.Common.Traits.Render
// Return to the caller whether the renderable position or size has changed
var visible = IsVisible;
var offset = Animation.OffsetFunc != null ? Animation.OffsetFunc() : WVec.Zero;
var offset = Animation.OffsetFunc?.Invoke() ?? WVec.Zero;
var sequence = Animation.Animation.CurrentSequence;
var updated = visible != cachedVisible || offset != cachedOffset || sequence != cachedSequence;

View File

@@ -93,7 +93,7 @@ namespace OpenRA.Mods.Common.Traits.Render
{
// Return to the caller whether the renderable position or size has changed
var visible = model.IsVisible;
var offset = model.OffsetFunc != null ? model.OffsetFunc() : WVec.Zero;
var offset = model.OffsetFunc?.Invoke() ?? WVec.Zero;
var updated = visible != cachedVisible || offset != cachedOffset;
cachedVisible = visible;