Aligns the naming conventions defined in editorconfig (dotnet_naming_style, dotnet_naming_symbols, dotnet_naming_rule) which are reported under the IDE1006 rule with the existing StyleCop rules from the SA13XX range. This ensures the two rulesets agree when rejecting and accepting naming conventions within the IDE, with a few edges cases where only one ruleset can enforce the convention. IDE1006 allows use to specify a naming convention for type parameters, const locals and protected readonly fields which SA13XX cannot enforce. Some StyleCop SA13XX rules such as SA1309 'Field names should not begin with underscore' are not possible to enforce with the naming rules of IDE1006. Therefore we enable the IDE1006 as a build time warning to enforce conventions and extend them. We disable SA13XX rules that can now be covered by IDE1006 to avoid double-reporting but leave the remaining SA13XX rules that cover additional cases enabled. We also re-enable the SA1311 rule convention but enforce it via IDE1006, requiring some violations to be fixed or duplication of existing suppressions. Most violations fixes are trivial renames with the following exception. In ActorInitializer.cs, we prefer to make the fields private instead. ValueActorInit provides a publicly accessible property for access and OwnerInit provides a publicly accessible method. Health.cs is adjusted to access the property base instead when overriding. The reflection calls must be adjusted to target the base class specifically, as searching for a private field from the derived class will fail to locate it on the base class. Unused suppressions were removed.
97 lines
3.3 KiB
C#
97 lines
3.3 KiB
C#
#region Copyright & License Information
|
|
/*
|
|
* Copyright 2007-2021 The OpenRA Developers (see AUTHORS)
|
|
* This file is part of OpenRA, which is free software. It is made
|
|
* available to you under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation, either version 3 of
|
|
* the License, or (at your option) any later version. For more
|
|
* information, see COPYING.
|
|
*/
|
|
#endregion
|
|
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using OpenRA.Graphics;
|
|
using OpenRA.Mods.Common.Graphics;
|
|
using OpenRA.Mods.Common.Orders;
|
|
using OpenRA.Primitives;
|
|
|
|
namespace OpenRA.Mods.Common.Traits
|
|
{
|
|
[Desc("Creates a building placement preview based on the map editor actor preview.")]
|
|
public class ActorPreviewPlaceBuildingPreviewInfo : FootprintPlaceBuildingPreviewInfo
|
|
{
|
|
[Desc("Enable the building's idle animation.")]
|
|
public readonly bool Animated = true;
|
|
|
|
[Desc("Custom opacity to apply to the actor preview.")]
|
|
public readonly float PreviewAlpha = 1f;
|
|
|
|
[Desc("Footprint types to draw underneath the actor preview.")]
|
|
public readonly PlaceBuildingCellType FootprintUnderPreview = PlaceBuildingCellType.Valid | PlaceBuildingCellType.LineBuild;
|
|
|
|
[Desc("Footprint types to draw above the actor preview.")]
|
|
public readonly PlaceBuildingCellType FootprintOverPreview = PlaceBuildingCellType.Invalid;
|
|
|
|
protected override IPlaceBuildingPreview CreatePreview(WorldRenderer wr, ActorInfo ai, TypeDictionary init)
|
|
{
|
|
return new ActorPreviewPlaceBuildingPreviewPreview(wr, ai, this, init);
|
|
}
|
|
|
|
public override object Create(ActorInitializer init)
|
|
{
|
|
return new ActorPreviewPlaceBuildingPreview();
|
|
}
|
|
}
|
|
|
|
public class ActorPreviewPlaceBuildingPreview { }
|
|
|
|
public class ActorPreviewPlaceBuildingPreviewPreview : FootprintPlaceBuildingPreviewPreview
|
|
{
|
|
readonly ActorPreviewPlaceBuildingPreviewInfo info;
|
|
readonly IActorPreview[] preview;
|
|
|
|
public ActorPreviewPlaceBuildingPreviewPreview(WorldRenderer wr, ActorInfo ai, ActorPreviewPlaceBuildingPreviewInfo info, TypeDictionary init)
|
|
: base(wr, ai, info, init)
|
|
{
|
|
this.info = info;
|
|
var previewInit = new ActorPreviewInitializer(ActorInfo, wr, init);
|
|
preview = ActorInfo.TraitInfos<IRenderActorPreviewInfo>()
|
|
.SelectMany(rpi => rpi.RenderPreview(previewInit))
|
|
.ToArray();
|
|
}
|
|
|
|
protected override void TickInner()
|
|
{
|
|
if (!info.Animated)
|
|
return;
|
|
|
|
foreach (var p in preview)
|
|
p.Tick();
|
|
}
|
|
|
|
protected override IEnumerable<IRenderable> RenderInner(WorldRenderer wr, CPos topLeft, Dictionary<CPos, PlaceBuildingCellType> footprint)
|
|
{
|
|
var centerPosition = wr.World.Map.CenterOfCell(topLeft) + CenterOffset;
|
|
var previewRenderables = preview
|
|
.SelectMany(p => p.Render(wr, centerPosition));
|
|
|
|
if (info.FootprintUnderPreview != PlaceBuildingCellType.None)
|
|
foreach (var r in RenderFootprint(wr, topLeft, footprint, info.FootprintUnderPreview))
|
|
yield return r;
|
|
|
|
foreach (var r in previewRenderables.OrderBy(WorldRenderer.RenderableZPositionComparisonKey))
|
|
{
|
|
if (info.PreviewAlpha < 1f && r is IModifyableRenderable mr)
|
|
yield return mr.WithAlpha(mr.Alpha * info.PreviewAlpha);
|
|
else
|
|
yield return r;
|
|
}
|
|
|
|
if (info.FootprintOverPreview != PlaceBuildingCellType.None)
|
|
foreach (var r in RenderFootprint(wr, topLeft, footprint, info.FootprintOverPreview))
|
|
yield return r;
|
|
}
|
|
}
|
|
}
|