Fix IDE0048

This commit is contained in:
RoosterDragon
2023-02-28 19:27:42 +00:00
committed by Pavel Penev
parent 65e28d5562
commit 8ee6957e6a
23 changed files with 46 additions and 37 deletions

View File

@@ -127,6 +127,12 @@ csharp_style_expression_bodied_local_functions = when_on_single_line
# Remove unused parameters on non public methods, ignore unused parameters on public methods. # Remove unused parameters on non public methods, ignore unused parameters on public methods.
dotnet_code_quality_unused_parameters = non_public dotnet_code_quality_unused_parameters = non_public
# Parentheses preferences.
dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary
dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity
dotnet_style_parentheses_in_other_operators = never_if_unnecessary
## Others: ## Others:
# Show an IDE warning when default access modifiers are explicitly specified. # Show an IDE warning when default access modifiers are explicitly specified.
@@ -201,6 +207,9 @@ dotnet_diagnostic.IDE0044.severity = warning
# Remove unnecessary parentheses. # Remove unnecessary parentheses.
dotnet_diagnostic.IDE0047.severity = warning dotnet_diagnostic.IDE0047.severity = warning
# Add parentheses for clarity.
dotnet_diagnostic.IDE0048.severity = warning
# Remove unused private member. # Remove unused private member.
dotnet_diagnostic.IDE0051.severity = warning dotnet_diagnostic.IDE0051.severity = warning

View File

@@ -1248,8 +1248,8 @@ namespace OpenRA
if (allProjected.Length > 0) if (allProjected.Length > 0)
{ {
var puv = allProjected.First(); var puv = allProjected.First();
var horizontalBound = ((puv.U - Bounds.Left) < Bounds.Width / 2) ? Bounds.Left : Bounds.Right; var horizontalBound = (puv.U - Bounds.Left < Bounds.Width / 2) ? Bounds.Left : Bounds.Right;
var verticalBound = ((puv.V - Bounds.Top) < Bounds.Height / 2) ? Bounds.Top : Bounds.Bottom; var verticalBound = (puv.V - Bounds.Top < Bounds.Height / 2) ? Bounds.Top : Bounds.Bottom;
var du = Math.Abs(horizontalBound - puv.U); var du = Math.Abs(horizontalBound - puv.U);
var dv = Math.Abs(verticalBound - puv.V); var dv = Math.Abs(verticalBound - puv.V);

View File

@@ -51,7 +51,7 @@ namespace OpenRA.Primitives
items[addLevel][addIndex] = item; items[addLevel][addIndex] = item;
if (++index >= (1 << level)) if (++index >= 1 << level)
{ {
index = 0; index = 0;
if (items.Count <= ++level) if (items.Count <= ++level)

View File

@@ -382,7 +382,7 @@ namespace OpenRA.Traits
{ {
var index = touched.Index(puv); var index = touched.Index(puv);
touched[index] = true; touched[index] = true;
explored[index] = (visibleCount[index] + passiveVisibleCount[index]) > 0; explored[index] = visibleCount[index] + passiveVisibleCount[index] > 0;
} }
anyCellTouched = true; anyCellTouched = true;

View File

@@ -228,7 +228,7 @@ namespace OpenRA.Mods.Cnc.FileFormats
InitBigNum(n1, 0, len); InitBigNum(n1, 0, len);
nTwoBitLen = (int)BitLenBigNum(n2, len); nTwoBitLen = (int)BitLenBigNum(n2, len);
bit = 1U << (nTwoBitLen % 32); bit = 1U << (nTwoBitLen % 32);
var j = ((nTwoBitLen + 32) / 32) - 1; var j = (nTwoBitLen + 32) / 32 - 1;
nTwoByteLen = (uint)((nTwoBitLen - 1) / 32) * 4; nTwoByteLen = (uint)((nTwoBitLen - 1) / 32) * 4;
nTmp[nTwoByteLen / 4] |= 1U << ((nTwoBitLen - 1) & 0x1f); nTmp[nTwoByteLen / 4] |= 1U << ((nTwoBitLen - 1) & 0x1f);
@@ -293,7 +293,7 @@ namespace OpenRA.Mods.Cnc.FileFormats
tmp = 0; tmp = 0;
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
{ {
tmp = mul * (*pn2) + (*pn1) + tmp; tmp = mul * *pn2 + *pn1 + tmp;
*pn1 = (ushort)tmp; *pn1 = (ushort)tmp;
pn1++; pn1++;
pn2++; pn2++;
@@ -371,8 +371,8 @@ namespace OpenRA.Mods.Cnc.FileFormats
IncrementBigNum(globTwo, len * 2 + 1); IncrementBigNum(globTwo, len * 2 + 1);
NegBigNum(globTwo, len * 2 + 1); NegBigNum(globTwo, len * 2 + 1);
lenDiff = globTwoXtwo + 1 - globOneLenXTwo; lenDiff = globTwoXtwo + 1 - globOneLenXTwo;
var esi = ((ushort*)g2) + (1 + globTwoXtwo - globOneLenXTwo); var esi = (ushort*)g2 + (1 + globTwoXtwo - globOneLenXTwo);
var edi = ((ushort*)g2) + (globTwoXtwo + 1); var edi = (ushort*)g2 + (globTwoXtwo + 1);
for (; lenDiff != 0; lenDiff--) for (; lenDiff != 0; lenDiff--)
{ {
edi--; edi--;

View File

@@ -218,7 +218,7 @@ namespace OpenRA.Mods.Cnc.FileFormats
goto match_done; goto match_done;
} }
if (t >= 2 * 4 - (3 - 1) && (op - mPos) >= 4) if (t >= 2 * 4 - (3 - 1) && op - mPos >= 4)
{ {
*(uint*)op = *(uint*)mPos; *(uint*)op = *(uint*)mPos;
op += 4; mPos += 4; t -= 4 - (3 - 1); op += 4; mPos += 4; t -= 4 - (3 - 1);

View File

@@ -164,7 +164,7 @@ namespace OpenRA.Mods.Cnc.FileSystem
if (count < 0) if (count < 0)
throw new ArgumentOutOfRangeException(nameof(count), "Non-negative number required."); throw new ArgumentOutOfRangeException(nameof(count), "Non-negative number required.");
if (offset + (count * 2) > s.Length) if (offset + count * 2 > s.Length)
throw new ArgumentException($"Bytes to read {count * 2} and offset {offset} greater than stream length {s.Length}."); throw new ArgumentException($"Bytes to read {count * 2} and offset {offset} greater than stream length {s.Length}.");
s.Seek(offset, SeekOrigin.Begin); s.Seek(offset, SeekOrigin.Begin);

View File

@@ -304,8 +304,8 @@ namespace OpenRA.Mods.Common.Widgets
for (var x = previousCell.X; x <= nextCell.X; x += terrainTemplate.Size.X) for (var x = previousCell.X; x <= nextCell.X; x += terrainTemplate.Size.X)
{ {
PaintSingleCell(new CPos(x, queuedCell.Y)); PaintSingleCell(new CPos(x, queuedCell.Y));
var upperCell = new CPos(x, queuedCell.Y - (1 * terrainTemplate.Size.Y)); var upperCell = new CPos(x, queuedCell.Y - 1 * terrainTemplate.Size.Y);
var lowerCell = new CPos(x, queuedCell.Y + (1 * terrainTemplate.Size.Y)); var lowerCell = new CPos(x, queuedCell.Y + 1 * terrainTemplate.Size.Y);
if (ShouldPaint(upperCell)) if (ShouldPaint(upperCell))
MaybeEnqueue(upperCell); MaybeEnqueue(upperCell);

View File

@@ -127,7 +127,7 @@ namespace OpenRA.Mods.Common.FileFormats
{ {
this.channels = channels; this.channels = channels;
numBlocks = dataSize / blockAlign; numBlocks = dataSize / blockAlign;
blockDataSize = blockAlign - (channels * 4); blockDataSize = blockAlign - channels * 4;
outputSize = uncompressedSize * channels * 2; outputSize = uncompressedSize * channels * 2;
predictor = new int[channels]; predictor = new int[channels];
index = new int[channels]; index = new int[channels];
@@ -268,7 +268,7 @@ namespace OpenRA.Mods.Common.FileFormats
// This code contains elements from libsndfile // This code contains elements from libsndfile
short DecodeNibble(short nibble, byte bpred, ref short idelta, ref short s1, ref short s2) short DecodeNibble(short nibble, byte bpred, ref short idelta, ref short s1, ref short s2)
{ {
var predict = ((s1 * AdaptCoeff1[bpred]) + (s2 * AdaptCoeff2[bpred])) >> 8; var predict = (s1 * AdaptCoeff1[bpred] + s2 * AdaptCoeff2[bpred]) >> 8;
var twosCompliment = (nibble & 0x8) > 0 var twosCompliment = (nibble & 0x8) > 0
? nibble - 0x10 ? nibble - 0x10

View File

@@ -376,7 +376,7 @@ namespace OpenRA.Mods.Common.Graphics
for (var frame = 0; frame < length; frame++) for (var frame = 0; frame < length; frame++)
{ {
var i = transpose ? frame % length * facings + facing : var i = transpose ? frame % length * facings + facing :
(facing * stride) + (frame % length); facing * stride + frame % length;
usedFrames.Add(frames != null ? frames[i] : start + i); usedFrames.Add(frames != null ? frames[i] : start + i);
} }
@@ -530,7 +530,7 @@ namespace OpenRA.Mods.Common.Graphics
for (var frame = 0; frame < length; frame++) for (var frame = 0; frame < length; frame++)
{ {
var i = transpose ? frame % length * facings + facing : var i = transpose ? frame % length * facings + facing :
(facing * stride) + (frame % length); facing * stride + frame % length;
var s = frames != null ? sprites[frames[i]] : sprites[start + i]; var s = frames != null ? sprites[frames[i]] : sprites[start + i];
if (!s.Bounds.IsEmpty) if (!s.Bounds.IsEmpty)
yield return new Rectangle( yield return new Rectangle(
@@ -574,7 +574,7 @@ namespace OpenRA.Mods.Common.Graphics
f = (facings - f) % facings; f = (facings - f) % facings;
var i = transpose ? frame % length * facings + f : var i = transpose ? frame % length * facings + f :
(f * stride) + (frame % length); f * stride + frame % length;
var j = frames != null ? frames[i] : start + i; var j = frames != null ? frames[i] : start + i;
if (sprites[j] == null) if (sprites[j] == null)

View File

@@ -699,8 +699,8 @@ namespace OpenRA.Mods.Common.Pathfinder
static CPos GetGridTopLeft(CPos cellInGrid, Grid mapBounds) static CPos GetGridTopLeft(CPos cellInGrid, Grid mapBounds)
{ {
return new CPos( return new CPos(
((cellInGrid.X - mapBounds.TopLeft.X) / GridSize * GridSize) + mapBounds.TopLeft.X, (cellInGrid.X - mapBounds.TopLeft.X) / GridSize * GridSize + mapBounds.TopLeft.X,
((cellInGrid.Y - mapBounds.TopLeft.Y) / GridSize * GridSize) + mapBounds.TopLeft.Y, (cellInGrid.Y - mapBounds.TopLeft.Y) / GridSize * GridSize + mapBounds.TopLeft.Y,
cellInGrid.Layer); cellInGrid.Layer);
} }

View File

@@ -223,8 +223,8 @@ namespace OpenRA.Mods.Common.Traits
bool HasSufficientPowerForActor(ActorInfo actorInfo) bool HasSufficientPowerForActor(ActorInfo actorInfo)
{ {
return playerPower == null || (actorInfo.TraitInfos<PowerInfo>().Where(i => i.EnabledByDefault) return playerPower == null || actorInfo.TraitInfos<PowerInfo>().Where(i => i.EnabledByDefault)
.Sum(p => p.Amount) + playerPower.ExcessPower) >= baseBuilder.Info.MinimumExcessPower; .Sum(p => p.Amount) + playerPower.ExcessPower >= baseBuilder.Info.MinimumExcessPower;
} }
ActorInfo ChooseBuildingToBuild(ProductionQueue queue) ActorInfo ChooseBuildingToBuild(ProductionQueue queue)

View File

@@ -186,11 +186,11 @@ namespace OpenRA.Mods.Common.Traits
var checkRadius = powerDecision.CoarseScanRadius; var checkRadius = powerDecision.CoarseScanRadius;
var fineCheck = powerDecision.FineScanRadius; var fineCheck = powerDecision.FineScanRadius;
for (var i = 0 - extendedRange; i <= (checkRadius + extendedRange); i += fineCheck) for (var i = 0 - extendedRange; i <= checkRadius + extendedRange; i += fineCheck)
{ {
var x = checkPos.X + i; var x = checkPos.X + i;
for (var j = 0 - extendedRange; j <= (checkRadius + extendedRange); j += fineCheck) for (var j = 0 - extendedRange; j <= checkRadius + extendedRange; j += fineCheck)
{ {
var y = checkPos.Y + j; var y = checkPos.Y + j;
var pos = world.Map.CenterOfCell(new CPos(x, y)); var pos = world.Map.CenterOfCell(new CPos(x, y));

View File

@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits
public override int GetSelectionShares(Actor collector) public override int GetSelectionShares(Actor collector)
{ {
var pr = collector.Owner.PlayerActor.Trait<PlayerResources>(); var pr = collector.Owner.PlayerActor.Trait<PlayerResources>();
if (info.Amount < 0 && (pr.Cash + pr.Resources) == 0) if (info.Amount < 0 && pr.Cash + pr.Resources == 0)
return 0; return 0;
return base.GetSelectionShares(collector); return base.GetSelectionShares(collector);

View File

@@ -185,7 +185,7 @@ namespace OpenRA.Mods.Common.Widgets
var xAxisText = GetXAxisValueFormat().F(n / XAxisTicksPerLabel); var xAxisText = GetXAxisValueFormat().F(n / XAxisTicksPerLabel);
var xAxisTickTextWidth = labelFont.Measure(xAxisText).X; var xAxisTickTextWidth = labelFont.Measure(xAxisText).X;
var xLocation = x - (xAxisTickTextWidth / 2); var xLocation = x - xAxisTickTextWidth / 2;
labelFont.DrawTextWithShadow(xAxisText, graphOrigin + new float2(xLocation, 2), Color.White, BackgroundColorDark, BackgroundColorLight, 1); labelFont.DrawTextWithShadow(xAxisText, graphOrigin + new float2(xLocation, 2), Color.White, BackgroundColorDark, BackgroundColorLight, 1);
} }

View File

@@ -58,8 +58,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
layerPreview.ResourceType = resourceType; layerPreview.ResourceType = resourceType;
layerPreview.Bounds.Width = size.Width; layerPreview.Bounds.Width = size.Width;
layerPreview.Bounds.Height = size.Height; layerPreview.Bounds.Height = size.Height;
newResourcePreviewTemplate.Bounds.Width = size.Width + (layerPreview.Bounds.X * 2); newResourcePreviewTemplate.Bounds.Width = size.Width + layerPreview.Bounds.X * 2;
newResourcePreviewTemplate.Bounds.Height = size.Height + (layerPreview.Bounds.Y * 2); newResourcePreviewTemplate.Bounds.Height = size.Height + layerPreview.Bounds.Y * 2;
newResourcePreviewTemplate.IsVisible = () => true; newResourcePreviewTemplate.IsVisible = () => true;
newResourcePreviewTemplate.GetTooltipText = () => resourceType; newResourcePreviewTemplate.GetTooltipText = () => resourceType;

View File

@@ -148,7 +148,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (scrollDown != null) if (scrollDown != null)
{ {
scrollDown.OnClick = palette.ScrollDown; scrollDown.OnClick = palette.ScrollDown;
scrollDown.IsVisible = () => palette.TotalIconCount > (palette.MaxIconRowOffset * palette.Columns); scrollDown.IsVisible = () => palette.TotalIconCount > palette.MaxIconRowOffset * palette.Columns;
scrollDown.IsDisabled = () => !palette.CanScrollDown; scrollDown.IsDisabled = () => !palette.CanScrollDown;
} }
@@ -157,7 +157,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (scrollUp != null) if (scrollUp != null)
{ {
scrollUp.OnClick = palette.ScrollUp; scrollUp.OnClick = palette.ScrollUp;
scrollUp.IsVisible = () => palette.TotalIconCount > (palette.MaxIconRowOffset * palette.Columns); scrollUp.IsVisible = () => palette.TotalIconCount > palette.MaxIconRowOffset * palette.Columns;
scrollUp.IsDisabled = () => !palette.CanScrollUp; scrollUp.IsDisabled = () => !palette.CanScrollUp;
} }
@@ -179,7 +179,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
// Check if icon heights exceed y resolution // Check if icon heights exceed y resolution
var maxItemsHeight = screenHeight - sidebarProductionHeight; var maxItemsHeight = screenHeight - sidebarProductionHeight;
var maxIconRowOffest = (maxItemsHeight / productionPalette.IconSize.Y) - 1; var maxIconRowOffest = maxItemsHeight / productionPalette.IconSize.Y - 1;
productionPalette.MaxIconRowOffset = Math.Min(maxIconRowOffest, productionPalette.MaximumRows); productionPalette.MaxIconRowOffset = Math.Min(maxIconRowOffest, productionPalette.MaximumRows);
} }
} }

View File

@@ -116,7 +116,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ {
var power = actor.TraitInfos<PowerInfo>().Where(i => i.EnabledByDefault).Sum(i => i.Amount); var power = actor.TraitInfos<PowerInfo>().Where(i => i.EnabledByDefault).Sum(i => i.Amount);
powerLabel.Text = power.ToString(); powerLabel.Text = power.ToString();
powerLabel.GetColor = () => ((pm.PowerProvided - pm.PowerDrained) >= -power || power > 0) powerLabel.GetColor = () => (pm.PowerProvided - pm.PowerDrained >= -power || power > 0)
? Color.White : Color.Red; ? Color.White : Color.Red;
powerLabel.Visible = power != 0; powerLabel.Visible = power != 0;
powerIcon.Visible = power != 0; powerIcon.Visible = power != 0;

View File

@@ -843,7 +843,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (game.State == (int)ServerState.WaitingPlayers && !filters.HasFlag(MPGameFilters.Waiting) && game.Players != 0) if (game.State == (int)ServerState.WaitingPlayers && !filters.HasFlag(MPGameFilters.Waiting) && game.Players != 0)
return true; return true;
if ((game.Players + game.Spectators) == 0 && !filters.HasFlag(MPGameFilters.Empty)) if (game.Players + game.Spectators == 0 && !filters.HasFlag(MPGameFilters.Empty))
return true; return true;
if (!game.IsCompatible && !filters.HasFlag(MPGameFilters.Incompatible)) if (!game.IsCompatible && !filters.HasFlag(MPGameFilters.Incompatible))

View File

@@ -372,7 +372,7 @@ namespace OpenRA.Mods.Common.Widgets
var thumbHeight = ContentHeight == 0 ? 0 : Math.Max(MinimumThumbSize, (int)(scrollbarHeight * Math.Min(rb.Height * 1f / ContentHeight, 1f))); var thumbHeight = ContentHeight == 0 ? 0 : Math.Max(MinimumThumbSize, (int)(scrollbarHeight * Math.Min(rb.Height * 1f / ContentHeight, 1f)));
var oldOffset = currentListOffset; var oldOffset = currentListOffset;
var newOffset = currentListOffset + ((int)((lastMouseLocation.Y - mi.Location.Y) * (ContentHeight - rb.Height) * 1f / (scrollbarHeight - thumbHeight))); var newOffset = currentListOffset + (int)((lastMouseLocation.Y - mi.Location.Y) * (ContentHeight - rb.Height) * 1f / (scrollbarHeight - thumbHeight));
newOffset = Math.Min(0, Math.Max(rb.Height - ContentHeight, newOffset)); newOffset = Math.Min(0, Math.Max(rb.Height - ContentHeight, newOffset));
SetListOffset(newOffset, false); SetListOffset(newOffset, false);

View File

@@ -128,7 +128,7 @@ namespace OpenRA.Mods.Common.Widgets
for (var i = 0; i < Ticks; i++) for (var i = 0; i < Ticks; i++)
{ {
var tickPos = new float2( var tickPos = new float2(
trackOrigin + (i * (trackRect.Width - (int)tick.Size.X) / (Ticks - 1)) - tick.Size.X / 2, trackOrigin + i * (trackRect.Width - (int)tick.Size.X) / (Ticks - 1) - tick.Size.X / 2,
trackRect.Bottom); trackRect.Bottom);
WidgetUtils.DrawSprite(tick, tickPos); WidgetUtils.DrawSprite(tick, tickPos);

View File

@@ -584,7 +584,7 @@ namespace OpenRA.Mods.Common.Widgets
var highlightEndX = font.Measure(apparentText.Substring(0, visualSelectionEndIndex)).X; var highlightEndX = font.Measure(apparentText.Substring(0, visualSelectionEndIndex)).X;
WidgetUtils.FillRectWithColor( WidgetUtils.FillRectWithColor(
new Rectangle(textPos.X + highlightStartX, textPos.Y, highlightEndX - highlightStartX, Bounds.Height - (verticalMargin * 2)), TextColorHighlight); new Rectangle(textPos.X + highlightStartX, textPos.Y, highlightEndX - highlightStartX, Bounds.Height - verticalMargin * 2), TextColorHighlight);
} }
var color = var color =

View File

@@ -409,8 +409,8 @@ namespace OpenRA.Mods.D2k.UtilityCommands
{ {
var tileIndex = (int)stream.Position / 4 - 2; var tileIndex = (int)stream.Position / 4 - 2;
var x = (tileIndex % mapSize.Width) + MapCordonWidth; var x = tileIndex % mapSize.Width + MapCordonWidth;
var y = (tileIndex / mapSize.Width) + MapCordonWidth; var y = tileIndex / mapSize.Width + MapCordonWidth;
return new CPos(x, y); return new CPos(x, y);
} }