From 36660b89e9547b75b10bfee4d589cd5f49c457ea Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Tue, 1 Apr 2025 19:26:19 +0100 Subject: [PATCH] Silence IDE0290. This rule recommends use of primary constructors. Apply the suggestions on simple POCOs, adjusting some to readonly/structs/records at the same time. For more complex classes, the use of primary constructors is more distracting than helpful, so silence the rule. IDEs can still offer fixes for using primary constructors, but it will not show up as a build issue. --- .editorconfig | 2 +- OpenRA.Game/FieldLoader.cs | 5 +- OpenRA.Game/Graphics/Model.cs | 14 +--- OpenRA.Game/Graphics/PlatformInterfaces.cs | 6 -- .../Graphics/RenderPostProcessPassVertex.cs | 23 +----- OpenRA.Game/Graphics/ShaderBindings.cs | 16 +--- OpenRA.Game/Input/IInputHandler.cs | 20 +---- OpenRA.Game/Map/ActorInitializer.cs | 4 +- OpenRA.Game/Map/TileReference.cs | 24 ++---- OpenRA.Game/MiniYaml.cs | 12 +-- OpenRA.Game/PlayerProfile.cs | 16 +--- OpenRA.Game/Scripting/ScriptContext.cs | 34 +++------ OpenRA.Game/Sound/SoundDevice.cs | 12 +-- OpenRA.Game/Support/Benchmark.cs | 12 +-- OpenRA.Game/Support/Log.cs | 12 +-- OpenRA.Game/Traits/LintAttributes.cs | 46 ++++------- OpenRA.Game/Traits/Player/Shroud.cs | 12 +-- OpenRA.Game/Traits/TraitsInterfaces.cs | 11 +-- OpenRA.Game/Traits/World/ScreenMap.cs | 8 +- OpenRA.Game/Widgets/Widget.cs | 12 +-- OpenRA.Game/World.cs | 8 +- OpenRA.Mods.Cnc/FileFormats/VxlReader.cs | 11 +-- OpenRA.Mods.Cnc/Traits/Chronoshiftable.cs | 18 ++--- OpenRA.Mods.Common/ActorInitializer.cs | 36 +++------ .../EditorBrushes/EditorBlit.cs | 30 +------- .../EditorBrushes/EditorResourceBrush.cs | 14 +--- .../EditorBrushes/EditorTileBrush.cs | 14 +--- .../InstallShieldCABCompression.cs | 76 ++++++------------- .../FileSystem/InstallShieldPackage.cs | 12 +-- .../Graphics/DefaultSpriteSequence.cs | 12 +-- OpenRA.Mods.Common/Lint/CheckChromeHotkeys.cs | 8 +- .../Orders/UnitOrderGenerator.cs | 21 ++--- .../ScriptEmmyTypeOverrideAttribute.cs | 12 +-- .../Terrain/DefaultTileCache.cs | 14 +--- .../Traits/Conditions/ExternalCondition.cs | 15 +--- OpenRA.Mods.Common/Traits/Demolishable.cs | 18 ++--- OpenRA.Mods.Common/Traits/LintAttributes.cs | 12 +-- .../Traits/Modifiers/FrozenUnderFog.cs | 8 +- .../SupportPowers/SelectDirectionalTarget.cs | 14 +--- OpenRA.Mods.Common/Traits/World/Locomotor.cs | 14 +--- .../Traits/World/MarkerLayerOverlay.cs | 12 +-- .../Traits/World/ResourceLayer.cs | 12 +-- .../Traits/World/ShroudRenderer.cs | 12 +-- .../Traits/World/TerrainLighting.cs | 21 ++--- .../Traits/World/WarheadDebugOverlay.cs | 18 ++--- .../UtilityCommands/ExtractChromeStrings.cs | 21 ++--- .../UtilityCommands/ExtractYamlStrings.cs | 21 ++--- OpenRA.Mods.Common/Widgets/LineGraphWidget.cs | 14 +--- .../Logic/Editor/ActorSelectorLogic.cs | 16 +--- .../Widgets/Logic/Editor/SaveMapLogic.cs | 14 +--- .../Widgets/Logic/Lobby/LobbyUtils.cs | 27 +------ .../PackageLoaders/D2kSoundResources.cs | 12 +-- 52 files changed, 161 insertions(+), 707 deletions(-) diff --git a/.editorconfig b/.editorconfig index b7b73db086..af8c093926 100644 --- a/.editorconfig +++ b/.editorconfig @@ -72,7 +72,7 @@ dotnet_diagnostic.IDE0211.severity = warning # IDE0290 Use primary constructor #csharp_style_prefer_primary_constructors = true -dotnet_diagnostic.IDE0290.severity = suggestion # TODO: Consider enabling +dotnet_diagnostic.IDE0290.severity = silent # IDE0330 Prefer 'System.Threading.Lock' #csharp_prefer_system_threading_lock = true diff --git a/OpenRA.Game/FieldLoader.cs b/OpenRA.Game/FieldLoader.cs index c81a71a9a8..c65623d8c9 100644 --- a/OpenRA.Game/FieldLoader.cs +++ b/OpenRA.Game/FieldLoader.cs @@ -841,9 +841,8 @@ namespace OpenRA // Mirrors DescriptionAttribute from System.ComponentModel but we don't want to have to use that everywhere. [AttributeUsage(AttributeTargets.All)] - public sealed class DescAttribute : Attribute + public sealed class DescAttribute(params string[] lines) : Attribute { - public readonly string[] Lines; - public DescAttribute(params string[] lines) { Lines = lines; } + public readonly string[] Lines = lines; } } diff --git a/OpenRA.Game/Graphics/Model.cs b/OpenRA.Game/Graphics/Model.cs index b49e0e5d91..362cf34dee 100644 --- a/OpenRA.Game/Graphics/Model.cs +++ b/OpenRA.Game/Graphics/Model.cs @@ -37,19 +37,7 @@ namespace OpenRA.Graphics Func getScale, Func getVoxel, Func getRotation); } - public readonly struct ModelRenderData - { - public readonly int Start; - public readonly int Count; - public readonly Sheet Sheet; - - public ModelRenderData(int start, int count, Sheet sheet) - { - Start = start; - Count = count; - Sheet = sheet; - } - } + public readonly record struct ModelRenderData(int Start, int Count, Sheet Sheet); public interface IModelCacheInfo : ITraitInfoInterface { } diff --git a/OpenRA.Game/Graphics/PlatformInterfaces.cs b/OpenRA.Game/Graphics/PlatformInterfaces.cs index f9aa7c5f89..fd31b6409a 100644 --- a/OpenRA.Game/Graphics/PlatformInterfaces.cs +++ b/OpenRA.Game/Graphics/PlatformInterfaces.cs @@ -179,12 +179,6 @@ namespace OpenRA TriangleList, } - public readonly struct Range - { - public readonly T Start, End; - public Range(T start, T end) { Start = start; End = end; } - } - public enum WindowMode { Windowed, diff --git a/OpenRA.Game/Graphics/RenderPostProcessPassVertex.cs b/OpenRA.Game/Graphics/RenderPostProcessPassVertex.cs index 364b2c9c05..abea0d223f 100644 --- a/OpenRA.Game/Graphics/RenderPostProcessPassVertex.cs +++ b/OpenRA.Game/Graphics/RenderPostProcessPassVertex.cs @@ -14,29 +14,10 @@ using System.Runtime.InteropServices; namespace OpenRA.Graphics { [StructLayout(LayoutKind.Sequential)] - public readonly struct RenderPostProcessPassVertex - { - public readonly float X, Y; - - public RenderPostProcessPassVertex(float x, float y) - { - X = x; Y = y; - } - } + public readonly record struct RenderPostProcessPassVertex(float X, float Y); [StructLayout(LayoutKind.Sequential)] - public readonly struct RenderPostProcessPassTexturedVertex - { - // 3d position - public readonly float X, Y; - public readonly float S, T; - - public RenderPostProcessPassTexturedVertex(float x, float y, float s, float t) - { - X = x; Y = y; - S = s; T = t; - } - } + public readonly record struct RenderPostProcessPassTexturedVertex(float X, float Y, float S, float T); public sealed class RenderPostProcessPassShaderBindings : ShaderBindings { diff --git a/OpenRA.Game/Graphics/ShaderBindings.cs b/OpenRA.Game/Graphics/ShaderBindings.cs index 6e11b3a63d..1c3f854e2c 100644 --- a/OpenRA.Game/Graphics/ShaderBindings.cs +++ b/OpenRA.Game/Graphics/ShaderBindings.cs @@ -23,21 +23,7 @@ namespace OpenRA.Graphics UInt = 0x1405 // GL_UNSIGNED_INT } - public readonly struct ShaderVertexAttribute - { - public readonly string Name; - public readonly ShaderVertexAttributeType Type; - public readonly int Components; - public readonly int Offset; - - public ShaderVertexAttribute(string name, ShaderVertexAttributeType type, int components, int offset) - { - Name = name; - Type = type; - Components = components; - Offset = offset; - } - } + public readonly record struct ShaderVertexAttribute(string Name, ShaderVertexAttributeType Type, int Components, int Offset); public abstract class ShaderBindings : IShaderBindings { diff --git a/OpenRA.Game/Input/IInputHandler.cs b/OpenRA.Game/Input/IInputHandler.cs index 0470c5f239..01d64a087d 100644 --- a/OpenRA.Game/Input/IInputHandler.cs +++ b/OpenRA.Game/Input/IInputHandler.cs @@ -23,25 +23,7 @@ namespace OpenRA } public enum MouseInputEvent { Down, Move, Up, Scroll } - public struct MouseInput - { - public MouseInputEvent Event; - public MouseButton Button; - public int2 Location; - public int2 Delta; - public Modifiers Modifiers; - public int MultiTapCount; - - public MouseInput(MouseInputEvent ev, MouseButton button, int2 location, int2 delta, Modifiers mods, int multiTapCount) - { - Event = ev; - Button = button; - Location = location; - Delta = delta; - Modifiers = mods; - MultiTapCount = multiTapCount; - } - } + public record struct MouseInput(MouseInputEvent Event, MouseButton Button, int2 Location, int2 Delta, Modifiers Modifiers, int MultiTapCount); [Flags] public enum MouseButton diff --git a/OpenRA.Game/Map/ActorInitializer.cs b/OpenRA.Game/Map/ActorInitializer.cs index 7382fca43a..fa8e9711c8 100644 --- a/OpenRA.Game/Map/ActorInitializer.cs +++ b/OpenRA.Game/Map/ActorInitializer.cs @@ -216,10 +216,8 @@ namespace OpenRA } } - public class LocationInit : ValueActorInit, ISingleInstanceInit + public class LocationInit(CPos value) : ValueActorInit(value), ISingleInstanceInit { - public LocationInit(CPos value) - : base(value) { } } public class OwnerInit : ActorInit, ISingleInstanceInit diff --git a/OpenRA.Game/Map/TileReference.cs b/OpenRA.Game/Map/TileReference.cs index 1d3c44d4a1..7a687dbc48 100644 --- a/OpenRA.Game/Map/TileReference.cs +++ b/OpenRA.Game/Map/TileReference.cs @@ -11,16 +11,10 @@ namespace OpenRA { - public readonly struct TerrainTile + public readonly struct TerrainTile(ushort type, byte index) { - public readonly ushort Type; - public readonly byte Index; - - public TerrainTile(ushort type, byte index) - { - Type = type; - Index = index; - } + public readonly ushort Type = type; + public readonly byte Index = index; public override int GetHashCode() { return Type.GetHashCode() ^ Index.GetHashCode(); } @@ -42,16 +36,10 @@ namespace OpenRA } } - public readonly struct ResourceTile + public readonly struct ResourceTile(byte type, byte index) { - public readonly byte Type; - public readonly byte Index; - - public ResourceTile(byte type, byte index) - { - Type = type; - Index = index; - } + public readonly byte Type = type; + public readonly byte Index = index; public override int GetHashCode() { return Type.GetHashCode() ^ Index.GetHashCode(); } } diff --git a/OpenRA.Game/MiniYaml.cs b/OpenRA.Game/MiniYaml.cs index d368190f18..b8b70f662b 100644 --- a/OpenRA.Game/MiniYaml.cs +++ b/OpenRA.Game/MiniYaml.cs @@ -59,16 +59,10 @@ namespace OpenRA public sealed class MiniYamlNode { - public readonly struct SourceLocation + public readonly struct SourceLocation(string name, int line) { - public readonly string Name; - public readonly int Line; - - public SourceLocation(string name, int line) - { - Name = name; - Line = line; - } + public readonly string Name = name; + public readonly int Line = line; public override string ToString() { return $"{Name}:{Line}"; } } diff --git a/OpenRA.Game/PlayerProfile.cs b/OpenRA.Game/PlayerProfile.cs index b9a74a8efd..9a8dbb7767 100644 --- a/OpenRA.Game/PlayerProfile.cs +++ b/OpenRA.Game/PlayerProfile.cs @@ -54,19 +54,5 @@ namespace OpenRA } } - public class PlayerBadge - { - public readonly string Label; - public readonly string Icon; - public readonly string Icon2x; - public readonly string Icon3x; - - public PlayerBadge(string label, string icon, string icon2x, string icon3x) - { - Label = label; - Icon = icon; - Icon2x = icon2x; - Icon3x = icon3x; - } - } + public record PlayerBadge(string Label, string Icon, string Icon2x, string Icon3x); } diff --git a/OpenRA.Game/Scripting/ScriptContext.cs b/OpenRA.Game/Scripting/ScriptContext.cs index fd7480e561..3d8500aeeb 100644 --- a/OpenRA.Game/Scripting/ScriptContext.cs +++ b/OpenRA.Game/Scripting/ScriptContext.cs @@ -33,10 +33,9 @@ namespace OpenRA.Scripting // For traitinfos that provide actor / player commands [AttributeUsage(AttributeTargets.Class)] - public sealed class ScriptPropertyGroupAttribute : Attribute + public sealed class ScriptPropertyGroupAttribute(string category) : Attribute { - public readonly string Category; - public ScriptPropertyGroupAttribute(string category) { Category = category; } + public readonly string Category = category; } // For property groups that are safe to initialize invoke on destroyed actors @@ -46,28 +45,16 @@ namespace OpenRA.Scripting [AttributeUsage(AttributeTargets.Property | AttributeTargets.Method)] public sealed class ScriptActorPropertyActivityAttribute : Attribute { } - public abstract class ScriptActorProperties + public abstract class ScriptActorProperties(ScriptContext context, Actor self) { - protected readonly Actor Self; - protected readonly ScriptContext Context; - - protected ScriptActorProperties(ScriptContext context, Actor self) - { - Self = self; - Context = context; - } + protected readonly Actor Self = self; + protected readonly ScriptContext Context = context; } - public abstract class ScriptPlayerProperties + public abstract class ScriptPlayerProperties(ScriptContext context, Player player) { - protected readonly Player Player; - protected readonly ScriptContext Context; - - protected ScriptPlayerProperties(ScriptContext context, Player player) - { - Player = player; - Context = context; - } + protected readonly Player Player = player; + protected readonly ScriptContext Context = context; } /// @@ -124,10 +111,9 @@ namespace OpenRA.Scripting } [AttributeUsage(AttributeTargets.Class)] - public sealed class ScriptGlobalAttribute : Attribute + public sealed class ScriptGlobalAttribute(string name) : Attribute { - public readonly string Name; - public ScriptGlobalAttribute(string name) { Name = name; } + public readonly string Name = name; } public sealed class ScriptContext : IDisposable diff --git a/OpenRA.Game/Sound/SoundDevice.cs b/OpenRA.Game/Sound/SoundDevice.cs index 6f1ba86f18..5cf8fd4174 100644 --- a/OpenRA.Game/Sound/SoundDevice.cs +++ b/OpenRA.Game/Sound/SoundDevice.cs @@ -32,17 +32,7 @@ namespace OpenRA void SetSoundPosition(ISound sound, WPos position); } - public class SoundDevice - { - public readonly string Device; - public readonly string Label; - - public SoundDevice(string device, string label) - { - Device = device; - Label = label; - } - } + public record SoundDevice(string Device, string Label); public interface ISoundSource : IDisposable { } diff --git a/OpenRA.Game/Support/Benchmark.cs b/OpenRA.Game/Support/Benchmark.cs index 9dba345f07..6eaa71e3db 100644 --- a/OpenRA.Game/Support/Benchmark.cs +++ b/OpenRA.Game/Support/Benchmark.cs @@ -30,17 +30,7 @@ namespace OpenRA.Support samples.GetOrAdd(item.Key).Add(new BenchmarkPoint(localTick, item.Value.LastValue)); } - sealed class BenchmarkPoint - { - public int Tick { get; } - public double Value { get; } - - public BenchmarkPoint(int tick, double value) - { - Tick = tick; - Value = value; - } - } + readonly record struct BenchmarkPoint(int Tick, double Value); public void Write() { diff --git a/OpenRA.Game/Support/Log.cs b/OpenRA.Game/Support/Log.cs index 037d99f328..ec56ecc05c 100644 --- a/OpenRA.Game/Support/Log.cs +++ b/OpenRA.Game/Support/Log.cs @@ -26,17 +26,7 @@ namespace OpenRA public TextWriter Writer; } - readonly struct ChannelData - { - public readonly string Channel; - public readonly string Text; - - public ChannelData(string channel, string text) - { - Text = text; - Channel = channel; - } - } + readonly record struct ChannelData(string Channel, string Text); public static class Log { diff --git a/OpenRA.Game/Traits/LintAttributes.cs b/OpenRA.Game/Traits/LintAttributes.cs index b631fd2a99..446341daa3 100644 --- a/OpenRA.Game/Traits/LintAttributes.cs +++ b/OpenRA.Game/Traits/LintAttributes.cs @@ -46,33 +46,21 @@ namespace OpenRA.Traits public sealed class WeaponReferenceAttribute : Attribute { } [AttributeUsage(AttributeTargets.Field)] - public sealed class SequenceReferenceAttribute : Attribute + public sealed class SequenceReferenceAttribute( + string imageReference = null, bool prefix = false, bool allowNullImage = false, + LintDictionaryReference dictionaryReference = LintDictionaryReference.None) : Attribute { // The field name in the same trait info that contains the image name. - public readonly string ImageReference; - public readonly bool Prefix; - public readonly bool AllowNullImage; - public readonly LintDictionaryReference DictionaryReference; - - public SequenceReferenceAttribute(string imageReference = null, bool prefix = false, bool allowNullImage = false, - LintDictionaryReference dictionaryReference = LintDictionaryReference.None) - { - ImageReference = imageReference; - Prefix = prefix; - AllowNullImage = allowNullImage; - DictionaryReference = dictionaryReference; - } + public readonly string ImageReference = imageReference; + public readonly bool Prefix = prefix; + public readonly bool AllowNullImage = allowNullImage; + public readonly LintDictionaryReference DictionaryReference = dictionaryReference; } [AttributeUsage(AttributeTargets.Field)] - public sealed class CursorReferenceAttribute : Attribute + public sealed class CursorReferenceAttribute(LintDictionaryReference dictionaryReference = LintDictionaryReference.None) : Attribute { - public readonly LintDictionaryReference DictionaryReference; - - public CursorReferenceAttribute(LintDictionaryReference dictionaryReference = LintDictionaryReference.None) - { - DictionaryReference = dictionaryReference; - } + public readonly LintDictionaryReference DictionaryReference = dictionaryReference; } [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] @@ -82,13 +70,9 @@ namespace OpenRA.Traits public sealed class ConsumedConditionReferenceAttribute : Attribute { } [AttributeUsage(AttributeTargets.Field)] - public sealed class PaletteDefinitionAttribute : Attribute + public sealed class PaletteDefinitionAttribute(bool isPlayerPalette = false) : Attribute { - public readonly bool IsPlayerPalette; - public PaletteDefinitionAttribute(bool isPlayerPalette = false) - { - IsPlayerPalette = isPlayerPalette; - } + public readonly bool IsPlayerPalette = isPlayerPalette; } [AttributeUsage(AttributeTargets.Field)] @@ -108,12 +92,8 @@ namespace OpenRA.Traits } [AttributeUsage(AttributeTargets.Class)] - public sealed class TraitLocationAttribute : Attribute + public sealed class TraitLocationAttribute(SystemActors systemActors) : Attribute { - public readonly SystemActors SystemActors; - public TraitLocationAttribute(SystemActors systemActors) - { - SystemActors = systemActors; - } + public readonly SystemActors SystemActors = systemActors; } } diff --git a/OpenRA.Game/Traits/Player/Shroud.cs b/OpenRA.Game/Traits/Player/Shroud.cs index 3e850385a2..2da8fb685e 100644 --- a/OpenRA.Game/Traits/Player/Shroud.cs +++ b/OpenRA.Game/Traits/Player/Shroud.cs @@ -76,17 +76,7 @@ namespace OpenRA.Traits public int RevealedCells { get; private set; } enum ShroudCellType : byte { Shroud, Fog, Visible } - sealed class ShroudSource - { - public readonly SourceType Type; - public readonly PPos[] ProjectedCells; - - public ShroudSource(SourceType type, PPos[] projectedCells) - { - Type = type; - ProjectedCells = projectedCells; - } - } + readonly record struct ShroudSource(SourceType Type, PPos[] ProjectedCells); // Visible is not a super set of Explored. IsExplored may return false even if IsVisible returns true. [Flags] diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index b4c34e70fd..91f062abf0 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -628,16 +628,7 @@ namespace OpenRA.Traits public interface IObservesVariablesInfo : ITraitInfoInterface { } public delegate void VariableObserverNotifier(Actor self, IReadOnlyDictionary variables); - public struct VariableObserver - { - public VariableObserverNotifier Notifier; - public IEnumerable Variables; - public VariableObserver(VariableObserverNotifier notifier, IEnumerable variables) - { - Notifier = notifier; - Variables = variables; - } - } + public readonly record struct VariableObserver(VariableObserverNotifier Notifier, IEnumerable Variables); public interface IObservesVariables { diff --git a/OpenRA.Game/Traits/World/ScreenMap.cs b/OpenRA.Game/Traits/World/ScreenMap.cs index 204e47c188..0cfd92905f 100644 --- a/OpenRA.Game/Traits/World/ScreenMap.cs +++ b/OpenRA.Game/Traits/World/ScreenMap.cs @@ -18,12 +18,10 @@ using OpenRA.Primitives; namespace OpenRA.Traits { - public readonly struct ActorBoundsPair + public readonly struct ActorBoundsPair(Actor actor, Polygon bounds) { - public readonly Actor Actor; - public readonly Polygon Bounds; - - public ActorBoundsPair(Actor actor, Polygon bounds) { Actor = actor; Bounds = bounds; } + public readonly Actor Actor = actor; + public readonly Polygon Bounds = bounds; public override int GetHashCode() { return Actor.GetHashCode() ^ Bounds.GetHashCode(); } diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs index c5ea984c5b..b88e4f6a04 100644 --- a/OpenRA.Game/Widgets/Widget.cs +++ b/OpenRA.Game/Widgets/Widget.cs @@ -182,22 +182,14 @@ namespace OpenRA.Widgets protected virtual void Dispose(bool disposing) { } } - public struct WidgetBounds + public struct WidgetBounds(int x, int y, int width, int height) { - public int X, Y, Width, Height; + public int X = x, Y = y, Width = width, Height = height; public readonly int Left => X; public readonly int Right => X + Width; public readonly int Top => Y; public readonly int Bottom => Y + Height; - public WidgetBounds(int x, int y, int width, int height) - { - X = x; - Y = y; - Width = width; - Height = height; - } - public readonly Rectangle ToRectangle() { return new Rectangle(X, Y, Width, Height); diff --git a/OpenRA.Game/World.cs b/OpenRA.Game/World.cs index 421ede47e9..a159f5496b 100644 --- a/OpenRA.Game/World.cs +++ b/OpenRA.Game/World.cs @@ -635,12 +635,10 @@ namespace OpenRA } } - public readonly struct TraitPair : IEquatable> + public readonly struct TraitPair(Actor actor, T trait) : IEquatable> { - public readonly Actor Actor; - public readonly T Trait; - - public TraitPair(Actor actor, T trait) { Actor = actor; Trait = trait; } + public readonly Actor Actor = actor; + public readonly T Trait = trait; public static bool operator ==(TraitPair me, TraitPair other) { return me.Actor == other.Actor && Equals(me.Trait, other.Trait); } public static bool operator !=(TraitPair me, TraitPair other) { return !(me == other); } diff --git a/OpenRA.Mods.Cnc/FileFormats/VxlReader.cs b/OpenRA.Mods.Cnc/FileFormats/VxlReader.cs index f09608de7a..5a141c4ae5 100644 --- a/OpenRA.Mods.Cnc/FileFormats/VxlReader.cs +++ b/OpenRA.Mods.Cnc/FileFormats/VxlReader.cs @@ -16,16 +16,7 @@ using System.IO; namespace OpenRA.Mods.Cnc.FileFormats { public enum NormalType : byte { TiberianSun = 2, RedAlert2 = 4 } - public readonly struct VxlElement - { - public readonly byte Color; - public readonly byte Normal; - public VxlElement(byte color, byte normal) - { - Color = color; - Normal = normal; - } - } + public readonly record struct VxlElement(byte Color, byte Normal); public class VxlLimb { diff --git a/OpenRA.Mods.Cnc/Traits/Chronoshiftable.cs b/OpenRA.Mods.Cnc/Traits/Chronoshiftable.cs index 7f92aaf3f6..d9c6063ad2 100644 --- a/OpenRA.Mods.Cnc/Traits/Chronoshiftable.cs +++ b/OpenRA.Mods.Cnc/Traits/Chronoshiftable.cs @@ -182,19 +182,11 @@ namespace OpenRA.Mods.Cnc.Traits void ITransformActorInitModifier.ModifyTransformActorInit(Actor self, TypeDictionary init) { ModifyActorInit(init); } } - public class ChronoshiftReturnInit : CompositeActorInit, ISingleInstanceInit + public class ChronoshiftReturnInit(int ticks, int duration, CPos origin, Actor chronosphere) : CompositeActorInit, ISingleInstanceInit { - public readonly int Ticks; - public readonly int Duration; - public readonly CPos Origin; - public readonly ActorInitActorReference Chronosphere; - - public ChronoshiftReturnInit(int ticks, int duration, CPos origin, Actor chronosphere) - { - Ticks = ticks; - Duration = duration; - Origin = origin; - Chronosphere = chronosphere; - } + public readonly int Ticks = ticks; + public readonly int Duration = duration; + public readonly CPos Origin = origin; + public readonly ActorInitActorReference Chronosphere = chronosphere; } } diff --git a/OpenRA.Mods.Common/ActorInitializer.cs b/OpenRA.Mods.Common/ActorInitializer.cs index 3281903381..6f6c523353 100644 --- a/OpenRA.Mods.Common/ActorInitializer.cs +++ b/OpenRA.Mods.Common/ActorInitializer.cs @@ -17,38 +17,26 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common { - public class FacingInit : ValueActorInit, ISingleInstanceInit + public class FacingInit(WAngle value) : ValueActorInit(value), ISingleInstanceInit { - public FacingInit(WAngle value) - : base(value) { } } - public class TerrainOrientationInit : ValueActorInit, ISingleInstanceInit, ISuppressInitExport + public class TerrainOrientationInit(WRot value) : ValueActorInit(value), ISingleInstanceInit, ISuppressInitExport { - public TerrainOrientationInit(WRot value) - : base(value) { } } - public class CreationActivityDelayInit : ValueActorInit, ISingleInstanceInit + public class CreationActivityDelayInit(int value) : ValueActorInit(value), ISingleInstanceInit { - public CreationActivityDelayInit(int value) - : base(value) { } } - public class DynamicFacingInit : ValueActorInit>, ISingleInstanceInit + public class DynamicFacingInit(Func value) : ValueActorInit>(value), ISingleInstanceInit { - public DynamicFacingInit(Func value) - : base(value) { } } // Cannot use ValueInit because map.yaml is expected to use the numeric value instead of enum name - public class SubCellInit : ActorInit, ISingleInstanceInit + public class SubCellInit(SubCell value) : ActorInit, ISingleInstanceInit { - readonly int value; - public SubCellInit(SubCell value) - { - this.value = (int)value; - } + readonly int value = (int)value; public virtual SubCell Value => (SubCell)value; @@ -70,23 +58,17 @@ namespace OpenRA.Mods.Common } } - public class CenterPositionInit : ValueActorInit, ISingleInstanceInit + public class CenterPositionInit(WPos value) : ValueActorInit(value), ISingleInstanceInit { - public CenterPositionInit(WPos value) - : base(value) { } } // Allows maps / transformations to specify the faction variant of an actor. - public class FactionInit : ValueActorInit, ISingleInstanceInit + public class FactionInit(string value) : ValueActorInit(value), ISingleInstanceInit { - public FactionInit(string value) - : base(value) { } } - public class EffectiveOwnerInit : ValueActorInit + public class EffectiveOwnerInit(Player value) : ValueActorInit(value) { - public EffectiveOwnerInit(Player value) - : base(value) { } } sealed class ActorInitLoader : TypeConverter diff --git a/OpenRA.Mods.Common/EditorBrushes/EditorBlit.cs b/OpenRA.Mods.Common/EditorBrushes/EditorBlit.cs index 7472e22cd3..e31313eab6 100644 --- a/OpenRA.Mods.Common/EditorBrushes/EditorBlit.cs +++ b/OpenRA.Mods.Common/EditorBrushes/EditorBlit.cs @@ -16,35 +16,9 @@ using OpenRA.Mods.Common.Traits; namespace OpenRA.Mods.Common.EditorBrushes { - public readonly struct BlitTile - { - public readonly TerrainTile TerrainTile; - public readonly ResourceTile ResourceTile; - public readonly ResourceLayerContents? ResourceLayerContents; - public readonly byte Height; + public readonly record struct BlitTile(TerrainTile TerrainTile, ResourceTile ResourceTile, ResourceLayerContents? ResourceLayerContents, byte Height); - public BlitTile(TerrainTile terrainTile, ResourceTile resourceTile, ResourceLayerContents? resourceLayerContents, byte height) - { - TerrainTile = terrainTile; - ResourceTile = resourceTile; - ResourceLayerContents = resourceLayerContents; - Height = height; - } - } - - public readonly struct EditorBlitSource - { - public readonly CellRegion CellRegion; - public readonly Dictionary Actors; - public readonly Dictionary Tiles; - - public EditorBlitSource(CellRegion cellRegion, Dictionary actors, Dictionary tiles) - { - CellRegion = cellRegion; - Actors = actors; - Tiles = tiles; - } - } + public readonly record struct EditorBlitSource(CellRegion CellRegion, Dictionary Actors, Dictionary Tiles); [Flags] public enum MapBlitFilters diff --git a/OpenRA.Mods.Common/EditorBrushes/EditorResourceBrush.cs b/OpenRA.Mods.Common/EditorBrushes/EditorResourceBrush.cs index 34d30800fc..4a5c4b4b01 100644 --- a/OpenRA.Mods.Common/EditorBrushes/EditorResourceBrush.cs +++ b/OpenRA.Mods.Common/EditorBrushes/EditorResourceBrush.cs @@ -109,19 +109,7 @@ namespace OpenRA.Mods.Common.Widgets public void Dispose() { } } - readonly struct CellResource - { - public readonly CPos Cell; - public readonly ResourceLayerContents OldResourceTile; - public readonly string NewResourceType; - - public CellResource(CPos cell, ResourceLayerContents oldResourceTile, string newResourceType) - { - Cell = cell; - OldResourceTile = oldResourceTile; - NewResourceType = newResourceType; - } - } + readonly record struct CellResource(CPos Cell, ResourceLayerContents OldResourceTile, string NewResourceType); sealed class AddResourcesEditorAction : IEditorAction { diff --git a/OpenRA.Mods.Common/EditorBrushes/EditorTileBrush.cs b/OpenRA.Mods.Common/EditorBrushes/EditorTileBrush.cs index ae7ac039d6..42e20200cf 100644 --- a/OpenRA.Mods.Common/EditorBrushes/EditorTileBrush.cs +++ b/OpenRA.Mods.Common/EditorBrushes/EditorTileBrush.cs @@ -380,17 +380,5 @@ namespace OpenRA.Mods.Common.Widgets } } - sealed class UndoTile - { - public CPos Cell { get; } - public TerrainTile MapTile { get; } - public byte Height { get; } - - public UndoTile(CPos cell, TerrainTile mapTile, byte height) - { - Cell = cell; - MapTile = mapTile; - Height = height; - } - } + sealed record UndoTile(CPos Cell, TerrainTile MapTile, byte Height); } diff --git a/OpenRA.Mods.Common/FileFormats/InstallShieldCABCompression.cs b/OpenRA.Mods.Common/FileFormats/InstallShieldCABCompression.cs index 732ff8f350..37464954a1 100644 --- a/OpenRA.Mods.Common/FileFormats/InstallShieldCABCompression.cs +++ b/OpenRA.Mods.Common/FileFormats/InstallShieldCABCompression.cs @@ -178,68 +178,36 @@ namespace OpenRA.Mods.Common.FileFormats } } - readonly struct CommonHeader + readonly struct CommonHeader(Stream stream) { public const long Size = 16; - public readonly uint Version; - public readonly uint VolumeInfo; - public readonly long CabDescriptorOffset; - public readonly uint CabDescriptorSize; - - public CommonHeader(Stream stream) - { - Version = stream.ReadUInt32(); - VolumeInfo = stream.ReadUInt32(); - CabDescriptorOffset = stream.ReadUInt32(); - CabDescriptorSize = stream.ReadUInt32(); - } + public readonly uint Version = stream.ReadUInt32(); + public readonly uint VolumeInfo = stream.ReadUInt32(); + public readonly long CabDescriptorOffset = stream.ReadUInt32(); + public readonly uint CabDescriptorSize = stream.ReadUInt32(); } - readonly struct VolumeHeader + readonly struct VolumeHeader(Stream stream) { - public readonly uint DataOffset; - public readonly uint DataOffsetHigh; - public readonly uint FirstFileIndex; - public readonly uint LastFileIndex; + public readonly uint DataOffset = stream.ReadUInt32(); + public readonly uint DataOffsetHigh = stream.ReadUInt32(); + public readonly uint FirstFileIndex = stream.ReadUInt32(); + public readonly uint LastFileIndex = stream.ReadUInt32(); - public readonly uint FirstFileOffset; - public readonly uint FirstFileOffsetHigh; - public readonly uint FirstFileSizeExpanded; - public readonly uint FirstFileSizeExpandedHigh; + public readonly uint FirstFileOffset = stream.ReadUInt32(); + public readonly uint FirstFileOffsetHigh = stream.ReadUInt32(); + public readonly uint FirstFileSizeExpanded = stream.ReadUInt32(); + public readonly uint FirstFileSizeExpandedHigh = stream.ReadUInt32(); - public readonly uint FirstFileSizeCompressed; - public readonly uint FirstFileSizeCompressedHigh; - public readonly uint LastFileOffset; - public readonly uint LastFileOffsetHigh; + public readonly uint FirstFileSizeCompressed = stream.ReadUInt32(); + public readonly uint FirstFileSizeCompressedHigh = stream.ReadUInt32(); + public readonly uint LastFileOffset = stream.ReadUInt32(); + public readonly uint LastFileOffsetHigh = stream.ReadUInt32(); - public readonly uint LastFileSizeExpanded; - public readonly uint LastFileSizeExpandedHigh; - public readonly uint LastFileSizeCompressed; - public readonly uint LastFileSizeCompressedHigh; - - public VolumeHeader(Stream stream) - { - DataOffset = stream.ReadUInt32(); - DataOffsetHigh = stream.ReadUInt32(); - - FirstFileIndex = stream.ReadUInt32(); - LastFileIndex = stream.ReadUInt32(); - FirstFileOffset = stream.ReadUInt32(); - FirstFileOffsetHigh = stream.ReadUInt32(); - - FirstFileSizeExpanded = stream.ReadUInt32(); - FirstFileSizeExpandedHigh = stream.ReadUInt32(); - FirstFileSizeCompressed = stream.ReadUInt32(); - FirstFileSizeCompressedHigh = stream.ReadUInt32(); - - LastFileOffset = stream.ReadUInt32(); - LastFileOffsetHigh = stream.ReadUInt32(); - LastFileSizeExpanded = stream.ReadUInt32(); - LastFileSizeExpandedHigh = stream.ReadUInt32(); - - LastFileSizeCompressed = stream.ReadUInt32(); - LastFileSizeCompressedHigh = stream.ReadUInt32(); - } + public readonly uint LastFileSizeExpanded = stream.ReadUInt32(); + public readonly uint LastFileSizeExpandedHigh = stream.ReadUInt32(); + public readonly uint LastFileSizeCompressed = stream.ReadUInt32(); + public readonly uint LastFileSizeCompressedHigh = stream.ReadUInt32(); } sealed class CabExtracter diff --git a/OpenRA.Mods.Common/FileSystem/InstallShieldPackage.cs b/OpenRA.Mods.Common/FileSystem/InstallShieldPackage.cs index e389bb0612..6d74b14b04 100644 --- a/OpenRA.Mods.Common/FileSystem/InstallShieldPackage.cs +++ b/OpenRA.Mods.Common/FileSystem/InstallShieldPackage.cs @@ -22,17 +22,7 @@ namespace OpenRA.Mods.Common.FileSystem { public sealed class InstallShieldPackage : IReadOnlyPackage { - public readonly struct Entry - { - public readonly uint Offset; - public readonly uint Length; - - public Entry(uint offset, uint length) - { - Offset = offset; - Length = length; - } - } + public readonly record struct Entry(uint Offset, uint Length); public string Name { get; } public IEnumerable Contents => index.Keys; diff --git a/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs b/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs index e51126d719..b024964773 100644 --- a/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs +++ b/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs @@ -74,17 +74,7 @@ namespace OpenRA.Mods.Common.Graphics } } - public struct SpriteSequenceField - { - public string Key; - public T DefaultValue; - - public SpriteSequenceField(string key, T defaultValue) - { - Key = key; - DefaultValue = defaultValue; - } - } + public readonly record struct SpriteSequenceField(string Key, T DefaultValue); [Desc("Generic sprite sequence implementation, mostly unencumbered with game- or artwork-specific logic.")] public class DefaultSpriteSequence : ISpriteSequence diff --git a/OpenRA.Mods.Common/Lint/CheckChromeHotkeys.cs b/OpenRA.Mods.Common/Lint/CheckChromeHotkeys.cs index e6b3785f88..1b76801634 100644 --- a/OpenRA.Mods.Common/Lint/CheckChromeHotkeys.cs +++ b/OpenRA.Mods.Common/Lint/CheckChromeHotkeys.cs @@ -18,13 +18,9 @@ using OpenRA.Widgets; namespace OpenRA.Mods.Common.Lint { [AttributeUsage(AttributeTargets.Class)] - public sealed class ChromeLogicArgsHotkeys : Attribute + public sealed class ChromeLogicArgsHotkeys(params string[] logicArgKeys) : Attribute { - public string[] LogicArgKeys; - public ChromeLogicArgsHotkeys(params string[] logicArgKeys) - { - LogicArgKeys = logicArgKeys; - } + public string[] LogicArgKeys = logicArgKeys; } [AttributeUsage(AttributeTargets.Method)] diff --git a/OpenRA.Mods.Common/Orders/UnitOrderGenerator.cs b/OpenRA.Mods.Common/Orders/UnitOrderGenerator.cs index 70847aa2d0..ee5e4a5bae 100644 --- a/OpenRA.Mods.Common/Orders/UnitOrderGenerator.cs +++ b/OpenRA.Mods.Common/Orders/UnitOrderGenerator.cs @@ -190,24 +190,15 @@ namespace OpenRA.Mods.Common.Orders return order; } - protected sealed class UnitOrderResult + protected sealed class UnitOrderResult(Actor actor, IOrderTargeter order, IIssueOrder trait, string cursor, in Target target) { - public readonly Actor Actor; - public readonly IOrderTargeter Order; - public readonly IIssueOrder Trait; - public readonly string Cursor; + public readonly Actor Actor = actor; + public readonly IOrderTargeter Order = order; + public readonly IIssueOrder Trait = trait; + public readonly string Cursor = cursor; public ref readonly Target Target => ref target; - readonly Target target; - - public UnitOrderResult(Actor actor, IOrderTargeter order, IIssueOrder trait, string cursor, in Target target) - { - Actor = actor; - Order = order; - Trait = trait; - Cursor = cursor; - this.target = target; - } + readonly Target target = target; } public virtual bool ClearSelectionOnLeftClick => true; diff --git a/OpenRA.Mods.Common/Scripting/ScriptEmmyTypeOverrideAttribute.cs b/OpenRA.Mods.Common/Scripting/ScriptEmmyTypeOverrideAttribute.cs index 0d64d4517b..8358631c3c 100644 --- a/OpenRA.Mods.Common/Scripting/ScriptEmmyTypeOverrideAttribute.cs +++ b/OpenRA.Mods.Common/Scripting/ScriptEmmyTypeOverrideAttribute.cs @@ -18,15 +18,9 @@ namespace OpenRA.Mods.Common.Scripting /// Used to override the Emmy Lua type generated by the utility command. /// [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.ReturnValue)] - public sealed class ScriptEmmyTypeOverrideAttribute : Attribute + public sealed class ScriptEmmyTypeOverrideAttribute(string typeDeclaration, string genericTypeDeclaration = null) : Attribute { - public readonly string TypeDeclaration; - public readonly string GenericTypeDeclaration; - - public ScriptEmmyTypeOverrideAttribute(string typeDeclaration, string genericTypeDeclaration = null) - { - TypeDeclaration = typeDeclaration; - GenericTypeDeclaration = genericTypeDeclaration; - } + public readonly string TypeDeclaration = typeDeclaration; + public readonly string GenericTypeDeclaration = genericTypeDeclaration; } } diff --git a/OpenRA.Mods.Common/Terrain/DefaultTileCache.cs b/OpenRA.Mods.Common/Terrain/DefaultTileCache.cs index 50df31ba36..6674f0ebba 100644 --- a/OpenRA.Mods.Common/Terrain/DefaultTileCache.cs +++ b/OpenRA.Mods.Common/Terrain/DefaultTileCache.cs @@ -19,19 +19,7 @@ using OpenRA.Support; namespace OpenRA.Mods.Common.Terrain { - public class TheaterTemplate - { - public readonly Sprite[] Sprites; - public readonly int Stride; - public readonly int Variants; - - public TheaterTemplate(Sprite[] sprites, int stride, int variants) - { - Sprites = sprites; - Stride = stride; - Variants = variants; - } - } + public record TheaterTemplate(Sprite[] Sprites, int Stride, int Variants); public sealed class DefaultTileCache : IDisposable { diff --git a/OpenRA.Mods.Common/Traits/Conditions/ExternalCondition.cs b/OpenRA.Mods.Common/Traits/Conditions/ExternalCondition.cs index 087f677a88..d701fd6ca9 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/ExternalCondition.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/ExternalCondition.cs @@ -40,18 +40,11 @@ namespace OpenRA.Mods.Common.Traits public class ExternalCondition : ITick, INotifyCreated, INotifyOwnerChanged { - readonly struct TimedToken + readonly struct TimedToken(int token, Actor self, object source, int duration) { - public readonly int Expires; - public readonly int Token; - public readonly object Source; - - public TimedToken(int token, Actor self, object source, int duration) - { - Token = token; - Expires = self.World.WorldTick + duration; - Source = source; - } + public readonly int Expires = self.World.WorldTick + duration; + public readonly int Token = token; + public readonly object Source = source; } public readonly ExternalConditionInfo Info; diff --git a/OpenRA.Mods.Common/Traits/Demolishable.cs b/OpenRA.Mods.Common/Traits/Demolishable.cs index 067aa4148c..f58466e0c1 100644 --- a/OpenRA.Mods.Common/Traits/Demolishable.cs +++ b/OpenRA.Mods.Common/Traits/Demolishable.cs @@ -30,20 +30,12 @@ namespace OpenRA.Mods.Common.Traits public class Demolishable : ConditionalTrait, IDemolishable, ITick, INotifyOwnerChanged { - sealed class DemolishAction + sealed class DemolishAction(Actor saboteur, int delay, int token, BitSet damageTypes) { - public readonly Actor Saboteur; - public readonly int Token; - public int Delay; - public readonly BitSet DamageTypes; - - public DemolishAction(Actor saboteur, int delay, int token, BitSet damageTypes) - { - Saboteur = saboteur; - Delay = delay; - Token = token; - DamageTypes = damageTypes; - } + public readonly Actor Saboteur = saboteur; + public readonly int Token = token; + public int Delay = delay; + public readonly BitSet DamageTypes = damageTypes; } readonly List actions = []; diff --git a/OpenRA.Mods.Common/Traits/LintAttributes.cs b/OpenRA.Mods.Common/Traits/LintAttributes.cs index aee3d0dae4..7f2b72d063 100644 --- a/OpenRA.Mods.Common/Traits/LintAttributes.cs +++ b/OpenRA.Mods.Common/Traits/LintAttributes.cs @@ -23,15 +23,9 @@ namespace OpenRA.Mods.Common.Traits public sealed class LocomotorReferenceAttribute : Attribute { } [AttributeUsage(AttributeTargets.Field)] - public sealed class NotificationReferenceAttribute : Attribute + public sealed class NotificationReferenceAttribute(string type = null, string typeFromField = null) : Attribute { - public readonly string NotificationTypeFieldName = null; - public readonly string NotificationType = null; - - public NotificationReferenceAttribute(string type = null, string typeFromField = null) - { - NotificationType = type; - NotificationTypeFieldName = typeFromField; - } + public readonly string NotificationTypeFieldName = typeFromField; + public readonly string NotificationType = type; } } diff --git a/OpenRA.Mods.Common/Traits/Modifiers/FrozenUnderFog.cs b/OpenRA.Mods.Common/Traits/Modifiers/FrozenUnderFog.cs index ccbc2254fa..5a676b54fd 100644 --- a/OpenRA.Mods.Common/Traits/Modifiers/FrozenUnderFog.cs +++ b/OpenRA.Mods.Common/Traits/Modifiers/FrozenUnderFog.cs @@ -40,14 +40,10 @@ namespace OpenRA.Mods.Common.Traits bool isRendering; bool created; - sealed class FrozenState + sealed class FrozenState(FrozenActor frozenActor) { - public readonly FrozenActor FrozenActor; + public readonly FrozenActor FrozenActor = frozenActor; public bool IsVisible; - public FrozenState(FrozenActor frozenActor) - { - FrozenActor = frozenActor; - } } public FrozenUnderFog(ActorInitializer init, FrozenUnderFogInfo info) diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/SelectDirectionalTarget.cs b/OpenRA.Mods.Common/Traits/SupportPowers/SelectDirectionalTarget.cs index 2e23705f0c..e82400d4b1 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/SelectDirectionalTarget.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/SelectDirectionalTarget.cs @@ -170,18 +170,6 @@ namespace OpenRA.Mods.Common.Traits return points; } - sealed class Arrow - { - public Sprite Sprite { get; } - public double EndAngle { get; } - public WAngle Direction { get; } - - public Arrow(Sprite sprite, double endAngle, WAngle direction) - { - Sprite = sprite; - EndAngle = endAngle; - Direction = direction; - } - } + sealed record Arrow(Sprite Sprite, double EndAngle, WAngle Direction); } } diff --git a/OpenRA.Mods.Common/Traits/World/Locomotor.cs b/OpenRA.Mods.Common/Traits/World/Locomotor.cs index 987c4c080f..ab692a16a6 100644 --- a/OpenRA.Mods.Common/Traits/World/Locomotor.cs +++ b/OpenRA.Mods.Common/Traits/World/Locomotor.cs @@ -130,19 +130,7 @@ namespace OpenRA.Mods.Common.Traits public class Locomotor : IWorldLoaded { - readonly struct CellCache - { - public readonly LongBitSet Immovable; - public readonly LongBitSet Crushable; - public readonly CellFlag CellFlag; - - public CellCache(LongBitSet immovable, CellFlag cellFlag, LongBitSet crushable) - { - Immovable = immovable; - Crushable = crushable; - CellFlag = cellFlag; - } - } + readonly record struct CellCache(LongBitSet Immovable, CellFlag CellFlag, LongBitSet Crushable); public readonly LocomotorInfo Info; diff --git a/OpenRA.Mods.Common/Traits/World/MarkerLayerOverlay.cs b/OpenRA.Mods.Common/Traits/World/MarkerLayerOverlay.cs index e8b10b4a1a..88bb6fee66 100644 --- a/OpenRA.Mods.Common/Traits/World/MarkerLayerOverlay.cs +++ b/OpenRA.Mods.Common/Traits/World/MarkerLayerOverlay.cs @@ -378,17 +378,7 @@ namespace OpenRA.Mods.Common.Traits disposed = true; } - readonly struct MapLine - { - public readonly float2 Start; - public readonly float2 End; - - public MapLine(float2 start, float2 end) - { - Start = start; - End = end; - } - } + readonly record struct MapLine(float2 Start, float2 End); IEnumerable IRenderAnnotations.RenderAnnotations(Actor self, WorldRenderer wr) { diff --git a/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs b/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs index 9ebf3414a4..bdd03a0471 100644 --- a/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs @@ -17,17 +17,11 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { - public readonly struct ResourceLayerContents + public readonly struct ResourceLayerContents(string type, int density) { public static readonly ResourceLayerContents Empty = default; - public readonly string Type; - public readonly int Density; - - public ResourceLayerContents(string type, int density) - { - Type = type; - Density = density; - } + public readonly string Type = type; + public readonly int Density = density; } [TraitLocation(SystemActors.World)] diff --git a/OpenRA.Mods.Common/Traits/World/ShroudRenderer.cs b/OpenRA.Mods.Common/Traits/World/ShroudRenderer.cs index d657466dfd..6d0cd33b75 100644 --- a/OpenRA.Mods.Common/Traits/World/ShroudRenderer.cs +++ b/OpenRA.Mods.Common/Traits/World/ShroudRenderer.cs @@ -94,16 +94,10 @@ namespace OpenRA.Mods.Common.Traits BottomLeft } - readonly struct TileInfo + readonly struct TileInfo(in float3 screenPosition, byte variant) { - public readonly float3 ScreenPosition; - public readonly byte Variant; - - public TileInfo(in float3 screenPosition, byte variant) - { - ScreenPosition = screenPosition; - Variant = variant; - } + public readonly float3 ScreenPosition = screenPosition; + public readonly byte Variant = variant; } readonly ShroudRendererInfo info; diff --git a/OpenRA.Mods.Common/Traits/World/TerrainLighting.cs b/OpenRA.Mods.Common/Traits/World/TerrainLighting.cs index ea63f7c835..ecdd6d83b5 100644 --- a/OpenRA.Mods.Common/Traits/World/TerrainLighting.cs +++ b/OpenRA.Mods.Common/Traits/World/TerrainLighting.cs @@ -35,22 +35,13 @@ namespace OpenRA.Mods.Common.Traits public sealed class TerrainLighting : ITerrainLighting { - sealed class LightSource + sealed class LightSource(WPos pos, CPos cell, WDist range, float intensity, in float3 tint) { - public readonly WPos Pos; - public readonly CPos Cell; - public readonly WDist Range; - public readonly float Intensity; - public readonly float3 Tint; - - public LightSource(WPos pos, CPos cell, WDist range, float intensity, in float3 tint) - { - Pos = pos; - Cell = cell; - Range = range; - Intensity = intensity; - Tint = tint; - } + public readonly WPos Pos = pos; + public readonly CPos Cell = cell; + public readonly WDist Range = range; + public readonly float Intensity = intensity; + public readonly float3 Tint = tint; } readonly TerrainLightingInfo info; diff --git a/OpenRA.Mods.Common/Traits/World/WarheadDebugOverlay.cs b/OpenRA.Mods.Common/Traits/World/WarheadDebugOverlay.cs index a138e7c689..bf92016417 100644 --- a/OpenRA.Mods.Common/Traits/World/WarheadDebugOverlay.cs +++ b/OpenRA.Mods.Common/Traits/World/WarheadDebugOverlay.cs @@ -28,22 +28,14 @@ namespace OpenRA.Mods.Common.Traits public class WarheadDebugOverlay : IRenderAnnotations { - sealed class WHImpact + sealed class WHImpact(WPos pos, WDist[] range, int time, Color color) { - public readonly WPos CenterPosition; - public readonly WDist[] Range; - public readonly Color Color; - public int Time; + public readonly WPos CenterPosition = pos; + public readonly WDist[] Range = range; + public readonly Color Color = color; + public int Time = time; public WDist OuterRange => Range[^1]; - - public WHImpact(WPos pos, WDist[] range, int time, Color color) - { - CenterPosition = pos; - Range = range; - Color = color; - Time = time; - } } readonly WarheadDebugOverlayInfo info; diff --git a/OpenRA.Mods.Common/UtilityCommands/ExtractChromeStrings.cs b/OpenRA.Mods.Common/UtilityCommands/ExtractChromeStrings.cs index 3f189b6434..9069097d46 100644 --- a/OpenRA.Mods.Common/UtilityCommands/ExtractChromeStrings.cs +++ b/OpenRA.Mods.Common/UtilityCommands/ExtractChromeStrings.cs @@ -200,22 +200,13 @@ namespace OpenRA.Mods.Common.UtilityCommands } } - struct ExtractionCandidate + struct ExtractionCandidate(string key, string type, string value, MiniYamlNodeBuilder node) { - public string Chrome; - public readonly string Key; - public readonly string Type; - public readonly string Value; - public readonly List Nodes; - - public ExtractionCandidate(string key, string type, string value, MiniYamlNodeBuilder node) - { - Chrome = null; - Key = key; - Type = type; - Value = value; - Nodes = [node]; - } + public string Chrome = null; + public readonly string Key = key; + public readonly string Type = type; + public readonly string Value = value; + public readonly List Nodes = [node]; } static string ClearContainersAndToLower(string node) diff --git a/OpenRA.Mods.Common/UtilityCommands/ExtractYamlStrings.cs b/OpenRA.Mods.Common/UtilityCommands/ExtractYamlStrings.cs index f62313f170..275f554743 100644 --- a/OpenRA.Mods.Common/UtilityCommands/ExtractYamlStrings.cs +++ b/OpenRA.Mods.Common/UtilityCommands/ExtractYamlStrings.cs @@ -229,22 +229,13 @@ namespace OpenRA.Mods.Common.UtilityCommands } } - struct ExtractionCandidate + struct ExtractionCandidate(string actor, string key, string value, MiniYamlNodeBuilder node) { - public string Filename; - public readonly string Actor; - public readonly string Key; - public readonly string Value; - public readonly List Nodes; - - public ExtractionCandidate(string actor, string key, string value, MiniYamlNodeBuilder node) - { - Filename = null; - Actor = actor; - Key = key; - Value = value; - Nodes = [node]; - } + public string Filename = null; + public readonly string Actor = actor; + public readonly string Key = key; + public readonly string Value = value; + public readonly List Nodes = [node]; } static string ToLowerActor(string actor) diff --git a/OpenRA.Mods.Common/Widgets/LineGraphWidget.cs b/OpenRA.Mods.Common/Widgets/LineGraphWidget.cs index b1249fa648..acd0a5f49d 100644 --- a/OpenRA.Mods.Common/Widgets/LineGraphWidget.cs +++ b/OpenRA.Mods.Common/Widgets/LineGraphWidget.cs @@ -230,17 +230,5 @@ namespace OpenRA.Mods.Common.Widgets } } - public class LineGraphSeries - { - public string Key; - public Color Color; - public IEnumerable Points; - - public LineGraphSeries(string key, Color color, IEnumerable points) - { - Key = key; - Color = color; - Points = points; - } - } + public record LineGraphSeries(string Key, Color Color, IEnumerable Points); } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorSelectorLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorSelectorLogic.cs index 1ab8480232..7ba382c53b 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorSelectorLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorSelectorLogic.cs @@ -24,21 +24,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic [FluentReference("actorType")] const string ActorTypeTooltip = "label-actor-type"; - sealed class ActorSelectorActor - { - public readonly ActorInfo Actor; - public readonly string[] Categories; - public readonly string[] SearchTerms; - public readonly string Tooltip; - - public ActorSelectorActor(ActorInfo actor, string[] categories, string[] searchTerms, string tooltip) - { - Actor = actor; - Categories = categories; - SearchTerms = searchTerms; - Tooltip = tooltip; - } - } + sealed record ActorSelectorActor(ActorInfo Actor, string[] Categories, string[] SearchTerms, string Tooltip); readonly DropDownButtonWidget ownersDropDown; readonly Ruleset mapRules; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs index 7d5593ba6c..6e86a279a1 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs @@ -30,19 +30,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic public string UiLabel; } - sealed class SaveDirectory - { - public readonly Folder Folder; - public readonly string DisplayName; - public readonly MapClassification Classification; - - public SaveDirectory(Folder folder, string displayName, MapClassification classification) - { - Folder = folder; - DisplayName = displayName; - Classification = classification; - } - } + sealed record SaveDirectory(Folder Folder, string DisplayName, MapClassification Classification); [FluentReference] const string SaveMapFailedTitle = "dialog-save-map-failed.title"; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs index 9d894b1785..cd4e2813eb 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs @@ -42,19 +42,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic [FluentReference] const string Slot = "options-lobby-slot.slot"; - sealed class SlotDropDownOption - { - public readonly string Title; - public readonly string Order; - public readonly Func Selected; - - public SlotDropDownOption(string title, string order, Func selected) - { - Title = title; - Order = order; - Selected = selected; - } - } + sealed record SlotDropDownOption(string Title, string Order, Func Selected); public static void ShowSlotDropDown(DropDownButtonWidget dropdown, Session.Slot slot, Session.Client client, OrderManager orderManager, MapPreview map, ModData modData) @@ -716,17 +704,4 @@ namespace OpenRA.Mods.Common.Widgets.Logic widget.IsVisible = () => false; } } - - sealed class ShowPlayerActionDropDownOption - { - public Action Click { get; set; } - public string Title; - public Func Selected = () => false; - - public ShowPlayerActionDropDownOption(string title, Action click) - { - Click = click; - Title = title; - } - } } diff --git a/OpenRA.Mods.D2k/PackageLoaders/D2kSoundResources.cs b/OpenRA.Mods.D2k/PackageLoaders/D2kSoundResources.cs index fdd3e86e6b..03015a94eb 100644 --- a/OpenRA.Mods.D2k/PackageLoaders/D2kSoundResources.cs +++ b/OpenRA.Mods.D2k/PackageLoaders/D2kSoundResources.cs @@ -21,17 +21,7 @@ namespace OpenRA.Mods.D2k.PackageLoaders { sealed class D2kSoundResources : IReadOnlyPackage { - readonly struct Entry - { - public readonly uint Offset; - public readonly uint Length; - - public Entry(uint offset, uint length) - { - Offset = offset; - Length = length; - } - } + readonly record struct Entry(uint Offset, uint Length); public string Name { get; } public IEnumerable Contents => index.Keys;