From 79454d8fd29b92cbafe8e2ba19f0269390a601eb Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Mon, 3 Mar 2025 17:29:45 +0000 Subject: [PATCH] Fix IDE0028, IDE0300, IDE0301, IDE0302, IDE0303, IDE0304. Silence IDE0305. --- .editorconfig | 14 +++--- OpenRA.Game/Actor.cs | 12 ++--- OpenRA.Game/CVec.cs | 4 +- OpenRA.Game/CryptoUtil.cs | 2 +- OpenRA.Game/ExternalMods.cs | 8 ++-- OpenRA.Game/Exts.cs | 15 ++---- OpenRA.Game/FieldLoader.cs | 10 ++-- OpenRA.Game/FileFormats/Png.cs | 4 +- OpenRA.Game/FileSystem/FileSystem.cs | 10 ++-- OpenRA.Game/FluentBundle.cs | 2 +- OpenRA.Game/Game.cs | 4 +- OpenRA.Game/GameInformation.cs | 6 +-- OpenRA.Game/GameRules/ActorInfo.cs | 2 +- OpenRA.Game/GameRules/SoundInfo.cs | 14 +++--- OpenRA.Game/GameRules/WeaponInfo.cs | 8 ++-- OpenRA.Game/Graphics/Animation.cs | 8 ++-- OpenRA.Game/Graphics/ChromeProvider.cs | 22 ++++----- OpenRA.Game/Graphics/CursorManager.cs | 4 +- OpenRA.Game/Graphics/HardwarePalette.cs | 10 ++-- OpenRA.Game/Graphics/ModelVertex.cs | 6 +-- .../Graphics/RenderPostProcessPassVertex.cs | 12 ++--- OpenRA.Game/Graphics/RgbaColorRenderer.cs | 2 +- OpenRA.Game/Graphics/SheetBuilder.cs | 2 +- OpenRA.Game/Graphics/SpriteCache.cs | 10 ++-- OpenRA.Game/Graphics/SpriteRenderable.cs | 3 +- OpenRA.Game/Graphics/TerrainSpriteLayer.cs | 4 +- OpenRA.Game/Graphics/Util.cs | 10 ++-- OpenRA.Game/Graphics/Vertex.cs | 6 +-- OpenRA.Game/Graphics/WorldRenderer.cs | 14 +++--- OpenRA.Game/HotkeyDefinition.cs | 4 +- OpenRA.Game/HotkeyManager.cs | 4 +- OpenRA.Game/Manifest.cs | 28 +++++------ OpenRA.Game/Map/ActorReference.cs | 4 +- OpenRA.Game/Map/Map.cs | 29 ++++++------ OpenRA.Game/Map/MapCache.cs | 10 ++-- OpenRA.Game/Map/MapDirectoryTracker.cs | 2 +- OpenRA.Game/Map/MapGrid.cs | 47 ++++++++++--------- OpenRA.Game/Map/MapPlayers.cs | 4 +- OpenRA.Game/Map/MapPreview.cs | 10 ++-- OpenRA.Game/Map/PlayerReference.cs | 5 +- OpenRA.Game/Map/TerrainInfo.cs | 2 +- OpenRA.Game/MiniYaml.cs | 18 +++---- OpenRA.Game/ModData.cs | 10 ++-- OpenRA.Game/Network/Connection.cs | 18 +++---- OpenRA.Game/Network/ConnectionTarget.cs | 6 +-- OpenRA.Game/Network/GameSave.cs | 16 +++---- OpenRA.Game/Network/GameServer.cs | 9 ++-- OpenRA.Game/Network/OrderIO.cs | 2 +- OpenRA.Game/Network/OrderManager.cs | 12 ++--- OpenRA.Game/Network/ReplayConnection.cs | 4 +- OpenRA.Game/Network/Session.cs | 10 ++-- OpenRA.Game/Network/SyncReport.cs | 14 +++--- OpenRA.Game/ObjectCreator.cs | 6 +-- OpenRA.Game/Player.cs | 2 +- OpenRA.Game/Primitives/ActionQueue.cs | 2 +- OpenRA.Game/Primitives/Color.cs | 4 +- OpenRA.Game/Primitives/ObservableList.cs | 2 +- OpenRA.Game/Primitives/Polygon.cs | 2 +- .../Primitives/SpatiallyPartitioned.cs | 2 +- OpenRA.Game/Primitives/TypeDictionary.cs | 6 +-- OpenRA.Game/Renderer.cs | 4 +- OpenRA.Game/Scripting/ScriptActorInterface.cs | 2 +- OpenRA.Game/Scripting/ScriptContext.cs | 6 +-- OpenRA.Game/Scripting/ScriptObjectWrapper.cs | 2 +- .../Scripting/ScriptPlayerInterface.cs | 2 +- OpenRA.Game/SelectableExts.cs | 2 +- OpenRA.Game/Server/Connection.cs | 4 +- OpenRA.Game/Server/Exts.cs | 2 +- OpenRA.Game/Server/MapStatusCache.cs | 2 +- OpenRA.Game/Server/OrderBuffer.cs | 4 +- OpenRA.Game/Server/PlayerMessageTracker.cs | 8 ++-- OpenRA.Game/Server/Server.cs | 22 ++++----- OpenRA.Game/Server/VoteKickTracker.cs | 6 +-- OpenRA.Game/Settings.cs | 14 +++--- OpenRA.Game/Sound/Sound.cs | 4 +- OpenRA.Game/StreamExts.cs | 2 +- OpenRA.Game/Support/Arguments.cs | 2 +- OpenRA.Game/Support/AssemblyLoader.cs | 22 ++++----- OpenRA.Game/Support/Benchmark.cs | 2 +- OpenRA.Game/Support/HttpQueryBuilder.cs | 2 +- OpenRA.Game/Support/Log.cs | 2 +- OpenRA.Game/Support/PerfHistory.cs | 4 +- OpenRA.Game/Support/PerfTimer.cs | 2 +- OpenRA.Game/Support/VariableExpression.cs | 6 +-- OpenRA.Game/Sync.cs | 2 +- OpenRA.Game/TextNotificationsManager.cs | 4 +- OpenRA.Game/TraitDictionary.cs | 6 +-- OpenRA.Game/Traits/LintAttributes.cs | 2 +- OpenRA.Game/Traits/Player/FrozenActorLayer.cs | 10 ++-- OpenRA.Game/Traits/Player/Shroud.cs | 2 +- OpenRA.Game/Traits/Target.cs | 8 ++-- OpenRA.Game/Traits/World/Faction.cs | 2 +- OpenRA.Game/Traits/World/ScreenMap.cs | 12 ++--- OpenRA.Game/Traits/World/ScreenShaker.cs | 2 +- .../UtilityCommands/RegisterModCommand.cs | 2 +- OpenRA.Game/WAngle.cs | 8 ++-- OpenRA.Game/Widgets/ChromeMetrics.cs | 4 +- OpenRA.Game/Widgets/Widget.cs | 12 ++--- OpenRA.Game/Widgets/WidgetLoader.cs | 2 +- OpenRA.Game/World.cs | 16 +++---- OpenRA.Mods.Cnc/Activities/Teleport.cs | 1 + OpenRA.Mods.Cnc/CncLoadScreen.cs | 6 +-- OpenRA.Mods.Cnc/FileFormats/Blowfish.cs | 4 +- OpenRA.Mods.Cnc/FileFormats/CRC32.cs | 6 +-- OpenRA.Mods.Cnc/FileFormats/IdxReader.cs | 2 +- .../FileFormats/XccLocalDatabase.cs | 2 +- OpenRA.Mods.Cnc/FileSystem/MixFile.cs | 2 +- OpenRA.Mods.Cnc/FileSystem/PackageEntry.cs | 2 +- OpenRA.Mods.Cnc/FileSystem/Pak.cs | 2 +- .../Graphics/ChronoVortexRenderable.cs | 2 +- .../ClassicTilesetSpecificSpriteSequence.cs | 4 +- OpenRA.Mods.Cnc/Graphics/ModelRenderable.cs | 6 +-- .../Graphics/TeslaZapRenderable.cs | 24 +++++----- OpenRA.Mods.Cnc/Graphics/UIModelRenderable.cs | 6 +-- OpenRA.Mods.Cnc/Graphics/Voxel.cs | 6 +-- OpenRA.Mods.Cnc/Graphics/VoxelLoader.cs | 12 ++--- OpenRA.Mods.Cnc/SpriteLoaders/TmpRALoader.cs | 3 +- OpenRA.Mods.Cnc/SpriteLoaders/TmpTDLoader.cs | 3 +- OpenRA.Mods.Cnc/SpriteLoaders/TmpTSLoader.cs | 3 +- OpenRA.Mods.Cnc/Traits/Disguise.cs | 2 +- OpenRA.Mods.Cnc/Traits/GpsWatcher.cs | 4 +- .../Infiltration/InfiltrateForDecoration.cs | 2 +- .../Infiltration/InfiltrateForSupportPower.cs | 6 +-- OpenRA.Mods.Cnc/Traits/MadTank.cs | 6 +-- .../PaletteEffects/LightPaletteRotator.cs | 4 +- OpenRA.Mods.Cnc/Traits/Render/RenderVoxels.cs | 14 +++--- .../Traits/Render/WithBuildingBib.cs | 2 +- OpenRA.Mods.Cnc/Traits/Render/WithCargo.cs | 6 +-- .../Traits/Render/WithHarvesterSpriteBody.cs | 3 +- .../Render/WithLandingCraftAnimation.cs | 2 +- OpenRA.Mods.Cnc/Traits/ResourcePurifier.cs | 2 +- .../Traits/SupportPowers/DropPodsPower.cs | 19 ++++---- .../GrantPrerequisiteChargeDrainPower.cs | 2 +- .../Traits/SupportPowers/IonCannonPower.cs | 7 ++- OpenRA.Mods.Cnc/Traits/TDGunboat.cs | 2 +- .../Traits/TransformsNearResources.cs | 2 +- .../Traits/World/ChronoVortexRenderer.cs | 2 +- .../Traits/World/JumpjetLocomotor.cs | 2 +- OpenRA.Mods.Cnc/Traits/World/ModelRenderer.cs | 24 +++++----- OpenRA.Mods.Cnc/Traits/World/ShroudPalette.cs | 12 ++--- .../Traits/World/TSEditorResourceLayer.cs | 2 +- .../Traits/World/TSResourceLayer.cs | 4 +- .../Traits/World/TSTiberiumRenderer.cs | 16 +++---- .../Traits/World/TSVeinsRenderer.cs | 20 ++++---- OpenRA.Mods.Cnc/Traits/World/VoxelCache.cs | 2 +- .../Traits/World/VoxelNormalsPalette.cs | 8 ++-- .../Traits/World/WithResourceAnimation.cs | 6 +-- OpenRA.Mods.Cnc/Util.cs | 32 ++++++------- OpenRA.Mods.Cnc/UtilityCommands/Glob.cs | 4 +- .../UtilityCommands/ImportGen1MapCommand.cs | 12 ++--- .../UtilityCommands/ImportGen2MapCommand.cs | 18 +++---- .../ImportRedAlertMapCommand.cs | 11 +++-- .../ImportTiberianDawnMapCommand.cs | 7 +-- .../ImportTiberianSunMapCommand.cs | 6 +-- .../UtilityCommands/RemapShpCommand.cs | 4 +- .../Widgets/Logic/PreReleaseWarningPrompt.cs | 2 +- OpenRA.Mods.Cnc/Widgets/ModelWidget.cs | 4 +- OpenRA.Mods.Common/Activities/Air/Land.cs | 2 +- .../Activities/FindAndDeliverResources.cs | 2 +- OpenRA.Mods.Common/Activities/LayMines.cs | 9 ++-- OpenRA.Mods.Common/Activities/Move/Move.cs | 10 ++-- .../Activities/Move/MoveAdjacentTo.cs | 2 +- OpenRA.Mods.Common/Activities/Transform.cs | 3 +- OpenRA.Mods.Common/ActorIndex.cs | 2 +- OpenRA.Mods.Common/AssetBrowser.cs | 10 ++-- OpenRA.Mods.Common/Commands/ChatCommands.cs | 2 +- OpenRA.Mods.Common/Commands/HelpCommand.cs | 2 +- OpenRA.Mods.Common/DiscordService.cs | 6 +-- .../EditorBrushes/EditorMarkerLayerBrush.cs | 4 +- .../EditorBrushes/EditorResourceBrush.cs | 4 +- .../EditorBrushes/EditorTileBrush.cs | 6 +-- .../Effects/RallyPointIndicator.cs | 4 +- .../Effects/RevealShroudEffect.cs | 3 +- .../Effects/SpawnActorEffect.cs | 5 +- OpenRA.Mods.Common/FileFormats/Blast.cs | 16 +++---- .../FileFormats/ImaAdpcmReader.cs | 6 +-- OpenRA.Mods.Common/FileFormats/IniFile.cs | 4 +- .../InstallShieldCABCompression.cs | 2 +- OpenRA.Mods.Common/FileFormats/WavReader.cs | 8 ++-- .../FileFormats/WestwoodCompressedReader.cs | 4 +- .../Graphics/DefaultSpriteSequence.cs | 8 ++-- ...ometricSelectionBoxAnnotationRenderable.cs | 8 ++-- .../SelectionBoxAnnotationRenderable.cs | 8 ++-- .../Graphics/TilesetSpecificSpriteSequence.cs | 4 +- OpenRA.Mods.Common/HitShapes/Rectangle.cs | 24 +++++----- .../SourceResolvers/DiscSourceResolver.cs | 6 +-- OpenRA.Mods.Common/Lint/CheckChromeHotkeys.cs | 2 +- .../Lint/CheckFluentReferences.cs | 24 +++++----- OpenRA.Mods.Common/Lint/CheckSequences.cs | 2 +- .../Lint/CheckWorldAndPlayerInherits.cs | 2 +- OpenRA.Mods.Common/Lint/LintExts.cs | 9 ++-- .../LoadScreens/LogoStripeLoadScreen.cs | 3 +- .../LoadScreens/ModContentLoadScreen.cs | 2 +- .../MapGenerator/CellLayerUtils.cs | 2 +- OpenRA.Mods.Common/MapGenerator/Direction.cs | 12 ++--- .../MapGenerator/MapGeneratorSettings.cs | 2 +- .../MapGenerator/MatrixUtils.cs | 6 +-- OpenRA.Mods.Common/MapGenerator/MultiBrush.cs | 14 +++--- .../MapGenerator/PlayableSpace.cs | 2 +- OpenRA.Mods.Common/MapGenerator/TilingPath.cs | 6 +-- OpenRA.Mods.Common/ModContent.cs | 17 ++++--- OpenRA.Mods.Common/Orders/OrderGenerator.cs | 3 +- .../Orders/PlaceBuildingOrderGenerator.cs | 6 +-- .../Pathfinder/CellInfoLayerPool.cs | 2 +- .../Pathfinder/DensePathGraph.cs | 24 +++++----- .../Pathfinder/HierarchicalPathFinder.cs | 24 +++++----- OpenRA.Mods.Common/Pathfinder/PathSearch.cs | 2 +- .../Pathfinder/SparsePathGraph.cs | 2 +- OpenRA.Mods.Common/Projectiles/AreaBeam.cs | 8 ++-- OpenRA.Mods.Common/Projectiles/Bullet.cs | 10 ++-- OpenRA.Mods.Common/Projectiles/GravityBomb.cs | 2 +- OpenRA.Mods.Common/Projectiles/InstantHit.cs | 3 +- OpenRA.Mods.Common/Projectiles/Missile.cs | 4 +- OpenRA.Mods.Common/Projectiles/NukeLaunch.cs | 3 +- .../Scripting/Global/ActorGlobal.cs | 2 +- OpenRA.Mods.Common/Scripting/LuaScript.cs | 2 +- .../Scripting/Properties/HealthProperties.cs | 2 +- .../Properties/ProductionProperties.cs | 6 +-- .../ServerTraits/LobbyCommands.cs | 22 ++++----- .../ServerTraits/LobbySettingsNotification.cs | 2 +- .../ServerTraits/MasterServerPinger.cs | 2 +- OpenRA.Mods.Common/SpriteLoaders/DdsLoader.cs | 2 +- .../SpriteLoaders/PngSheetLoader.cs | 14 +++--- OpenRA.Mods.Common/SpriteLoaders/TgaLoader.cs | 5 +- OpenRA.Mods.Common/Terrain/DefaultTerrain.cs | 4 +- .../Terrain/DefaultTileCache.cs | 2 +- OpenRA.Mods.Common/Terrain/TerrainInfo.cs | 3 +- .../Traits/AcceptsDeliveredCash.cs | 5 +- .../Traits/AcceptsDeliveredExperience.cs | 2 +- OpenRA.Mods.Common/Traits/ActorSpawner.cs | 2 +- OpenRA.Mods.Common/Traits/AffectsShroud.cs | 5 +- OpenRA.Mods.Common/Traits/Air/Aircraft.cs | 12 ++--- OpenRA.Mods.Common/Traits/AmmoPool.cs | 4 +- OpenRA.Mods.Common/Traits/Armament.cs | 6 +-- .../Traits/Attack/AttackBase.cs | 4 +- .../Traits/Attack/AttackGarrisoned.cs | 10 ++-- .../Traits/Attack/AttackTurreted.cs | 2 +- OpenRA.Mods.Common/Traits/AutoTarget.cs | 2 +- .../Traits/BotModules/BaseBuilderBotModule.cs | 34 +++++++------- .../BotModuleLogic/BaseBuilderQueueManager.cs | 2 +- .../BotModuleLogic/MinelayerBotModule.cs | 8 ++-- .../BotModuleLogic/SupportPowerDecision.cs | 2 +- .../BotModules/CaptureManagerBotModule.cs | 6 +-- .../Traits/BotModules/HarvesterBotModule.cs | 10 ++-- .../Traits/BotModules/McvManagerBotModule.cs | 12 ++--- .../BotModules/SquadManagerBotModule.cs | 38 +++++++-------- .../BotModules/Squads/AttackOrFleeFuzzy.cs | 24 +++++----- .../Traits/BotModules/Squads/Squad.cs | 4 +- .../BotModules/SupportPowerBotModule.cs | 16 +++---- .../Traits/BotModules/UnitBuilderBotModule.cs | 10 ++-- OpenRA.Mods.Common/Traits/Buildable.cs | 5 +- OpenRA.Mods.Common/Traits/Buildings/Bridge.cs | 4 +- .../Traits/Buildings/BridgeHut.cs | 10 ++-- .../Traits/Buildings/BridgePlaceholder.cs | 9 ++-- .../Traits/Buildings/Building.cs | 8 ++-- .../Traits/Buildings/BuildingUtils.cs | 6 +-- OpenRA.Mods.Common/Traits/Buildings/Exit.cs | 4 +- .../Traits/Buildings/FreeActor.cs | 7 ++- .../Traits/Buildings/FreeActorWithDelivery.cs | 13 +++-- OpenRA.Mods.Common/Traits/Buildings/Gate.cs | 2 +- .../Traits/Buildings/GivesBuildableArea.cs | 4 +- .../Traits/Buildings/GroundLevelBridge.cs | 3 +- .../Traits/Buildings/LineBuild.cs | 9 ++-- .../Traits/Buildings/LineBuildNode.cs | 4 +- .../Traits/Buildings/PrimaryBuilding.cs | 2 +- .../Traits/Buildings/ProductionAirdrop.cs | 8 ++-- .../Traits/Buildings/RallyPoint.cs | 3 +- .../Traits/Buildings/RepairableBuilding.cs | 6 +-- .../Traits/Buildings/RequiresBuildableArea.cs | 2 +- .../Buildings/TransformsIntoAircraft.cs | 2 +- .../Traits/Buildings/TransformsIntoMobile.cs | 2 +- .../Buildings/TransformsIntoRepairable.cs | 2 +- .../Traits/CapturableProgressBar.cs | 2 +- .../Traits/CapturableProgressBlink.cs | 4 +- OpenRA.Mods.Common/Traits/CaptureManager.cs | 2 +- OpenRA.Mods.Common/Traits/Cargo.cs | 20 ++++---- OpenRA.Mods.Common/Traits/Carryall.cs | 8 ++-- .../Traits/CombatDebugOverlay.cs | 2 +- .../Traits/Conditions/ExternalCondition.cs | 6 +-- .../Conditions/GrantConditionOnAttack.cs | 6 +-- .../Conditions/GrantConditionOnBotOwner.cs | 2 +- .../Conditions/GrantConditionOnDamageState.cs | 5 +- .../Conditions/GrantConditionOnDeploy.cs | 2 +- .../Conditions/GrantConditionOnFaction.cs | 2 +- .../Conditions/GrantConditionOnHealth.cs | 5 +- .../GrantConditionOnPrerequisite.cs | 3 +- .../Conditions/GrantConditionOnProduction.cs | 2 +- .../Conditions/GrantConditionOnTerrain.cs | 2 +- .../Conditions/GrantConditionOnTileSet.cs | 2 +- .../LineBuildSegmentExternalCondition.cs | 4 +- .../Conditions/ProximityExternalCondition.cs | 2 +- OpenRA.Mods.Common/Traits/Crates/Crate.cs | 4 +- .../Traits/Crates/CrateAction.cs | 4 +- .../Traits/Crates/DuplicateUnitCrateAction.cs | 8 ++-- .../Traits/Crates/GiveUnitCrateAction.cs | 12 ++--- .../Traits/Crates/SupportPowerCrateAction.cs | 7 ++- OpenRA.Mods.Common/Traits/DamagedByTerrain.cs | 2 +- OpenRA.Mods.Common/Traits/DeliversCash.cs | 3 +- OpenRA.Mods.Common/Traits/Demolishable.cs | 4 +- OpenRA.Mods.Common/Traits/DockHost.cs | 2 +- .../Traits/FireProjectilesOnDeath.cs | 7 ++- OpenRA.Mods.Common/Traits/FireWarheads.cs | 3 +- OpenRA.Mods.Common/Traits/GainsExperience.cs | 2 +- OpenRA.Mods.Common/Traits/GivesBounty.cs | 2 +- OpenRA.Mods.Common/Traits/GivesExperience.cs | 2 +- OpenRA.Mods.Common/Traits/Harvester.cs | 2 +- OpenRA.Mods.Common/Traits/HitShape.cs | 4 +- OpenRA.Mods.Common/Traits/Husk.cs | 4 +- OpenRA.Mods.Common/Traits/Immobile.cs | 7 ++- .../Traits/Infantry/ScaredyCat.cs | 2 +- .../Traits/Infantry/TakeCover.cs | 2 +- .../Traits/IsometricSelectable.cs | 4 +- OpenRA.Mods.Common/Traits/KillsSelf.cs | 2 +- OpenRA.Mods.Common/Traits/Minelayer.cs | 4 +- OpenRA.Mods.Common/Traits/Mobile.cs | 10 ++-- .../Traits/Modifiers/FrozenUnderFog.cs | 2 +- .../Multipliers/ProductionCostMultiplier.cs | 5 +- .../Multipliers/ProductionTimeMultiplier.cs | 5 +- .../PaletteEffects/CloakPaletteEffect.cs | 4 +- .../PaletteEffects/RotationPaletteEffect.cs | 8 ++-- .../Traits/Palettes/ColorPickerPalette.cs | 3 +- .../Traits/Palettes/FixedColorPalette.cs | 3 +- .../Traits/Palettes/IndexedPalette.cs | 7 ++- .../Traits/Palettes/IndexedPlayerPalette.cs | 3 +- .../Traits/Palettes/PaletteFromFile.cs | 4 +- .../Palettes/PaletteFromGimpOrJascFile.cs | 4 +- .../Traits/Palettes/PaletteFromPng.cs | 2 +- .../Traits/Palettes/PlayerColorPalette.cs | 3 +- OpenRA.Mods.Common/Traits/Parachutable.cs | 2 +- OpenRA.Mods.Common/Traits/Passenger.cs | 2 +- .../Player/ClassicParallelProductionQueue.cs | 6 +-- .../Traits/Player/ClassicProductionQueue.cs | 4 +- .../Traits/Player/EnemyWatcher.cs | 8 ++-- .../GrantConditionOnPrerequisiteManager.cs | 4 +- .../Player/LobbyPrerequisiteCheckbox.cs | 4 +- .../Traits/Player/MissionObjectives.cs | 2 +- .../Traits/Player/ModularBot.cs | 2 +- .../Traits/Player/PlaceBuilding.cs | 21 ++++----- .../Traits/Player/PlayerResources.cs | 4 +- .../Traits/Player/ProductionQueue.cs | 12 ++--- .../Traits/Player/ProvidesPrerequisite.cs | 11 ++--- .../Traits/Player/ProvidesTechPrerequisite.cs | 3 +- OpenRA.Mods.Common/Traits/Player/TechTree.cs | 2 +- OpenRA.Mods.Common/Traits/Pluggable.cs | 6 +-- .../Traits/Power/Player/PowerManager.cs | 2 +- .../Traits/ProducibleWithLevel.cs | 3 +- OpenRA.Mods.Common/Traits/Production.cs | 4 +- .../Traits/ProductionFromMapEdge.cs | 3 +- .../Traits/ProductionParadrop.cs | 8 ++-- .../Traits/ProximityCapturableBase.cs | 6 +-- OpenRA.Mods.Common/Traits/Rearmable.cs | 4 +- .../Traits/RegionProximityCapturable.cs | 6 +-- OpenRA.Mods.Common/Traits/RejectsOrders.cs | 4 +- OpenRA.Mods.Common/Traits/Render/Contrail.cs | 5 +- .../Traits/Render/DrawLineToTarget.cs | 11 ++--- .../Traits/Render/FloatingSpriteEmitter.cs | 10 ++-- .../Traits/Render/LeavesTrails.cs | 6 +-- .../Render/ProductionIconOverlayManager.cs | 2 +- .../Traits/Render/ReloadArmamentsBar.cs | 2 +- .../Traits/Render/RenderMouseBounds.cs | 3 +- .../Traits/Render/RenderShroudCircle.cs | 2 +- .../Traits/Render/RenderSprites.cs | 6 +-- .../Traits/Render/SelectionDecorationsBase.cs | 2 +- .../Render/WithAircraftLandingEffect.cs | 4 +- .../Traits/Render/WithAmmoPipsDecoration.cs | 2 +- .../Traits/Render/WithBridgeSpriteBody.cs | 8 ++-- .../Traits/Render/WithCargoPipsDecoration.cs | 2 +- .../Traits/Render/WithCrateBody.cs | 6 +-- .../Traits/Render/WithDeadBridgeSpriteBody.cs | 8 ++-- .../Traits/Render/WithDeathAnimation.cs | 2 +- .../Traits/Render/WithDecoration.cs | 9 ++-- .../Traits/Render/WithDecorationBase.cs | 9 ++-- .../Traits/Render/WithGateSpriteBody.cs | 2 +- .../Traits/Render/WithIdleAnimation.cs | 4 +- .../Traits/Render/WithInfantryBody.cs | 7 ++- .../Traits/Render/WithMakeAnimation.cs | 2 +- .../Traits/Render/WithMuzzleOverlay.cs | 4 +- .../Traits/Render/WithNameTagDecoration.cs | 9 ++-- .../Traits/Render/WithParachute.cs | 21 ++++----- .../Render/WithProductionIconOverlay.cs | 4 +- .../Traits/Render/WithProductionOverlay.cs | 2 +- .../WithSpriteControlGroupDecoration.cs | 9 ++-- .../WithStoresResourcesPipsDecoration.cs | 2 +- .../Render/WithTextControlGroupDecoration.cs | 9 ++-- .../Traits/Render/WithTextDecoration.cs | 9 ++-- OpenRA.Mods.Common/Traits/Repairable.cs | 2 +- OpenRA.Mods.Common/Traits/RepairableNear.cs | 2 +- OpenRA.Mods.Common/Traits/Replaceable.cs | 2 +- OpenRA.Mods.Common/Traits/Replacement.cs | 2 +- .../Traits/RequiresSpecificOwners.cs | 2 +- OpenRA.Mods.Common/Traits/RevealOnFire.cs | 2 +- OpenRA.Mods.Common/Traits/ScriptTags.cs | 2 +- OpenRA.Mods.Common/Traits/Sellable.cs | 2 +- .../Traits/Sound/AmbientSound.cs | 6 +-- .../Traits/Sound/AttackSounds.cs | 3 +- .../Traits/Sound/SoundOnDamageTransition.cs | 5 +- .../Traits/SpawnActorsOnSell.cs | 18 ++++--- OpenRA.Mods.Common/Traits/StoresResources.cs | 4 +- .../Traits/SupportPowers/AirstrikePower.cs | 13 +++-- .../SupportPowers/DirectionalSupportPower.cs | 2 +- .../Traits/SupportPowers/NukePower.cs | 3 +- .../Traits/SupportPowers/ParatroopersPower.cs | 21 ++++----- .../Traits/SupportPowers/SpawnActorPower.cs | 7 ++- .../Traits/SupportPowers/SupportPower.cs | 3 +- .../SupportPowers/SupportPowerManager.cs | 6 +-- OpenRA.Mods.Common/Traits/Targetable.cs | 3 +- OpenRA.Mods.Common/Traits/Transforms.cs | 5 +- OpenRA.Mods.Common/Traits/Wanders.cs | 2 +- OpenRA.Mods.Common/Traits/World/ActorMap.cs | 30 ++++++------ .../Traits/World/ActorSpawnManager.cs | 14 +++--- OpenRA.Mods.Common/Traits/World/AutoSave.cs | 2 +- .../Traits/World/CellTriggerOverlay.cs | 1 + .../Traits/World/ClearMapGenerator.cs | 3 +- .../Traits/World/ColorPickerManager.cs | 8 ++-- .../Traits/World/ControlGroups.cs | 8 ++-- .../Traits/World/CrateSpawner.cs | 19 ++++---- .../Traits/World/EditorActionManager.cs | 4 +- .../Traits/World/EditorActorLayer.cs | 8 ++-- .../Traits/World/EditorActorPreview.cs | 2 +- .../Traits/World/EditorCursorLayer.cs | 3 +- .../Traits/World/EditorResourceLayer.cs | 2 +- .../Traits/World/ElevatedBridgeLayer.cs | 2 +- .../Traits/World/ExperimentalMapGenerator.cs | 2 +- .../World/HierarchicalPathFinderOverlay.cs | 2 +- .../Traits/World/LegacyBridgeLayer.cs | 11 ++--- .../Traits/World/LoadWidgetAtGameStart.cs | 2 +- OpenRA.Mods.Common/Traits/World/Locomotor.cs | 6 +-- .../Traits/World/MapStartingLocations.cs | 4 +- .../Traits/World/MapStartingUnits.cs | 5 +- .../Traits/World/MarkerLayerOverlay.cs | 12 ++--- OpenRA.Mods.Common/Traits/World/PathFinder.cs | 4 +- .../Traits/World/PathFinderOverlay.cs | 14 +++--- OpenRA.Mods.Common/Traits/World/RadarPings.cs | 2 +- .../Traits/World/ResourceClaimLayer.cs | 2 +- .../Traits/World/ResourceRenderer.cs | 8 ++-- OpenRA.Mods.Common/Traits/World/Selection.cs | 10 ++-- .../Traits/World/ShroudRenderer.cs | 6 +-- .../Traits/World/SmudgeLayer.cs | 9 ++-- .../Traits/World/SpawnMapActors.cs | 2 +- .../Traits/World/SpawnStartingUnits.cs | 17 ++++--- .../Traits/World/SubterraneanLocomotor.cs | 2 +- .../Traits/World/TerrainLighting.cs | 2 +- .../Traits/World/TerrainTunnelLayer.cs | 2 +- .../Traits/World/TimeLimitManager.cs | 2 +- .../Traits/World/WarheadDebugOverlay.cs | 2 +- .../Traits/World/WeatherOverlay.cs | 20 ++++---- .../Rules/20210321/ConvertBoundsToWDist.cs | 4 +- .../20210321/RemovePlaceBuildingPalette.cs | 2 +- .../20210321/RemoveSmokeTrailWhenDamaged.cs | 2 +- .../Rules/20210321/ReplaceShadowPalette.cs | 2 +- .../ReplaceWithColoredOverlayPalette.cs | 2 +- .../UnhardcodeBaseBuilderBotModule.cs | 6 +-- .../Rules/20210321/UnhardcodeSquadManager.cs | 12 ++--- .../UnhardcodeVeteranProductionIconOverlay.cs | 2 +- .../20230225/ExplicitSequenceFilenames.cs | 34 +++++++------- .../RemoveExperienceFromInfiltrates.cs | 2 +- .../20230225/RemoveNegativeSequenceLength.cs | 2 +- .../RemoveSequenceHasEmbeddedPalette.cs | 2 +- .../Rules/20231010/AbstractDocking.cs | 12 ++--- .../RemoveValidRelationsFromCapturable.cs | 2 +- .../Rules/20231010/ReplaceCloakPalette.cs | 2 +- OpenRA.Mods.Common/UpdateRules/UpdatePath.cs | 25 +++++----- OpenRA.Mods.Common/UpdateRules/UpdateUtils.cs | 6 +-- .../ConvertSpriteToPngCommand.cs | 2 +- .../UtilityCommands/CreateManPage.cs | 2 +- .../UtilityCommands/DebugChromeRegions.cs | 6 +-- .../ExtractSettingsDocsCommand.cs | 2 +- .../DumpSequenceSheetsCommand.cs | 4 +- .../UtilityCommands/ExtractChromeStrings.cs | 8 ++-- .../UtilityCommands/ExtractYamlStrings.cs | 14 +++--- .../Warheads/ChangeOwnerWarhead.cs | 2 +- .../Warheads/CreateEffectWarhead.cs | 5 +- .../Warheads/CreateResourceWarhead.cs | 2 +- OpenRA.Mods.Common/Warheads/DamageWarhead.cs | 2 +- .../Warheads/DestroyResourceWarhead.cs | 4 +- .../Warheads/FireClusterWarhead.cs | 5 +- .../Warheads/FlashTargetsInRadiusWarhead.cs | 2 +- .../Warheads/GrantExternalConditionWarhead.cs | 2 +- .../Warheads/LeaveSmudgeWarhead.cs | 4 +- .../Warheads/SpreadDamageWarhead.cs | 2 +- .../Warheads/TargetDamageWarhead.cs | 2 +- .../Widgets/ActorPreviewWidget.cs | 2 +- .../Widgets/HotkeyEntryWidget.cs | 6 +-- OpenRA.Mods.Common/Widgets/LineGraphWidget.cs | 2 +- .../Widgets/Logic/AssetBrowserLogic.cs | 8 ++-- .../Widgets/Logic/ColorPickerLogic.cs | 2 +- .../Widgets/Logic/ConnectionLogic.cs | 2 +- .../Widgets/Logic/Editor/ActorEditLogic.cs | 4 +- .../Logic/Editor/CommonSelectorLogic.cs | 6 +-- .../Widgets/Logic/Editor/HistoryLogLogic.cs | 2 +- .../Logic/Editor/MapGeneratorToolLogic.cs | 4 +- .../Widgets/Logic/Editor/MapOverlaysLogic.cs | 4 +- .../Widgets/Logic/Editor/MapToolsLogic.cs | 2 +- .../Widgets/Logic/Editor/SaveMapLogic.cs | 2 +- .../Widgets/Logic/Editor/TileSelectorLogic.cs | 2 +- .../Widgets/Logic/EncyclopediaLogic.cs | 4 +- .../Widgets/Logic/GameSaveBrowserLogic.cs | 8 ++-- .../Widgets/Logic/Ingame/CommandBarLogic.cs | 4 +- .../Widgets/Logic/Ingame/GameInfoLogic.cs | 4 +- .../Logic/Ingame/GameInfoStatsLogic.cs | 10 ++-- .../Ingame/Hotkeys/CycleBasesHotkeyLogic.cs | 4 +- .../Hotkeys/CycleHarvestersHotkeyLogic.cs | 2 +- .../CycleProductionActorsHotkeyLogic.cs | 2 +- .../Hotkeys/CycleStatusBarsHotkeyLogic.cs | 2 +- .../Widgets/Logic/Ingame/IngameChatLogic.cs | 4 +- .../Widgets/Logic/Ingame/IngameMenuLogic.cs | 4 +- ...ngameHierarchicalPathFinderOverlayLogic.cs | 2 +- .../Logic/Ingame/LoadIngamePerfLogic.cs | 2 +- .../LoadIngamePlayerOrObserverUILogic.cs | 10 ++-- .../Logic/Ingame/LoadMapEditorLogic.cs | 4 +- .../Logic/Ingame/MenuButtonsChromeLogic.cs | 2 +- .../Ingame/ObserverShroudSelectorLogic.cs | 2 +- .../Logic/Ingame/StanceSelectorLogic.cs | 3 +- .../Installation/DownloadPackageLogic.cs | 2 +- .../Logic/Installation/ModContentLogic.cs | 4 +- .../Widgets/Logic/Lobby/LobbyLogic.cs | 14 +++--- .../Widgets/Logic/Lobby/MapPreviewLogic.cs | 28 +++++------ .../Widgets/Logic/MainMenuLogic.cs | 2 +- .../Widgets/Logic/MapChooserLogic.cs | 8 ++-- .../Widgets/Logic/MissionBrowserLogic.cs | 2 +- .../Widgets/Logic/ReplayBrowserLogic.cs | 10 ++-- .../Widgets/Logic/ServerListLogic.cs | 8 ++-- .../Logic/Settings/GamePlaySettingsLogic.cs | 4 +- .../Logic/Settings/HotkeysSettingsLogic.cs | 4 +- .../Widgets/Logic/Settings/SettingsLogic.cs | 10 ++-- .../Widgets/Logic/TabCompletionLogic.cs | 2 +- .../Widgets/LogicKeyListenerWidget.cs | 2 +- .../Widgets/MapPreviewWidget.cs | 4 +- .../Widgets/ObserverArmyIconsWidget.cs | 2 +- .../Widgets/ObserverProductionIconsWidget.cs | 6 +-- .../ObserverSupportPowerIconsWidget.cs | 6 +-- OpenRA.Mods.Common/Widgets/PerfGraphWidget.cs | 6 +-- .../Widgets/ProductionPaletteWidget.cs | 10 ++-- .../Widgets/ProductionTabsWidget.cs | 4 +- OpenRA.Mods.Common/Widgets/SelectionUtils.cs | 2 +- .../Widgets/SupportPowersWidget.cs | 6 +-- .../Widgets/TextNotificationsDisplayWidget.cs | 14 +++--- OpenRA.Mods.Common/WorldExtensions.cs | 6 +-- .../Graphics/SonicBlastRenderable.cs | 3 +- .../PackageLoaders/D2kSoundResources.cs | 2 +- OpenRA.Mods.D2k/Projectiles/SonicBlast.cs | 8 ++-- OpenRA.Mods.D2k/Traits/AttractsWorms.cs | 2 +- .../D2kActorPreviewPlaceBuildingPreview.cs | 5 +- .../Traits/Buildings/D2kBuilding.cs | 4 +- OpenRA.Mods.D2k/Traits/SpiceBloom.cs | 12 ++--- .../Traits/World/BuildableTerrainLayer.cs | 2 +- .../Traits/World/SonicBlastRenderer.cs | 2 +- .../UtilityCommands/D2kMapImporter.cs | 8 ++-- OpenRA.Platforms.Default/OpenAlSoundEngine.cs | 4 +- OpenRA.Platforms.Default/Shader.cs | 10 ++-- .../ThreadedGraphicsContext.cs | 10 ++-- OpenRA.Server/Program.cs | 4 +- OpenRA.Test/OpenRA.Game/ActionQueueTest.cs | 2 +- OpenRA.Test/OpenRA.Game/FluentTest.cs | 4 +- OpenRA.Test/OpenRA.Game/MiniYamlTest.cs | 8 ++-- OpenRA.Test/OpenRA.Game/PngTest.cs | 2 +- OpenRA.Test/OpenRA.Mods.Common/ShapeTest.cs | 14 +++--- OpenRA.Utility/Program.cs | 6 +-- OpenRA.WindowsLauncher/Program.cs | 2 +- 559 files changed, 1661 insertions(+), 1751 deletions(-) diff --git a/.editorconfig b/.editorconfig index f275e86cac..b7b73db086 100644 --- a/.editorconfig +++ b/.editorconfig @@ -138,7 +138,7 @@ dotnet_diagnostic.IDE0017.severity = warning # IDE0028 Use collection initializers #dotnet_style_collection_initializer = true -dotnet_diagnostic.IDE0028.severity = suggestion # TODO: Consider enabling +dotnet_diagnostic.IDE0028.severity = warning # IDE0029/IDE0030/IDE0270 Use coalesce expression (non-nullable types)/Use coalesce expression (nullable types)/Use coalesce expression (if null) #dotnet_style_coalesce_expression = true @@ -308,27 +308,27 @@ dotnet_diagnostic.IDE0241.severity = warning # IDE0300 Use collection expression for array # From above, uses dotnet_style_prefer_collection_expression -dotnet_diagnostic.IDE0300.severity = suggestion # TODO: Consider enabling +dotnet_diagnostic.IDE0300.severity = warning # IDE0301 Use collection expression for empty # From above, uses dotnet_style_prefer_collection_expression -dotnet_diagnostic.IDE0301.severity = suggestion # TODO: Consider enabling +dotnet_diagnostic.IDE0301.severity = warning # IDE0302 Use collection expression for stackalloc # From above, uses dotnet_style_prefer_collection_expression -dotnet_diagnostic.IDE0302.severity = suggestion # TODO: Consider enabling +dotnet_diagnostic.IDE0302.severity = warning # IDE0303 Use collection expression for 'Create()' # From above, uses dotnet_style_prefer_collection_expression -dotnet_diagnostic.IDE0303.severity = suggestion # TODO: Consider enabling +dotnet_diagnostic.IDE0303.severity = warning # IDE0304 Use collection expression for builder # From above, uses dotnet_style_prefer_collection_expression -dotnet_diagnostic.IDE0304.severity = suggestion # TODO: Consider enabling +dotnet_diagnostic.IDE0304.severity = warning # IDE0305 Use collection expression for fluent # From above, uses dotnet_style_prefer_collection_expression -dotnet_diagnostic.IDE0305.severity = suggestion # TODO: Consider enabling +dotnet_diagnostic.IDE0305.severity = silent ## Field preferences diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index 1e6b245ace..c2b35f7d75 100644 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -89,21 +89,21 @@ namespace OpenRA sealed class ConditionState { /// Delegates that have registered to be notified when this condition changes. - public readonly List Notifiers = new(); + public readonly List Notifiers = []; /// Unique integers identifying granted instances of the condition. - public readonly HashSet Tokens = new(); + public readonly HashSet Tokens = []; } - readonly Dictionary conditionStates = new(); + readonly Dictionary conditionStates = []; /// Each granted condition receives a unique token that is used when revoking. - readonly Dictionary conditionTokens = new(); + readonly Dictionary conditionTokens = []; int nextConditionToken = 1; /// Cache of condition -> enabled state for quick evaluation of token counter conditions. - readonly Dictionary conditionCache = new(); + readonly Dictionary conditionCache = []; /// Read-only version of conditionCache that is passed to IConditionConsumers. readonly IReadOnlyDictionary readOnlyConditionCache; @@ -541,7 +541,7 @@ namespace OpenRA if (EnabledTargetablePositions.Any()) return enabledTargetableWorldPositions; - return new[] { CenterPosition }; + return [CenterPosition]; } #region Conditions diff --git a/OpenRA.Game/CVec.cs b/OpenRA.Game/CVec.cs index c4706ce394..f0a90864cc 100644 --- a/OpenRA.Game/CVec.cs +++ b/OpenRA.Game/CVec.cs @@ -62,7 +62,7 @@ namespace OpenRA public override string ToString() { return X + "," + Y; } public static readonly CVec[] Directions = - { + [ new(-1, -1), new(-1, 0), new(-1, 1), @@ -71,7 +71,7 @@ namespace OpenRA new(1, -1), new(1, 0), new(1, 1), - }; + ]; #region Scripting interface diff --git a/OpenRA.Game/CryptoUtil.cs b/OpenRA.Game/CryptoUtil.cs index 89285ff0fb..f568160a73 100644 --- a/OpenRA.Game/CryptoUtil.cs +++ b/OpenRA.Game/CryptoUtil.cs @@ -20,7 +20,7 @@ namespace OpenRA public static class CryptoUtil { // Fixed byte pattern for the OID header - static readonly byte[] OIDHeader = { 0x30, 0xD, 0x6, 0x9, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0xD, 0x1, 0x1, 0x1, 0x5, 0x0 }; + static readonly byte[] OIDHeader = [0x30, 0xD, 0x6, 0x9, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0xD, 0x1, 0x1, 0x1, 0x5, 0x0]; static readonly char[] HexUpperAlphabet = "0123456789ABCDEF".ToArray(); static readonly char[] HexLowerAlphabet = "0123456789abcdef".ToArray(); diff --git a/OpenRA.Game/ExternalMods.cs b/OpenRA.Game/ExternalMods.cs index 2cb1c42cf9..40dff9d933 100644 --- a/OpenRA.Game/ExternalMods.cs +++ b/OpenRA.Game/ExternalMods.cs @@ -40,7 +40,7 @@ namespace OpenRA public class ExternalMods : IReadOnlyDictionary { - readonly Dictionary mods = new(); + readonly Dictionary mods = []; readonly SheetBuilder sheetBuilder; Sheet CreateSheet() @@ -122,13 +122,13 @@ namespace OpenRA return; var key = ExternalMod.MakeKey(mod); - var yaml = new MiniYamlNode("Registration", new MiniYaml("", new[] - { + var yaml = new MiniYamlNode("Registration", new MiniYaml("", + [ new MiniYamlNode("Id", mod.Id), new MiniYamlNode("Version", mod.Metadata.Version), new MiniYamlNode("LaunchPath", launchPath), new MiniYamlNode("LaunchArgs", new[] { "Game.Mod=" + mod.Id }.Concat(launchArgs).JoinWith(", ")) - })); + ])); var iconNodes = new List(); diff --git a/OpenRA.Game/Exts.cs b/OpenRA.Game/Exts.cs index a01a62d205..1511835fa4 100644 --- a/OpenRA.Game/Exts.cs +++ b/OpenRA.Game/Exts.cs @@ -413,11 +413,6 @@ namespace OpenRA return ts.Except(exclusions); } - public static HashSet ToHashSet(this IEnumerable source) - { - return new HashSet(source); - } - public static Dictionary ToDictionaryWithConflictLog( this IEnumerable source, Func keySelector, string debugName, Func logKey, Func logValue) @@ -460,14 +455,14 @@ namespace OpenRA // Check for a key conflict: if (!output.TryAdd(key, element)) { - dupKeys ??= new Dictionary>(); + dupKeys ??= []; if (!dupKeys.TryGetValue(key, out var dupKeyMessages)) { // Log the initial conflicting value already inserted: - dupKeyMessages = new List - { + dupKeyMessages = + [ logValue(output[key]) - }; + ]; dupKeys.Add(key, dupKeyMessages); } @@ -664,7 +659,7 @@ namespace OpenRA if (index == -1) { // The remaining string is an empty string - str = ReadOnlySpan.Empty; + str = []; Current = span; return true; } diff --git a/OpenRA.Game/FieldLoader.cs b/OpenRA.Game/FieldLoader.cs index a8a62a5ce2..c81a71a9a8 100644 --- a/OpenRA.Game/FieldLoader.cs +++ b/OpenRA.Game/FieldLoader.cs @@ -530,8 +530,8 @@ namespace OpenRA if (value != null) { var parts = value.Split(SplitComma, StringSplitOptions.RemoveEmptyEntries); - var ctor = fieldType.GetConstructor(new[] { typeof(string[]) }); - return ctor.Invoke(new object[] { parts.Select(p => p.Trim()).ToArray() }); + var ctor = fieldType.GetConstructor([typeof(string[])]); + return ctor.Invoke([parts.Select(p => p.Trim()).ToArray()]); } return InvalidValueAction(value, fieldType, fieldName); @@ -544,7 +544,7 @@ namespace OpenRA var innerType = fieldType.GetGenericArguments()[0]; var innerValue = GetValue("Nullable", innerType, value, field); - return fieldType.GetConstructor(new[] { innerType }).Invoke(new[] { innerValue }); + return fieldType.GetConstructor([innerType]).Invoke([innerValue]); } public static void Load(object self, MiniYaml my) @@ -565,7 +565,7 @@ namespace OpenRA val = fli.Loader(my); else { - missing ??= new List(); + missing ??= []; missing.Add(fli.YamlName); continue; } @@ -576,7 +576,7 @@ namespace OpenRA { if (fli.Attribute.Required) { - missing ??= new List(); + missing ??= []; missing.Add(fli.YamlName); } diff --git a/OpenRA.Game/FileFormats/Png.cs b/OpenRA.Game/FileFormats/Png.cs index f4b603fba0..e033e2940d 100644 --- a/OpenRA.Game/FileFormats/Png.cs +++ b/OpenRA.Game/FileFormats/Png.cs @@ -25,14 +25,14 @@ namespace OpenRA.FileFormats { public class Png { - static readonly byte[] Signature = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a }; + static readonly byte[] Signature = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]; public int Width { get; } public int Height { get; } public Color[] Palette { get; } public byte[] Data { get; } public SpriteFrameType Type { get; } - public Dictionary EmbeddedData = new(); + public Dictionary EmbeddedData = []; public int PixelStride => Type == SpriteFrameType.Indexed8 ? 1 : Type == SpriteFrameType.Rgb24 ? 3 : 4; diff --git a/OpenRA.Game/FileSystem/FileSystem.cs b/OpenRA.Game/FileSystem/FileSystem.cs index 5178efc164..bbc710a549 100644 --- a/OpenRA.Game/FileSystem/FileSystem.cs +++ b/OpenRA.Game/FileSystem/FileSystem.cs @@ -29,16 +29,16 @@ namespace OpenRA.FileSystem public class FileSystem : IReadOnlyFileSystem { public IEnumerable MountedPackages => mountedPackages.Keys; - readonly Dictionary mountedPackages = new(); - readonly Dictionary explicitMounts = new(); + readonly Dictionary mountedPackages = []; + readonly Dictionary explicitMounts = []; readonly string modID; // Mod packages that should not be disposed - readonly List modPackages = new(); + readonly List modPackages = []; readonly IReadOnlyDictionary installedMods; readonly IPackageLoader[] packageLoaders; - Cache> fileIndex = new(_ => new List()); + Cache> fileIndex = new(_ => []); public FileSystem(string modID, IReadOnlyDictionary installedMods, IPackageLoader[] packageLoaders) { @@ -178,7 +178,7 @@ namespace OpenRA.FileSystem explicitMounts.Clear(); modPackages.Clear(); - fileIndex = new Cache>(_ => new List()); + fileIndex = new Cache>(_ => []); } public void TrimExcess() diff --git a/OpenRA.Game/FluentBundle.cs b/OpenRA.Game/FluentBundle.cs index fc7cde5262..b7511d44f1 100644 --- a/OpenRA.Game/FluentBundle.cs +++ b/OpenRA.Game/FluentBundle.cs @@ -128,7 +128,7 @@ namespace OpenRA throw new ArgumentException("Expected a comma separated list of name, value arguments " + "but the number of arguments is not a multiple of two", nameof(args)); - fluentArgs = new Dictionary(); + fluentArgs = []; for (var i = 0; i < args.Length; i += 2) { var argKey = args[i] as string; diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index fca786f774..e6d94e6cd3 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -356,7 +356,7 @@ namespace OpenRA var explicitModPaths = Array.Empty(); if (modID != null && (File.Exists(modID) || Directory.Exists(modID))) { - explicitModPaths = new[] { modID }; + explicitModPaths = [modID]; modID = Path.GetFileNameWithoutExtension(modID); } @@ -402,7 +402,7 @@ namespace OpenRA var modSearchArg = args.GetValue("Engine.ModSearchPaths", null); var modSearchPaths = modSearchArg != null ? FieldLoader.GetValue("Engine.ModsPath", modSearchArg) : - new[] { Path.Combine(Platform.EngineDir, "mods") }; + [Path.Combine(Platform.EngineDir, "mods")]; Mods = new InstalledMods(modSearchPaths, explicitModPaths); Console.WriteLine("Internal mods:"); diff --git a/OpenRA.Game/GameInformation.cs b/OpenRA.Game/GameInformation.cs index 9149b35d65..7017fa3d7c 100644 --- a/OpenRA.Game/GameInformation.cs +++ b/OpenRA.Game/GameInformation.cs @@ -39,7 +39,7 @@ namespace OpenRA public TimeSpan Duration => EndTimeUtc > StartTimeUtc ? EndTimeUtc - StartTimeUtc : TimeSpan.Zero; public IList Players { get; } - public HashSet DisabledSpawnPoints = new(); + public HashSet DisabledSpawnPoints = []; public MapPreview MapPreview => Game.ModData.MapCache[MapUid]; public IEnumerable HumanPlayers { get { return Players.Where(p => p.IsHuman); } } public bool IsSinglePlayer => HumanPlayers.Count() == 1; @@ -48,8 +48,8 @@ namespace OpenRA public GameInformation() { - Players = new List(); - playersByRuntime = new Dictionary(); + Players = []; + playersByRuntime = []; } public static GameInformation Deserialize(string data, string path) diff --git a/OpenRA.Game/GameRules/ActorInfo.cs b/OpenRA.Game/GameRules/ActorInfo.cs index d4bcbc3c99..8518daf14f 100644 --- a/OpenRA.Game/GameRules/ActorInfo.cs +++ b/OpenRA.Game/GameRules/ActorInfo.cs @@ -32,7 +32,7 @@ namespace OpenRA /// You can remove inherited traits by adding a - in front of them as in -TraitName: to inherit everything, but this trait. /// public readonly string Name; - readonly TypeDictionary traits = new(); + readonly TypeDictionary traits = []; TraitInfo[] constructOrderCache = null; public ActorInfo(ObjectCreator creator, string name, MiniYaml node) diff --git a/OpenRA.Game/GameRules/SoundInfo.cs b/OpenRA.Game/GameRules/SoundInfo.cs index e2711ccf45..8f704d54b6 100644 --- a/OpenRA.Game/GameRules/SoundInfo.cs +++ b/OpenRA.Game/GameRules/SoundInfo.cs @@ -17,14 +17,14 @@ namespace OpenRA.GameRules { public class SoundInfo { - public readonly Dictionary Variants = new(); - public readonly Dictionary Prefixes = new(); - public readonly Dictionary Voices = new(); - public readonly Dictionary Notifications = new(); + public readonly Dictionary Variants = []; + public readonly Dictionary Prefixes = []; + public readonly Dictionary Voices = []; + public readonly Dictionary Notifications = []; public readonly string DefaultVariant = ".aud"; public readonly string DefaultPrefix = ""; - public readonly HashSet DisableVariants = new(); - public readonly HashSet DisablePrefixes = new(); + public readonly HashSet DisableVariants = []; + public readonly HashSet DisablePrefixes = []; public readonly Lazy> VoicePools; public readonly Lazy> NotificationsPools; @@ -69,7 +69,7 @@ namespace OpenRA.GameRules public readonly float VolumeModifier; public readonly InterruptType Type; readonly string[] clips; - readonly List liveclips = new(); + readonly List liveclips = []; public SoundPool(float volumeModifier, InterruptType interruptType, params string[] clips) { diff --git a/OpenRA.Game/GameRules/WeaponInfo.cs b/OpenRA.Game/GameRules/WeaponInfo.cs index bac06ff470..adb8c26e69 100644 --- a/OpenRA.Game/GameRules/WeaponInfo.cs +++ b/OpenRA.Game/GameRules/WeaponInfo.cs @@ -36,7 +36,7 @@ namespace OpenRA.GameRules public class WarheadArgs { public WeaponInfo Weapon; - public int[] DamageModifiers = Array.Empty(); + public int[] DamageModifiers = []; public WPos? Source; public WRot ImpactOrientation; public WPos ImpactPosition; @@ -116,7 +116,7 @@ namespace OpenRA.GameRules [Desc("Delay in ticks between firing shots from the same ammo magazine. If one entry, it will be used for all bursts.", "If multiple entries, their number needs to match Burst - 1.")] - public readonly int[] BurstDelays = { 5 }; + public readonly int[] BurstDelays = [5]; [Desc("The minimum range the weapon can fire.")] public readonly WDist MinRange = WDist.Zero; @@ -128,7 +128,7 @@ namespace OpenRA.GameRules public readonly IProjectileInfo Projectile; [FieldLoader.LoadUsing(nameof(LoadWarheads))] - public readonly List Warheads = new(); + public readonly List Warheads = []; /// /// This constructor is used solely for documentation generation. @@ -139,7 +139,7 @@ namespace OpenRA.GameRules { // Resolve any weapon-level yaml inheritance or removals // HACK: The "Defaults" sequence syntax prevents us from doing this generally during yaml parsing - content = content.WithNodes(MiniYaml.Merge(new IReadOnlyCollection[] { content.Nodes })); + content = content.WithNodes(MiniYaml.Merge([content.Nodes])); FieldLoader.Load(this, content); } diff --git a/OpenRA.Game/Graphics/Animation.cs b/OpenRA.Game/Graphics/Animation.cs index d2ce02874b..9397f2058f 100644 --- a/OpenRA.Game/Graphics/Animation.cs +++ b/OpenRA.Game/Graphics/Animation.cs @@ -73,10 +73,10 @@ namespace OpenRA.Graphics shadow, pos, offset - new WVec(0, 0, height), CurrentSequence.ShadowZOffset + zOffset + height, palette, CurrentSequence.Scale, 1f, float3.Ones, tintModifiers, true, rotation); - return new IRenderable[] { shadowRenderable, imageRenderable }; + return [shadowRenderable, imageRenderable]; } - return new IRenderable[] { imageRenderable }; + return [imageRenderable]; } public IRenderable[] RenderUI(WorldRenderer wr, int2 pos, in WVec offset, int zOffset, PaletteReference palette, float scale = 1f, float rotation = 0f) @@ -92,10 +92,10 @@ namespace OpenRA.Graphics { var shadowPos = pos - new int2((int)(scale * shadow.Size.X / 2), (int)(scale * shadow.Size.Y / 2)); var shadowRenderable = new UISpriteRenderable(shadow, WPos.Zero + offset, shadowPos, CurrentSequence.ShadowZOffset + zOffset, palette, scale, 1f, rotation); - return new IRenderable[] { shadowRenderable, imageRenderable }; + return [shadowRenderable, imageRenderable]; } - return new IRenderable[] { imageRenderable }; + return [imageRenderable]; } public Rectangle ScreenBounds(WorldRenderer wr, WPos pos, in WVec offset) diff --git a/OpenRA.Game/Graphics/ChromeProvider.cs b/OpenRA.Game/Graphics/ChromeProvider.cs index 49e6f95c93..ba20c69d40 100644 --- a/OpenRA.Game/Graphics/ChromeProvider.cs +++ b/OpenRA.Game/Graphics/ChromeProvider.cs @@ -49,7 +49,7 @@ namespace OpenRA.Graphics public readonly int[] PanelRegion = null; public readonly PanelSides PanelSides = PanelSides.All; - public readonly Dictionary Regions = new(); + public readonly Dictionary Regions = []; } public static IReadOnlyDictionary Collections => collections; @@ -71,11 +71,11 @@ namespace OpenRA.Graphics dpiScale = Game.Renderer.WindowScale; fileSystem = modData.DefaultFileSystem; - collections = new Dictionary(); - cachedSheets = new Dictionary(); - cachedSprites = new Dictionary>(); - cachedPanelSprites = new Dictionary(); - cachedCollectionSheets = new Dictionary(); + collections = []; + cachedSheets = []; + cachedSprites = []; + cachedPanelSprites = []; + cachedCollectionSheets = []; var stringPool = new HashSet(); // Reuse common strings in YAML var chrome = MiniYaml.Merge(modData.Manifest.Chrome @@ -170,7 +170,7 @@ namespace OpenRA.Graphics var sheetDensity = SheetForCollection(collection); if (cachedCollection == null) { - cachedCollection = new Dictionary(); + cachedCollection = []; cachedSprites.Add(collectionName, cachedCollection); } @@ -240,11 +240,11 @@ namespace OpenRA.Graphics // PERF: We don't need to search for images if there are no definitions. // PERF: It's more efficient to send an empty array rather than an array of 9 nulls. if (collection.Regions.Count == 0) - return Array.Empty(); + return []; // Support manual definitions for unusual dialog layouts - sprites = new[] - { + sprites = + [ TryGetImage(collectionName, "corner-tl"), TryGetImage(collectionName, "border-t"), TryGetImage(collectionName, "corner-tr"), @@ -254,7 +254,7 @@ namespace OpenRA.Graphics TryGetImage(collectionName, "corner-bl"), TryGetImage(collectionName, "border-b"), TryGetImage(collectionName, "corner-br") - }; + ]; } cachedPanelSprites.Add(collectionName, sprites); diff --git a/OpenRA.Game/Graphics/CursorManager.cs b/OpenRA.Game/Graphics/CursorManager.cs index 8c7e480183..1837c1a048 100644 --- a/OpenRA.Game/Graphics/CursorManager.cs +++ b/OpenRA.Game/Graphics/CursorManager.cs @@ -29,7 +29,7 @@ namespace OpenRA.Graphics public IHardwareCursor[] Cursors; } - readonly Dictionary cursors = new(); + readonly Dictionary cursors = []; readonly SheetBuilder sheetBuilder; readonly GraphicSettings graphicSettings; @@ -233,7 +233,7 @@ namespace OpenRA.Graphics var height = frame.Size.Height; if (width == 0 || height == 0) - return Array.Empty(); + return []; var data = new byte[4 * width * height]; unsafe diff --git a/OpenRA.Game/Graphics/HardwarePalette.cs b/OpenRA.Game/Graphics/HardwarePalette.cs index 4c111eb2bc..315dd09a67 100644 --- a/OpenRA.Game/Graphics/HardwarePalette.cs +++ b/OpenRA.Game/Graphics/HardwarePalette.cs @@ -21,11 +21,11 @@ namespace OpenRA.Graphics public ITexture ColorShifts { get; } public int Height { get; private set; } - readonly Dictionary palettes = new(); - readonly Dictionary mutablePalettes = new(); - readonly Dictionary indices = new(); - byte[] buffer = Array.Empty(); - float[] colorShiftBuffer = Array.Empty(); + readonly Dictionary palettes = []; + readonly Dictionary mutablePalettes = []; + readonly Dictionary indices = []; + byte[] buffer = []; + float[] colorShiftBuffer = []; public HardwarePalette() { diff --git a/OpenRA.Game/Graphics/ModelVertex.cs b/OpenRA.Game/Graphics/ModelVertex.cs index 0eecad7a9a..3d9f861b0c 100644 --- a/OpenRA.Game/Graphics/ModelVertex.cs +++ b/OpenRA.Game/Graphics/ModelVertex.cs @@ -43,11 +43,11 @@ namespace OpenRA.Graphics : base("model") { } - public override ShaderVertexAttribute[] Attributes { get; } = new[] - { + public override ShaderVertexAttribute[] Attributes { get; } = + [ new ShaderVertexAttribute("aVertexPosition", ShaderVertexAttributeType.Float, 3, 0), new ShaderVertexAttribute("aVertexTexCoord", ShaderVertexAttributeType.Float, 4, 12), new ShaderVertexAttribute("aVertexTexMetadata", ShaderVertexAttributeType.Float, 2, 28), - }; + ]; } } diff --git a/OpenRA.Game/Graphics/RenderPostProcessPassVertex.cs b/OpenRA.Game/Graphics/RenderPostProcessPassVertex.cs index 0bb501e49a..364b2c9c05 100644 --- a/OpenRA.Game/Graphics/RenderPostProcessPassVertex.cs +++ b/OpenRA.Game/Graphics/RenderPostProcessPassVertex.cs @@ -43,10 +43,10 @@ namespace OpenRA.Graphics public RenderPostProcessPassShaderBindings(string name) : base("postprocess", "postprocess_" + name) { } - public override ShaderVertexAttribute[] Attributes { get; } = new[] - { + public override ShaderVertexAttribute[] Attributes { get; } = + [ new ShaderVertexAttribute("aVertexPosition", ShaderVertexAttributeType.Float, 2, 0) - }; + ]; } public sealed class RenderPostProcessPassTexturedShaderBindings : ShaderBindings @@ -55,10 +55,10 @@ namespace OpenRA.Graphics : base("postprocess_textured", "postprocess_textured_" + name) { } - public override ShaderVertexAttribute[] Attributes { get; } = new[] - { + public override ShaderVertexAttribute[] Attributes { get; } = + [ new ShaderVertexAttribute("aVertexPosition", ShaderVertexAttributeType.Float, 2, 0), new ShaderVertexAttribute("aVertexTexCoord", ShaderVertexAttributeType.Float, 2, 8), - }; + ]; } } diff --git a/OpenRA.Game/Graphics/RgbaColorRenderer.cs b/OpenRA.Game/Graphics/RgbaColorRenderer.cs index f2ceac5337..b36d2c3bca 100644 --- a/OpenRA.Game/Graphics/RgbaColorRenderer.cs +++ b/OpenRA.Game/Graphics/RgbaColorRenderer.cs @@ -191,7 +191,7 @@ namespace OpenRA.Graphics { var tr = new float3(br.X, tl.Y, tl.Z); var bl = new float3(tl.X, br.Y, br.Z); - DrawPolygon(new[] { tl, tr, br, bl }, width, color, blendMode); + DrawPolygon([tl, tr, br, bl], width, color, blendMode); } public void FillRect(in float3 tl, in float3 br, Color color, BlendMode blendMode = BlendMode.Alpha) diff --git a/OpenRA.Game/Graphics/SheetBuilder.cs b/OpenRA.Game/Graphics/SheetBuilder.cs index d38e76e5af..27721c91c0 100644 --- a/OpenRA.Game/Graphics/SheetBuilder.cs +++ b/OpenRA.Game/Graphics/SheetBuilder.cs @@ -33,7 +33,7 @@ namespace OpenRA.Graphics public sealed class SheetBuilder : IDisposable { public readonly SheetType Type; - readonly List sheets = new(); + readonly List sheets = []; readonly Func allocateSheet; readonly int margin; int rowHeight = 0; diff --git a/OpenRA.Game/Graphics/SpriteCache.cs b/OpenRA.Game/Graphics/SpriteCache.cs index c3e1e1391d..e75aa844ab 100644 --- a/OpenRA.Game/Graphics/SpriteCache.cs +++ b/OpenRA.Game/Graphics/SpriteCache.cs @@ -27,12 +27,12 @@ namespace OpenRA.Graphics readonly Dictionary< int, - (int[] Frames, MiniYamlNode.SourceLocation Location, AdjustFrame AdjustFrame, bool Premultiplied)> spriteReservations = new(); - readonly Dictionary> reservationsByFilename = new(); + (int[] Frames, MiniYamlNode.SourceLocation Location, AdjustFrame AdjustFrame, bool Premultiplied)> spriteReservations = []; + readonly Dictionary> reservationsByFilename = []; - readonly Dictionary resolvedSprites = new(); + readonly Dictionary resolvedSprites = []; - readonly Dictionary missingFiles = new(); + readonly Dictionary missingFiles = []; int nextReservationToken = 1; @@ -54,7 +54,7 @@ namespace OpenRA.Graphics { var token = nextReservationToken++; spriteReservations[token] = (frames?.ToArray(), location, adjustFrame, premultiplied); - reservationsByFilename.GetOrAdd(filename, _ => new List()).Add(token); + reservationsByFilename.GetOrAdd(filename, _ => []).Add(token); return token; } diff --git a/OpenRA.Game/Graphics/SpriteRenderable.cs b/OpenRA.Game/Graphics/SpriteRenderable.cs index f8a6cb03ff..32fb1ff924 100644 --- a/OpenRA.Game/Graphics/SpriteRenderable.cs +++ b/OpenRA.Game/Graphics/SpriteRenderable.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using OpenRA.Primitives; @@ -17,7 +16,7 @@ namespace OpenRA.Graphics { public class SpriteRenderable : IPalettedRenderable, IModifyableRenderable, IFinalizedRenderable { - public static readonly IEnumerable None = Array.Empty(); + public static readonly IEnumerable None = []; readonly Sprite sprite; readonly WPos pos; diff --git a/OpenRA.Game/Graphics/TerrainSpriteLayer.cs b/OpenRA.Game/Graphics/TerrainSpriteLayer.cs index 802e5e85b9..9efc2d65e9 100644 --- a/OpenRA.Game/Graphics/TerrainSpriteLayer.cs +++ b/OpenRA.Game/Graphics/TerrainSpriteLayer.cs @@ -19,7 +19,7 @@ namespace OpenRA.Graphics public sealed class TerrainSpriteLayer : IDisposable { // PERF: we can reuse the IndexBuffer as all layers have the same size. - static readonly ConditionalWeakTable IndexBuffers = new(); + static readonly ConditionalWeakTable IndexBuffers = []; readonly IndexBufferRc indexBufferWrapper; public readonly BlendMode BlendMode; @@ -30,7 +30,7 @@ namespace OpenRA.Graphics readonly IVertexBuffer vertexBuffer; readonly Vertex[] vertices; readonly bool[] ignoreTint; - readonly HashSet dirtyRows = new(); + readonly HashSet dirtyRows = []; readonly int indexRowStride; readonly int vertexRowStride; readonly bool restrictToBounds; diff --git a/OpenRA.Game/Graphics/Util.cs b/OpenRA.Game/Graphics/Util.cs index f8d6be32db..69d47b4f45 100644 --- a/OpenRA.Game/Graphics/Util.cs +++ b/OpenRA.Game/Graphics/Util.cs @@ -19,12 +19,12 @@ namespace OpenRA.Graphics public static class Util { // yes, our channel order is nuts. - static readonly int[] ChannelMasks = { 2, 1, 0, 3 }; + static readonly int[] ChannelMasks = [2, 1, 0, 3]; public static uint[] CreateQuadIndices(int quads) { var indices = new uint[quads * 6]; - ReadOnlySpan cornerVertexMap = stackalloc uint[] { 0, 1, 2, 2, 3, 0 }; + ReadOnlySpan cornerVertexMap = [0, 1, 2, 2, 3, 0]; for (var i = 0; i < indices.Length; i++) indices[i] = cornerVertexMap[i % 6] + (uint)(4 * (i / 6)); @@ -277,13 +277,13 @@ namespace OpenRA.Graphics size.X * angleSin - size.Y * angleCos, (size.X * angleSin - size.Y * angleCos) * size.Z / size.Y); - return new float3[] - { + return + [ center - ra, center + rb, center + ra, center - rb - }; + ]; } /// diff --git a/OpenRA.Game/Graphics/Vertex.cs b/OpenRA.Game/Graphics/Vertex.cs index 9e31c99279..0270e658aa 100644 --- a/OpenRA.Game/Graphics/Vertex.cs +++ b/OpenRA.Game/Graphics/Vertex.cs @@ -53,12 +53,12 @@ namespace OpenRA.Graphics : base("combined") { } - public override ShaderVertexAttribute[] Attributes { get; } = new[] - { + public override ShaderVertexAttribute[] Attributes { get; } = + [ new ShaderVertexAttribute("aVertexPosition", ShaderVertexAttributeType.Float, 3, 0), new ShaderVertexAttribute("aVertexTexCoord", ShaderVertexAttributeType.Float, 4, 12), new ShaderVertexAttribute("aVertexAttributes", ShaderVertexAttributeType.UInt, 1, 28), new ShaderVertexAttribute("aVertexTint", ShaderVertexAttributeType.Float, 4, 32) - }; + ]; } } diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index 336d00e5d6..523a08f2ea 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -31,19 +31,19 @@ namespace OpenRA.Graphics public event Action PaletteInvalidated = null; - readonly HashSet onScreenActors = new(); + readonly HashSet onScreenActors = []; readonly HardwarePalette palette = new(); - readonly Dictionary palettes = new(); + readonly Dictionary palettes = []; readonly IRenderTerrain terrainRenderer; readonly Lazy debugVis; readonly Func createPaletteReference; readonly bool enableDepthBuffer; - readonly List preparedRenderables = new(); - readonly List preparedOverlayRenderables = new(); - readonly List preparedAnnotationRenderables = new(); + readonly List preparedRenderables = []; + readonly List preparedOverlayRenderables = []; + readonly List preparedAnnotationRenderables = []; - readonly List renderablesBuffer = new(); + readonly List renderablesBuffer = []; readonly IRenderer[] renderers; readonly IRenderPostProcessPass[] postProcessPasses; @@ -429,7 +429,7 @@ namespace OpenRA.Graphics public float[] ScreenVector(in WVec vec) { var xyz = ScreenVectorComponents(vec); - return new[] { xyz.X, xyz.Y, xyz.Z, 1f }; + return [xyz.X, xyz.Y, xyz.Z, 1f]; } public int2 ScreenPxOffset(in WVec vec) diff --git a/OpenRA.Game/HotkeyDefinition.cs b/OpenRA.Game/HotkeyDefinition.cs index 7775583892..5228d51bea 100644 --- a/OpenRA.Game/HotkeyDefinition.cs +++ b/OpenRA.Game/HotkeyDefinition.cs @@ -24,10 +24,10 @@ namespace OpenRA [FluentReference] public readonly string Description = ""; - public readonly HashSet Types = new(); + public readonly HashSet Types = []; [FluentReference] - public readonly HashSet Contexts = new(); + public readonly HashSet Contexts = []; public readonly bool Readonly = false; public bool HasDuplicates { get; internal set; } diff --git a/OpenRA.Game/HotkeyManager.cs b/OpenRA.Game/HotkeyManager.cs index a28f9266a3..825b3cbfe5 100644 --- a/OpenRA.Game/HotkeyManager.cs +++ b/OpenRA.Game/HotkeyManager.cs @@ -18,8 +18,8 @@ namespace OpenRA public sealed class HotkeyManager { readonly Dictionary settings; - readonly Dictionary definitions = new(); - readonly Dictionary keys = new(); + readonly Dictionary definitions = []; + readonly Dictionary keys = []; public HotkeyManager(IReadOnlyFileSystem fileSystem, Dictionary settings, Manifest manifest) { diff --git a/OpenRA.Game/Manifest.cs b/OpenRA.Game/Manifest.cs index bb71c1ea8a..bdab33ebe0 100644 --- a/OpenRA.Game/Manifest.cs +++ b/OpenRA.Game/Manifest.cs @@ -78,11 +78,11 @@ namespace OpenRA public readonly MiniYaml LoadScreen; public readonly string DefaultOrderGenerator; - public readonly string[] Assemblies = Array.Empty(); - public readonly string[] SoundFormats = Array.Empty(); - public readonly string[] SpriteFormats = Array.Empty(); - public readonly string[] PackageFormats = Array.Empty(); - public readonly string[] VideoFormats = Array.Empty(); + public readonly string[] Assemblies = []; + public readonly string[] SoundFormats = []; + public readonly string[] SpriteFormats = []; + public readonly string[] PackageFormats = []; + public readonly string[] VideoFormats = []; public readonly int FontSheetSize = 512; public readonly int CursorSheetSize = 512; @@ -91,15 +91,15 @@ namespace OpenRA public readonly bool AllowUnusedFluentMessagesInExternalPackages = true; readonly string[] reservedModuleNames = - { + [ "Include", "Metadata", "FileSystem", "MapFolders", "Rules", "Sequences", "ModelSequences", "Cursors", "Chrome", "Assemblies", "ChromeLayout", "Weapons", "Voices", "Notifications", "Music", "FluentMessages", "TileSets", "ChromeMetrics", "Missions", "Hotkeys", "ServerTraits", "LoadScreen", "DefaultOrderGenerator", "SupportsMapsFrom", "SoundFormats", "SpriteFormats", "VideoFormats", "RequiresMods", "PackageFormats", "AllowUnusedFluentMessagesInExternalPackages", "FontSheetSize", "CursorSheetSize" - }; + ]; - readonly TypeDictionary modules = new(); + readonly TypeDictionary modules = []; readonly Dictionary yaml; bool customDataLoaded; @@ -127,7 +127,7 @@ namespace OpenRA } // Merge inherited overrides - yaml = new MiniYaml(null, MiniYaml.Merge(new[] { nodes })).ToDictionary(); + yaml = new MiniYaml(null, MiniYaml.Merge([nodes])).ToDictionary(); Metadata = FieldLoader.Load(yaml["Metadata"]); @@ -207,11 +207,11 @@ namespace OpenRA throw new InvalidDataException($"`{kv.Key}` is not a valid mod manifest entry."); IGlobalModData module; - var ctor = t.GetConstructor(new[] { typeof(MiniYaml) }); + var ctor = t.GetConstructor([typeof(MiniYaml)]); if (ctor != null) { // Class has opted-in to DIY initialization - module = (IGlobalModData)ctor.Invoke(new object[] { kv.Value }); + module = (IGlobalModData)ctor.Invoke([kv.Value]); } else { @@ -229,7 +229,7 @@ namespace OpenRA static string[] YamlList(Dictionary yaml, string key) { if (!yaml.TryGetValue(key, out var value)) - return Array.Empty(); + return []; return value.Nodes.Select(n => n.Key).ToArray(); } @@ -279,11 +279,11 @@ namespace OpenRA } IGlobalModData module; - var ctor = t.GetConstructor(new[] { typeof(MiniYaml) }); + var ctor = t.GetConstructor([typeof(MiniYaml)]); if (ctor != null) { // Class has opted-in to DIY initialization - module = (IGlobalModData)ctor.Invoke(new object[] { data.Value }); + module = (IGlobalModData)ctor.Invoke([data.Value]); } else { diff --git a/OpenRA.Game/Map/ActorReference.cs b/OpenRA.Game/Map/ActorReference.cs index 55e1b078f4..35c45cb968 100644 --- a/OpenRA.Game/Map/ActorReference.cs +++ b/OpenRA.Game/Map/ActorReference.cs @@ -74,11 +74,11 @@ namespace OpenRA if (initInstance.Length > 1) type.GetField(nameof(ActorInit.InstanceName)).SetValue(init, initInstance[1]); - var loader = type.GetMethod("Initialize", new[] { typeof(MiniYaml) }); + var loader = type.GetMethod("Initialize", [typeof(MiniYaml)]); if (loader == null) throw new InvalidDataException($"{initInstance[0]}Init does not define a yaml-assignable type."); - loader.Invoke(init, new[] { initYaml }); + loader.Invoke(init, [initYaml]); return init; } diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index 64f4b6a2c6..937a2dc2ab 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -11,7 +11,6 @@ using System; using System.Collections.Generic; -using System.Collections.Immutable; using System.IO; using System.Linq; using System.Reflection; @@ -158,7 +157,7 @@ namespace OpenRA /// Defines the order of the fields in map.yaml. static readonly MapField[] YamlFields = - { + [ new("MapFormat"), new("RequiresMod"), new("Title"), @@ -179,7 +178,7 @@ namespace OpenRA new("Voices", nameof(VoiceDefinitions), required: false), new("Music", nameof(MusicDefinitions), required: false), new("Notifications", nameof(NotificationDefinitions), required: false), - }; + ]; // Format versions public int MapFormat { get; private set; } @@ -193,13 +192,13 @@ namespace OpenRA public bool LockPreview; public Rectangle Bounds; public MapVisibility Visibility = MapVisibility.Lobby; - public string[] Categories = { "Conquest" }; + public string[] Categories = ["Conquest"]; public int2 MapSize { get; private set; } // Player and actor yaml. Public for access by the map importers and lint checks. - public IReadOnlyCollection PlayerDefinitions = ImmutableArray.Empty; - public IReadOnlyCollection ActorDefinitions = ImmutableArray.Empty; + public IReadOnlyCollection PlayerDefinitions = []; + public IReadOnlyCollection ActorDefinitions = []; // Custom map yaml. Public for access by the map importers and lint checks public MiniYaml RuleDefinitions; @@ -211,7 +210,7 @@ namespace OpenRA public MiniYaml MusicDefinitions; public MiniYaml NotificationDefinitions; - public readonly Dictionary ReplacedInvalidTerrainTiles = new(); + public readonly Dictionary ReplacedInvalidTerrainTiles = []; // Generated data public readonly MapGrid Grid; @@ -283,7 +282,7 @@ namespace OpenRA // Take the SHA1 if (streams.Count == 0) - return CryptoUtil.SHA1Hash(Array.Empty()); + return CryptoUtil.SHA1Hash([]); var merged = streams[0]; for (var i = 1; i < streams.Count; i++) @@ -368,8 +367,8 @@ namespace OpenRA if (MapFormat < SupportedMapFormat) throw new InvalidDataException($"Map format {MapFormat} is not supported.\n File: {package.Name}"); - PlayerDefinitions = yaml.NodeWithKeyOrDefault("Players")?.Value.Nodes ?? ImmutableArray.Empty; - ActorDefinitions = yaml.NodeWithKeyOrDefault("Actors")?.Value.Nodes ?? ImmutableArray.Empty; + PlayerDefinitions = yaml.NodeWithKeyOrDefault("Players")?.Value.Nodes ?? []; + ActorDefinitions = yaml.NodeWithKeyOrDefault("Actors")?.Value.Nodes ?? []; Grid = modData.Manifest.Get(); @@ -516,7 +515,7 @@ namespace OpenRA foreach (var cell in AllCells) { var uv = cell.ToMPos(Grid.Type); - cellProjection[uv] = Array.Empty(); + cellProjection[uv] = []; inverseCellProjection[uv] = new List(1); } @@ -532,7 +531,7 @@ namespace OpenRA if (Grid.MaximumTerrainHeight == 0) { uv = cell.ToMPos(Grid.Type); - cellProjection[cell] = new[] { (PPos)uv }; + cellProjection[cell] = [(PPos)uv]; var inverse = inverseCellProjection[uv]; inverse.Clear(); inverse.Add(uv); @@ -607,7 +606,7 @@ namespace OpenRA // Any changes to this function should be reflected when setting projectionSafeBounds. var height = mapHeight[uv]; if (height == 0) - return new[] { (PPos)uv }; + return [(PPos)uv]; // Odd-height ramps get bumped up a level to the next even height layer if ((height & 1) == 1 && Ramp[uv] != 0) @@ -1044,7 +1043,7 @@ namespace OpenRA return (PPos)CellContaining(projectedPos).ToMPos(Grid.Type); } - static readonly PPos[] NoProjectedCells = Array.Empty(); + static readonly PPos[] NoProjectedCells = []; public PPos[] ProjectedCellsCovering(MPos uv) { if (!initializedCellProjection) @@ -1064,7 +1063,7 @@ namespace OpenRA InitializeCellProjection(); if (!inverseCellProjection.Contains(uv)) - return new List(); + return []; return inverseCellProjection[uv]; } diff --git a/OpenRA.Game/Map/MapCache.cs b/OpenRA.Game/Map/MapCache.cs index d79ff28a0b..b58ceb2f02 100644 --- a/OpenRA.Game/Map/MapCache.cs +++ b/OpenRA.Game/Map/MapCache.cs @@ -28,7 +28,7 @@ namespace OpenRA { public static readonly MapPreview UnknownMap = new(null, null, MapGridType.Rectangular, null); public IReadOnlyDictionary MapLocations => mapLocations; - readonly Dictionary mapLocations = new(); + readonly Dictionary mapLocations = []; public bool LoadPreviewImages = true; readonly Cache previews; @@ -37,17 +37,17 @@ namespace OpenRA Thread previewLoaderThread; bool previewLoaderThreadShutDown = true; readonly object syncRoot = new(); - readonly Queue generateMinimap = new(); + readonly Queue generateMinimap = []; - public HashSet StringPool { get; } = new(); + public HashSet StringPool { get; } = []; - readonly List mapDirectoryTrackers = new(); + readonly List mapDirectoryTrackers = []; /// /// The most recently modified or loaded map at runtime. /// public string LastModifiedMap { get; private set; } = null; - readonly Dictionary mapUpdates = new(); + readonly Dictionary mapUpdates = []; string lastLoadedLastModifiedMap; diff --git a/OpenRA.Game/Map/MapDirectoryTracker.cs b/OpenRA.Game/Map/MapDirectoryTracker.cs index 04c75c23cf..171c0dfbe9 100644 --- a/OpenRA.Game/Map/MapDirectoryTracker.cs +++ b/OpenRA.Game/Map/MapDirectoryTracker.cs @@ -24,7 +24,7 @@ namespace OpenRA readonly MapClassification classification; enum MapAction { Add, Delete, Update } - readonly Dictionary mapActionQueue = new(); + readonly Dictionary mapActionQueue = []; bool dirty = false; diff --git a/OpenRA.Game/Map/MapGrid.cs b/OpenRA.Game/Map/MapGrid.cs index cfa13b2d22..a44bbd8211 100644 --- a/OpenRA.Game/Map/MapGrid.cs +++ b/OpenRA.Game/Map/MapGrid.cs @@ -37,43 +37,43 @@ namespace OpenRA Orientation = orientation; if (type == MapGridType.RectangularIsometric) { - Corners = new[] - { + Corners = + [ new WVec(0, -724, 724 * (int)tl), new WVec(724, 0, 724 * (int)tr), new WVec(0, 724, 724 * (int)br), new WVec(-724, 0, 724 * (int)bl), - }; + ]; } else { - Corners = new[] - { + Corners = + [ new WVec(-512, -512, 512 * (int)tl), new WVec(512, -512, 512 * (int)tr), new WVec(512, 512, 512 * (int)br), new WVec(-512, 512, 512 * (int)bl) - }; + ]; } if (split == RampSplit.X) { - Polygons = new[] - { - new[] { Corners[0], Corners[1], Corners[3] }, - new[] { Corners[1], Corners[2], Corners[3] } - }; + Polygons = + [ + [Corners[0], Corners[1], Corners[3]], + [Corners[1], Corners[2], Corners[3]] + ]; } else if (split == RampSplit.Y) { - Polygons = new[] - { - new[] { Corners[0], Corners[1], Corners[2] }, - new[] { Corners[0], Corners[2], Corners[3] } - }; + Polygons = + [ + [Corners[0], Corners[1], Corners[2]], + [Corners[0], Corners[2], Corners[3]] + ]; } else - Polygons = new[] { Corners }; + Polygons = [Corners]; // Initial value must be assigned before HeightOffset can be called CenterHeightOffset = 0; @@ -115,14 +115,14 @@ namespace OpenRA public readonly bool EnableDepthBuffer = false; public readonly WVec[] SubCellOffsets = - { + [ new(0, 0, 0), // full cell - index 0 new(-299, -256, 0), // top left - index 1 new(256, -256, 0), // top right - index 2 new(0, 0, 0), // center - index 3 new(-299, 256, 0), // bottom left - index 4 new(256, 256, 0), // bottom right - index 5 - }; + ]; public CellRamp[] Ramps { get; } @@ -159,8 +159,9 @@ namespace OpenRA var halfBackward = -halfForward; // Slope types are hardcoded following the convention from the TS and RA2 map format - Ramps = new[] - { + Ramps = + [ + // Flat new CellRamp(Type, WRot.None), @@ -193,7 +194,7 @@ namespace OpenRA new CellRamp(Type, WRot.None, tl: RampCornerHeight.Half, br: RampCornerHeight.Half, split: RampSplit.Y), new CellRamp(Type, WRot.None, tr: RampCornerHeight.Half, bl: RampCornerHeight.Half, split: RampSplit.X), new CellRamp(Type, WRot.None, tl: RampCornerHeight.Half, br: RampCornerHeight.Half, split: RampSplit.X), - }; + ]; TilesByDistance = CreateTilesByDistance(); } @@ -202,7 +203,7 @@ namespace OpenRA { var ts = new List[MaximumTileSearchRange + 1]; for (var i = 0; i < MaximumTileSearchRange + 1; i++) - ts[i] = new List(); + ts[i] = []; for (var j = -MaximumTileSearchRange; j <= MaximumTileSearchRange; j++) for (var i = -MaximumTileSearchRange; i <= MaximumTileSearchRange; i++) diff --git a/OpenRA.Game/Map/MapPlayers.cs b/OpenRA.Game/Map/MapPlayers.cs index caf5108d18..7e26d1549c 100644 --- a/OpenRA.Game/Map/MapPlayers.cs +++ b/OpenRA.Game/Map/MapPlayers.cs @@ -24,7 +24,7 @@ namespace OpenRA public readonly Dictionary Players; public MapPlayers() - : this(new List()) { } + : this([]) { } public MapPlayers(IEnumerable playerDefinitions) { @@ -66,7 +66,7 @@ namespace OpenRA Name = $"Multi{index}", Faction = "Random", Playable = true, - Enemies = new[] { "Creeps" } + Enemies = ["Creeps"] }; Players.Add(p.Name, p); } diff --git a/OpenRA.Game/Map/MapPreview.cs b/OpenRA.Game/Map/MapPreview.cs index a22830ddbe..f5dd1a9a85 100644 --- a/OpenRA.Game/Map/MapPreview.cs +++ b/OpenRA.Game/Map/MapPreview.cs @@ -51,7 +51,7 @@ namespace OpenRA public readonly string[] categories; public readonly int players; public readonly Rectangle bounds; - public readonly short[] spawnpoints = Array.Empty(); + public readonly short[] spawnpoints = []; public readonly MapGridType map_grid_type; public readonly string minimap; public readonly bool downloading; @@ -195,7 +195,7 @@ namespace OpenRA } } - static readonly CPos[] NoSpawns = Array.Empty(); + static readonly CPos[] NoSpawns = []; readonly MapCache cache; readonly ModData modData; IReadOnlyPackage package; @@ -321,7 +321,7 @@ namespace OpenRA { MapFormat = 0, Title = "Unknown Map", - Categories = new[] { "Unknown" }, + Categories = ["Unknown"], Author = "Unknown Author", TileSet = "unknown", Players = null, @@ -421,11 +421,11 @@ namespace OpenRA newData.SpawnPoints = spawns.ToArray(); } else - newData.SpawnPoints = Array.Empty(); + newData.SpawnPoints = []; } catch (Exception) { - newData.SpawnPoints = Array.Empty(); + newData.SpawnPoints = []; newData.Status = MapStatus.Unavailable; } diff --git a/OpenRA.Game/Map/PlayerReference.cs b/OpenRA.Game/Map/PlayerReference.cs index 5c3a4beae7..b01b43937f 100644 --- a/OpenRA.Game/Map/PlayerReference.cs +++ b/OpenRA.Game/Map/PlayerReference.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using OpenRA.Primitives; namespace OpenRA @@ -54,8 +53,8 @@ namespace OpenRA public bool LockHandicap = false; public int Handicap = 0; - public string[] Allies = Array.Empty(); - public string[] Enemies = Array.Empty(); + public string[] Allies = []; + public string[] Enemies = []; public PlayerReference() { } public PlayerReference(MiniYaml my) { FieldLoader.Load(this, my); } diff --git a/OpenRA.Game/Map/TerrainInfo.cs b/OpenRA.Game/Map/TerrainInfo.cs index 24b3d12fd0..090033e1eb 100644 --- a/OpenRA.Game/Map/TerrainInfo.cs +++ b/OpenRA.Game/Map/TerrainInfo.cs @@ -60,7 +60,7 @@ namespace OpenRA { public readonly string Type; public readonly BitSet TargetTypes; - public readonly HashSet AcceptsSmudgeType = new(); + public readonly HashSet AcceptsSmudgeType = []; public readonly Color Color; public readonly bool RestrictPlayerColor = false; diff --git a/OpenRA.Game/MiniYaml.cs b/OpenRA.Game/MiniYaml.cs index 2b534bc1ee..d368190f18 100644 --- a/OpenRA.Game/MiniYaml.cs +++ b/OpenRA.Game/MiniYaml.cs @@ -99,7 +99,7 @@ namespace OpenRA } public MiniYamlNode(string k, string v, string c = null) - : this(k, new MiniYaml(v, Enumerable.Empty()), c) { } + : this(k, new MiniYaml(v, []), c) { } public MiniYamlNode(string k, string v, IEnumerable n) : this(k, new MiniYaml(v, n), null) { } @@ -115,7 +115,7 @@ namespace OpenRA const int SpacesPerLevel = 4; static readonly Func StringIdentity = s => s; static readonly Func MiniYamlIdentity = my => my; - static readonly Dictionary ConflictScratch = new(); + static readonly Dictionary ConflictScratch = []; public readonly string Value; public readonly ImmutableArray Nodes; @@ -196,12 +196,12 @@ namespace OpenRA } public MiniYaml(string value) - : this(value, Enumerable.Empty()) { } + : this(value, []) { } public MiniYaml(string value, IEnumerable nodes) { Value = value; - Nodes = ImmutableArray.CreateRange(nodes); + Nodes = nodes.ToImmutableArray(); } static List FromLines(IEnumerable> lines, string name, bool discardCommentsAndWhitespace, HashSet stringPool) @@ -210,7 +210,7 @@ namespace OpenRA // Pool these strings so we only need one copy of each unique string. // This saves on long-term memory usage as parsed values can often live a long time. // A caller can also provide a pool as input, allowing de-duplication across multiple parses. - stringPool ??= new HashSet(); + stringPool ??= []; var result = new List> { @@ -352,7 +352,7 @@ namespace OpenRA { var lastLevel = parsedLines[^1].Level; while (lastLevel >= result.Count) - result.Add(new List()); + result.Add([]); while (parsedLines.Count > 0 && parsedLines[^1].Level >= level) { @@ -393,14 +393,14 @@ namespace OpenRA public static List FromString(string text, string name, bool discardCommentsAndWhitespace = true, HashSet stringPool = null) { - return FromLines(text.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None).Select(s => s.AsMemory()), name, discardCommentsAndWhitespace, stringPool); + return FromLines(text.Split(["\r\n", "\n"], StringSplitOptions.None).Select(s => s.AsMemory()), name, discardCommentsAndWhitespace, stringPool); } public static List Merge(IEnumerable> sources) { var sourcesList = sources.ToList(); if (sourcesList.Count == 0) - return new List(); + return []; var tree = sourcesList .Where(s => s != null) @@ -696,7 +696,7 @@ namespace OpenRA public MiniYamlBuilder(string value, List nodes) { Value = value; - Nodes = nodes == null ? new List() : nodes.ConvertAll(x => new MiniYamlNodeBuilder(x)); + Nodes = nodes == null ? [] : nodes.ConvertAll(x => new MiniYamlNodeBuilder(x)); } public MiniYaml Build() diff --git a/OpenRA.Game/ModData.cs b/OpenRA.Game/ModData.cs index 32a7ffc15f..6cb0ec8b98 100644 --- a/OpenRA.Game/ModData.cs +++ b/OpenRA.Game/ModData.cs @@ -49,7 +49,7 @@ namespace OpenRA public ModData(Manifest mod, InstalledMods mods, bool useLoadScreen = false) { - Languages = Array.Empty(); + Languages = []; // Take a local copy of the manifest Manifest = new Manifest(mod.Id, mod.Package); @@ -82,19 +82,19 @@ namespace OpenRA var terrainFormat = Manifest.Get(); var terrainLoader = ObjectCreator.FindType(terrainFormat.Type + "Loader"); - var terrainCtor = terrainLoader?.GetConstructor(new[] { typeof(ModData) }); + var terrainCtor = terrainLoader?.GetConstructor([typeof(ModData)]); if (terrainLoader == null || !terrainLoader.GetInterfaces().Contains(typeof(ITerrainLoader)) || terrainCtor == null) throw new InvalidOperationException($"Unable to find a terrain loader for type '{terrainFormat.Type}'."); - TerrainLoader = (ITerrainLoader)terrainCtor.Invoke(new[] { this }); + TerrainLoader = (ITerrainLoader)terrainCtor.Invoke([this]); var sequenceFormat = Manifest.Get(); var sequenceLoader = ObjectCreator.FindType(sequenceFormat.Type + "Loader"); - var sequenceCtor = sequenceLoader?.GetConstructor(new[] { typeof(ModData) }); + var sequenceCtor = sequenceLoader?.GetConstructor([typeof(ModData)]); if (sequenceLoader == null || !sequenceLoader.GetInterfaces().Contains(typeof(ISpriteSequenceLoader)) || sequenceCtor == null) throw new InvalidOperationException($"Unable to find a sequence loader for type '{sequenceFormat.Type}'."); - SpriteSequenceLoader = (ISpriteSequenceLoader)sequenceCtor.Invoke(new[] { this }); + SpriteSequenceLoader = (ISpriteSequenceLoader)sequenceCtor.Invoke([this]); Hotkeys = new HotkeyManager(ModFiles, Game.Settings.Keys, Manifest); diff --git a/OpenRA.Game/Network/Connection.cs b/OpenRA.Game/Network/Connection.cs index 9063ce80b3..6bc57a16b2 100644 --- a/OpenRA.Game/Network/Connection.cs +++ b/OpenRA.Game/Network/Connection.cs @@ -42,9 +42,9 @@ namespace OpenRA.Network public sealed class EchoConnection : IConnection { const int LocalClientId = 1; - readonly Queue<(int Frame, int SyncHash, ulong DefeatState)> sync = new(); - readonly Queue<(int Frame, OrderPacket Orders)> orders = new(); - readonly Queue immediateOrders = new(); + readonly Queue<(int Frame, int SyncHash, ulong DefeatState)> sync = []; + readonly Queue<(int Frame, OrderPacket Orders)> orders = []; + readonly Queue immediateOrders = []; bool disposed; int IConnection.LocalClientId => LocalClientId; @@ -52,7 +52,7 @@ namespace OpenRA.Network void IConnection.StartGame() { // Inject an empty frame to fill the gap we are making by projecting forward orders - orders.Enqueue((0, new OrderPacket(Array.Empty()))); + orders.Enqueue((0, new OrderPacket([]))); } void IConnection.Send(int frame, IEnumerable o) @@ -100,12 +100,12 @@ namespace OpenRA.Network { public readonly ConnectionTarget Target; internal ReplayRecorder Recorder { get; private set; } - readonly Queue<(int Frame, int SyncHash, ulong DefeatState)> sentSync = new(); - readonly Queue<(int Frame, int SyncHash, ulong DefeatState)> queuedSyncPackets = new(); + readonly Queue<(int Frame, int SyncHash, ulong DefeatState)> sentSync = []; + readonly Queue<(int Frame, int SyncHash, ulong DefeatState)> queuedSyncPackets = []; - readonly Queue<(int Frame, OrderPacket Orders)> sentOrders = new(); - readonly Queue sentImmediateOrders = new(); - readonly ConcurrentQueue<(int FromClient, byte[] Data)> receivedPackets = new(); + readonly Queue<(int Frame, OrderPacket Orders)> sentOrders = []; + readonly Queue sentImmediateOrders = []; + readonly ConcurrentQueue<(int FromClient, byte[] Data)> receivedPackets = []; TcpClient tcp; volatile ConnectionState connectionState = ConnectionState.Connecting; volatile int clientId; diff --git a/OpenRA.Game/Network/ConnectionTarget.cs b/OpenRA.Game/Network/ConnectionTarget.cs index 53b153b70e..3ff70b223f 100644 --- a/OpenRA.Game/Network/ConnectionTarget.cs +++ b/OpenRA.Game/Network/ConnectionTarget.cs @@ -22,12 +22,12 @@ namespace OpenRA.Network public ConnectionTarget() { - endpoints = new[] { new DnsEndPoint("invalid", 0) }; + endpoints = [new DnsEndPoint("invalid", 0)]; } public ConnectionTarget(string host, int port) { - endpoints = new[] { new DnsEndPoint(host, port) }; + endpoints = [new DnsEndPoint(host, port)]; } public ConnectionTarget(IEnumerable endpoints) @@ -48,7 +48,7 @@ namespace OpenRA.Network } catch (Exception) { - return Enumerable.Empty(); + return []; } }).ToList(); } diff --git a/OpenRA.Game/Network/GameSave.cs b/OpenRA.Game/Network/GameSave.cs index 29f8a3a224..85ffdaad8f 100644 --- a/OpenRA.Game/Network/GameSave.cs +++ b/OpenRA.Game/Network/GameSave.cs @@ -86,22 +86,22 @@ namespace OpenRA.Network // Loaded from file and updated during gameplay public int LastOrdersFrame { get; private set; } public int LastSyncFrame { get; private set; } - byte[] lastSyncPacket = Array.Empty(); + byte[] lastSyncPacket = []; // Loaded from file or set on game start public Session.Global GlobalSettings { get; private set; } public Dictionary Slots { get; private set; } public Dictionary SlotClients { get; private set; } - public Dictionary TraitData = new(); + public Dictionary TraitData = []; // Set on game start - int[] clientsBySlotIndex = Array.Empty(); + int[] clientsBySlotIndex = []; int firstBotSlotIndex = -1; public GameSave() { LastOrdersFrame = -1; - Slots = new Dictionary(); + Slots = []; } public GameSave(string filepath) @@ -126,7 +126,7 @@ namespace OpenRA.Network GlobalSettings = Session.Global.Deserialize(globalSettings[0].Value); var slots = MiniYaml.FromString(rs.ReadLengthPrefixedString(Encoding.UTF8, Connection.MaxOrderLength), $"{filepath}:slots"); - Slots = new Dictionary(); + Slots = []; foreach (var s in slots) { var slot = Session.Slot.Deserialize(s.Value); @@ -134,7 +134,7 @@ namespace OpenRA.Network } var slotClients = MiniYaml.FromString(rs.ReadLengthPrefixedString(Encoding.UTF8, Connection.MaxOrderLength), $"{filepath}:slotClients"); - SlotClients = new Dictionary(); + SlotClients = []; foreach (var s in slotClients) { var slotClient = SlotClient.Deserialize(s.Value); @@ -166,8 +166,8 @@ namespace OpenRA.Network // Perform a deep clone by round-tripping the data GlobalSettings = Session.Global.Deserialize(lobbyInfo.GlobalSettings.Serialize().Value); - Slots = new Dictionary(); - SlotClients = new Dictionary(); + Slots = []; + SlotClients = []; foreach (var s in lobbyInfo.Slots) { Slots[s.Key] = Session.Slot.Deserialize(s.Value.Serialize().Value); diff --git a/OpenRA.Game/Network/GameServer.cs b/OpenRA.Game/Network/GameServer.cs index ce4fe4f3e3..0c335e1a53 100644 --- a/OpenRA.Game/Network/GameServer.cs +++ b/OpenRA.Game/Network/GameServer.cs @@ -48,7 +48,8 @@ namespace OpenRA.Network public class GameServer { static readonly string[] SerializeFields = - { + [ + // Server information "Name", "Address", @@ -57,7 +58,7 @@ namespace OpenRA.Network // Current server state "Map", "State", "MaxPlayers", "Protected", "Authentication", "DisabledSpawnPoints" - }; + ]; public const int ProtocolVersion = 2; @@ -133,7 +134,7 @@ namespace OpenRA.Network public readonly GameClient[] Clients; /// The list of spawnpoints that are disabled for this game. - public readonly int[] DisabledSpawnPoints = Array.Empty(); + public readonly int[] DisabledSpawnPoints = []; public string ModLabel => $"{ModTitle} ({Version})"; @@ -228,7 +229,7 @@ namespace OpenRA.Network Protected = !string.IsNullOrEmpty(server.Settings.Password); Authentication = server.Settings.RequireAuthentication || server.Settings.ProfileIDWhitelist.Length > 0; Clients = server.LobbyInfo.Clients.Select(c => new GameClient(c)).ToArray(); - DisabledSpawnPoints = server.LobbyInfo.DisabledSpawnPoints?.ToArray() ?? Array.Empty(); + DisabledSpawnPoints = server.LobbyInfo.DisabledSpawnPoints?.ToArray() ?? []; } public string ToPOSTData(bool lanGame) diff --git a/OpenRA.Game/Network/OrderIO.cs b/OpenRA.Game/Network/OrderIO.cs index afb587ab79..0366f96d84 100644 --- a/OpenRA.Game/Network/OrderIO.cs +++ b/OpenRA.Game/Network/OrderIO.cs @@ -78,7 +78,7 @@ namespace OpenRA.Network public static class OrderIO { - static readonly OrderPacket NoOrders = new(Array.Empty()); + static readonly OrderPacket NoOrders = new([]); public static byte[] SerializeSync((int Frame, int SyncHash, ulong DefeatState) data) { diff --git a/OpenRA.Game/Network/OrderManager.cs b/OpenRA.Game/Network/OrderManager.cs index f955d7804c..5f8ec3d701 100644 --- a/OpenRA.Game/Network/OrderManager.cs +++ b/OpenRA.Game/Network/OrderManager.cs @@ -26,8 +26,8 @@ namespace OpenRA.Network const string DesyncCompareLogs = "notification-desync-compare-logs"; readonly SyncReport syncReport; - readonly Dictionary> pendingOrders = new(); - readonly Dictionary syncForFrame = new(); + readonly Dictionary> pendingOrders = []; + readonly Dictionary syncForFrame = []; public Session LobbyInfo = new(); @@ -53,11 +53,11 @@ namespace OpenRA.Network internal int GameSaveLastFrame = -1; internal int GameSaveLastSyncFrame = -1; - readonly List localOrders = new(); - readonly List localImmediateOrders = new(); + readonly List localOrders = []; + readonly List localImmediateOrders = []; - readonly List processClientOrders = new(); - readonly List processClientsToRemove = new(); + readonly List processClientOrders = []; + readonly List processClientsToRemove = []; bool disposed; bool generateSyncReport = false; diff --git a/OpenRA.Game/Network/ReplayConnection.cs b/OpenRA.Game/Network/ReplayConnection.cs index b372d23acb..88133aafe6 100644 --- a/OpenRA.Game/Network/ReplayConnection.cs +++ b/OpenRA.Game/Network/ReplayConnection.cs @@ -24,8 +24,8 @@ namespace OpenRA.Network public (int ClientId, byte[] Packet)[] Packets; } - readonly Queue chunks = new(); - readonly Queue<(int Frame, int SyncHash, ulong DefeatState)> sync = new(); + readonly Queue chunks = []; + readonly Queue<(int Frame, int SyncHash, ulong DefeatState)> sync = []; readonly int orderLatency; public readonly int TickCount; diff --git a/OpenRA.Game/Network/Session.cs b/OpenRA.Game/Network/Session.cs index 143a9575fc..7807a00aa0 100644 --- a/OpenRA.Game/Network/Session.cs +++ b/OpenRA.Game/Network/Session.cs @@ -20,12 +20,12 @@ namespace OpenRA.Network { public class Session { - public List Clients = new(); + public List Clients = []; // Keyed by the PlayerReference id that the slot corresponds to - public Dictionary Slots = new(); + public Dictionary Slots = []; - public HashSet DisabledSpawnPoints = new(); + public HashSet DisabledSpawnPoints = []; public Global GlobalSettings = new(); @@ -221,7 +221,7 @@ namespace OpenRA.Network public int NetFrameInterval = 3; [FieldLoader.Ignore] - public Dictionary LobbyOptions = new(); + public Dictionary LobbyOptions = []; public static Global Deserialize(MiniYaml data) { @@ -240,7 +240,7 @@ namespace OpenRA.Network var data = new MiniYamlNode("GlobalSettings", FieldSaver.Save(this)); var options = LobbyOptions.Select(kv => new MiniYamlNode(kv.Key, FieldSaver.Save(kv.Value))); data = data.WithValue(data.Value.WithNodesAppended( - new[] { new MiniYamlNode("Options", new MiniYaml(null, options)) })); + [new MiniYamlNode("Options", new MiniYaml(null, options))])); return data; } diff --git a/OpenRA.Game/Network/SyncReport.cs b/OpenRA.Game/Network/SyncReport.cs index 4c563a17b6..9c55b54bd7 100644 --- a/OpenRA.Game/Network/SyncReport.cs +++ b/OpenRA.Game/Network/SyncReport.cs @@ -166,9 +166,9 @@ namespace OpenRA.Network public int Frame; public int SyncedRandom; public int TotalCount; - public readonly List Traits = new(); - public readonly List Effects = new(); - public readonly List Orders = new(); + public readonly List Traits = []; + public readonly List Effects = []; + public readonly List Orders = []; } struct TraitReport @@ -238,11 +238,11 @@ namespace OpenRA.Network // PERF: If the member is a Boolean, we can also avoid the allocation caused by boxing it. // Instead, we can just return the resulting strings directly. var getBoolString = Expression.Condition(getMember, TrueString, FalseString); - return Expression.Lambda>(getBoolString, name, new[] { SyncParam }).Compile(); + return Expression.Lambda>(getBoolString, name, [SyncParam]).Compile(); } var boxedCopy = Expression.Convert(getMember, typeof(object)); - return Expression.Lambda>(boxedCopy, name, new[] { SyncParam }).Compile(); + return Expression.Lambda>(boxedCopy, name, [SyncParam]).Compile(); } // For reference types, we have to call ToString right away to get a snapshot of the value. We cannot @@ -266,13 +266,13 @@ namespace OpenRA.Network // (ISync sync) => { var foo = ((TSync)sync).Foo; return foo == null ? null : foo.ToString(); } var memberVariable = Expression.Variable(memberType, getMember.Member.Name); var assignMemberVariable = Expression.Assign(memberVariable, getMember); - var member = Expression.Block(new[] { memberVariable }, assignMemberVariable); + var member = Expression.Block([memberVariable], assignMemberVariable); getString = Expression.Call(member, toString); var nullMember = Expression.Constant(null, memberType); getString = Expression.Condition(Expression.Equal(member, nullMember), NullString, getString); } - return Expression.Lambda>(getString, name, new[] { SyncParam }).Compile(); + return Expression.Lambda>(getString, name, [SyncParam]).Compile(); } } diff --git a/OpenRA.Game/ObjectCreator.cs b/OpenRA.Game/ObjectCreator.cs index 44901f5df6..27cc299ca1 100644 --- a/OpenRA.Game/ObjectCreator.cs +++ b/OpenRA.Game/ObjectCreator.cs @@ -22,7 +22,7 @@ namespace OpenRA { // .NET does not support unloading assemblies, so mod libraries will leak across mod changes. // This tracks the assemblies that have been loaded since game start so that we don't load multiple copies - static readonly Dictionary ResolvedAssemblies = new(); + static readonly Dictionary ResolvedAssemblies = []; readonly Cache typeCache; readonly Cache ctorCache; @@ -77,7 +77,7 @@ namespace OpenRA public T CreateObject(string className) { - return CreateObject(className, new Dictionary()); + return CreateObject(className, []); } public T CreateObject(string className, Dictionary args) @@ -119,7 +119,7 @@ namespace OpenRA public object CreateBasic(Type type) { - return type.GetConstructor(Array.Empty()).Invoke(Array.Empty()); + return type.GetConstructor([]).Invoke([]); } public object CreateUsingArgs(ConstructorInfo ctor, Dictionary args) diff --git a/OpenRA.Game/Player.cs b/OpenRA.Game/Player.cs index 62e6942866..c39634bd8c 100644 --- a/OpenRA.Game/Player.cs +++ b/OpenRA.Game/Player.cs @@ -207,7 +207,7 @@ namespace OpenRA // Therefore assign the uninitialized actor and run the Created callbacks // by calling Initialize ourselves. var playerActorType = world.Type == WorldType.Editor ? SystemActors.EditorPlayer : SystemActors.Player; - PlayerActor = new Actor(world, playerActorType.ToString(), new TypeDictionary { new OwnerInit(this) }); + PlayerActor = new Actor(world, playerActorType.ToString(), [new OwnerInit(this)]); PlayerActor.Initialize(true); Shroud = PlayerActor.Trait(); diff --git a/OpenRA.Game/Primitives/ActionQueue.cs b/OpenRA.Game/Primitives/ActionQueue.cs index f229ddab6a..11a303ac3e 100644 --- a/OpenRA.Game/Primitives/ActionQueue.cs +++ b/OpenRA.Game/Primitives/ActionQueue.cs @@ -19,7 +19,7 @@ namespace OpenRA.Primitives /// public class ActionQueue { - readonly List actions = new(); + readonly List actions = []; public void Add(Action a, long desiredTime) { diff --git a/OpenRA.Game/Primitives/Color.cs b/OpenRA.Game/Primitives/Color.cs index 58c7e7aa37..e50c107f96 100644 --- a/OpenRA.Game/Primitives/Color.cs +++ b/OpenRA.Game/Primitives/Color.cs @@ -219,9 +219,9 @@ namespace OpenRA.Primitives public override string ToString() { if (A == 255) - return CryptoUtil.ToHex(stackalloc byte[3] { R, G, B }); + return CryptoUtil.ToHex([R, G, B]); - return CryptoUtil.ToHex(stackalloc byte[4] { R, G, B, A }); + return CryptoUtil.ToHex([R, G, B, A]); } public static Color Transparent => FromArgb(0x00FFFFFF); diff --git a/OpenRA.Game/Primitives/ObservableList.cs b/OpenRA.Game/Primitives/ObservableList.cs index 75db986eed..2a94098dbb 100644 --- a/OpenRA.Game/Primitives/ObservableList.cs +++ b/OpenRA.Game/Primitives/ObservableList.cs @@ -33,7 +33,7 @@ namespace OpenRA.Primitives public ObservableList() { - innerList = new List(); + innerList = []; } public virtual void Add(T item) diff --git a/OpenRA.Game/Primitives/Polygon.cs b/OpenRA.Game/Primitives/Polygon.cs index 8af66c593f..c18ef0749e 100644 --- a/OpenRA.Game/Primitives/Polygon.cs +++ b/OpenRA.Game/Primitives/Polygon.cs @@ -25,7 +25,7 @@ namespace OpenRA.Primitives public Polygon(Rectangle bounds) { BoundingRect = bounds; - Vertices = new[] { bounds.TopLeft, bounds.BottomLeft, bounds.BottomRight, bounds.TopRight }; + Vertices = [bounds.TopLeft, bounds.BottomLeft, bounds.BottomRight, bounds.TopRight]; isRectangle = true; } diff --git a/OpenRA.Game/Primitives/SpatiallyPartitioned.cs b/OpenRA.Game/Primitives/SpatiallyPartitioned.cs index 85ce02c31e..57afd91dd6 100644 --- a/OpenRA.Game/Primitives/SpatiallyPartitioned.cs +++ b/OpenRA.Game/Primitives/SpatiallyPartitioned.cs @@ -23,7 +23,7 @@ namespace OpenRA.Primitives readonly int rows, cols, binSize; readonly Dictionary[] itemBoundsBins; - readonly Dictionary itemBounds = new(); + readonly Dictionary itemBounds = []; public SpatiallyPartitioned(int width, int height, int binSize) { diff --git a/OpenRA.Game/Primitives/TypeDictionary.cs b/OpenRA.Game/Primitives/TypeDictionary.cs index 6aa99590bc..4c440ab17b 100644 --- a/OpenRA.Game/Primitives/TypeDictionary.cs +++ b/OpenRA.Game/Primitives/TypeDictionary.cs @@ -20,7 +20,7 @@ namespace OpenRA.Primitives static readonly Func CreateTypeContainer = t => (ITypeContainer)typeof(TypeContainer<>).MakeGenericType(t).GetConstructor(Type.EmptyTypes).Invoke(null); - readonly Dictionary data = new(); + readonly Dictionary data = []; ITypeContainer InnerGet(Type t) { @@ -81,7 +81,7 @@ namespace OpenRA.Primitives { if (data.TryGetValue(typeof(T), out var container)) return ((TypeContainer)container).Objects; - return Array.Empty(); + return []; } public void Remove(T val) @@ -131,7 +131,7 @@ namespace OpenRA.Primitives sealed class TypeContainer : ITypeContainer { - public List Objects { get; } = new List(); + public List Objects { get; } = []; public int Count => Objects.Count; diff --git a/OpenRA.Game/Renderer.cs b/OpenRA.Game/Renderer.cs index 8c29f58d8a..81d5602e9f 100644 --- a/OpenRA.Game/Renderer.cs +++ b/OpenRA.Game/Renderer.cs @@ -27,7 +27,7 @@ namespace OpenRA public SpriteRenderer WorldSpriteRenderer { get; } public RgbaSpriteRenderer WorldRgbaSpriteRenderer { get; } public RgbaColorRenderer WorldRgbaColorRenderer { get; } - public IRenderer[] WorldRenderers = Array.Empty(); + public IRenderer[] WorldRenderers = []; public RgbaColorRenderer RgbaColorRenderer { get; } public SpriteRenderer SpriteRenderer { get; } public RgbaSpriteRenderer RgbaSpriteRenderer { get; } @@ -46,7 +46,7 @@ namespace OpenRA readonly IVertexBuffer tempVertexBuffer; readonly IIndexBuffer quadIndexBuffer; - readonly Stack scissorState = new(); + readonly Stack scissorState = []; readonly ITexture worldBufferSnapshot; IFrameBuffer screenBuffer; diff --git a/OpenRA.Game/Scripting/ScriptActorInterface.cs b/OpenRA.Game/Scripting/ScriptActorInterface.cs index c5c4df582b..d9d058579a 100644 --- a/OpenRA.Game/Scripting/ScriptActorInterface.cs +++ b/OpenRA.Game/Scripting/ScriptActorInterface.cs @@ -43,7 +43,7 @@ namespace OpenRA.Scripting if (actor.Disposed) commandClasses = commandClasses.Where(c => c.HasAttribute()).ToArray(); - Bind(CreateObjects(commandClasses, new object[] { Context, actor })); + Bind(CreateObjects(commandClasses, [Context, actor])); } public void OnActorDestroyed() diff --git a/OpenRA.Game/Scripting/ScriptContext.cs b/OpenRA.Game/Scripting/ScriptContext.cs index 95f12b137a..fd7480e561 100644 --- a/OpenRA.Game/Scripting/ScriptContext.cs +++ b/OpenRA.Game/Scripting/ScriptContext.cs @@ -103,7 +103,7 @@ namespace OpenRA.Scripting throw new InvalidOperationException($"[ScriptGlobal] attribute not found for global table '{type}'"); Name = names[0].Name; - Bind(new[] { this }); + Bind([this]); } protected IEnumerable FilteredObjects(IEnumerable objects, LuaFunction filter) @@ -220,7 +220,7 @@ namespace OpenRA.Scripting if (ctor == null) throw new InvalidOperationException($"{b.Name} must define a constructor that takes a {nameof(ScriptContext)} context parameter"); - var binding = (ScriptGlobal)ctor.Invoke(new[] { this }); + var binding = (ScriptGlobal)ctor.Invoke([this]); using (var obj = binding.ToLuaValue(this)) runtime.Globals.Add(binding.Name, obj); } @@ -341,7 +341,7 @@ namespace OpenRA.Scripting return outer.SelectMany(i => i.GetGenericArguments()); } - static readonly object[] NoArguments = Array.Empty(); + static readonly object[] NoArguments = []; Type[] FilterActorCommands(ActorInfo ai) { return FilterCommands(ai, knownActorCommands); diff --git a/OpenRA.Game/Scripting/ScriptObjectWrapper.cs b/OpenRA.Game/Scripting/ScriptObjectWrapper.cs index 60b281318b..a8edb18f67 100644 --- a/OpenRA.Game/Scripting/ScriptObjectWrapper.cs +++ b/OpenRA.Game/Scripting/ScriptObjectWrapper.cs @@ -22,7 +22,7 @@ namespace OpenRA.Scripting protected abstract string MemberNotFoundError(string memberName); protected readonly ScriptContext Context; - readonly Dictionary members = new(); + readonly Dictionary members = []; protected ScriptObjectWrapper(ScriptContext context) { diff --git a/OpenRA.Game/Scripting/ScriptPlayerInterface.cs b/OpenRA.Game/Scripting/ScriptPlayerInterface.cs index 065aa3bf2a..43d6195a67 100644 --- a/OpenRA.Game/Scripting/ScriptPlayerInterface.cs +++ b/OpenRA.Game/Scripting/ScriptPlayerInterface.cs @@ -24,7 +24,7 @@ namespace OpenRA.Scripting : base(context) { this.player = player; - Bind(CreateObjects(context.PlayerCommands, new object[] { context, player })); + Bind(CreateObjects(context.PlayerCommands, [context, player])); } } } diff --git a/OpenRA.Game/SelectableExts.cs b/OpenRA.Game/SelectableExts.cs index 10b6507b0b..a4501ee0c3 100644 --- a/OpenRA.Game/SelectableExts.cs +++ b/OpenRA.Game/SelectableExts.cs @@ -87,7 +87,7 @@ namespace OpenRA.Traits return info.SelectionPriority(modifiers) - (long)pixelDistance << 16; } - static readonly Actor[] NoActors = Array.Empty(); + static readonly Actor[] NoActors = []; public static IEnumerable SubsetWithHighestSelectionPriority(this IEnumerable actors, Modifiers modifiers) { diff --git a/OpenRA.Game/Server/Connection.cs b/OpenRA.Game/Server/Connection.cs index dd94d80000..e4fd71ad96 100644 --- a/OpenRA.Game/Server/Connection.cs +++ b/OpenRA.Game/Server/Connection.cs @@ -41,8 +41,8 @@ namespace OpenRA.Server long lastReceivedTime = 0; - readonly BlockingCollection sendQueue = new(); - readonly Queue pingHistory = new(); + readonly BlockingCollection sendQueue = []; + readonly Queue pingHistory = []; public Connection(Server server, Socket socket, string authToken) { diff --git a/OpenRA.Game/Server/Exts.cs b/OpenRA.Game/Server/Exts.cs index 7d5ae82ebf..483e170671 100644 --- a/OpenRA.Game/Server/Exts.cs +++ b/OpenRA.Game/Server/Exts.cs @@ -18,7 +18,7 @@ namespace OpenRA.Server { public static IEnumerable Except(this IEnumerable ts, T t) { - return ts.Except(new[] { t }); + return ts.Except([t]); } } } diff --git a/OpenRA.Game/Server/MapStatusCache.cs b/OpenRA.Game/Server/MapStatusCache.cs index e92e0897d5..386da229b9 100644 --- a/OpenRA.Game/Server/MapStatusCache.cs +++ b/OpenRA.Game/Server/MapStatusCache.cs @@ -20,7 +20,7 @@ namespace OpenRA.Server public class MapStatusCache { - readonly Dictionary cache = new(); + readonly Dictionary cache = []; readonly Action onStatusChanged; readonly bool enableRemoteLinting; readonly ModData modData; diff --git a/OpenRA.Game/Server/OrderBuffer.cs b/OpenRA.Game/Server/OrderBuffer.cs index 6fdc8bbc84..cddb0e2569 100644 --- a/OpenRA.Game/Server/OrderBuffer.cs +++ b/OpenRA.Game/Server/OrderBuffer.cs @@ -31,8 +31,8 @@ namespace OpenRA.Server Stopwatch gameTimer; long nextUpdate = 0; - readonly ConcurrentDictionary timestamps = new(); - readonly ConcurrentDictionary> deltas = new(); + readonly ConcurrentDictionary timestamps = []; + readonly ConcurrentDictionary> deltas = []; int timestep; int ticksPerInterval; diff --git a/OpenRA.Game/Server/PlayerMessageTracker.cs b/OpenRA.Game/Server/PlayerMessageTracker.cs index 8fe7289ce4..b66591a6cc 100644 --- a/OpenRA.Game/Server/PlayerMessageTracker.cs +++ b/OpenRA.Game/Server/PlayerMessageTracker.cs @@ -19,7 +19,7 @@ namespace OpenRA.Server [FluentReference("remaining")] const string ChatTemporaryDisabled = "notification-chat-temp-disabled"; - readonly Dictionary> messageTracker = new(); + readonly Dictionary> messageTracker = []; readonly Server server; readonly Action dispatchOrdersToClient; readonly Action sendFluentMessageTo; @@ -42,7 +42,7 @@ namespace OpenRA.Server public bool IsPlayerAtFloodLimit(Connection conn) { if (!messageTracker.ContainsKey(conn.PlayerIndex)) - messageTracker.Add(conn.PlayerIndex, new List()); + messageTracker.Add(conn.PlayerIndex, []); var isAdmin = server.GetClient(conn)?.IsAdmin ?? false; var settings = server.Settings; @@ -56,7 +56,7 @@ namespace OpenRA.Server if (!isAdmin && time < settings.FloodLimitJoinCooldown) { var remaining = CalculateRemaining(settings.FloodLimitJoinCooldown); - sendFluentMessageTo(conn, ChatTemporaryDisabled, new object[] { "remaining", remaining }); + sendFluentMessageTo(conn, ChatTemporaryDisabled, ["remaining", remaining]); return true; } @@ -64,7 +64,7 @@ namespace OpenRA.Server if (tracker.Count >= settings.FloodLimitMessageCount) { var remaining = CalculateRemaining(tracker[0] + settings.FloodLimitInterval); - sendFluentMessageTo(conn, ChatTemporaryDisabled, new object[] { "remaining", remaining }); + sendFluentMessageTo(conn, ChatTemporaryDisabled, ["remaining", remaining]); return true; } diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs index c4b8e42241..ae283f6e0e 100644 --- a/OpenRA.Game/Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -120,12 +120,12 @@ namespace OpenRA.Server public readonly ServerType Type; public bool IsMultiplayer => Type == ServerType.Dedicated || Type == ServerType.Multiplayer; - public readonly List Conns = new(); + public readonly List Conns = []; public Session LobbyInfo; public ServerSettings Settings; public ModData ModData; - public List TempBans = new(); + public List TempBans = []; // Managed by LobbyCommands public MapPreview Map; @@ -137,19 +137,19 @@ namespace OpenRA.Server public int OrderLatency = 1; readonly int randomSeed; - readonly List listeners = new(); - readonly TypeDictionary serverTraits = new(); + readonly List listeners = []; + readonly TypeDictionary serverTraits = []; readonly PlayerDatabase playerDatabase; OrderBuffer orderBuffer; volatile ServerState internalState = ServerState.WaitingPlayers; - readonly BlockingCollection events = new(); + readonly BlockingCollection events = []; ReplayRecorder recorder; GameInformation gameInfo; - readonly List worldPlayers = new(); + readonly List worldPlayers = []; readonly Stopwatch pingUpdated = Stopwatch.StartNew(); public readonly VoteKickTracker VoteKickTracker; @@ -802,7 +802,7 @@ namespace OpenRA.Server recorder = null; } - readonly Dictionary syncForFrame = new(); + readonly Dictionary syncForFrame = []; int lastDefeatStateFrame; ulong lastDefeatState; @@ -998,7 +998,7 @@ namespace OpenRA.Server if (!InterpretCommand(o.TargetString, conn)) { Log.Write("server", $"Unknown server command: {o.TargetString}"); - SendFluentMessageTo(conn, UnknownServerCommand, new object[] { "command", o.TargetString }); + SendFluentMessageTo(conn, UnknownServerCommand, ["command", o.TargetString]); } break; @@ -1401,12 +1401,12 @@ namespace OpenRA.Server for (var i = 0; i < OrderLatency; i++) { from.LastOrdersFrame = firstFrame + i; - var frameData = CreateFrame(from.PlayerIndex, from.LastOrdersFrame, Array.Empty()); + var frameData = CreateFrame(from.PlayerIndex, from.LastOrdersFrame, []); foreach (var to in conns) DispatchFrameToClient(to, from.PlayerIndex, frameData); - RecordOrder(from.LastOrdersFrame, Array.Empty(), from.PlayerIndex); - GameSave?.DispatchOrders(from, from.LastOrdersFrame, Array.Empty()); + RecordOrder(from.LastOrdersFrame, [], from.PlayerIndex); + GameSave?.DispatchOrders(from, from.LastOrdersFrame, []); } } } diff --git a/OpenRA.Game/Server/VoteKickTracker.cs b/OpenRA.Game/Server/VoteKickTracker.cs index ab3947f77f..5358907a7e 100644 --- a/OpenRA.Game/Server/VoteKickTracker.cs +++ b/OpenRA.Game/Server/VoteKickTracker.cs @@ -35,8 +35,8 @@ namespace OpenRA.Server [FluentReference("kickee")] const string VoteKickEnded = "notification-vote-kick-ended"; - readonly Dictionary voteTracker = new(); - readonly Dictionary failedVoteKickers = new(); + readonly Dictionary voteTracker = []; + readonly Dictionary failedVoteKickers = []; readonly Server server; Stopwatch voteKickTimer; @@ -107,7 +107,7 @@ namespace OpenRA.Server if (!kickee.IsObserver && !server.HasClientWonOrLost(kickee)) { // Vote kick cannot be the sole deciding factor for a game. - server.SendFluentMessageTo(conn, InsufficientVotes, new object[] { "kickee", kickee.Name }); + server.SendFluentMessageTo(conn, InsufficientVotes, ["kickee", kickee.Name]); EndKickVote(); return false; } diff --git a/OpenRA.Game/Settings.cs b/OpenRA.Game/Settings.cs index 3b55844258..276c258033 100644 --- a/OpenRA.Game/Settings.cs +++ b/OpenRA.Game/Settings.cs @@ -66,16 +66,16 @@ namespace OpenRA public string Map = null; [Desc("Takes a comma separated list of IP addresses that are not allowed to join.")] - public string[] Ban = Array.Empty(); + public string[] Ban = []; [Desc("For dedicated servers only, allow anonymous clients to join.")] public bool RequireAuthentication = false; [Desc("For dedicated servers only, if non-empty, only allow authenticated players with these profile IDs to join.")] - public int[] ProfileIDWhitelist = Array.Empty(); + public int[] ProfileIDWhitelist = []; [Desc("For dedicated servers only, if non-empty, always reject players with these user IDs from joining.")] - public int[] ProfileIDBlacklist = Array.Empty(); + public int[] ProfileIDBlacklist = []; [Desc("For dedicated servers only, controls whether a game can be started with just one human player in the lobby.")] public bool EnableSingleplayer = false; @@ -102,7 +102,7 @@ namespace OpenRA public bool EnableLintChecks = true; [Desc("For dedicated servers only, a comma separated list of map uids that are allowed to be used.")] - public string[] MapPool = Array.Empty(); + public string[] MapPool = []; [Desc("Delay in milliseconds before newly joined players can send chat messages.")] public int FloodLimitJoinCooldown = 5000; @@ -248,7 +248,7 @@ namespace OpenRA public string Name = "Commander"; public Color Color = Color.FromArgb(200, 32, 32); public string LastServer = "localhost:1234"; - public Color[] CustomColors = Array.Empty(); + public Color[] CustomColors = []; } public class SinglePlayerGameSettings @@ -317,13 +317,13 @@ namespace OpenRA public readonly ServerSettings Server = new(); public readonly DebugSettings Debug = new(); public readonly SinglePlayerGameSettings SinglePlayerSettings = new(); - internal Dictionary Keys = new(); + internal Dictionary Keys = []; public readonly Dictionary Sections; // A direct clone of the file loaded from disk. // Any changed settings will be merged over this on save, // allowing us to persist any unknown configuration keys - readonly List yamlCache = new(); + readonly List yamlCache = []; public Settings(string file, Arguments args) { diff --git a/OpenRA.Game/Sound/Sound.cs b/OpenRA.Game/Sound/Sound.cs index fa381ce87b..54656cba9f 100644 --- a/OpenRA.Game/Sound/Sound.cs +++ b/OpenRA.Game/Sound/Sound.cs @@ -43,8 +43,8 @@ namespace OpenRA ISoundSource videoSource; ISound music; ISound video; - readonly Dictionary currentSounds = new(); - readonly Dictionary currentNotifications = new(); + readonly Dictionary currentSounds = []; + readonly Dictionary currentNotifications = []; public bool DummyEngine { get; } public Sound(IPlatform platform, SoundSettings soundSettings) diff --git a/OpenRA.Game/StreamExts.cs b/OpenRA.Game/StreamExts.cs index 6b4a6b5bd3..c0eef557ae 100644 --- a/OpenRA.Game/StreamExts.cs +++ b/OpenRA.Game/StreamExts.cs @@ -278,7 +278,7 @@ namespace OpenRA if (!string.IsNullOrEmpty(text)) bytes = encoding.GetBytes(text); else - bytes = Array.Empty(); + bytes = []; s.Write(bytes.Length); s.Write(bytes); diff --git a/OpenRA.Game/Support/Arguments.cs b/OpenRA.Game/Support/Arguments.cs index a72cd2f2d5..be6be683f8 100644 --- a/OpenRA.Game/Support/Arguments.cs +++ b/OpenRA.Game/Support/Arguments.cs @@ -16,7 +16,7 @@ namespace OpenRA { public class Arguments { - readonly Dictionary args = new(); + readonly Dictionary args = []; public static Arguments Empty => new(); diff --git a/OpenRA.Game/Support/AssemblyLoader.cs b/OpenRA.Game/Support/AssemblyLoader.cs index ed8bb9d97d..879e719037 100644 --- a/OpenRA.Game/Support/AssemblyLoader.cs +++ b/OpenRA.Game/Support/AssemblyLoader.cs @@ -105,34 +105,34 @@ namespace OpenRA.Support static readonly string[] NativeLibraryPrefixes; static readonly string[] ManagedAssemblyExtensions = - { + [ ".dll", ".ni.dll", ".exe", ".ni.exe" - }; + ]; static ManagedLoadContext() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - NativeLibraryPrefixes = new[] { "" }; - NativeLibraryExtensions = new[] { ".dll" }; + NativeLibraryPrefixes = [""]; + NativeLibraryExtensions = [".dll"]; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { - NativeLibraryPrefixes = new[] { "", "lib", }; - NativeLibraryExtensions = new[] { ".dylib" }; + NativeLibraryPrefixes = ["", "lib",]; + NativeLibraryExtensions = [".dylib"]; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { - NativeLibraryPrefixes = new[] { "", "lib" }; - NativeLibraryExtensions = new[] { ".so", ".so.1" }; + NativeLibraryPrefixes = ["", "lib"]; + NativeLibraryExtensions = [".so", ".so.1"]; } else { - NativeLibraryPrefixes = Array.Empty(); - NativeLibraryExtensions = Array.Empty(); + NativeLibraryPrefixes = []; + NativeLibraryExtensions = []; } } @@ -344,7 +344,7 @@ namespace OpenRA.Support static IEnumerable GetRids(RuntimeFallbacks runtimeGraph) { - return Enumerable.Concat(new[] { runtimeGraph.Runtime }, runtimeGraph?.Fallbacks ?? Enumerable.Empty()); + return Enumerable.Concat([runtimeGraph.Runtime], runtimeGraph?.Fallbacks ?? Enumerable.Empty()); } static IEnumerable SelectAssets(IEnumerable rids, IReadOnlyCollection groups) diff --git a/OpenRA.Game/Support/Benchmark.cs b/OpenRA.Game/Support/Benchmark.cs index 3117544bdc..9dba345f07 100644 --- a/OpenRA.Game/Support/Benchmark.cs +++ b/OpenRA.Game/Support/Benchmark.cs @@ -17,7 +17,7 @@ namespace OpenRA.Support sealed class Benchmark { readonly string prefix; - readonly Dictionary> samples = new(); + readonly Dictionary> samples = []; public Benchmark(string prefix) { diff --git a/OpenRA.Game/Support/HttpQueryBuilder.cs b/OpenRA.Game/Support/HttpQueryBuilder.cs index 49e2a29990..282722fba0 100644 --- a/OpenRA.Game/Support/HttpQueryBuilder.cs +++ b/OpenRA.Game/Support/HttpQueryBuilder.cs @@ -20,7 +20,7 @@ namespace OpenRA.Support public class HttpQueryBuilder : IEnumerable> { readonly string url; - readonly List> parameters = new(); + readonly List> parameters = []; public HttpQueryBuilder(string url) { diff --git a/OpenRA.Game/Support/Log.cs b/OpenRA.Game/Support/Log.cs index ff836d421f..037d99f328 100644 --- a/OpenRA.Game/Support/Log.cs +++ b/OpenRA.Game/Support/Log.cs @@ -42,7 +42,7 @@ namespace OpenRA { const int CreateLogFileMaxRetryCount = 128; - static readonly ConcurrentDictionary Channels = new(); + static readonly ConcurrentDictionary Channels = []; static readonly Channel Channel; static readonly ChannelWriter ChannelWriter; static readonly CancellationTokenSource CancellationToken = new(); diff --git a/OpenRA.Game/Support/PerfHistory.cs b/OpenRA.Game/Support/PerfHistory.cs index 13731a8105..39fb458fa4 100644 --- a/OpenRA.Game/Support/PerfHistory.cs +++ b/OpenRA.Game/Support/PerfHistory.cs @@ -16,7 +16,7 @@ namespace OpenRA.Support public static class PerfHistory { static readonly Color[] Colors = - { + [ Color.Red, Color.Green, Color.Orange, Color.Yellow, Color.Fuchsia, Color.Lime, @@ -24,7 +24,7 @@ namespace OpenRA.Support Color.White, Color.Teal, Color.Pink, Color.MediumPurple, Color.Olive, Color.CornflowerBlue - }; + ]; static int nextColor; diff --git a/OpenRA.Game/Support/PerfTimer.cs b/OpenRA.Game/Support/PerfTimer.cs index d0b92a56d0..06384cddd6 100644 --- a/OpenRA.Game/Support/PerfTimer.cs +++ b/OpenRA.Game/Support/PerfTimer.cs @@ -56,7 +56,7 @@ namespace OpenRA.Support Write(); else if (ticks > thresholdTicks) { - parent.children ??= new List(); + parent.children ??= []; parent.children.Add(this); } } diff --git a/OpenRA.Game/Support/VariableExpression.cs b/OpenRA.Game/Support/VariableExpression.cs index 74bba59da1..a4df3b052d 100644 --- a/OpenRA.Game/Support/VariableExpression.cs +++ b/OpenRA.Game/Support/VariableExpression.cs @@ -24,7 +24,7 @@ namespace OpenRA.Support public static readonly IReadOnlyDictionary NoVariables = new ReadOnlyDictionary(new Dictionary()); public readonly string Expression; - readonly HashSet variables = new(); + readonly HashSet variables = []; public IEnumerable Variables => variables; enum CharClass { Whitespace, Operator, Mixed, Id, Digit } @@ -717,8 +717,8 @@ namespace OpenRA.Support sealed class AstStack { - readonly List expressions = new(); - readonly List types = new(); + readonly List expressions = []; + readonly List types = []; public ExpressionType PeekType() { return types[^1]; } diff --git a/OpenRA.Game/Sync.cs b/OpenRA.Game/Sync.cs index ae8db21c1e..d33624e4f1 100644 --- a/OpenRA.Game/Sync.cs +++ b/OpenRA.Game/Sync.cs @@ -76,7 +76,7 @@ namespace OpenRA static Func GenerateHashFunc(Type t) { - var d = new DynamicMethod($"hash_{t.Name}", typeof(int), new Type[] { typeof(object) }, t); + var d = new DynamicMethod($"hash_{t.Name}", typeof(int), [typeof(object)], t); var il = d.GetILGenerator(); var this_ = il.DeclareLocal(t).LocalIndex; il.Emit(OpCodes.Ldarg_0); diff --git a/OpenRA.Game/TextNotificationsManager.cs b/OpenRA.Game/TextNotificationsManager.cs index 82f6b38e80..24bdbcf129 100644 --- a/OpenRA.Game/TextNotificationsManager.cs +++ b/OpenRA.Game/TextNotificationsManager.cs @@ -21,9 +21,9 @@ namespace OpenRA static readonly string SystemMessageLabel; public static long ChatDisabledUntil { get; internal set; } - public static readonly Dictionary MutedPlayers = new(); + public static readonly Dictionary MutedPlayers = []; - static readonly List NotificationsCache = new(); + static readonly List NotificationsCache = []; public static IReadOnlyList Notifications => NotificationsCache; static TextNotificationsManager() diff --git a/OpenRA.Game/TraitDictionary.cs b/OpenRA.Game/TraitDictionary.cs index 0a978eae2e..71a6e14f4c 100644 --- a/OpenRA.Game/TraitDictionary.cs +++ b/OpenRA.Game/TraitDictionary.cs @@ -44,7 +44,7 @@ namespace OpenRA static readonly Func CreateTraitContainer = t => (ITraitContainer)typeof(TraitContainer<>).MakeGenericType(t).GetConstructor(Type.EmptyTypes).Invoke(null); - readonly Dictionary traits = new(); + readonly Dictionary traits = []; ITraitContainer InnerGet(Type t) { @@ -143,8 +143,8 @@ namespace OpenRA sealed class TraitContainer : ITraitContainer { - readonly List actors = new(); - readonly List traits = new(); + readonly List actors = []; + readonly List traits = []; public int Queries { get; private set; } diff --git a/OpenRA.Game/Traits/LintAttributes.cs b/OpenRA.Game/Traits/LintAttributes.cs index 16f1081290..b631fd2a99 100644 --- a/OpenRA.Game/Traits/LintAttributes.cs +++ b/OpenRA.Game/Traits/LintAttributes.cs @@ -37,7 +37,7 @@ namespace OpenRA.Traits public ActorReferenceAttribute(Type requiredTrait = null, LintDictionaryReference dictionaryReference = LintDictionaryReference.None) { - RequiredTraits = requiredTrait != null ? new[] { requiredTrait } : Array.Empty(); + RequiredTraits = requiredTrait != null ? [requiredTrait] : []; DictionaryReference = dictionaryReference; } } diff --git a/OpenRA.Game/Traits/Player/FrozenActorLayer.cs b/OpenRA.Game/Traits/Player/FrozenActorLayer.cs index f55a180845..16585f84e2 100644 --- a/OpenRA.Game/Traits/Player/FrozenActorLayer.cs +++ b/OpenRA.Game/Traits/Player/FrozenActorLayer.cs @@ -39,7 +39,7 @@ namespace OpenRA.Traits readonly Actor actor; readonly ICreatesFrozenActors frozenTrait; readonly Shroud shroud; - readonly List targetablePositions = new(); + readonly List targetablePositions = []; public Player Viewer { get; } public Player Owner { get; private set; } @@ -75,8 +75,8 @@ namespace OpenRA.Traits public Polygon MouseBounds = Polygon.Empty; - static readonly IRenderable[] NoRenderables = Array.Empty(); - static readonly Rectangle[] NoBounds = Array.Empty(); + static readonly IRenderable[] NoRenderables = []; + static readonly Rectangle[] NoBounds = []; int flashTicks; TintModifiers flashModifiers; @@ -261,7 +261,7 @@ namespace OpenRA.Traits binSize = info.BinSize; world = self.World; owner = self.Owner; - frozenActorsById = new Dictionary(); + frozenActorsById = []; partitionedFrozenActors = new SpatiallyPartitioned( world.Map.MapSize.X, world.Map.MapSize.Y, binSize); @@ -329,7 +329,7 @@ namespace OpenRA.Traits VisibilityHash += hash; else if (frozenActor.Actor == null) { - frozenActorsToRemove ??= new List(); + frozenActorsToRemove ??= []; frozenActorsToRemove.Add(frozenActor); } } diff --git a/OpenRA.Game/Traits/Player/Shroud.cs b/OpenRA.Game/Traits/Player/Shroud.cs index 95f547b3c3..3e850385a2 100644 --- a/OpenRA.Game/Traits/Player/Shroud.cs +++ b/OpenRA.Game/Traits/Player/Shroud.cs @@ -96,7 +96,7 @@ namespace OpenRA.Traits readonly Map map; // Individual shroud modifier sources (type and area) - readonly Dictionary sources = new(); + readonly Dictionary sources = []; // Per-cell count of each source type, used to resolve the final cell type readonly ProjectedCellLayer passiveVisibleCount; diff --git a/OpenRA.Game/Traits/Target.cs b/OpenRA.Game/Traits/Target.cs index c021bcf1e5..12307d4bdd 100644 --- a/OpenRA.Game/Traits/Target.cs +++ b/OpenRA.Game/Traits/Target.cs @@ -18,7 +18,7 @@ namespace OpenRA.Traits public enum TargetType : byte { Invalid, Actor, Terrain, FrozenActor } public readonly struct Target : IEquatable { - public static readonly Target[] None = Array.Empty(); + public static readonly Target[] None = []; public static readonly Target Invalid = default; public Actor Actor { get; } public FrozenActor FrozenActor { get; } @@ -34,7 +34,7 @@ namespace OpenRA.Traits { type = TargetType.Terrain; this.terrainCenterPosition = terrainCenterPosition; - this.terrainPositions = terrainPositions ?? new[] { terrainCenterPosition }; + this.terrainPositions = terrainPositions ?? [terrainCenterPosition]; Actor = null; FrozenActor = null; @@ -47,7 +47,7 @@ namespace OpenRA.Traits { type = TargetType.Terrain; terrainCenterPosition = w.Map.CenterOfSubCell(c, subCell); - terrainPositions = new[] { terrainCenterPosition }; + terrainPositions = [terrainCenterPosition]; cell = c; this.subCell = subCell; @@ -172,7 +172,7 @@ namespace OpenRA.Traits } // Positions available to target for range checks - static readonly WPos[] NoPositions = Array.Empty(); + static readonly WPos[] NoPositions = []; public IEnumerable Positions { get diff --git a/OpenRA.Game/Traits/World/Faction.cs b/OpenRA.Game/Traits/World/Faction.cs index 63f21a98b8..a013771e63 100644 --- a/OpenRA.Game/Traits/World/Faction.cs +++ b/OpenRA.Game/Traits/World/Faction.cs @@ -25,7 +25,7 @@ namespace OpenRA.Traits public readonly string InternalName = null; [Desc("Pick a random faction as the player's faction out of this list.")] - public readonly HashSet RandomFactionMembers = new(); + public readonly HashSet RandomFactionMembers = []; [Desc("The side that the faction belongs to. For example, England belongs to the 'Allies' side.")] public readonly string Side = null; diff --git a/OpenRA.Game/Traits/World/ScreenMap.cs b/OpenRA.Game/Traits/World/ScreenMap.cs index 6e19f092cf..d2ec915c62 100644 --- a/OpenRA.Game/Traits/World/ScreenMap.cs +++ b/OpenRA.Game/Traits/World/ScreenMap.cs @@ -41,21 +41,21 @@ namespace OpenRA.Traits public class ScreenMap : IWorldLoaded { - static readonly IEnumerable NoFrozenActors = Array.Empty(); + static readonly IEnumerable NoFrozenActors = []; readonly Func frozenActorIsValid = fa => fa.IsValid; readonly Func actorIsInWorld = a => a.IsInWorld; readonly Func selectActorAndBounds; readonly Cache> partitionedMouseFrozenActors; readonly SpatiallyPartitioned partitionedMouseActors; - readonly Dictionary partitionedMouseActorBounds = new(); + readonly Dictionary partitionedMouseActorBounds = []; readonly Cache> partitionedRenderableFrozenActors; readonly SpatiallyPartitioned partitionedRenderableActors; readonly SpatiallyPartitioned partitionedRenderableEffects; // Updates are done in one pass to ensure all bound changes have been applied - readonly HashSet addOrUpdateActors = new(); - readonly HashSet removeActors = new(); + readonly HashSet addOrUpdateActors = []; + readonly HashSet removeActors = []; readonly Cache> addOrUpdateFrozenActors; readonly Cache> removeFrozenActors; @@ -77,8 +77,8 @@ namespace OpenRA.Traits partitionedRenderableActors = new SpatiallyPartitioned(width, height, info.BinSize); partitionedRenderableEffects = new SpatiallyPartitioned(width, height, info.BinSize); - addOrUpdateFrozenActors = new Cache>(_ => new HashSet()); - removeFrozenActors = new Cache>(_ => new HashSet()); + addOrUpdateFrozenActors = new Cache>(_ => []); + removeFrozenActors = new Cache>(_ => []); } public void WorldLoaded(World w, WorldRenderer wr) { worldRenderer = wr; } diff --git a/OpenRA.Game/Traits/World/ScreenShaker.cs b/OpenRA.Game/Traits/World/ScreenShaker.cs index 9b17b36911..2cc10f6429 100644 --- a/OpenRA.Game/Traits/World/ScreenShaker.cs +++ b/OpenRA.Game/Traits/World/ScreenShaker.cs @@ -29,7 +29,7 @@ namespace OpenRA.Traits { readonly ScreenShakerInfo info; WorldRenderer worldRenderer; - readonly List shakeEffects = new(); + readonly List shakeEffects = []; int ticks = 0; public ScreenShaker(ScreenShakerInfo info) diff --git a/OpenRA.Game/UtilityCommands/RegisterModCommand.cs b/OpenRA.Game/UtilityCommands/RegisterModCommand.cs index b1de8432c5..72a88d0ce6 100644 --- a/OpenRA.Game/UtilityCommands/RegisterModCommand.cs +++ b/OpenRA.Game/UtilityCommands/RegisterModCommand.cs @@ -32,7 +32,7 @@ namespace OpenRA.UtilityCommands if (args[2] == "user" || args[2] == "both") type |= ModRegistration.User; - new ExternalMods().Register(utility.ModData.Manifest, args[1], Enumerable.Empty(), type); + new ExternalMods().Register(utility.ModData.Manifest, args[1], [], type); } } } diff --git a/OpenRA.Game/WAngle.cs b/OpenRA.Game/WAngle.cs index d258081b09..284dee94bb 100644 --- a/OpenRA.Game/WAngle.cs +++ b/OpenRA.Game/WAngle.cs @@ -172,7 +172,7 @@ namespace OpenRA public override string ToString() { return Angle.ToStringInvariant(); } static readonly int[] CosineTable = - { + [ 1024, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1022, 1022, 1022, 1021, 1021, 1020, 1020, 1019, 1019, 1018, 1017, 1017, 1016, 1015, 1014, 1013, 1012, 1011, 1010, 1009, 1008, 1007, 1006, 1005, 1004, 1003, 1001, 1000, @@ -192,10 +192,10 @@ namespace OpenRA 236, 230, 224, 218, 212, 205, 199, 193, 187, 181, 175, 168, 162, 156, 150, 144, 137, 131, 125, 119, 112, 106, 100, 94, 87, 81, 75, 69, 62, 56, 50, 43, 37, 31, 25, 18, 12, 6, 0 - }; + ]; static readonly int[] TanTable = - { + [ 0, 6, 12, 18, 25, 31, 37, 44, 50, 56, 62, 69, 75, 81, 88, 94, 100, 107, 113, 119, 126, 132, 139, 145, 151, 158, 164, 171, 177, 184, 190, 197, 203, 210, 216, 223, 229, 236, 243, 249, 256, 263, 269, 276, 283, 290, @@ -216,7 +216,7 @@ namespace OpenRA 5499, 5693, 5901, 6124, 6364, 6622, 6903, 7207, 7539, 7902, 8302, 8743, 9233, 9781, 10396, 11094, 11891, 12810, 13882, 15148, 16667, 18524, 20843, 23826, 27801, 33366, 41713, 55622, 83438, 166883, int.MaxValue - }; + ]; #region Scripting interface diff --git a/OpenRA.Game/Widgets/ChromeMetrics.cs b/OpenRA.Game/Widgets/ChromeMetrics.cs index a0020e2bc8..5e02529e31 100644 --- a/OpenRA.Game/Widgets/ChromeMetrics.cs +++ b/OpenRA.Game/Widgets/ChromeMetrics.cs @@ -16,14 +16,14 @@ namespace OpenRA.Widgets { public static class ChromeMetrics { - static Dictionary data = new(); + static Dictionary data = []; public static void Initialize(ModData modData) { var stringPool = new HashSet(); // Reuse common strings in YAML var metrics = MiniYaml.Merge(modData.Manifest.ChromeMetrics.Select( y => MiniYaml.FromStream(modData.DefaultFileSystem.Open(y), y, stringPool: stringPool))); - data = new Dictionary(); + data = []; foreach (var m in metrics) foreach (var n in m.Value.Nodes) data[n.Key] = n.Value.Value; diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs index d9af6dfa56..c5ea984c5b 100644 --- a/OpenRA.Game/Widgets/Widget.cs +++ b/OpenRA.Game/Widgets/Widget.cs @@ -28,7 +28,7 @@ namespace OpenRA.Widgets public static TickTime LastTickTime = new(() => Timestep, Game.RunTime); - static readonly Stack WindowList = new(); + static readonly Stack WindowList = []; public static Widget MouseFocusWidget; public static Widget KeyboardFocusWidget; @@ -60,7 +60,7 @@ namespace OpenRA.Widgets public static Widget OpenWindow(string id) { - return OpenWindow(id, new WidgetArgs()); + return OpenWindow(id, []); } public static Widget OpenWindow(string id, WidgetArgs args) @@ -208,7 +208,7 @@ namespace OpenRA.Widgets { string defaultCursor = null; - public readonly List Children = new(); + public readonly List Children = []; // Info defined in YAML public string Id = null; @@ -216,7 +216,7 @@ namespace OpenRA.Widgets public IntegerExpression Y; public IntegerExpression Width; public IntegerExpression Height; - public string[] Logic = Array.Empty(); + public string[] Logic = []; public ChromeLogic[] LogicObjects { get; private set; } public bool Visible = true; public bool IgnoreMouseOver; @@ -288,7 +288,7 @@ namespace OpenRA.Widgets var substitutions = args.TryGetValue("substitutions", out var subs) ? new Dictionary((Dictionary)subs) : - new Dictionary(); + []; substitutions.Add("WINDOW_WIDTH", Game.Renderer.Resolution.Width); substitutions.Add("WINDOW_HEIGHT", Game.Renderer.Resolution.Height); @@ -668,7 +668,7 @@ namespace OpenRA.Widgets public sealed class Mediator { - readonly TypeDictionary types = new(); + readonly TypeDictionary types = []; public void Subscribe(T instance) { diff --git a/OpenRA.Game/Widgets/WidgetLoader.cs b/OpenRA.Game/Widgets/WidgetLoader.cs index c68dc94589..1866501b5e 100644 --- a/OpenRA.Game/Widgets/WidgetLoader.cs +++ b/OpenRA.Game/Widgets/WidgetLoader.cs @@ -18,7 +18,7 @@ namespace OpenRA { public class WidgetLoader { - readonly Dictionary widgets = new(); + readonly Dictionary widgets = []; readonly ModData modData; public WidgetLoader(ModData modData) diff --git a/OpenRA.Game/World.cs b/OpenRA.Game/World.cs index e343452055..421ede47e9 100644 --- a/OpenRA.Game/World.cs +++ b/OpenRA.Game/World.cs @@ -29,14 +29,14 @@ namespace OpenRA public sealed class World : IDisposable { internal readonly TraitDictionary TraitDict = new(); - readonly SortedDictionary actors = new(); - readonly List effects = new(); - readonly List unpartitionedEffects = new(); - readonly List syncedEffects = new(); + readonly SortedDictionary actors = []; + readonly List effects = []; + readonly List unpartitionedEffects = []; + readonly List syncedEffects = []; readonly GameSettings gameSettings; readonly ModData modData; - readonly Queue> frameEndActions = new(); + readonly Queue> frameEndActions = []; public readonly GameSpeed GameSpeed; @@ -52,7 +52,7 @@ namespace OpenRA public LongBitSet AllPlayersMask = default; public readonly LongBitSet NoPlayersMask = default; - public Player[] Players = Array.Empty(); + public Player[] Players = []; public event Action RenderPlayerChanged; @@ -213,7 +213,7 @@ namespace OpenRA LocalRandom = new MersenneTwister(); var worldActorType = type == WorldType.Editor ? SystemActors.EditorWorld : SystemActors.World; - WorldActor = CreateActor(worldActorType.ToString(), new TypeDictionary()); + WorldActor = CreateActor(worldActorType.ToString(), []); ActorMap = WorldActor.Trait(); ScreenMap = WorldActor.Trait(); Selection = WorldActor.Trait(); @@ -399,7 +399,7 @@ namespace OpenRA public int WorldTick { get; private set; } - readonly Dictionary gameSaveTraitData = new(); + readonly Dictionary gameSaveTraitData = []; internal void AddGameSaveTraitData(int traitIndex, MiniYaml yaml) { gameSaveTraitData[traitIndex] = yaml; diff --git a/OpenRA.Mods.Cnc/Activities/Teleport.cs b/OpenRA.Mods.Cnc/Activities/Teleport.cs index ae2b6a5119..bf08a876d2 100644 --- a/OpenRA.Mods.Cnc/Activities/Teleport.cs +++ b/OpenRA.Mods.Cnc/Activities/Teleport.cs @@ -10,6 +10,7 @@ #endregion using System; +using System.Linq; using OpenRA.Activities; using OpenRA.Mods.Cnc.Traits; using OpenRA.Mods.Common.Traits; diff --git a/OpenRA.Mods.Cnc/CncLoadScreen.cs b/OpenRA.Mods.Cnc/CncLoadScreen.cs index 4fcab29d0e..bdcdce4c83 100644 --- a/OpenRA.Mods.Cnc/CncLoadScreen.cs +++ b/OpenRA.Mods.Cnc/CncLoadScreen.cs @@ -52,8 +52,8 @@ namespace OpenRA.Mods.Cnc lastSheet = s; lastDensity = density; - border = new[] - { + border = + [ CreateSprite(s, density, new Rectangle(129, 129, 32, 32)), CreateSprite(s, density, new Rectangle(161, 129, 62, 32)), CreateSprite(s, density, new Rectangle(223, 129, 32, 32)), @@ -63,7 +63,7 @@ namespace OpenRA.Mods.Cnc CreateSprite(s, density, new Rectangle(129, 223, 32, 32)), CreateSprite(s, density, new Rectangle(161, 223, 62, 32)), CreateSprite(s, density, new Rectangle(223, 223, 32, 32)) - }; + ]; nodLogo = CreateSprite(s, density, new Rectangle(0, 256, 256, 256)); gdiLogo = CreateSprite(s, density, new Rectangle(256, 256, 256, 256)); diff --git a/OpenRA.Mods.Cnc/FileFormats/Blowfish.cs b/OpenRA.Mods.Cnc/FileFormats/Blowfish.cs index 35105db6c4..5bcdfecc6b 100644 --- a/OpenRA.Mods.Cnc/FileFormats/Blowfish.cs +++ b/OpenRA.Mods.Cnc/FileFormats/Blowfish.cs @@ -131,13 +131,13 @@ namespace OpenRA.Mods.Cnc.FileFormats } readonly uint[] lookupMfromP = - { + [ 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, 0x9216d5d9, 0x8979fb1b - }; + ]; readonly uint[,] lookupMfromS = { diff --git a/OpenRA.Mods.Cnc/FileFormats/CRC32.cs b/OpenRA.Mods.Cnc/FileFormats/CRC32.cs index afe7aa139e..54eeb7548c 100644 --- a/OpenRA.Mods.Cnc/FileFormats/CRC32.cs +++ b/OpenRA.Mods.Cnc/FileFormats/CRC32.cs @@ -22,8 +22,8 @@ namespace OpenRA.Mods.Cnc.FileFormats /// /// The CRC32 lookup table. /// - static readonly uint[] LookUp = new uint[256] - { + static readonly uint[] LookUp = + [ 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, @@ -88,7 +88,7 @@ namespace OpenRA.Mods.Cnc.FileFormats 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D - }; + ]; /// /// A CRC32 implementation that can be used on spans of bytes. diff --git a/OpenRA.Mods.Cnc/FileFormats/IdxReader.cs b/OpenRA.Mods.Cnc/FileFormats/IdxReader.cs index 1260e6a287..71248d4fca 100644 --- a/OpenRA.Mods.Cnc/FileFormats/IdxReader.cs +++ b/OpenRA.Mods.Cnc/FileFormats/IdxReader.cs @@ -35,7 +35,7 @@ namespace OpenRA.Mods.Cnc.FileFormats SoundCount = s.ReadInt32(); - Entries = new List(); + Entries = []; for (var i = 0; i < SoundCount; i++) Entries.Add(new IdxEntry(s)); diff --git a/OpenRA.Mods.Cnc/FileFormats/XccLocalDatabase.cs b/OpenRA.Mods.Cnc/FileFormats/XccLocalDatabase.cs index 95877040c2..5596cd561b 100644 --- a/OpenRA.Mods.Cnc/FileFormats/XccLocalDatabase.cs +++ b/OpenRA.Mods.Cnc/FileFormats/XccLocalDatabase.cs @@ -49,7 +49,7 @@ namespace OpenRA.Mods.Cnc.FileFormats using (var writer = new BinaryWriter(data)) { writer.Write(Encoding.ASCII.GetBytes("XCC by Olaf van der Spek")); - writer.Write(new byte[] { 0x1A, 0x04, 0x17, 0x27, 0x10, 0x19, 0x80, 0x00 }); + writer.Write([0x1A, 0x04, 0x17, 0x27, 0x10, 0x19, 0x80, 0x00]); writer.Write(Entries.Sum(e => e.Length) + Entries.Length + 52); // Size writer.Write(0); // Type diff --git a/OpenRA.Mods.Cnc/FileSystem/MixFile.cs b/OpenRA.Mods.Cnc/FileSystem/MixFile.cs index 6f8da0ec28..b8d3d1f8ab 100644 --- a/OpenRA.Mods.Cnc/FileSystem/MixFile.cs +++ b/OpenRA.Mods.Cnc/FileSystem/MixFile.cs @@ -241,7 +241,7 @@ namespace OpenRA.Mods.Cnc.FileSystem using (var db = new XccGlobalDatabase(mixDatabase)) globalFilenames = db.Entries.ToHashSet().ToArray(); - package = new MixFile(s, filename, globalFilenames ?? Array.Empty()); + package = new MixFile(s, filename, globalFilenames ?? []); return true; } } diff --git a/OpenRA.Mods.Cnc/FileSystem/PackageEntry.cs b/OpenRA.Mods.Cnc/FileSystem/PackageEntry.cs index eb5b39c3ff..e4ff06ea20 100644 --- a/OpenRA.Mods.Cnc/FileSystem/PackageEntry.cs +++ b/OpenRA.Mods.Cnc/FileSystem/PackageEntry.cs @@ -105,7 +105,7 @@ namespace OpenRA.Mods.Cnc.FileSystem } } - static readonly Dictionary Names = new(); + static readonly Dictionary Names = []; public static void AddStandardName(string s) { diff --git a/OpenRA.Mods.Cnc/FileSystem/Pak.cs b/OpenRA.Mods.Cnc/FileSystem/Pak.cs index 2d686091d2..7f1decc334 100644 --- a/OpenRA.Mods.Cnc/FileSystem/Pak.cs +++ b/OpenRA.Mods.Cnc/FileSystem/Pak.cs @@ -32,7 +32,7 @@ namespace OpenRA.Mods.Cnc.FileSystem public string Name { get; } public IEnumerable Contents => index.Keys; - readonly Dictionary index = new(); + readonly Dictionary index = []; readonly Stream stream; public PakFile(Stream stream, string filename) diff --git a/OpenRA.Mods.Cnc/Graphics/ChronoVortexRenderable.cs b/OpenRA.Mods.Cnc/Graphics/ChronoVortexRenderable.cs index c1f5f741b3..b7831848d5 100644 --- a/OpenRA.Mods.Cnc/Graphics/ChronoVortexRenderable.cs +++ b/OpenRA.Mods.Cnc/Graphics/ChronoVortexRenderable.cs @@ -19,7 +19,7 @@ namespace OpenRA.Mods.Cnc.Graphics { public class ChronoVortexRenderable : IRenderable, IFinalizedRenderable { - public static readonly IEnumerable None = Array.Empty(); + public static readonly IEnumerable None = []; readonly ChronoVortexRenderer renderer; public WPos Pos { get; } readonly int frame; diff --git a/OpenRA.Mods.Cnc/Graphics/ClassicTilesetSpecificSpriteSequence.cs b/OpenRA.Mods.Cnc/Graphics/ClassicTilesetSpecificSpriteSequence.cs index 07d58a44ad..429d09e0b8 100644 --- a/OpenRA.Mods.Cnc/Graphics/ClassicTilesetSpecificSpriteSequence.cs +++ b/OpenRA.Mods.Cnc/Graphics/ClassicTilesetSpecificSpriteSequence.cs @@ -64,7 +64,7 @@ namespace OpenRA.Mods.Cnc.Graphics if (tilesetNode != null) { var loadFrames = CalculateFrameIndices(start, length, stride ?? length ?? 0, facings, frames, transpose, reverseFacings, shadowStart); - return new[] { new ReservationInfo(tilesetNode.Value.Value, loadFrames, frames, tilesetNode.Location) }; + return [new ReservationInfo(tilesetNode.Value.Value, loadFrames, frames, tilesetNode.Location)]; } } @@ -86,7 +86,7 @@ namespace OpenRA.Mods.Cnc.Graphics frames = Exts.MakeArray(subLength, i => subStart + i); } - return new[] { new ReservationInfo(tilesetNode.Value.Value, frames, frames, tilesetNode.Location) }; + return [new ReservationInfo(tilesetNode.Value.Value, frames, frames, tilesetNode.Location)]; } } diff --git a/OpenRA.Mods.Cnc/Graphics/ModelRenderable.cs b/OpenRA.Mods.Cnc/Graphics/ModelRenderable.cs index 22ba14693e..7eaec17942 100644 --- a/OpenRA.Mods.Cnc/Graphics/ModelRenderable.cs +++ b/OpenRA.Mods.Cnc/Graphics/ModelRenderable.cs @@ -218,9 +218,9 @@ namespace OpenRA.Mods.Cnc.Graphics } } - static readonly uint[] CornerXIndex = new uint[] { 0, 0, 0, 0, 3, 3, 3, 3 }; - static readonly uint[] CornerYIndex = new uint[] { 1, 1, 4, 4, 1, 1, 4, 4 }; - static readonly uint[] CornerZIndex = new uint[] { 2, 5, 2, 5, 2, 5, 2, 5 }; + static readonly uint[] CornerXIndex = [0, 0, 0, 0, 3, 3, 3, 3]; + static readonly uint[] CornerYIndex = [1, 1, 4, 4, 1, 1, 4, 4]; + static readonly uint[] CornerZIndex = [2, 5, 2, 5, 2, 5, 2, 5]; static void DrawBoundsBox(WorldRenderer wr, in float3 pxPos, float[] transform, float[] bounds, float width, Color c) { var cr = Game.Renderer.RgbaColorRenderer; diff --git a/OpenRA.Mods.Cnc/Graphics/TeslaZapRenderable.cs b/OpenRA.Mods.Cnc/Graphics/TeslaZapRenderable.cs index 1df9d28b55..2104a44424 100644 --- a/OpenRA.Mods.Cnc/Graphics/TeslaZapRenderable.cs +++ b/OpenRA.Mods.Cnc/Graphics/TeslaZapRenderable.cs @@ -19,17 +19,17 @@ namespace OpenRA.Mods.Cnc.Graphics { sealed class TeslaZapRenderable : IPalettedRenderable, IFinalizedRenderable { - static readonly int[][] Steps = new[] - { - new int[] { 8, 8, 4, 4, 0 }, - new int[] { -8, -8, -4, -4, 0 }, - new int[] { 8, 0, 4, 4, 1 }, - new int[] { -8, 0, -4, 4, 1 }, - new int[] { 0, 8, 4, 4, 2 }, - new int[] { 0, -8, 4, -4, 2 }, - new int[] { -8, 8, -4, 4, 3 }, - new int[] { 8, -8, 4, -4, 3 } - }; + static readonly int[][] Steps = + [ + [8, 8, 4, 4, 0], + [-8, -8, -4, -4, 0], + [8, 0, 4, 4, 1], + [-8, 0, -4, 4, 1], + [0, 8, 4, 4, 2], + [0, -8, 4, -4, 2], + [-8, 8, -4, 4, 3], + [8, -8, 4, -4, 3] + ]; readonly WVec length; readonly string image; readonly string palette; @@ -59,7 +59,7 @@ namespace OpenRA.Mods.Cnc.Graphics cachedPos = WPos.Zero; cachedLength = WVec.Zero; - cache = Array.Empty(); + cache = []; } public WPos Pos { get; } diff --git a/OpenRA.Mods.Cnc/Graphics/UIModelRenderable.cs b/OpenRA.Mods.Cnc/Graphics/UIModelRenderable.cs index 7e8fddde5e..bbdd311e35 100644 --- a/OpenRA.Mods.Cnc/Graphics/UIModelRenderable.cs +++ b/OpenRA.Mods.Cnc/Graphics/UIModelRenderable.cs @@ -108,9 +108,9 @@ namespace OpenRA.Mods.Cnc.Graphics return Screen3DBounds(wr).Bounds; } - static readonly uint[] CornerXIndex = { 0, 0, 0, 0, 3, 3, 3, 3 }; - static readonly uint[] CornerYIndex = { 1, 1, 4, 4, 1, 1, 4, 4 }; - static readonly uint[] CornerZIndex = { 2, 5, 2, 5, 2, 5, 2, 5 }; + static readonly uint[] CornerXIndex = [0, 0, 0, 0, 3, 3, 3, 3]; + static readonly uint[] CornerYIndex = [1, 1, 4, 4, 1, 1, 4, 4]; + static readonly uint[] CornerZIndex = [2, 5, 2, 5, 2, 5, 2, 5]; (Rectangle Bounds, float2 Z) Screen3DBounds(WorldRenderer wr) { var pxOrigin = model.screenPos; diff --git a/OpenRA.Mods.Cnc/Graphics/Voxel.cs b/OpenRA.Mods.Cnc/Graphics/Voxel.cs index d9f149d9ca..b7360357b5 100644 --- a/OpenRA.Mods.Cnc/Graphics/Voxel.cs +++ b/OpenRA.Mods.Cnc/Graphics/Voxel.cs @@ -90,12 +90,12 @@ namespace OpenRA.Mods.Cnc.Graphics get { return limbData.Select(a => a.Size.Select(b => a.Scale * b).ToArray()) - .Aggregate((a, b) => new float[] - { + .Aggregate((a, b) => + [ Math.Max(a[0], b[0]), Math.Max(a[1], b[1]), Math.Max(a[2], b[2]) - }); + ]); } } diff --git a/OpenRA.Mods.Cnc/Graphics/VoxelLoader.cs b/OpenRA.Mods.Cnc/Graphics/VoxelLoader.cs index 8c3caec0e8..20e1b6b524 100644 --- a/OpenRA.Mods.Cnc/Graphics/VoxelLoader.cs +++ b/OpenRA.Mods.Cnc/Graphics/VoxelLoader.cs @@ -21,9 +21,9 @@ namespace OpenRA.Mods.Cnc.Graphics { public sealed class VoxelLoader : IDisposable { - static readonly float[] ChannelSelect = { 0.75f, 0.25f, -0.25f, -0.75f }; + static readonly float[] ChannelSelect = [0.75f, 0.25f, -0.25f, -0.75f]; - readonly List vertices = new(); + readonly List vertices = []; readonly Cache<(string, string), Voxel> voxels; readonly IReadOnlyFileSystem fileSystem; IVertexBuffer vertexBuffer; @@ -50,7 +50,7 @@ namespace OpenRA.Mods.Cnc.Graphics { this.fileSystem = fileSystem; voxels = new Cache<(string, string), Voxel>(LoadFile); - vertices = new List(); + vertices = []; totalVertexCount = 0; cachedVertexCount = 0; @@ -86,15 +86,15 @@ namespace OpenRA.Mods.Cnc.Graphics var channelP = ChannelSelect[(int)s.Channel]; var channelC = ChannelSelect[(int)t.Channel]; - return new ModelVertex[6] - { + return + [ new(coord(0, 0), s.Left, s.Top, t.Left, t.Top, channelP, channelC), new(coord(su, 0), s.Right, s.Top, t.Right, t.Top, channelP, channelC), new(coord(su, sv), s.Right, s.Bottom, t.Right, t.Bottom, channelP, channelC), new(coord(su, sv), s.Right, s.Bottom, t.Right, t.Bottom, channelP, channelC), new(coord(0, sv), s.Left, s.Bottom, t.Left, t.Bottom, channelP, channelC), new(coord(0, 0), s.Left, s.Top, t.Left, t.Top, channelP, channelC) - }; + ]; } IEnumerable GenerateSlicePlanes(VxlLimb l) diff --git a/OpenRA.Mods.Cnc/SpriteLoaders/TmpRALoader.cs b/OpenRA.Mods.Cnc/SpriteLoaders/TmpRALoader.cs index 3b3bdbff04..9de4bf8b8b 100644 --- a/OpenRA.Mods.Cnc/SpriteLoaders/TmpRALoader.cs +++ b/OpenRA.Mods.Cnc/SpriteLoaders/TmpRALoader.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.IO; using OpenRA.Graphics; using OpenRA.Primitives; @@ -33,7 +32,7 @@ namespace OpenRA.Mods.Cnc.SpriteLoaders Data = data; if (data == null) - Data = Array.Empty(); + Data = []; else Size = size; } diff --git a/OpenRA.Mods.Cnc/SpriteLoaders/TmpTDLoader.cs b/OpenRA.Mods.Cnc/SpriteLoaders/TmpTDLoader.cs index f90db35c70..e7df9846aa 100644 --- a/OpenRA.Mods.Cnc/SpriteLoaders/TmpTDLoader.cs +++ b/OpenRA.Mods.Cnc/SpriteLoaders/TmpTDLoader.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.IO; using OpenRA.Graphics; using OpenRA.Primitives; @@ -33,7 +32,7 @@ namespace OpenRA.Mods.Cnc.SpriteLoaders Data = data; if (data == null) - Data = Array.Empty(); + Data = []; else Size = size; } diff --git a/OpenRA.Mods.Cnc/SpriteLoaders/TmpTSLoader.cs b/OpenRA.Mods.Cnc/SpriteLoaders/TmpTSLoader.cs index a5fb452ab5..1322522fb9 100644 --- a/OpenRA.Mods.Cnc/SpriteLoaders/TmpTSLoader.cs +++ b/OpenRA.Mods.Cnc/SpriteLoaders/TmpTSLoader.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.IO; using OpenRA.Graphics; using OpenRA.Primitives; @@ -110,7 +109,7 @@ namespace OpenRA.Mods.Cnc.SpriteLoaders } } else - Data = Array.Empty(); + Data = []; } } diff --git a/OpenRA.Mods.Cnc/Traits/Disguise.cs b/OpenRA.Mods.Cnc/Traits/Disguise.cs index 9d27eebded..3d47e58ec7 100644 --- a/OpenRA.Mods.Cnc/Traits/Disguise.cs +++ b/OpenRA.Mods.Cnc/Traits/Disguise.cs @@ -87,7 +87,7 @@ namespace OpenRA.Mods.Cnc.Traits [ActorReference(dictionaryReference: LintDictionaryReference.Keys)] [Desc("Conditions to grant when disguised as specified actor.", "A dictionary of [actor id]: [condition].")] - public readonly Dictionary DisguisedAsConditions = new(); + public readonly Dictionary DisguisedAsConditions = []; [CursorReference] [Desc("Cursor to display when hovering over a valid actor to disguise as.")] diff --git a/OpenRA.Mods.Cnc/Traits/GpsWatcher.cs b/OpenRA.Mods.Cnc/Traits/GpsWatcher.cs index 1e352e6ec7..3404ef207b 100644 --- a/OpenRA.Mods.Cnc/Traits/GpsWatcher.cs +++ b/OpenRA.Mods.Cnc/Traits/GpsWatcher.cs @@ -42,8 +42,8 @@ namespace OpenRA.Mods.Cnc.Traits readonly Player owner; - readonly List actors = new(); - readonly HashSet> notifyOnRefresh = new(); + readonly List actors = []; + readonly HashSet> notifyOnRefresh = []; public GpsWatcher(Player owner) { diff --git a/OpenRA.Mods.Cnc/Traits/Infiltration/InfiltrateForDecoration.cs b/OpenRA.Mods.Cnc/Traits/Infiltration/InfiltrateForDecoration.cs index f402259e44..27a8308229 100644 --- a/OpenRA.Mods.Cnc/Traits/Infiltration/InfiltrateForDecoration.cs +++ b/OpenRA.Mods.Cnc/Traits/Infiltration/InfiltrateForDecoration.cs @@ -32,7 +32,7 @@ namespace OpenRA.Mods.Cnc.Traits sealed class InfiltrateForDecoration : WithDecoration, INotifyInfiltrated { - readonly HashSet infiltrators = new(); + readonly HashSet infiltrators = []; readonly InfiltrateForDecorationInfo info; public InfiltrateForDecoration(Actor self, InfiltrateForDecorationInfo info) diff --git a/OpenRA.Mods.Cnc/Traits/Infiltration/InfiltrateForSupportPower.cs b/OpenRA.Mods.Cnc/Traits/Infiltration/InfiltrateForSupportPower.cs index 88b671266a..27a17418b5 100644 --- a/OpenRA.Mods.Cnc/Traits/Infiltration/InfiltrateForSupportPower.cs +++ b/OpenRA.Mods.Cnc/Traits/Infiltration/InfiltrateForSupportPower.cs @@ -71,10 +71,10 @@ namespace OpenRA.Mods.Cnc.Traits infiltrator.Owner.PlayerActor.TraitOrDefault()?.GiveExperience(info.PlayerExperience); - infiltrator.World.AddFrameEndTask(w => w.CreateActor(info.Proxy, new TypeDictionary - { + infiltrator.World.AddFrameEndTask(w => w.CreateActor(info.Proxy, + [ new OwnerInit(infiltrator.Owner) - })); + ])); } } } diff --git a/OpenRA.Mods.Cnc/Traits/MadTank.cs b/OpenRA.Mods.Cnc/Traits/MadTank.cs index fa96514061..f5f089465c 100644 --- a/OpenRA.Mods.Cnc/Traits/MadTank.cs +++ b/OpenRA.Mods.Cnc/Traits/MadTank.cs @@ -243,11 +243,11 @@ namespace OpenRA.Mods.Cnc.Traits void EjectDriver() { - var driver = self.World.CreateActor(mad.info.DriverActor.ToLowerInvariant(), new TypeDictionary - { + var driver = self.World.CreateActor(mad.info.DriverActor.ToLowerInvariant(), + [ new LocationInit(self.Location), new OwnerInit(self.Owner) - }); + ]); driver.QueueActivity(false, new Nudge(driver)); } } diff --git a/OpenRA.Mods.Cnc/Traits/PaletteEffects/LightPaletteRotator.cs b/OpenRA.Mods.Cnc/Traits/PaletteEffects/LightPaletteRotator.cs index 259abb7720..464826d8a8 100644 --- a/OpenRA.Mods.Cnc/Traits/PaletteEffects/LightPaletteRotator.cs +++ b/OpenRA.Mods.Cnc/Traits/PaletteEffects/LightPaletteRotator.cs @@ -20,7 +20,7 @@ namespace OpenRA.Mods.Cnc.Traits sealed class LightPaletteRotatorInfo : TraitInfo { [Desc("Palettes this effect should not apply to.")] - public readonly HashSet ExcludePalettes = new(); + public readonly HashSet ExcludePalettes = []; [Desc("'Speed' at which the effect cycles through palette indices.")] public readonly float TimeStep = .5f; @@ -29,7 +29,7 @@ namespace OpenRA.Mods.Cnc.Traits public readonly int ModifyIndex = 103; [Desc("Palette indices to rotate through.")] - public readonly int[] RotationIndices = { 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 238, 237, 236, 235, 234, 233, 232, 231 }; + public readonly int[] RotationIndices = [230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 238, 237, 236, 235, 234, 233, 232, 231]; public override object Create(ActorInitializer init) { return new LightPaletteRotator(this); } } diff --git a/OpenRA.Mods.Cnc/Traits/Render/RenderVoxels.cs b/OpenRA.Mods.Cnc/Traits/Render/RenderVoxels.cs index eebdfd90b5..e5b56f4aa1 100644 --- a/OpenRA.Mods.Cnc/Traits/Render/RenderVoxels.cs +++ b/OpenRA.Mods.Cnc/Traits/Render/RenderVoxels.cs @@ -52,8 +52,8 @@ namespace OpenRA.Mods.Cnc.Traits.Render public readonly WAngle LightPitch = WAngle.FromDegrees(50); public readonly WAngle LightYaw = WAngle.FromDegrees(240); - public readonly float[] LightAmbientColor = { 0.6f, 0.6f, 0.6f }; - public readonly float[] LightDiffuseColor = { 0.4f, 0.4f, 0.4f }; + public readonly float[] LightAmbientColor = [0.6f, 0.6f, 0.6f]; + public readonly float[] LightDiffuseColor = [0.4f, 0.4f, 0.4f]; public override object Create(ActorInitializer init) { return new RenderVoxels(init.Self, this); } @@ -111,8 +111,8 @@ namespace OpenRA.Mods.Cnc.Traits.Render public readonly RenderVoxelsInfo Info; public readonly ModelRenderer Renderer; - readonly List components = new(); - readonly Dictionary wrappers = new(); + readonly List components = []; + readonly Dictionary wrappers = []; readonly Actor self; readonly BodyOrientation body; @@ -154,13 +154,13 @@ namespace OpenRA.Mods.Cnc.Traits.Render initializePalettes = false; } - return new IRenderable[] - { + return + [ new ModelRenderable( Renderer, components, self.CenterPosition, 0, camera, Info.Scale, lightSource, Info.LightAmbientColor, Info.LightDiffuseColor, colorPalette, normalsPalette, shadowPalette) - }; + ]; } IEnumerable IRender.ScreenBounds(Actor self, WorldRenderer wr) diff --git a/OpenRA.Mods.Cnc/Traits/Render/WithBuildingBib.cs b/OpenRA.Mods.Cnc/Traits/Render/WithBuildingBib.cs index 7d595e072f..2d74941f6a 100644 --- a/OpenRA.Mods.Cnc/Traits/Render/WithBuildingBib.cs +++ b/OpenRA.Mods.Cnc/Traits/Render/WithBuildingBib.cs @@ -84,7 +84,7 @@ namespace OpenRA.Mods.Cnc.Traits readonly WithBuildingBibInfo info; readonly RenderSprites rs; readonly BuildingInfo bi; - readonly List anims = new(); + readonly List anims = []; public WithBuildingBib(Actor self, WithBuildingBibInfo info) { diff --git a/OpenRA.Mods.Cnc/Traits/Render/WithCargo.cs b/OpenRA.Mods.Cnc/Traits/Render/WithCargo.cs index 8c744cd65f..ca76a76dce 100644 --- a/OpenRA.Mods.Cnc/Traits/Render/WithCargo.cs +++ b/OpenRA.Mods.Cnc/Traits/Render/WithCargo.cs @@ -24,10 +24,10 @@ namespace OpenRA.Mods.Cnc.Traits.Render public class WithCargoInfo : TraitInfo, Requires, Requires { [Desc("Cargo position relative to turret or body in (forward, right, up) triples. The default offset should be in the middle of the list.")] - public readonly WVec[] LocalOffset = { WVec.Zero }; + public readonly WVec[] LocalOffset = [WVec.Zero]; [Desc("Passenger CargoType to display.")] - public readonly HashSet DisplayTypes = new(); + public readonly HashSet DisplayTypes = []; public override object Create(ActorInitializer init) { return new WithCargo(init.Self, this); } } @@ -40,7 +40,7 @@ namespace OpenRA.Mods.Cnc.Traits.Render readonly IFacing facing; WAngle cachedFacing; - readonly Dictionary previews = new(); + readonly Dictionary previews = []; public WithCargo(Actor self, WithCargoInfo info) { diff --git a/OpenRA.Mods.Cnc/Traits/Render/WithHarvesterSpriteBody.cs b/OpenRA.Mods.Cnc/Traits/Render/WithHarvesterSpriteBody.cs index e685b13f90..5617e8f094 100644 --- a/OpenRA.Mods.Cnc/Traits/Render/WithHarvesterSpriteBody.cs +++ b/OpenRA.Mods.Cnc/Traits/Render/WithHarvesterSpriteBody.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using OpenRA.Mods.Common.Traits; using OpenRA.Mods.Common.Traits.Render; using OpenRA.Traits; @@ -19,7 +18,7 @@ namespace OpenRA.Mods.Cnc.Traits.Render public class WithHarvesterSpriteBodyInfo : WithFacingSpriteBodyInfo, Requires { [Desc("Images switched between depending on fullness of harvester. Overrides RenderSprites.Image.")] - public readonly string[] ImageByFullness = Array.Empty(); + public readonly string[] ImageByFullness = []; public override object Create(ActorInitializer init) { return new WithHarvesterSpriteBody(init, this); } } diff --git a/OpenRA.Mods.Cnc/Traits/Render/WithLandingCraftAnimation.cs b/OpenRA.Mods.Cnc/Traits/Render/WithLandingCraftAnimation.cs index 7561a07386..3361cc6580 100644 --- a/OpenRA.Mods.Cnc/Traits/Render/WithLandingCraftAnimation.cs +++ b/OpenRA.Mods.Cnc/Traits/Render/WithLandingCraftAnimation.cs @@ -19,7 +19,7 @@ namespace OpenRA.Mods.Cnc.Traits.Render { public class WithLandingCraftAnimationInfo : TraitInfo, Requires, Requires, Requires { - public readonly HashSet OpenTerrainTypes = new() { "Clear" }; + public readonly HashSet OpenTerrainTypes = ["Clear"]; [SequenceReference] public readonly string OpenSequence = "open"; diff --git a/OpenRA.Mods.Cnc/Traits/ResourcePurifier.cs b/OpenRA.Mods.Cnc/Traits/ResourcePurifier.cs index d2c4afd91e..5f67446a78 100644 --- a/OpenRA.Mods.Cnc/Traits/ResourcePurifier.cs +++ b/OpenRA.Mods.Cnc/Traits/ResourcePurifier.cs @@ -45,7 +45,7 @@ namespace OpenRA.Mods.Cnc.Traits public ResourcePurifier(ResourcePurifierInfo info) : base(info) { - modifier = new int[] { Info.Modifier }; + modifier = [Info.Modifier]; currentDisplayTick = Info.TickRate; } diff --git a/OpenRA.Mods.Cnc/Traits/SupportPowers/DropPodsPower.cs b/OpenRA.Mods.Cnc/Traits/SupportPowers/DropPodsPower.cs index b6e25691d1..a329cf238f 100644 --- a/OpenRA.Mods.Cnc/Traits/SupportPowers/DropPodsPower.cs +++ b/OpenRA.Mods.Cnc/Traits/SupportPowers/DropPodsPower.cs @@ -17,7 +17,6 @@ using OpenRA.Mods.Cnc.Effects; using OpenRA.Mods.Common; using OpenRA.Mods.Common.Activities; using OpenRA.Mods.Common.Traits; -using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Cnc.Traits @@ -26,7 +25,7 @@ namespace OpenRA.Mods.Cnc.Traits { [FieldLoader.Require] [Desc("Drop pod unit")] - [ActorReference(new[] { typeof(AircraftInfo), typeof(FallsToEarthInfo) })] + [ActorReference([typeof(AircraftInfo), typeof(FallsToEarthInfo)])] public readonly string[] UnitTypes = null; [Desc("Number of drop pods spawned.")] @@ -82,8 +81,8 @@ namespace OpenRA.Mods.Cnc.Traits { readonly DropPodsPowerInfo info; readonly string[] unitTypes; - readonly Dictionary> getLaunchLocation = new(); - readonly Dictionary> landableTerrainTypes = new(); + readonly Dictionary> getLaunchLocation = []; + readonly Dictionary> landableTerrainTypes = []; public DropPodsPower(Actor self, DropPodsPowerInfo info) : base(self, info) @@ -134,11 +133,11 @@ namespace OpenRA.Mods.Cnc.Traits if (info.CameraActor != null) { - var camera = world.CreateActor(info.CameraActor, new TypeDictionary - { + var camera = world.CreateActor(info.CameraActor, + [ new LocationInit(targetCell), new OwnerInit(self.Owner), - }); + ]); camera.QueueActivity(new Wait(info.CameraRemoveDelay)); camera.QueueActivity(new RemoveSelf()); @@ -166,12 +165,12 @@ namespace OpenRA.Mods.Cnc.Traits var dropLocation = validDropLocations.Random(world.SharedRandom); var launchLocation = getLaunchLocation[unitType](dropLocation); - var pod = world.CreateActor(false, unitType, new TypeDictionary - { + var pod = world.CreateActor(false, unitType, + [ new CenterPositionInit(launchLocation), new OwnerInit(self.Owner), new FacingInit(info.PodFacing) - }); + ]); var aircraft = pod.Trait(); if (!aircraft.CanLand(dropLocation)) diff --git a/OpenRA.Mods.Cnc/Traits/SupportPowers/GrantPrerequisiteChargeDrainPower.cs b/OpenRA.Mods.Cnc/Traits/SupportPowers/GrantPrerequisiteChargeDrainPower.cs index 0fcaa98cc3..6efc97221e 100644 --- a/OpenRA.Mods.Cnc/Traits/SupportPowers/GrantPrerequisiteChargeDrainPower.cs +++ b/OpenRA.Mods.Cnc/Traits/SupportPowers/GrantPrerequisiteChargeDrainPower.cs @@ -51,7 +51,7 @@ namespace OpenRA.Mods.Cnc.Traits : base(self, info) { this.info = info; - prerequisites = new[] { info.Prerequisite }; + prerequisites = [info.Prerequisite]; } protected override void Created(Actor self) diff --git a/OpenRA.Mods.Cnc/Traits/SupportPowers/IonCannonPower.cs b/OpenRA.Mods.Cnc/Traits/SupportPowers/IonCannonPower.cs index 562a5b0f18..66d9c52a3c 100644 --- a/OpenRA.Mods.Cnc/Traits/SupportPowers/IonCannonPower.cs +++ b/OpenRA.Mods.Cnc/Traits/SupportPowers/IonCannonPower.cs @@ -13,7 +13,6 @@ using OpenRA.GameRules; using OpenRA.Mods.Cnc.Effects; using OpenRA.Mods.Common.Activities; using OpenRA.Mods.Common.Traits; -using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Cnc.Traits @@ -91,11 +90,11 @@ namespace OpenRA.Mods.Cnc.Traits if (info.CameraActor == null) return; - var camera = w.CreateActor(info.CameraActor, new TypeDictionary - { + var camera = w.CreateActor(info.CameraActor, + [ new LocationInit(self.World.Map.CellContaining(target.CenterPosition)), new OwnerInit(self.Owner), - }); + ]); camera.QueueActivity(new Wait(info.CameraRemoveDelay)); camera.QueueActivity(new RemoveSelf()); diff --git a/OpenRA.Mods.Cnc/Traits/TDGunboat.cs b/OpenRA.Mods.Cnc/Traits/TDGunboat.cs index bcf2621e7b..2366a1e51b 100644 --- a/OpenRA.Mods.Cnc/Traits/TDGunboat.cs +++ b/OpenRA.Mods.Cnc/Traits/TDGunboat.cs @@ -142,7 +142,7 @@ namespace OpenRA.Mods.Cnc.Traits int MovementSpeed => Common.Util.ApplyPercentageModifiers(Info.Speed, speedModifiers); - public (CPos, SubCell)[] OccupiedCells() { return new[] { (TopLeft, SubCell.FullCell) }; } + public (CPos, SubCell)[] OccupiedCells() { return [(TopLeft, SubCell.FullCell)]; } WVec MoveStep(WAngle facing) { diff --git a/OpenRA.Mods.Cnc/Traits/TransformsNearResources.cs b/OpenRA.Mods.Cnc/Traits/TransformsNearResources.cs index 227be62e1b..1164122fc2 100644 --- a/OpenRA.Mods.Cnc/Traits/TransformsNearResources.cs +++ b/OpenRA.Mods.Cnc/Traits/TransformsNearResources.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.Cnc.Traits public readonly int Adjacency = 1; [Desc("The range of time (in ticks) until the transformation starts.")] - public readonly int[] Delay = { 1000, 3000 }; + public readonly int[] Delay = [1000, 3000]; public override object Create(ActorInitializer init) { return new TransformsNearResources(init.Self, this); } } diff --git a/OpenRA.Mods.Cnc/Traits/World/ChronoVortexRenderer.cs b/OpenRA.Mods.Cnc/Traits/World/ChronoVortexRenderer.cs index c5fcb07e71..12b576865d 100644 --- a/OpenRA.Mods.Cnc/Traits/World/ChronoVortexRenderer.cs +++ b/OpenRA.Mods.Cnc/Traits/World/ChronoVortexRenderer.cs @@ -29,7 +29,7 @@ namespace OpenRA.Mods.Cnc.Traits readonly IShader shader; readonly IVertexBuffer vortexBuffer; readonly Sheet vortexSheet; - readonly List<(float3, int)> vortices = new(); + readonly List<(float3, int)> vortices = []; public ChronoVortexRenderer(Actor self) { diff --git a/OpenRA.Mods.Cnc/Traits/World/JumpjetLocomotor.cs b/OpenRA.Mods.Cnc/Traits/World/JumpjetLocomotor.cs index 35c2713c8d..7b7395263c 100644 --- a/OpenRA.Mods.Cnc/Traits/World/JumpjetLocomotor.cs +++ b/OpenRA.Mods.Cnc/Traits/World/JumpjetLocomotor.cs @@ -23,7 +23,7 @@ namespace OpenRA.Mods.Cnc.Traits public readonly short JumpjetTransitionCost = 0; [Desc("The terrain types that this actor can transition on. Leave empty to allow any.")] - public readonly HashSet JumpjetTransitionTerrainTypes = new(); + public readonly HashSet JumpjetTransitionTerrainTypes = []; [Desc("Can this actor transition on slopes?")] public readonly bool JumpjetTransitionOnRamps = true; diff --git a/OpenRA.Mods.Cnc/Traits/World/ModelRenderer.cs b/OpenRA.Mods.Cnc/Traits/World/ModelRenderer.cs index 1964c5a915..0708f81318 100644 --- a/OpenRA.Mods.Cnc/Traits/World/ModelRenderer.cs +++ b/OpenRA.Mods.Cnc/Traits/World/ModelRenderer.cs @@ -44,22 +44,22 @@ namespace OpenRA.Mods.Cnc.Traits public sealed class ModelRenderer : IDisposable, IRenderer, INotifyActorDisposing { // Static constants - static readonly float[] ShadowDiffuse = new float[] { 0, 0, 0 }; - static readonly float[] ShadowAmbient = new float[] { 1, 1, 1 }; + static readonly float[] ShadowDiffuse = [0, 0, 0]; + static readonly float[] ShadowAmbient = [1, 1, 1]; static readonly float2 SpritePadding = new(2, 2); - static readonly float[] ZeroVector = new float[] { 0, 0, 0, 1 }; - static readonly float[] ZVector = new float[] { 0, 0, 1, 1 }; + static readonly float[] ZeroVector = [0, 0, 0, 1]; + static readonly float[] ZVector = [0, 0, 1, 1]; static readonly float[] FlipMtx = Util.ScaleMatrix(1, -1, 1); static readonly float[] ShadowScaleFlipMtx = Util.ScaleMatrix(2, -2, 2); - static readonly float[] GroundNormal = { 0, 0, 1, 1 }; + static readonly float[] GroundNormal = [0, 0, 1, 1]; readonly Renderer renderer; readonly IShader shader; public readonly IModelCache ModelCache; - readonly Dictionary mappedBuffers = new(); - readonly Stack> unmappedBuffers = new(); - readonly List<(Sheet Sheet, Action Func)> doRender = new(); + readonly Dictionary mappedBuffers = []; + readonly Stack> unmappedBuffers = []; + readonly List<(Sheet Sheet, Action Func)> doRender = []; readonly int sheetSize; SheetBuilder sheetBuilderForFrame; @@ -156,10 +156,10 @@ namespace OpenRA.Mods.Cnc.Traits // Corners of the shadow quad, in shadow-space var corners = new float[][] { - new[] { stl.X, stl.Y, 0, 1 }, - new[] { sbr.X, sbr.Y, 0, 1 }, - new[] { sbr.X, stl.Y, 0, 1 }, - new[] { stl.X, sbr.Y, 0, 1 } + [stl.X, stl.Y, 0, 1], + [sbr.X, sbr.Y, 0, 1], + [sbr.X, stl.Y, 0, 1], + [stl.X, sbr.Y, 0, 1] }; var shadowScreenTransform = Util.MatrixMultiply(cameraTransform, invShadowTransform); diff --git a/OpenRA.Mods.Cnc/Traits/World/ShroudPalette.cs b/OpenRA.Mods.Cnc/Traits/World/ShroudPalette.cs index 73e48f4720..754df9950e 100644 --- a/OpenRA.Mods.Cnc/Traits/World/ShroudPalette.cs +++ b/OpenRA.Mods.Cnc/Traits/World/ShroudPalette.cs @@ -45,25 +45,25 @@ namespace OpenRA.Mods.Cnc.Traits wr.AddPalette(info.Name, new ImmutablePalette(Enumerable.Range(0, Palette.Size).Select(i => c[i % 8].ToArgb()))); } - static readonly Color[] Fog = new[] - { + static readonly Color[] Fog = + [ Color.FromArgb(0, 0, 0, 0), Color.Green, Color.Blue, Color.Yellow, Color.FromArgb(128, 0, 0, 0), Color.FromArgb(96, 0, 0, 0), Color.FromArgb(64, 0, 0, 0), Color.FromArgb(32, 0, 0, 0) - }; + ]; - static readonly Color[] Shroud = new[] - { + static readonly Color[] Shroud = + [ Color.FromArgb(0, 0, 0, 0), Color.Green, Color.Blue, Color.Yellow, Color.Black, Color.FromArgb(160, 0, 0, 0), Color.FromArgb(128, 0, 0, 0), Color.FromArgb(64, 0, 0, 0) - }; + ]; public IEnumerable PaletteNames { get { yield return info.Name; } } } diff --git a/OpenRA.Mods.Cnc/Traits/World/TSEditorResourceLayer.cs b/OpenRA.Mods.Cnc/Traits/World/TSEditorResourceLayer.cs index 3bf3b92e9a..5315c39e26 100644 --- a/OpenRA.Mods.Cnc/Traits/World/TSEditorResourceLayer.cs +++ b/OpenRA.Mods.Cnc/Traits/World/TSEditorResourceLayer.cs @@ -23,7 +23,7 @@ namespace OpenRA.Mods.Cnc.Traits [ActorReference] [Desc("Actor types that should be treated as veins for adjacency.")] - public readonly HashSet VeinholeActors = new(); + public readonly HashSet VeinholeActors = []; public override object Create(ActorInitializer init) { return new TSEditorResourceLayer(init.Self, this); } } diff --git a/OpenRA.Mods.Cnc/Traits/World/TSResourceLayer.cs b/OpenRA.Mods.Cnc/Traits/World/TSResourceLayer.cs index c99e332304..efa492962d 100644 --- a/OpenRA.Mods.Cnc/Traits/World/TSResourceLayer.cs +++ b/OpenRA.Mods.Cnc/Traits/World/TSResourceLayer.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.Cnc.Traits [ActorReference] [Desc("Actor types that should be treated as veins for adjacency.")] - public readonly HashSet VeinholeActors = new(); + public readonly HashSet VeinholeActors = []; public override object Create(ActorInitializer init) { return new TSResourceLayer(init.Self, this); } } @@ -33,7 +33,7 @@ namespace OpenRA.Mods.Cnc.Traits sealed class TSResourceLayer : ResourceLayer, INotifyActorDisposing { readonly TSResourceLayerInfo info; - readonly HashSet veinholeCells = new(); + readonly HashSet veinholeCells = []; public TSResourceLayer(Actor self, TSResourceLayerInfo info) : base(self, info) diff --git a/OpenRA.Mods.Cnc/Traits/World/TSTiberiumRenderer.cs b/OpenRA.Mods.Cnc/Traits/World/TSTiberiumRenderer.cs index 25d041623d..db40b3ae97 100644 --- a/OpenRA.Mods.Cnc/Traits/World/TSTiberiumRenderer.cs +++ b/OpenRA.Mods.Cnc/Traits/World/TSTiberiumRenderer.cs @@ -22,16 +22,16 @@ namespace OpenRA.Mods.Cnc.Traits public class TSTiberiumRendererInfo : ResourceRendererInfo { [Desc("Sequences to use for ramp type 1.", "Dictionary of [resource type]: [list of sequences].")] - public readonly Dictionary Ramp1Sequences = new(); + public readonly Dictionary Ramp1Sequences = []; [Desc("Sequences to use for ramp type 2.", "Dictionary of [resource type]: [list of sequences].")] - public readonly Dictionary Ramp2Sequences = new(); + public readonly Dictionary Ramp2Sequences = []; [Desc("Sequences to use for ramp type 3.", "Dictionary of [resource type]: [list of sequences].")] - public readonly Dictionary Ramp3Sequences = new(); + public readonly Dictionary Ramp3Sequences = []; [Desc("Sequences to use for ramp type 4.", "Dictionary of [resource type]: [list of sequences].")] - public readonly Dictionary Ramp4Sequences = new(); + public readonly Dictionary Ramp4Sequences = []; public override object Create(ActorInitializer init) { return new TSTiberiumRenderer(init.Self, this); } } @@ -40,10 +40,10 @@ namespace OpenRA.Mods.Cnc.Traits { readonly TSTiberiumRendererInfo info; readonly World world; - readonly Dictionary> ramp1Variants = new(); - readonly Dictionary> ramp2Variants = new(); - readonly Dictionary> ramp3Variants = new(); - readonly Dictionary> ramp4Variants = new(); + readonly Dictionary> ramp1Variants = []; + readonly Dictionary> ramp2Variants = []; + readonly Dictionary> ramp3Variants = []; + readonly Dictionary> ramp4Variants = []; public TSTiberiumRenderer(Actor self, TSTiberiumRendererInfo info) : base(self, info) diff --git a/OpenRA.Mods.Cnc/Traits/World/TSVeinsRenderer.cs b/OpenRA.Mods.Cnc/Traits/World/TSVeinsRenderer.cs index 8c1877a536..40be41418f 100644 --- a/OpenRA.Mods.Cnc/Traits/World/TSVeinsRenderer.cs +++ b/OpenRA.Mods.Cnc/Traits/World/TSVeinsRenderer.cs @@ -45,7 +45,7 @@ namespace OpenRA.Mods.Cnc.Traits [ActorReference] [Desc("Actor types that should be treated as veins for adjacency.")] - public readonly HashSet VeinholeActors = new(); + public readonly HashSet VeinholeActors = []; void IMapPreviewSignatureInfo.PopulateMapPreviewSignatureCells(Map map, ActorInfo ai, ActorReference s, List<(MPos Uv, Color Color)> destinationBuffer) { @@ -140,21 +140,21 @@ namespace OpenRA.Mods.Cnc.Traits { Adjacency.MinusX | Adjacency.PlusX | Adjacency.MinusY | Adjacency.PlusY, new[] { 45, 46, 47 } }, }; - static readonly int[] HeavyIndices = { 48, 49, 50, 51 }; - static readonly int[] LightIndices = { 52 }; - static readonly int[] Ramp1Indices = { 53, 54 }; - static readonly int[] Ramp2Indices = { 55, 56 }; - static readonly int[] Ramp3Indices = { 57, 58 }; - static readonly int[] Ramp4Indices = { 59, 60 }; + static readonly int[] HeavyIndices = [48, 49, 50, 51]; + static readonly int[] LightIndices = [52]; + static readonly int[] Ramp1Indices = [53, 54]; + static readonly int[] Ramp2Indices = [55, 56]; + static readonly int[] Ramp3Indices = [57, 58]; + static readonly int[] Ramp4Indices = [59, 60]; readonly TSVeinsRendererInfo info; readonly World world; readonly IResourceLayer resourceLayer; readonly CellLayer renderIndices; readonly CellLayer borders; - readonly HashSet dirty = new(); - readonly Queue cleanDirty = new(); - readonly HashSet veinholeCells = new(); + readonly HashSet dirty = []; + readonly Queue cleanDirty = []; + readonly HashSet veinholeCells = []; readonly int maxDensity; readonly Color veinRadarColor; diff --git a/OpenRA.Mods.Cnc/Traits/World/VoxelCache.cs b/OpenRA.Mods.Cnc/Traits/World/VoxelCache.cs index 2e07e7e26e..6893c94e6b 100644 --- a/OpenRA.Mods.Cnc/Traits/World/VoxelCache.cs +++ b/OpenRA.Mods.Cnc/Traits/World/VoxelCache.cs @@ -28,7 +28,7 @@ namespace OpenRA.Mods.Cnc.Traits public sealed class VoxelCache : IModelCache, INotifyActorDisposing, IDisposable { readonly VoxelLoader loader; - readonly Dictionary> models = new(); + readonly Dictionary> models = []; public VoxelCache(VoxelCacheInfo info, Actor self) { diff --git a/OpenRA.Mods.Cnc/Traits/World/VoxelNormalsPalette.cs b/OpenRA.Mods.Cnc/Traits/World/VoxelNormalsPalette.cs index 8de0bc71cf..9767ac4ed6 100644 --- a/OpenRA.Mods.Cnc/Traits/World/VoxelNormalsPalette.cs +++ b/OpenRA.Mods.Cnc/Traits/World/VoxelNormalsPalette.cs @@ -61,7 +61,7 @@ namespace OpenRA.Mods.Cnc.Traits // Normal vector tables from https://web.archive.org/web/20041022134721/https://www.sleipnirstuff.com/forum/viewtopic.php?t=8048 static readonly float[] TSNormals = - { + [ 0.671214f, 0.198492f, -0.714194f, 0.269643f, 0.584394f, -0.765360f, -0.040546f, 0.096988f, -0.994459f, @@ -98,10 +98,10 @@ namespace OpenRA.Mods.Cnc.Traits -0.596251f, 0.220132f, 0.772028f, -0.506455f, -0.396977f, 0.765449f, 0.070569f, -0.478474f, 0.875262f - }; + ]; static readonly float[] RA2Normals = - { + [ 0.526578f, -0.359621f, -0.770317f, 0.150482f, 0.435984f, 0.887284f, 0.414195f, 0.738255f, -0.532374f, @@ -346,6 +346,6 @@ namespace OpenRA.Mods.Cnc.Traits -0.328188f, 0.140251f, 0.934143f, -0.328188f, 0.140251f, 0.934143f, -0.328188f, 0.140251f, 0.934143f - }; + ]; } } diff --git a/OpenRA.Mods.Cnc/Traits/World/WithResourceAnimation.cs b/OpenRA.Mods.Cnc/Traits/World/WithResourceAnimation.cs index 7087bd8fa9..dcbe23055d 100644 --- a/OpenRA.Mods.Cnc/Traits/World/WithResourceAnimation.cs +++ b/OpenRA.Mods.Cnc/Traits/World/WithResourceAnimation.cs @@ -29,10 +29,10 @@ namespace OpenRA.Mods.Cnc.Traits public readonly HashSet Types = null; [Desc("The percentage of resource cells to play the animation on.", "Use two values to randomize between them.")] - public readonly int[] Ratio = { 1, 10 }; + public readonly int[] Ratio = [1, 10]; [Desc("Tick interval between two animation spawning.", "Use two values to randomize between them.")] - public readonly int[] Interval = { 200, 500 }; + public readonly int[] Interval = [200, 500]; [FieldLoader.Require] [Desc("Animation image.")] @@ -40,7 +40,7 @@ namespace OpenRA.Mods.Cnc.Traits [SequenceReference(nameof(Image))] [Desc("Randomly select one of these sequences to render.")] - public readonly string[] Sequences = new string[] { "idle" }; + public readonly string[] Sequences = ["idle"]; [PaletteReference] [Desc("Animation palette.")] diff --git a/OpenRA.Mods.Cnc/Util.cs b/OpenRA.Mods.Cnc/Util.cs index 8ba055611b..f9e9972c13 100644 --- a/OpenRA.Mods.Cnc/Util.cs +++ b/OpenRA.Mods.Cnc/Util.cs @@ -20,21 +20,21 @@ namespace OpenRA.Mods.Cnc // i.e. sprite frame 1 is used for facings 20-55, sprite frame 2 for 56-87, and so on. // Sprite frame 0 is used for facings smaller than 20 or larger than 999. static readonly int[] SpriteRanges = - { + [ 20, 56, 88, 132, 156, 184, 212, 240, 268, 296, 324, 352, 384, 416, 452, 488, 532, 568, 604, 644, 668, 696, 724, 752, 780, 808, 836, 864, 896, 928, 964, 1000 - }; + ]; // The actual facing associated with each sprite frame. static readonly WAngle[] SpriteFacings = - { + [ WAngle.Zero, new(40), new(74), new(112), new(146), new(172), new(200), new(228), new(256), new(284), new(312), new(340), new(370), new(402), new(436), new(472), new(512), new(552), new(588), new(626), new(658), new(684), new(712), new(740), new(768), new(796), new(824), new(852), new(882), new(914), new(948), new(984) - }; + ]; /// /// Calculate the frame index (between 0..numFrames) that @@ -70,35 +70,35 @@ namespace OpenRA.Mods.Cnc public static float[] IdentityMatrix() { - return new float[] - { + return + [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, - }; + ]; } public static float[] ScaleMatrix(float sx, float sy, float sz) { - return new float[] - { + return + [ sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0, 0, 0, 0, 1, - }; + ]; } public static float[] TranslationMatrix(float x, float y, float z) { - return new float[] - { + return + [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, z, 1, - }; + ]; } public static float[] MatrixMultiply(float[] lhs, float[] rhs) @@ -257,8 +257,8 @@ namespace OpenRA.Mods.Cnc public static float[] MakeFloatMatrix(Int32Matrix4x4 imtx) { var multipler = 1f / imtx.M44; - return new[] - { + return + [ imtx.M11 * multipler, imtx.M12 * multipler, imtx.M13 * multipler, @@ -278,7 +278,7 @@ namespace OpenRA.Mods.Cnc imtx.M42 * multipler, imtx.M43 * multipler, imtx.M44 * multipler, - }; + ]; } public static float[] MatrixAABBMultiply(float[] mtx, float[] bounds) diff --git a/OpenRA.Mods.Cnc/UtilityCommands/Glob.cs b/OpenRA.Mods.Cnc/UtilityCommands/Glob.cs index 652da65ec6..c0842d3c79 100644 --- a/OpenRA.Mods.Cnc/UtilityCommands/Glob.cs +++ b/OpenRA.Mods.Cnc/UtilityCommands/Glob.cs @@ -19,8 +19,8 @@ namespace OpenRA.Mods.Cnc.UtilityCommands { public static bool Enabled = true; - static readonly char[] GlobChars = new char[] { '*', '?' }; - static readonly char[] DirectorySeparators = new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }; + static readonly char[] GlobChars = ['*', '?']; + static readonly char[] DirectorySeparators = [Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar]; static bool NeedsExpansion(string filePath) { diff --git a/OpenRA.Mods.Cnc/UtilityCommands/ImportGen1MapCommand.cs b/OpenRA.Mods.Cnc/UtilityCommands/ImportGen1MapCommand.cs index 02e0760370..0a93c0e0be 100644 --- a/OpenRA.Mods.Cnc/UtilityCommands/ImportGen1MapCommand.cs +++ b/OpenRA.Mods.Cnc/UtilityCommands/ImportGen1MapCommand.cs @@ -35,7 +35,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands public ModData ModData; public Map Map; - public List Players = new(); + public List Players = []; public MapPlayers MapPlayers; bool singlePlayer; int spawnCount; @@ -137,7 +137,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands var worldNode = Map.RuleDefinitions.NodeWithKeyOrDefault("World"); var worldNodeBuilder = worldNode != null ? new MiniYamlNodeBuilder(worldNode) - : new MiniYamlNodeBuilder("World", new MiniYamlBuilder("", new List())); + : new MiniYamlNodeBuilder("World", new MiniYamlBuilder("", [])); return worldNodeBuilder; } @@ -173,7 +173,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands var missionData = worldNodeBuilder.Value.NodeWithKeyOrDefault("MissionData"); if (missionData == null) { - missionData = new MiniYamlNodeBuilder("MissionData", new MiniYamlBuilder("", new List())); + missionData = new MiniYamlNodeBuilder("MissionData", new MiniYamlBuilder("", [])); worldNodeBuilder.Value.Nodes.Add(missionData); } @@ -244,7 +244,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands var missionData = worldNodeBuilder.Value.NodeWithKeyOrDefault("MissionData"); if (missionData == null) { - missionData = new MiniYamlNodeBuilder("MissionData", new MiniYamlBuilder("", new List())); + missionData = new MiniYamlNodeBuilder("MissionData", new MiniYamlBuilder("", [])); worldNodeBuilder.Value.Nodes.Add(missionData); } @@ -347,14 +347,14 @@ namespace OpenRA.Mods.Cnc.UtilityCommands if (scorches.Count > 0) { var initialScorches = new MiniYamlNode("InitialSmudges", new MiniYaml("", scorches)); - var smudgeLayer = new MiniYamlNodeBuilder("SmudgeLayer@SCORCH", new MiniYamlBuilder("", new List() { initialScorches })); + var smudgeLayer = new MiniYamlNodeBuilder("SmudgeLayer@SCORCH", new MiniYamlBuilder("", [initialScorches])); worldNodeBuilder.Value.Nodes.Add(smudgeLayer); } if (craters.Count > 0) { var initialCraters = new MiniYamlNode("InitialSmudges", new MiniYaml("", craters)); - var smudgeLayer = new MiniYamlNodeBuilder("SmudgeLayer@CRATER", new MiniYamlBuilder("", new List() { initialCraters })); + var smudgeLayer = new MiniYamlNodeBuilder("SmudgeLayer@CRATER", new MiniYamlBuilder("", [initialCraters])); worldNodeBuilder.Value.Nodes.Add(smudgeLayer); } diff --git a/OpenRA.Mods.Cnc/UtilityCommands/ImportGen2MapCommand.cs b/OpenRA.Mods.Cnc/UtilityCommands/ImportGen2MapCommand.cs index 16300f51fe..52952d2c72 100644 --- a/OpenRA.Mods.Cnc/UtilityCommands/ImportGen2MapCommand.cs +++ b/OpenRA.Mods.Cnc/UtilityCommands/ImportGen2MapCommand.cs @@ -356,13 +356,13 @@ namespace OpenRA.Mods.Cnc.UtilityCommands if (lightingNodes.Count > 0) { - map.RuleDefinitions = map.RuleDefinitions.WithNodesAppended(new[] - { - new MiniYamlNode("^BaseWorld", new MiniYaml("", new[] - { + map.RuleDefinitions = map.RuleDefinitions.WithNodesAppended( + [ + new MiniYamlNode("^BaseWorld", new MiniYaml("", + [ new MiniYamlNode("TerrainLighting", new MiniYaml("", lightingNodes)) - })) - }); + ])) + ]); } } @@ -400,10 +400,10 @@ namespace OpenRA.Mods.Cnc.UtilityCommands if (lightingNodes.Count > 0) { - nodes.Add(new MiniYamlNode(lamp, new MiniYaml("", new[] - { + nodes.Add(new MiniYamlNode(lamp, new MiniYaml("", + [ new MiniYamlNode("TerrainLightSource", new MiniYaml("", lightingNodes)) - }))); + ]))); } } diff --git a/OpenRA.Mods.Cnc/UtilityCommands/ImportRedAlertMapCommand.cs b/OpenRA.Mods.Cnc/UtilityCommands/ImportRedAlertMapCommand.cs index 070c4aa26d..aca6872633 100644 --- a/OpenRA.Mods.Cnc/UtilityCommands/ImportRedAlertMapCommand.cs +++ b/OpenRA.Mods.Cnc/UtilityCommands/ImportRedAlertMapCommand.cs @@ -39,13 +39,13 @@ namespace OpenRA.Mods.Cnc.UtilityCommands // Mapping from RA95 overlay index to type string static readonly string[] RedAlertOverlayNames = - { + [ "sbag", "cycl", "brik", "barb", "wood", "gold01", "gold02", "gold03", "gold04", "gem01", "gem02", "gem03", "gem04", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "fpls", "wcrate", "scrate", "fenc", "sbag", - }; + ]; static readonly Dictionary OverlayResourceMapping = new() { @@ -77,8 +77,9 @@ namespace OpenRA.Mods.Cnc.UtilityCommands Map.Tiles[new CPos(i, j)] = new TerrainTile(types[i, j], ms.ReadUInt8()); } - static readonly string[] OverlayActors = new string[] - { + static readonly string[] OverlayActors = + [ + // Fences "sbag", "cycl", "brik", "barb", "wood", "fenc", @@ -87,7 +88,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands // Crates "wcrate", "scrate" - }; + ]; void UnpackOverlayData(MemoryStream ms) { diff --git a/OpenRA.Mods.Cnc/UtilityCommands/ImportTiberianDawnMapCommand.cs b/OpenRA.Mods.Cnc/UtilityCommands/ImportTiberianDawnMapCommand.cs index 24d85d68af..5c78aa603c 100644 --- a/OpenRA.Mods.Cnc/UtilityCommands/ImportTiberianDawnMapCommand.cs +++ b/OpenRA.Mods.Cnc/UtilityCommands/ImportTiberianDawnMapCommand.cs @@ -65,8 +65,9 @@ namespace OpenRA.Mods.Cnc.UtilityCommands } } - static readonly string[] OverlayActors = new string[] - { + static readonly string[] OverlayActors = + [ + // Fences "sbag", "cycl", "brik", "barb", "wood", @@ -75,7 +76,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands // Crates "wcrate", "scrate" - }; + ]; void ReadOverlay(IniFile file) { diff --git a/OpenRA.Mods.Cnc/UtilityCommands/ImportTiberianSunMapCommand.cs b/OpenRA.Mods.Cnc/UtilityCommands/ImportTiberianSunMapCommand.cs index f8ccf713ac..b42a48a897 100644 --- a/OpenRA.Mods.Cnc/UtilityCommands/ImportTiberianSunMapCommand.cs +++ b/OpenRA.Mods.Cnc/UtilityCommands/ImportTiberianSunMapCommand.cs @@ -260,12 +260,12 @@ namespace OpenRA.Mods.Cnc.UtilityCommands }; protected override string[] LampActors { get; } = - { + [ "GALITE", "INGALITE", "NEGLAMP", "REDLAMP", "NEGRED", "GRENLAMP", "BLUELAMP", "YELWLAMP", "INYELWLAMP", "PURPLAMP", "INPURPLAMP", "INORANLAMP", "INGRNLMP", "INREDLMP", "INBLULMP" - }; + ]; - protected override string[] CreepActors { get; } = { "DOGGIE", "VISC_SML", "VISC_LRG", "JFISH" }; + protected override string[] CreepActors { get; } = ["DOGGIE", "VISC_SML", "VISC_LRG", "JFISH"]; #endregion diff --git a/OpenRA.Mods.Cnc/UtilityCommands/RemapShpCommand.cs b/OpenRA.Mods.Cnc/UtilityCommands/RemapShpCommand.cs index cb49ddb9e3..38a7a5e26f 100644 --- a/OpenRA.Mods.Cnc/UtilityCommands/RemapShpCommand.cs +++ b/OpenRA.Mods.Cnc/UtilityCommands/RemapShpCommand.cs @@ -57,8 +57,8 @@ namespace OpenRA.Mods.Cnc.UtilityCommands remap[srcRemapIndex[i]] = destRemapIndex[i]; // map everything else to the best match based on channel-wise distance - var srcPalette = new ImmutablePalette(args[1].Split(':')[1], new[] { 0 }, shadowIndex); - var destPalette = new ImmutablePalette(args[2].Split(':')[1], new[] { 0 }, shadowIndex); + var srcPalette = new ImmutablePalette(args[1].Split(':')[1], [0], shadowIndex); + var destPalette = new ImmutablePalette(args[2].Split(':')[1], [0], shadowIndex); for (var i = 0; i < Palette.Size; i++) if (!remap.ContainsKey(i)) diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/PreReleaseWarningPrompt.cs b/OpenRA.Mods.Cnc/Widgets/Logic/PreReleaseWarningPrompt.cs index f8ce20a4a0..e1e7165ef8 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/PreReleaseWarningPrompt.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/PreReleaseWarningPrompt.cs @@ -31,7 +31,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic { promptAccepted = true; Ui.ResetAll(); - Game.LoadWidget(world, "MAINMENU", Ui.Root, new WidgetArgs()); + Game.LoadWidget(world, "MAINMENU", Ui.Root, []); } } } diff --git a/OpenRA.Mods.Cnc/Widgets/ModelWidget.cs b/OpenRA.Mods.Cnc/Widgets/ModelWidget.cs index 097a769e90..ecddb5083c 100644 --- a/OpenRA.Mods.Cnc/Widgets/ModelWidget.cs +++ b/OpenRA.Mods.Cnc/Widgets/ModelWidget.cs @@ -26,8 +26,8 @@ namespace OpenRA.Mods.Cnc.Widgets public float Scale = 10f; public int LightPitch = 142; public int LightYaw = 682; - public float[] LightAmbientColor = new float[] { 0.6f, 0.6f, 0.6f }; - public float[] LightDiffuseColor = new float[] { 0.4f, 0.4f, 0.4f }; + public float[] LightAmbientColor = [0.6f, 0.6f, 0.6f]; + public float[] LightDiffuseColor = [0.4f, 0.4f, 0.4f]; public WRot Rotation = WRot.None; public WAngle CameraAngle = WAngle.FromDegrees(40); diff --git a/OpenRA.Mods.Common/Activities/Air/Land.cs b/OpenRA.Mods.Common/Activities/Air/Land.cs index 73fcfa15b3..ece6ed3fc8 100644 --- a/OpenRA.Mods.Common/Activities/Air/Land.cs +++ b/OpenRA.Mods.Common/Activities/Air/Land.cs @@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Activities aircraft = self.Trait(); this.target = target; this.offset = offset; - this.clearCells = clearCells ?? Array.Empty(); + this.clearCells = clearCells ?? []; this.landRange = landRange.Length >= 0 ? landRange : aircraft.Info.LandRange; this.targetLineColor = targetLineColor; diff --git a/OpenRA.Mods.Common/Activities/FindAndDeliverResources.cs b/OpenRA.Mods.Common/Activities/FindAndDeliverResources.cs index 6bb9652f21..b942c776c7 100644 --- a/OpenRA.Mods.Common/Activities/FindAndDeliverResources.cs +++ b/OpenRA.Mods.Common/Activities/FindAndDeliverResources.cs @@ -197,7 +197,7 @@ namespace OpenRA.Mods.Common.Activities // Find any harvestable resources: var path = mobile.PathFinder.FindPathToTargetCellByPredicate( self, - new[] { searchFromLoc, self.Location }, + [searchFromLoc, self.Location], loc => harv.CanHarvestCell(loc) && claimLayer.CanClaimCell(self, loc), diff --git a/OpenRA.Mods.Common/Activities/LayMines.cs b/OpenRA.Mods.Common/Activities/LayMines.cs index a5d93bcb70..422f95c1e6 100644 --- a/OpenRA.Mods.Common/Activities/LayMines.cs +++ b/OpenRA.Mods.Common/Activities/LayMines.cs @@ -13,7 +13,6 @@ using System.Collections.Generic; using System.Linq; using OpenRA.Activities; using OpenRA.Mods.Common.Traits; -using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Activities @@ -46,7 +45,7 @@ namespace OpenRA.Mods.Common.Activities protected override void OnFirstRun(Actor self) { - minefield ??= new List { self.Location }; + minefield ??= [self.Location]; } CPos? NextValidCell(Actor self) @@ -218,11 +217,11 @@ namespace OpenRA.Mods.Common.Activities if (!CanLayMine(self, self.Location)) return; - var mine = w.CreateActor(minelayer.Info.Mine, new TypeDictionary - { + var mine = w.CreateActor(minelayer.Info.Mine, + [ new LocationInit(self.Location), new OwnerInit(self.Owner), - }); + ]); foreach (var t in self.TraitsImplementing()) t.MineLaid(self, mine); diff --git a/OpenRA.Mods.Common/Activities/Move/Move.cs b/OpenRA.Mods.Common/Activities/Move/Move.cs index f3f5a5f8aa..e76a7c87f8 100644 --- a/OpenRA.Mods.Common/Activities/Move/Move.cs +++ b/OpenRA.Mods.Common/Activities/Move/Move.cs @@ -29,12 +29,12 @@ namespace OpenRA.Mods.Common.Activities readonly Color? targetLineColor; static readonly BlockedByActor[] PathSearchOrder = - { + [ BlockedByActor.All, BlockedByActor.Stationary, BlockedByActor.Immovable, BlockedByActor.None - }; + ]; int carryoverProgress; int lastMovePartCompletedTick; @@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common.Activities return (true, PathFinder.NoPath); return (false, mobile.PathFinder.FindPathToTargetCell( - self, new[] { mobile.ToCell }, destination, check, laneBias: false)); + self, [mobile.ToCell], destination, check, laneBias: false)); }; this.destination = destination; @@ -88,7 +88,7 @@ namespace OpenRA.Mods.Common.Activities return (true, PathFinder.NoPath); return (false, mobile.PathFinder.FindPathToTargetCell( - self, new[] { mobile.ToCell }, this.destination.Value, check, ignoreActor: ignoreActor)); + self, [mobile.ToCell], this.destination.Value, check, ignoreActor: ignoreActor)); }; // Note: Will be recalculated from OnFirstRun if evaluateNearestMovableCell is true @@ -379,7 +379,7 @@ namespace OpenRA.Mods.Common.Activities if (path != null) return Enumerable.Reverse(path).Select(c => Target.FromCell(self.World, c)); if (destination != null) - return new Target[] { Target.FromCell(self.World, destination.Value) }; + return [Target.FromCell(self.World, destination.Value)]; return Target.None; } diff --git a/OpenRA.Mods.Common/Activities/Move/MoveAdjacentTo.cs b/OpenRA.Mods.Common/Activities/Move/MoveAdjacentTo.cs index b43f6c7146..720217020a 100644 --- a/OpenRA.Mods.Common/Activities/Move/MoveAdjacentTo.cs +++ b/OpenRA.Mods.Common/Activities/Move/MoveAdjacentTo.cs @@ -112,7 +112,7 @@ namespace OpenRA.Mods.Common.Activities return true; } - protected readonly List SearchCells = new(); + protected readonly List SearchCells = []; protected int searchCellsTick = -1; diff --git a/OpenRA.Mods.Common/Activities/Transform.cs b/OpenRA.Mods.Common/Activities/Transform.cs index dd78143d3a..02185c4443 100644 --- a/OpenRA.Mods.Common/Activities/Transform.cs +++ b/OpenRA.Mods.Common/Activities/Transform.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using OpenRA.Activities; using OpenRA.Mods.Common.Traits; @@ -24,7 +23,7 @@ namespace OpenRA.Mods.Common.Activities public readonly string ToActor; public CVec Offset = CVec.Zero; public WAngle Facing = new(384); - public string[] Sounds = Array.Empty(); + public string[] Sounds = []; public string Notification = null; public string TextNotification = null; public int ForceHealthPercentage = 0; diff --git a/OpenRA.Mods.Common/ActorIndex.cs b/OpenRA.Mods.Common/ActorIndex.cs index eee8482f68..71f27c92e6 100644 --- a/OpenRA.Mods.Common/ActorIndex.cs +++ b/OpenRA.Mods.Common/ActorIndex.cs @@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common public abstract class ActorIndex : IDisposable { readonly World world; - readonly HashSet actors = new(); + readonly HashSet actors = []; public IReadOnlyCollection Actors => actors; diff --git a/OpenRA.Mods.Common/AssetBrowser.cs b/OpenRA.Mods.Common/AssetBrowser.cs index 69b910c4da..db40a7213c 100644 --- a/OpenRA.Mods.Common/AssetBrowser.cs +++ b/OpenRA.Mods.Common/AssetBrowser.cs @@ -9,15 +9,13 @@ */ #endregion -using System; - namespace OpenRA { public class AssetBrowser : IGlobalModData { - public readonly string[] SpriteExtensions = Array.Empty(); - public readonly string[] ModelExtensions = Array.Empty(); - public readonly string[] AudioExtensions = Array.Empty(); - public readonly string[] VideoExtensions = Array.Empty(); + public readonly string[] SpriteExtensions = []; + public readonly string[] ModelExtensions = []; + public readonly string[] AudioExtensions = []; + public readonly string[] VideoExtensions = []; } } diff --git a/OpenRA.Mods.Common/Commands/ChatCommands.cs b/OpenRA.Mods.Common/Commands/ChatCommands.cs index 3a312e1282..02f816d778 100644 --- a/OpenRA.Mods.Common/Commands/ChatCommands.cs +++ b/OpenRA.Mods.Common/Commands/ChatCommands.cs @@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Commands public ChatCommands() { - Commands = new Dictionary(); + Commands = []; } public bool OnChat(string playername, string message) diff --git a/OpenRA.Mods.Common/Commands/HelpCommand.cs b/OpenRA.Mods.Common/Commands/HelpCommand.cs index 388f8473ce..7709ba826d 100644 --- a/OpenRA.Mods.Common/Commands/HelpCommand.cs +++ b/OpenRA.Mods.Common/Commands/HelpCommand.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Commands public HelpCommand() { - helpDescriptions = new Dictionary(); + helpDescriptions = []; } public void WorldLoaded(World w, WorldRenderer wr) diff --git a/OpenRA.Mods.Common/DiscordService.cs b/OpenRA.Mods.Common/DiscordService.cs index 324d983512..852baf4095 100644 --- a/OpenRA.Mods.Common/DiscordService.cs +++ b/OpenRA.Mods.Common/DiscordService.cs @@ -161,14 +161,14 @@ namespace OpenRA.Mods.Common if (party == null) { - buttons = new[] - { + buttons = + [ new Button { Label = "Visit Website", Url = Game.ModData.Manifest.Metadata.Website } - }; + ]; } var richPresence = new RichPresence diff --git a/OpenRA.Mods.Common/EditorBrushes/EditorMarkerLayerBrush.cs b/OpenRA.Mods.Common/EditorBrushes/EditorMarkerLayerBrush.cs index fb3b1de302..b84ceca419 100644 --- a/OpenRA.Mods.Common/EditorBrushes/EditorMarkerLayerBrush.cs +++ b/OpenRA.Mods.Common/EditorBrushes/EditorMarkerLayerBrush.cs @@ -109,7 +109,7 @@ namespace OpenRA.Mods.Common.Widgets readonly int? type; readonly MarkerLayerOverlay markerLayerOverlay; - readonly List paintTiles = new(); + readonly List paintTiles = []; public bool DidPaintTiles => paintTiles.Count > 0; @@ -174,7 +174,7 @@ namespace OpenRA.Mods.Common.Widgets this.tile = tile; this.markerLayerOverlay = markerLayerOverlay; - tiles = new HashSet(markerLayerOverlay.Tiles[tile]); + tiles = markerLayerOverlay.Tiles[tile].ToHashSet(); Text = FluentProvider.GetMessage(ClearedSelectedMarkerTiles, "amount", tiles.Count, "type", tile); } diff --git a/OpenRA.Mods.Common/EditorBrushes/EditorResourceBrush.cs b/OpenRA.Mods.Common/EditorBrushes/EditorResourceBrush.cs index b4480ce7ce..34d30800fc 100644 --- a/OpenRA.Mods.Common/EditorBrushes/EditorResourceBrush.cs +++ b/OpenRA.Mods.Common/EditorBrushes/EditorResourceBrush.cs @@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.Widgets bool resourceAdded; CPos cell; - readonly List preview = new(); + readonly List preview = []; readonly IResourceRenderer[] resourceRenderers; public EditorResourceBrush(EditorViewportControllerWidget editorWidget, string resourceType, WorldRenderer wr) @@ -132,7 +132,7 @@ namespace OpenRA.Mods.Common.Widgets readonly IResourceLayer resourceLayer; readonly string resourceType; - readonly List cellResources = new(); + readonly List cellResources = []; public AddResourcesEditorAction(string resourceType, IResourceLayer resourceLayer) { diff --git a/OpenRA.Mods.Common/EditorBrushes/EditorTileBrush.cs b/OpenRA.Mods.Common/EditorBrushes/EditorTileBrush.cs index 38281515f9..ae7ac039d6 100644 --- a/OpenRA.Mods.Common/EditorBrushes/EditorTileBrush.cs +++ b/OpenRA.Mods.Common/EditorBrushes/EditorTileBrush.cs @@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.Widgets readonly ITiledTerrainRenderer terrainRenderer; CPos cell; - readonly List preview = new(); + readonly List preview = []; public EditorTileBrush(EditorViewportControllerWidget editorWidget, ushort id, WorldRenderer wr) { @@ -181,7 +181,7 @@ namespace OpenRA.Mods.Common.Widgets readonly Map map; readonly CPos cell; - readonly Queue undoTiles = new(); + readonly Queue undoTiles = []; readonly TerrainTemplateInfo terrainTemplate; public PaintTileEditorAction(ushort template, Map map, CPos cell) @@ -253,7 +253,7 @@ namespace OpenRA.Mods.Common.Widgets readonly Map map; readonly CPos cell; - readonly Queue undoTiles = new(); + readonly Queue undoTiles = []; readonly TerrainTemplateInfo terrainTemplate; public FloodFillEditorAction(ushort template, Map map, CPos cell) diff --git a/OpenRA.Mods.Common/Effects/RallyPointIndicator.cs b/OpenRA.Mods.Common/Effects/RallyPointIndicator.cs index c44e9dcf93..5d4163cf97 100644 --- a/OpenRA.Mods.Common/Effects/RallyPointIndicator.cs +++ b/OpenRA.Mods.Common/Effects/RallyPointIndicator.cs @@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Effects readonly Animation flag; readonly Animation circles; - readonly List targetLineNodes = new(); + readonly List targetLineNodes = []; List cachedLocations; public RallyPointIndicator(Actor building, RallyPoint rp) @@ -69,7 +69,7 @@ namespace OpenRA.Mods.Common.Effects void UpdateTargetLineNodes(World world) { - cachedLocations = new List(rp.Path); + cachedLocations = rp.Path.ToList(); targetLineNodes.Clear(); foreach (var c in cachedLocations) targetLineNodes.Add(world.Map.CenterOfCell(c)); diff --git a/OpenRA.Mods.Common/Effects/RevealShroudEffect.cs b/OpenRA.Mods.Common/Effects/RevealShroudEffect.cs index e1814b02fd..192db3ec0d 100644 --- a/OpenRA.Mods.Common/Effects/RevealShroudEffect.cs +++ b/OpenRA.Mods.Common/Effects/RevealShroudEffect.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using System.Linq; using OpenRA.Effects; @@ -20,7 +19,7 @@ namespace OpenRA.Mods.Common.Effects { public class RevealShroudEffect : IEffect { - static readonly PPos[] NoCells = Array.Empty(); + static readonly PPos[] NoCells = []; readonly WPos pos; readonly Player player; diff --git a/OpenRA.Mods.Common/Effects/SpawnActorEffect.cs b/OpenRA.Mods.Common/Effects/SpawnActorEffect.cs index 6b0c40013d..bcd5ea2118 100644 --- a/OpenRA.Mods.Common/Effects/SpawnActorEffect.cs +++ b/OpenRA.Mods.Common/Effects/SpawnActorEffect.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using OpenRA.Activities; using OpenRA.Effects; @@ -27,10 +26,10 @@ namespace OpenRA.Mods.Common.Effects int remainingDelay; public SpawnActorEffect(Actor actor) - : this(actor, 0, Array.Empty(), null) { } + : this(actor, 0, [], null) { } public SpawnActorEffect(Actor actor, int delay) - : this(actor, delay, Array.Empty(), null) { } + : this(actor, delay, [], null) { } public SpawnActorEffect(Actor actor, int delay, CPos[] pathAfterSpawn, Activity activityAtDestination) { diff --git a/OpenRA.Mods.Common/FileFormats/Blast.cs b/OpenRA.Mods.Common/FileFormats/Blast.cs index cf1ee7b168..15a51ff16a 100644 --- a/OpenRA.Mods.Common/FileFormats/Blast.cs +++ b/OpenRA.Mods.Common/FileFormats/Blast.cs @@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.FileFormats public const int MAXWIN = 4096; // maximum window size static readonly byte[] LitLen = - { + [ 11, 124, 8, 7, 28, 7, 188, 13, 76, 4, 10, 8, 12, 10, 12, 10, 8, 23, 8, 9, 7, 6, 7, 8, 7, 6, 55, 8, 23, 24, @@ -37,27 +37,27 @@ namespace OpenRA.Mods.Common.FileFormats 6, 21, 6, 10, 53, 8, 7, 24, 10, 27, 44, 253, 253, 253, 252, 252, 252, 13, 12, 45, 12, 45, 12, 61, 12, 45, 44, 173 - }; + ]; // bit lengths of length codes 0..15 - static readonly byte[] LenLen = { 2, 35, 36, 53, 38, 23 }; + static readonly byte[] LenLen = [2, 35, 36, 53, 38, 23]; // bit lengths of distance codes 0..63 - static readonly byte[] DistLen = { 2, 20, 53, 230, 247, 151, 248 }; + static readonly byte[] DistLen = [2, 20, 53, 230, 247, 151, 248]; // base for length codes static readonly short[] LengthBase = - { + [ 3, 2, 4, 5, 6, 7, 8, 9, 10, 12, 16, 24, 40, 72, 136, 264 - }; + ]; // extra bits for length codes static readonly byte[] Extra = - { + [ 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8 - }; + ]; static readonly Huffman LitCode = new(LitLen, 256); static readonly Huffman LenCode = new(LenLen, 16); diff --git a/OpenRA.Mods.Common/FileFormats/ImaAdpcmReader.cs b/OpenRA.Mods.Common/FileFormats/ImaAdpcmReader.cs index 7e66a0c4e2..6f61732788 100644 --- a/OpenRA.Mods.Common/FileFormats/ImaAdpcmReader.cs +++ b/OpenRA.Mods.Common/FileFormats/ImaAdpcmReader.cs @@ -15,9 +15,9 @@ namespace OpenRA.Mods.Common.FileFormats { public static class ImaAdpcmReader { - static readonly int[] IndexAdjust = { -1, -1, -1, -1, 2, 4, 6, 8 }; + static readonly int[] IndexAdjust = [-1, -1, -1, -1, 2, 4, 6, 8]; static readonly int[] StepTable = - { + [ 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, 50, 55, 60, 66, 73, 80, 88, @@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.FileFormats 3024, 3327, 3660, 4026, 4428, 4871, 5358, 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899, 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767 - }; + ]; public static short DecodeImaAdpcmSample(byte b, ref int index, ref int current) { diff --git a/OpenRA.Mods.Common/FileFormats/IniFile.cs b/OpenRA.Mods.Common/FileFormats/IniFile.cs index 93eaaefaaa..9e313a512a 100644 --- a/OpenRA.Mods.Common/FileFormats/IniFile.cs +++ b/OpenRA.Mods.Common/FileFormats/IniFile.cs @@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.FileFormats { public class IniFile { - readonly Dictionary sections = new(); + readonly Dictionary sections = []; public IniFile(Stream s) { @@ -116,7 +116,7 @@ namespace OpenRA.Mods.Common.FileFormats public class IniSection : IEnumerable> { public string Name { get; } - readonly Dictionary values = new(); + readonly Dictionary values = []; public IniSection(string name) { diff --git a/OpenRA.Mods.Common/FileFormats/InstallShieldCABCompression.cs b/OpenRA.Mods.Common/FileFormats/InstallShieldCABCompression.cs index e76b47c576..732ff8f350 100644 --- a/OpenRA.Mods.Common/FileFormats/InstallShieldCABCompression.cs +++ b/OpenRA.Mods.Common/FileFormats/InstallShieldCABCompression.cs @@ -373,7 +373,7 @@ namespace OpenRA.Mods.Common.FileFormats } } - readonly Dictionary index = new(); + readonly Dictionary index = []; readonly Dictionary volumes; readonly uint version; diff --git a/OpenRA.Mods.Common/FileFormats/WavReader.cs b/OpenRA.Mods.Common/FileFormats/WavReader.cs index d24d829b23..564e3437fc 100644 --- a/OpenRA.Mods.Common/FileFormats/WavReader.cs +++ b/OpenRA.Mods.Common/FileFormats/WavReader.cs @@ -197,14 +197,14 @@ namespace OpenRA.Mods.Common.FileFormats public sealed class WavStreamMsAdpcm : ReadOnlyAdapterStream { static readonly int[] AdaptationTable = - { + [ 230, 230, 230, 230, 307, 409, 512, 614, 768, 614, 512, 409, 307, 230, 230, 230 - }; + ]; - static readonly int[] AdaptCoeff1 = { 256, 512, 0, 192, 240, 460, 392 }; + static readonly int[] AdaptCoeff1 = [256, 512, 0, 192, 240, 460, 392]; - static readonly int[] AdaptCoeff2 = { 0, -256, 0, 64, 0, -208, -232 }; + static readonly int[] AdaptCoeff2 = [0, -256, 0, 64, 0, -208, -232]; readonly short channels; readonly int blockDataSize; diff --git a/OpenRA.Mods.Common/FileFormats/WestwoodCompressedReader.cs b/OpenRA.Mods.Common/FileFormats/WestwoodCompressedReader.cs index d2ebf3c292..02f711dc27 100644 --- a/OpenRA.Mods.Common/FileFormats/WestwoodCompressedReader.cs +++ b/OpenRA.Mods.Common/FileFormats/WestwoodCompressedReader.cs @@ -17,8 +17,8 @@ namespace OpenRA.Mods.Common.FileFormats { public static class WestwoodCompressedReader { - static readonly int[] AudWsStepTable2 = { -2, -1, 0, 1 }; - static readonly int[] AudWsStepTable4 = { -9, -8, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 8 }; + static readonly int[] AudWsStepTable2 = [-2, -1, 0, 1]; + static readonly int[] AudWsStepTable4 = [-9, -8, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 8]; public static void DecodeWestwoodCompressedSample(ReadOnlySpan input, Span output) { diff --git a/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs b/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs index d1da42968d..e51126d719 100644 --- a/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs +++ b/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs @@ -206,12 +206,12 @@ namespace OpenRA.Mods.Common.Graphics protected static readonly SpriteSequenceField DepthSpriteOffset = new(nameof(DepthSpriteOffset), float2.Zero); protected static readonly MiniYaml NoData = new(null); - protected static readonly int[] FirstFrame = { 0 }; + protected static readonly int[] FirstFrame = [0]; protected readonly ISpriteSequenceLoader Loader; protected string image; - protected List spritesToLoad = new(); + protected List spritesToLoad = []; protected Sprite[] sprites; protected Sprite[] shadowSprites; protected bool reverseFacings; @@ -354,7 +354,7 @@ namespace OpenRA.Mods.Common.Graphics var filename = LoadField(Filename, data, defaults, out var location); var loadFrames = CalculateFrameIndices(start, length, stride ?? length ?? 0, facings, frames, transpose, reverseFacings, shadowStart); - return new[] { new ReservationInfo(filename, loadFrames, frames, location) }; + return [new ReservationInfo(filename, loadFrames, frames, location)]; } protected virtual IEnumerable ParseCombineFilenames(ModData modData, string tileset, int[] frames, MiniYaml data) @@ -403,7 +403,7 @@ namespace OpenRA.Mods.Common.Graphics var depthSprite = LoadField(DepthSprite, data, defaults, out var depthSpriteLocation); if (!string.IsNullOrEmpty(depthSprite)) - depthSpriteReservation = cache.ReserveSprites(depthSprite, new[] { LoadField(DepthSpriteFrame, data, defaults) }, depthSpriteLocation); + depthSpriteReservation = cache.ReserveSprites(depthSprite, [LoadField(DepthSpriteFrame, data, defaults)], depthSpriteLocation); depthSpriteOffset = LoadField(DepthSpriteOffset, data, defaults); diff --git a/OpenRA.Mods.Common/Graphics/IsometricSelectionBoxAnnotationRenderable.cs b/OpenRA.Mods.Common/Graphics/IsometricSelectionBoxAnnotationRenderable.cs index 41082e8bb1..941e0f82e9 100644 --- a/OpenRA.Mods.Common/Graphics/IsometricSelectionBoxAnnotationRenderable.cs +++ b/OpenRA.Mods.Common/Graphics/IsometricSelectionBoxAnnotationRenderable.cs @@ -21,14 +21,14 @@ namespace OpenRA.Mods.Common.Graphics static readonly float2 TROffset = new(12, -6); static readonly float2 TOffset = new(0, -13); static readonly float2[] Offsets = - { + [ -TROffset, -TLOffset, -TOffset, TROffset, -TOffset, -TLOffset, -TLOffset, TOffset, TROffset, TLOffset, TROffset, TOffset, -TROffset, TOffset, TLOffset, TLOffset, -TOffset, -TROffset - }; + ]; readonly Polygon bounds; readonly Color color; @@ -68,8 +68,8 @@ namespace OpenRA.Mods.Common.Graphics var cr = Game.Renderer.RgbaColorRenderer; for (var i = 0; i < 6; i++) { - cr.DrawLine(new float3[] { screen[i] + Offsets[3 * i], screen[i], screen[i] + Offsets[3 * i + 1] }, 1, color, true); - cr.DrawLine(new float3[] { screen[i], screen[i] + Offsets[3 * i + 2] }, 1, color, true); + cr.DrawLine([screen[i] + Offsets[3 * i], screen[i], screen[i] + Offsets[3 * i + 1]], 1, color, true); + cr.DrawLine([screen[i], screen[i] + Offsets[3 * i + 2]], 1, color, true); } } diff --git a/OpenRA.Mods.Common/Graphics/SelectionBoxAnnotationRenderable.cs b/OpenRA.Mods.Common/Graphics/SelectionBoxAnnotationRenderable.cs index c8d4642204..cc4fcf8020 100644 --- a/OpenRA.Mods.Common/Graphics/SelectionBoxAnnotationRenderable.cs +++ b/OpenRA.Mods.Common/Graphics/SelectionBoxAnnotationRenderable.cs @@ -49,10 +49,10 @@ namespace OpenRA.Mods.Common.Graphics var v = new float2(0, 4); var cr = Game.Renderer.RgbaColorRenderer; - cr.DrawLine(new float3[] { tl + u, tl, tl + v }, 1, color, true); - cr.DrawLine(new float3[] { tr - u, tr, tr + v }, 1, color, true); - cr.DrawLine(new float3[] { br - u, br, br - v }, 1, color, true); - cr.DrawLine(new float3[] { bl + u, bl, bl - v }, 1, color, true); + cr.DrawLine([tl + u, tl, tl + v], 1, color, true); + cr.DrawLine([tr - u, tr, tr + v], 1, color, true); + cr.DrawLine([br - u, br, br - v], 1, color, true); + cr.DrawLine([bl + u, bl, bl - v], 1, color, true); } public void RenderDebugGeometry(WorldRenderer wr) { } diff --git a/OpenRA.Mods.Common/Graphics/TilesetSpecificSpriteSequence.cs b/OpenRA.Mods.Common/Graphics/TilesetSpecificSpriteSequence.cs index c9ec489576..6e50cb0c05 100644 --- a/OpenRA.Mods.Common/Graphics/TilesetSpecificSpriteSequence.cs +++ b/OpenRA.Mods.Common/Graphics/TilesetSpecificSpriteSequence.cs @@ -62,7 +62,7 @@ namespace OpenRA.Mods.Common.Graphics if (tilesetNode != null) { var loadFrames = CalculateFrameIndices(start, length, stride ?? length ?? 0, facings, frames, transpose, reverseFacings, shadowStart); - return new[] { new ReservationInfo(tilesetNode.Value.Value, loadFrames, frames, tilesetNode.Location) }; + return [new ReservationInfo(tilesetNode.Value.Value, loadFrames, frames, tilesetNode.Location)]; } } @@ -84,7 +84,7 @@ namespace OpenRA.Mods.Common.Graphics frames = Exts.MakeArray(subLength, i => subStart + i); } - return new[] { new ReservationInfo(tilesetNode.Value.Value, frames, frames, tilesetNode.Location) }; + return [new ReservationInfo(tilesetNode.Value.Value, frames, frames, tilesetNode.Location)]; } } diff --git a/OpenRA.Mods.Common/HitShapes/Rectangle.cs b/OpenRA.Mods.Common/HitShapes/Rectangle.cs index 2fcb9d1951..39848069ad 100644 --- a/OpenRA.Mods.Common/HitShapes/Rectangle.cs +++ b/OpenRA.Mods.Common/HitShapes/Rectangle.cs @@ -71,37 +71,37 @@ namespace OpenRA.Mods.Common.HitShapes var corners = new[] { TopLeft, BottomRight, topRight, bottomLeft }; OuterRadius = new WDist(corners.Max(x => x.Length)); - combatOverlayVertsTop = new WVec[] - { + combatOverlayVertsTop = + [ new(TopLeft.X, TopLeft.Y, VerticalTopOffset), new(BottomRight.X, TopLeft.Y, VerticalTopOffset), new(BottomRight.X, BottomRight.Y, VerticalTopOffset), new(TopLeft.X, BottomRight.Y, VerticalTopOffset), - }; + ]; - combatOverlayVertsBottom = new WVec[] - { + combatOverlayVertsBottom = + [ new(TopLeft.X, TopLeft.Y, VerticalBottomOffset), new(BottomRight.X, TopLeft.Y, VerticalBottomOffset), new(BottomRight.X, BottomRight.Y, VerticalBottomOffset), new(TopLeft.X, BottomRight.Y, VerticalBottomOffset), - }; + ]; - combatOverlayVertsSide1 = new WVec[] - { + combatOverlayVertsSide1 = + [ new(TopLeft.X, TopLeft.Y, VerticalBottomOffset), new(TopLeft.X, TopLeft.Y, VerticalTopOffset), new(TopLeft.X, BottomRight.Y, VerticalTopOffset), new(TopLeft.X, BottomRight.Y, VerticalBottomOffset), - }; + ]; - combatOverlayVertsSide2 = new WVec[] - { + combatOverlayVertsSide2 = + [ new(BottomRight.X, TopLeft.Y, VerticalBottomOffset), new(BottomRight.X, TopLeft.Y, VerticalTopOffset), new(BottomRight.X, BottomRight.Y, VerticalTopOffset), new(BottomRight.X, BottomRight.Y, VerticalBottomOffset), - }; + ]; } public WDist DistanceFromEdge(in WVec v) diff --git a/OpenRA.Mods.Common/Installer/SourceResolvers/DiscSourceResolver.cs b/OpenRA.Mods.Common/Installer/SourceResolvers/DiscSourceResolver.cs index bdff6931b1..e0702c5799 100644 --- a/OpenRA.Mods.Common/Installer/SourceResolvers/DiscSourceResolver.cs +++ b/OpenRA.Mods.Common/Installer/SourceResolvers/DiscSourceResolver.cs @@ -37,12 +37,12 @@ namespace OpenRA.Mods.Common.Installer { // Outside of Gnome, most mounting tools on Linux don't set DriveType.CDRom // so provide a fallback by allowing users to manually mount images on known paths - volumes = volumes.Concat(new[] - { + volumes = volumes.Concat( + [ "/media/openra", "/media/" + Environment.UserName + "/openra", "/mnt/openra" - }); + ]); } foreach (var volume in volumes) diff --git a/OpenRA.Mods.Common/Lint/CheckChromeHotkeys.cs b/OpenRA.Mods.Common/Lint/CheckChromeHotkeys.cs index 84a8fda3c4..e6b3785f88 100644 --- a/OpenRA.Mods.Common/Lint/CheckChromeHotkeys.cs +++ b/OpenRA.Mods.Common/Lint/CheckChromeHotkeys.cs @@ -94,7 +94,7 @@ namespace OpenRA.Mods.Common.Lint if (customLintMethods.TryGetValue(widgetType, out var checkMethods)) { var type = modData.ObjectCreator.FindType(widgetType + "Widget"); - var keyNames = checkMethods.SelectMany(m => (IEnumerable)type.GetMethod(m).Invoke(null, new object[] { node, emitError })); + var keyNames = checkMethods.SelectMany(m => (IEnumerable)type.GetMethod(m).Invoke(null, [node, emitError])); foreach (var name in keyNames) if (!namedKeys.Contains(name) && !Hotkey.TryParse(name, out var unused)) diff --git a/OpenRA.Mods.Common/Lint/CheckFluentReferences.cs b/OpenRA.Mods.Common/Lint/CheckFluentReferences.cs index 0808baa3ee..496f7029e7 100644 --- a/OpenRA.Mods.Common/Lint/CheckFluentReferences.cs +++ b/OpenRA.Mods.Common/Lint/CheckFluentReferences.cs @@ -243,7 +243,7 @@ namespace OpenRA.Mods.Common.Lint GetUsedFluentKeys( usedKeys, testedFields, Utility.GetFields(typeof(GameSpeed)), - new[] { speed.Value }, + [speed.Value], (obj, field) => $"`GameSpeeds.Speeds.{speed.Key}.{field.Name}` in mod.yaml"); // TODO: linter does not work with LoadUsing @@ -253,7 +253,7 @@ namespace OpenRA.Mods.Common.Lint GetUsedFluentKeys( usedKeys, testedFields, Utility.GetFields(typeof(ResourceRendererInfo.ResourceTypeInfo)), - new[] { resource.Value }, + [resource.Value], (obj, field) => $"`ResourceRenderer.ResourceTypes.{resource.Key}.{field.Name}` in rules yaml"); const BindingFlags Binding = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static; @@ -261,21 +261,21 @@ namespace OpenRA.Mods.Common.Lint GetUsedFluentKeys( usedKeys, testedFields, constFields, - new[] { (object)null }, + [(object)null], (obj, field) => $"`{field.ReflectedType.Name}.{field.Name}`"); var modMetadataFields = typeof(ModMetadata).GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); GetUsedFluentKeys( usedKeys, testedFields, modMetadataFields, - new[] { modData.Manifest.Metadata }, + [modData.Manifest.Metadata], (obj, field) => $"`Metadata.{field.Name}` in mod.yaml"); var modContent = modData.Manifest.Get(); GetUsedFluentKeys( usedKeys, testedFields, Utility.GetFields(typeof(ModContent)), - new[] { modContent }, + [modContent], (obj, field) => $"`ModContent.{field.Name}` in mod.yaml"); GetUsedFluentKeys( usedKeys, testedFields, @@ -293,7 +293,7 @@ namespace OpenRA.Mods.Common.Lint GetUsedFluentKeys( usedKeys, testedFields, Utility.GetFields(typeof(KeycodeExts)).Concat(Utility.GetFields(typeof(ModifiersExts))), - new[] { (object)null }, + [(object)null], (obj, field) => $"`{field.ReflectedType.Name}.{field.Name}`"); foreach (var filename in modData.Manifest.ChromeLayout) @@ -426,7 +426,7 @@ namespace OpenRA.Mods.Common.Lint IEnumerable<(Pattern Node, string AttributeName)> nodeAndAttributeNames; if (message.Attributes.Count == 0) - nodeAndAttributeNames = new[] { (message.Value, (string)null) }; + nodeAndAttributeNames = [(message.Value, null)]; else nodeAndAttributeNames = message.Attributes.Select(a => (a.Value, a.Id.Name.ToString())); @@ -504,10 +504,10 @@ namespace OpenRA.Mods.Common.Lint sealed class Keys { - readonly HashSet keys = new(); - readonly List<(string Key, string Context)> keysWithContext = new(); - readonly Dictionary> requiredVariablesByKey = new(); - readonly List contextForEmptyKeys = new(); + readonly HashSet keys = []; + readonly List<(string Key, string Context)> keysWithContext = []; + readonly Dictionary> requiredVariablesByKey = []; + readonly List contextForEmptyKeys = []; public void Add(string key, FluentReferenceAttribute fluentReference, string context) { @@ -520,7 +520,7 @@ namespace OpenRA.Mods.Common.Lint if (fluentReference.RequiredVariableNames != null && fluentReference.RequiredVariableNames.Length > 0) { - var rv = requiredVariablesByKey.GetOrAdd(key, _ => new HashSet()); + var rv = requiredVariablesByKey.GetOrAdd(key, _ => []); rv.UnionWith(fluentReference.RequiredVariableNames); } diff --git a/OpenRA.Mods.Common/Lint/CheckSequences.cs b/OpenRA.Mods.Common/Lint/CheckSequences.cs index a9325eb970..107e459c34 100644 --- a/OpenRA.Mods.Common/Lint/CheckSequences.cs +++ b/OpenRA.Mods.Common/Lint/CheckSequences.cs @@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Lint continue; } - sequenceImages = new[] { imageOverride.ToLowerInvariant() }; + sequenceImages = [imageOverride.ToLowerInvariant()]; } foreach (var sequence in LintExts.GetFieldValues(traitInfo, field, sequenceReference.DictionaryReference)) diff --git a/OpenRA.Mods.Common/Lint/CheckWorldAndPlayerInherits.cs b/OpenRA.Mods.Common/Lint/CheckWorldAndPlayerInherits.cs index 0bb9ee0f02..1af91323bc 100644 --- a/OpenRA.Mods.Common/Lint/CheckWorldAndPlayerInherits.cs +++ b/OpenRA.Mods.Common/Lint/CheckWorldAndPlayerInherits.cs @@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common.Lint var inheritsMap = new Dictionary>(); foreach (var actorNode in nodes) { - var inherits = inheritsMap.GetOrAdd(actorNode.Key, _ => new List()); + var inherits = inheritsMap.GetOrAdd(actorNode.Key, _ => []); foreach (var inheritsNode in new MiniYamlNodeBuilder(actorNode).ChildrenMatching("Inherits")) inherits.Add(inheritsNode.Value.Value); } diff --git a/OpenRA.Mods.Common/Lint/LintExts.cs b/OpenRA.Mods.Common/Lint/LintExts.cs index 81c056fe89..7ed5c1bad3 100644 --- a/OpenRA.Mods.Common/Lint/LintExts.cs +++ b/OpenRA.Mods.Common/Lint/LintExts.cs @@ -12,7 +12,6 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Linq; using System.Reflection; using OpenRA.Support; using OpenRA.Traits; @@ -26,7 +25,7 @@ namespace OpenRA.Mods.Common.Lint { var type = fieldInfo.FieldType; if (type == typeof(string)) - return new[] { (string)fieldInfo.GetValue(ruleInfo) }; + return [(string)fieldInfo.GetValue(ruleInfo)]; if (typeof(IEnumerable).IsAssignableFrom(type)) return fieldInfo.GetValue(ruleInfo) as IEnumerable; @@ -34,7 +33,7 @@ namespace OpenRA.Mods.Common.Lint if (type == typeof(BooleanExpression) || type == typeof(IntegerExpression)) { var expr = (VariableExpression)fieldInfo.GetValue(ruleInfo); - return expr != null ? expr.Variables : Enumerable.Empty(); + return expr != null ? expr.Variables : []; } if (type.IsGenericType && @@ -78,7 +77,7 @@ namespace OpenRA.Mods.Common.Lint { var type = propertyInfo.PropertyType; if (type == typeof(string)) - return new[] { (string)propertyInfo.GetValue(ruleInfo) }; + return [(string)propertyInfo.GetValue(ruleInfo)]; if (typeof(IEnumerable).IsAssignableFrom(type)) return (IEnumerable)propertyInfo.GetValue(ruleInfo); @@ -86,7 +85,7 @@ namespace OpenRA.Mods.Common.Lint if (type == typeof(BooleanExpression) || type == typeof(IntegerExpression)) { var expr = (VariableExpression)propertyInfo.GetValue(ruleInfo); - return expr != null ? expr.Variables : Enumerable.Empty(); + return expr != null ? expr.Variables : []; } if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary<,>)) diff --git a/OpenRA.Mods.Common/LoadScreens/LogoStripeLoadScreen.cs b/OpenRA.Mods.Common/LoadScreens/LogoStripeLoadScreen.cs index f768293662..ec3aa6aa35 100644 --- a/OpenRA.Mods.Common/LoadScreens/LogoStripeLoadScreen.cs +++ b/OpenRA.Mods.Common/LoadScreens/LogoStripeLoadScreen.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using System.Linq; using OpenRA.Graphics; @@ -31,7 +30,7 @@ namespace OpenRA.Mods.Common.LoadScreens int lastDensity; Size lastResolution; - string[] messages = Array.Empty(); + string[] messages = []; public override void Init(ModData modData, Dictionary info) { diff --git a/OpenRA.Mods.Common/LoadScreens/ModContentLoadScreen.cs b/OpenRA.Mods.Common/LoadScreens/ModContentLoadScreen.cs index cf1eeddcc0..8278d305e9 100644 --- a/OpenRA.Mods.Common/LoadScreens/ModContentLoadScreen.cs +++ b/OpenRA.Mods.Common/LoadScreens/ModContentLoadScreen.cs @@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.LoadScreens public override void StartGame(Arguments args) { - Ui.LoadWidget("MODCONTENT_BACKGROUND", Ui.Root, new WidgetArgs()); + Ui.LoadWidget("MODCONTENT_BACKGROUND", Ui.Root, []); } public override bool BeforeLoad() diff --git a/OpenRA.Mods.Common/MapGenerator/CellLayerUtils.cs b/OpenRA.Mods.Common/MapGenerator/CellLayerUtils.cs index 3a2344d9da..2e3e99a6ad 100644 --- a/OpenRA.Mods.Common/MapGenerator/CellLayerUtils.cs +++ b/OpenRA.Mods.Common/MapGenerator/CellLayerUtils.cs @@ -498,7 +498,7 @@ namespace OpenRA.Mods.Common.MapGenerator while (next.Count != 0) { var current = next; - next = new List<(CPos, P)>(); + next = []; foreach (var (source, prop) in current) { var newProp = filler(source, prop); diff --git a/OpenRA.Mods.Common/MapGenerator/Direction.cs b/OpenRA.Mods.Common/MapGenerator/Direction.cs index 08398f50ac..662c6f6be6 100644 --- a/OpenRA.Mods.Common/MapGenerator/Direction.cs +++ b/OpenRA.Mods.Common/MapGenerator/Direction.cs @@ -73,13 +73,13 @@ namespace OpenRA.Mods.Common.MapGenerator public const int MRU = 1 << RU; /// Adjacent offsets with directions, excluding diagonals. - public static readonly ImmutableArray<(int2, int)> Spread4D = ImmutableArray.Create(new[] - { + public static readonly ImmutableArray<(int2, int)> Spread4D = + [ (new int2(1, 0), R), (new int2(0, 1), D), (new int2(-1, 0), L), (new int2(0, -1), U) - }); + ]; /// Adjacent offsets, excluding diagonals. public static readonly ImmutableArray Spread4 = @@ -93,8 +93,8 @@ namespace OpenRA.Mods.Common.MapGenerator Spread4.Select(xy => new CVec(xy.X, xy.Y)).ToImmutableArray(); /// Adjacent offsets with directions, including diagonals. - public static readonly ImmutableArray<(int2, int)> Spread8D = ImmutableArray.Create(new[] - { + public static readonly ImmutableArray<(int2, int)> Spread8D = + [ (new int2(1, 0), R), (new int2(1, 1), RD), (new int2(0, 1), D), @@ -103,7 +103,7 @@ namespace OpenRA.Mods.Common.MapGenerator (new int2(-1, -1), LU), (new int2(0, -1), U), (new int2(1, -1), RU) - }); + ]; /// Adjacent offsets, including diagonals. public static readonly ImmutableArray Spread8 = diff --git a/OpenRA.Mods.Common/MapGenerator/MapGeneratorSettings.cs b/OpenRA.Mods.Common/MapGenerator/MapGeneratorSettings.cs index 0941ad2ad6..b8d5cbc793 100644 --- a/OpenRA.Mods.Common/MapGenerator/MapGeneratorSettings.cs +++ b/OpenRA.Mods.Common/MapGenerator/MapGeneratorSettings.cs @@ -72,7 +72,7 @@ namespace OpenRA.Mods.Common.MapGenerator Label = value; Description = null; Tileset = null; - Settings = new MiniYaml(null, new[] { new MiniYamlNode(setting, value) }); + Settings = new MiniYaml(null, [new MiniYamlNode(setting, value)]); } public static void DumpFluent(MiniYaml my, List references) diff --git a/OpenRA.Mods.Common/MapGenerator/MatrixUtils.cs b/OpenRA.Mods.Common/MapGenerator/MatrixUtils.cs index 09c3b51cdf..b95e1a1479 100644 --- a/OpenRA.Mods.Common/MapGenerator/MatrixUtils.cs +++ b/OpenRA.Mods.Common/MapGenerator/MatrixUtils.cs @@ -141,7 +141,7 @@ namespace OpenRA.Mods.Common.MapGenerator while (next.Count != 0) { var current = next; - next = new List<(int2, P)>(); + next = []; foreach (var (source, prop) in current) { var newProp = filler(source, prop); @@ -249,7 +249,7 @@ namespace OpenRA.Mods.Common.MapGenerator } } - FloodFill(space.Size, new[] { (new int2(x, y), holeCount) }, Filler, Direction.Spread4); + FloodFill(space.Size, [(new int2(x, y), holeCount)], Filler, Direction.Spread4); } const int UNASSIGNED = int.MaxValue; @@ -1402,7 +1402,7 @@ namespace OpenRA.Mods.Common.MapGenerator { if (mask.ContainsXY(pointArray[i]) && mask[pointArray[i]]) { - currentPointArray ??= new List(); + currentPointArray ??= []; currentPointArray.Add(pointArray[i]); } else diff --git a/OpenRA.Mods.Common/MapGenerator/MultiBrush.cs b/OpenRA.Mods.Common/MapGenerator/MultiBrush.cs index fd86197aa6..43a3430e8e 100644 --- a/OpenRA.Mods.Common/MapGenerator/MultiBrush.cs +++ b/OpenRA.Mods.Common/MapGenerator/MultiBrush.cs @@ -137,16 +137,16 @@ namespace OpenRA.Mods.Common.MapGenerator public MultiBrush() { Weight = DefaultWeight; - tiles = new List<(CVec, TerrainTile)>(); - actorPlans = new List(); - shape = Array.Empty(); + tiles = []; + actorPlans = []; + shape = []; } MultiBrush(MultiBrush other) { Weight = other.Weight; - tiles = new List<(CVec, TerrainTile)>(other.tiles); - actorPlans = new List(other.actorPlans); + tiles = other.tiles.ToList(); + actorPlans = other.actorPlans.ToList(); shape = other.shape.ToArray(); } @@ -195,7 +195,7 @@ namespace OpenRA.Mods.Common.MapGenerator if (xys.Count != 0) shape = xys.OrderBy(xy => (xy.Y, xy.X)).ToArray(); else - shape = new[] { new CVec(0, 0) }; + shape = [new CVec(0, 0)]; } /// @@ -345,7 +345,7 @@ namespace OpenRA.Mods.Common.MapGenerator foreach (var brush in availableBrushes) { if (!brushesByAreaDict.ContainsKey(brush.Area)) - brushesByAreaDict.Add(brush.Area, new List()); + brushesByAreaDict.Add(brush.Area, []); brushesByAreaDict[brush.Area].Add(brush); } diff --git a/OpenRA.Mods.Common/MapGenerator/PlayableSpace.cs b/OpenRA.Mods.Common/MapGenerator/PlayableSpace.cs index 5b8470da69..df04a02532 100644 --- a/OpenRA.Mods.Common/MapGenerator/PlayableSpace.cs +++ b/OpenRA.Mods.Common/MapGenerator/PlayableSpace.cs @@ -122,7 +122,7 @@ namespace OpenRA.Mods.Common.MapGenerator CellLayerUtils.FloodFill( playable, - new[] { (start, true) }, + [(start, true)], Filler, Direction.Spread4CVec); } diff --git a/OpenRA.Mods.Common/MapGenerator/TilingPath.cs b/OpenRA.Mods.Common/MapGenerator/TilingPath.cs index b5d091c92b..a1b4059601 100644 --- a/OpenRA.Mods.Common/MapGenerator/TilingPath.cs +++ b/OpenRA.Mods.Common/MapGenerator/TilingPath.cs @@ -576,8 +576,8 @@ namespace OpenRA.Mods.Common.MapGenerator return; var newId = segmentTypeToId.Count; segmentTypeToId.Add(type, newId); - segmentsByStart.Add(new List()); - segmentsByEnd.Add(new List()); + segmentsByStart.Add([]); + segmentsByEnd.Add([]); costs.Add(new Matrix(size).Fill(MaxCost)); } @@ -944,7 +944,7 @@ namespace OpenRA.Mods.Common.MapGenerator if (ox == oy) { // We're either not on an edge or we're at a corner, so don't extend. - return Array.Empty(); + return []; } var offset = new CVec(ox, oy); diff --git a/OpenRA.Mods.Common/ModContent.cs b/OpenRA.Mods.Common/ModContent.cs index f10941fe44..80d0339006 100644 --- a/OpenRA.Mods.Common/ModContent.cs +++ b/OpenRA.Mods.Common/ModContent.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using System.Collections.Immutable; using System.IO; @@ -24,8 +23,8 @@ namespace OpenRA.Mods.Common [FluentReference] public readonly string Title; public readonly string Identifier; - public readonly string[] TestFiles = Array.Empty(); - public readonly string[] Sources = Array.Empty(); + public readonly string[] TestFiles = []; + public readonly string[] Sources = []; public readonly bool Required; public readonly string Download; @@ -46,7 +45,7 @@ namespace OpenRA.Mods.Common public readonly MiniYaml Type; // Used to find installation locations for SourceType.Install - public readonly string[] RegistryPrefixes = { string.Empty }; + public readonly string[] RegistryPrefixes = [string.Empty]; public readonly string RegistryKey; public readonly string RegistryValue; @@ -102,7 +101,7 @@ namespace OpenRA.Mods.Common public readonly string Mod; [FieldLoader.LoadUsing(nameof(LoadPackages))] - public readonly Dictionary Packages = new(); + public readonly Dictionary Packages = []; static object LoadPackages(MiniYaml yaml) { @@ -116,21 +115,21 @@ namespace OpenRA.Mods.Common } [FieldLoader.LoadUsing(nameof(LoadDownloads))] - public readonly string[] Downloads = Array.Empty(); + public readonly string[] Downloads = []; static object LoadDownloads(MiniYaml yaml) { var downloadNode = yaml.NodeWithKeyOrDefault("Downloads"); - return downloadNode != null ? downloadNode.Value.Nodes.Select(n => n.Key).ToArray() : Array.Empty(); + return downloadNode != null ? downloadNode.Value.Nodes.Select(n => n.Key).ToArray() : []; } [FieldLoader.LoadUsing(nameof(LoadSources))] - public readonly string[] Sources = Array.Empty(); + public readonly string[] Sources = []; static object LoadSources(MiniYaml yaml) { var sourceNode = yaml.NodeWithKeyOrDefault("Sources"); - return sourceNode != null ? sourceNode.Value.Nodes.Select(n => n.Key).ToArray() : Array.Empty(); + return sourceNode != null ? sourceNode.Value.Nodes.Select(n => n.Key).ToArray() : []; } } } diff --git a/OpenRA.Mods.Common/Orders/OrderGenerator.cs b/OpenRA.Mods.Common/Orders/OrderGenerator.cs index 271aa90d93..ae6a62e068 100644 --- a/OpenRA.Mods.Common/Orders/OrderGenerator.cs +++ b/OpenRA.Mods.Common/Orders/OrderGenerator.cs @@ -10,7 +10,6 @@ #endregion using System.Collections.Generic; -using System.Linq; using OpenRA.Graphics; using OpenRA.Orders; @@ -23,7 +22,7 @@ namespace OpenRA.Mods.Common.Orders if ((mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Down) || (mi.Button == MouseButton.Right && mi.Event == MouseInputEvent.Up)) return OrderInner(world, cell, worldPixel, mi); - return Enumerable.Empty(); + return []; } void IOrderGenerator.Tick(World world) { Tick(world); } diff --git a/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs b/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs index 7e9f22ca00..f73d529fcc 100644 --- a/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs +++ b/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs @@ -145,7 +145,7 @@ namespace OpenRA.Mods.Common.Orders return ret; } - return Enumerable.Empty(); + return []; } CPos TopLeft @@ -302,13 +302,13 @@ namespace OpenRA.Mods.Common.Orders (resourceLayer == null || resourceLayer.GetResource(t).Type == null))); } - return preview?.Render(wr, topLeft, footprint) ?? Enumerable.Empty(); + return preview?.Render(wr, topLeft, footprint) ?? []; } IEnumerable IOrderGenerator.RenderAnnotations(WorldRenderer wr, World world) { var preview = variants[variant].Preview; - return preview?.RenderAnnotations(wr, TopLeft) ?? Enumerable.Empty(); + return preview?.RenderAnnotations(wr, TopLeft) ?? []; } public virtual string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) diff --git a/OpenRA.Mods.Common/Pathfinder/CellInfoLayerPool.cs b/OpenRA.Mods.Common/Pathfinder/CellInfoLayerPool.cs index 24d2a7e135..44c1803863 100644 --- a/OpenRA.Mods.Common/Pathfinder/CellInfoLayerPool.cs +++ b/OpenRA.Mods.Common/Pathfinder/CellInfoLayerPool.cs @@ -58,7 +58,7 @@ namespace OpenRA.Mods.Common.Pathfinder public sealed class PooledCellInfoLayer : IDisposable { CellInfoLayerPool layerPool; - List> layers = new(); + List> layers = []; public PooledCellInfoLayer(CellInfoLayerPool layerPool) { diff --git a/OpenRA.Mods.Common/Pathfinder/DensePathGraph.cs b/OpenRA.Mods.Common/Pathfinder/DensePathGraph.cs index 7e04c39647..70ff66b69b 100644 --- a/OpenRA.Mods.Common/Pathfinder/DensePathGraph.cs +++ b/OpenRA.Mods.Common/Pathfinder/DensePathGraph.cs @@ -73,17 +73,17 @@ namespace OpenRA.Mods.Common.Pathfinder // We can do this because for any cell in range of both the current and parent location, // if we can reach it from one we are guaranteed to be able to reach it from the other. static readonly CVec[][] DirectedNeighbors = - { - new[] { new CVec(-1, -1), new CVec(0, -1), new CVec(1, -1), new CVec(-1, 0), new CVec(-1, 1) }, // TL - new[] { new CVec(-1, -1), new CVec(0, -1), new CVec(1, -1) }, // T - new[] { new CVec(-1, -1), new CVec(0, -1), new CVec(1, -1), new CVec(1, 0), new CVec(1, 1) }, // TR - new[] { new CVec(-1, -1), new CVec(-1, 0), new CVec(-1, 1) }, // L + [ + [new CVec(-1, -1), new CVec(0, -1), new CVec(1, -1), new CVec(-1, 0), new CVec(-1, 1)], // TL + [new CVec(-1, -1), new CVec(0, -1), new CVec(1, -1)], // T + [new CVec(-1, -1), new CVec(0, -1), new CVec(1, -1), new CVec(1, 0), new CVec(1, 1)], // TR + [new CVec(-1, -1), new CVec(-1, 0), new CVec(-1, 1)], // L CVec.Directions, - new[] { new CVec(1, -1), new CVec(1, 0), new CVec(1, 1) }, // R - new[] { new CVec(-1, -1), new CVec(-1, 0), new CVec(-1, 1), new CVec(0, 1), new CVec(1, 1) }, // BL - new[] { new CVec(-1, 1), new CVec(0, 1), new CVec(1, 1) }, // B - new[] { new CVec(1, -1), new CVec(1, 0), new CVec(-1, 1), new CVec(0, 1), new CVec(1, 1) }, // BR - }; + [new CVec(1, -1), new CVec(1, 0), new CVec(1, 1)], // R + [new CVec(-1, -1), new CVec(-1, 0), new CVec(-1, 1), new CVec(0, 1), new CVec(1, 1)], // BL + [new CVec(-1, 1), new CVec(0, 1), new CVec(1, 1)], // B + [new CVec(1, -1), new CVec(1, 0), new CVec(-1, 1), new CVec(0, 1), new CVec(1, 1)], // BR + ]; // With height discontinuities between the parent and current cell, we cannot optimize the possible neighbors. // It is no longer true that for any cell in range of both the current and parent location, @@ -92,7 +92,7 @@ namespace OpenRA.Mods.Common.Pathfinder // but our current cell on a new height may be able to reach as the height difference may be small enough. // Therefore, we can only exclude the parent cell in each set of directions. static readonly CVec[][] DirectedNeighborsConservative = - { + [ CVec.Directions.Exclude(new CVec(1, 1)).ToArray(), // TL CVec.Directions.Exclude(new CVec(0, 1)).ToArray(), // T CVec.Directions.Exclude(new CVec(-1, 1)).ToArray(), // TR @@ -102,7 +102,7 @@ namespace OpenRA.Mods.Common.Pathfinder CVec.Directions.Exclude(new CVec(1, -1)).ToArray(), // BL CVec.Directions.Exclude(new CVec(0, -1)).ToArray(), // B CVec.Directions.Exclude(new CVec(-1, -1)).ToArray(), // BR - }; + ]; public List GetConnections(CPos position, Func targetPredicate) { diff --git a/OpenRA.Mods.Common/Pathfinder/HierarchicalPathFinder.cs b/OpenRA.Mods.Common/Pathfinder/HierarchicalPathFinder.cs index 2911fe591d..2456676452 100644 --- a/OpenRA.Mods.Common/Pathfinder/HierarchicalPathFinder.cs +++ b/OpenRA.Mods.Common/Pathfinder/HierarchicalPathFinder.cs @@ -103,7 +103,7 @@ namespace OpenRA.Mods.Common.Pathfinder readonly Locomotor locomotor; readonly IActorMap actorMap; readonly Func costEstimator; - readonly HashSet dirtyGridIndexes = new(); + readonly HashSet dirtyGridIndexes = []; readonly HashSet cellsWithBlockingActor; Grid mapBounds; int gridXs; @@ -209,7 +209,7 @@ namespace OpenRA.Mods.Common.Pathfinder void InsertConnections(CPos localCell, CPos abstractCell, Func costEstimator) { if (!abstractEdges.TryGetValue(abstractCell, out var edges)) - edges = new List(); + edges = []; changedEdges[localCell] = edges .Select(e => new GraphConnection(e.Destination, costEstimator(localCell, e.Destination))) .Append(new GraphConnection(abstractCell, costEstimator(localCell, abstractCell))); @@ -239,7 +239,7 @@ namespace OpenRA.Mods.Common.Pathfinder return changedEdge.ToList(); if (abstractEdges.TryGetValue(position, out var abstractEdge)) return abstractEdge; - return new List(); + return []; } } @@ -414,7 +414,7 @@ namespace OpenRA.Mods.Common.Pathfinder { var src = accessibleCells.First(); using (var search = GetLocalPathSearch( - null, new[] { src }, src, customCost, null, BlockedByActor.None, false, grid, 100, null, false, null)) + null, [src], src, customCost, null, BlockedByActor.None, false, grid, 100, null, false, null)) { var localCellsInRegion = search.ExpandAll(); var abstractCell = AbstractCellForLocalCells(localCellsInRegion, gridLayer); @@ -785,7 +785,7 @@ namespace OpenRA.Mods.Common.Pathfinder var adjacentSourceDomain = abstractDomains[adjacentSourceAbstractCell.Value]; if (adjacentSourceDomain != targetDomain) { - unpathableNodes ??= new List(); + unpathableNodes ??= []; unpathableNodes.Add(adjacentSource); continue; } @@ -847,11 +847,11 @@ namespace OpenRA.Mods.Common.Pathfinder source.Layer), false); - pathFinderOverlay?.NewRecording(self, new[] { source }, target); + pathFinderOverlay?.NewRecording(self, [source], target); List localPath; using (var search = GetLocalPathSearch( - self, new[] { source }, target, customCost, ignoreActor, check, laneBias, gridToSearch, heuristicWeightPercentage, + self, [source], target, customCost, ignoreActor, check, laneBias, gridToSearch, heuristicWeightPercentage, null, inReverse, pathFinderOverlay?.RecordLocalEdges(self))) @@ -861,7 +861,7 @@ namespace OpenRA.Mods.Common.Pathfinder return localPath; } - pathFinderOverlay?.NewRecording(self, new[] { source }, target); + pathFinderOverlay?.NewRecording(self, [source], target); RebuildDirtyGrids(); @@ -875,7 +875,7 @@ namespace OpenRA.Mods.Common.Pathfinder // Call the other overload which can handle this scenario. var sourceAbstractCell = AbstractCellForLocalCell(source); if (sourceAbstractCell == null) - return FindPath(self, new[] { source }, target, check, heuristicWeightPercentage, customCost, ignoreActor, inReverse, laneBias, pathFinderOverlay); + return FindPath(self, [source], target, check, heuristicWeightPercentage, customCost, ignoreActor, inReverse, laneBias, pathFinderOverlay); // If the source and target belong to different domains, there is no path. RebuildDomains(); @@ -889,7 +889,7 @@ namespace OpenRA.Mods.Common.Pathfinder // The new edges will be treated as bi-directional. var fullGraph = new AbstractGraphWithInsertedEdges( - abstractGraph, sourceEdge != null ? new[] { sourceEdge.Value } : Array.Empty(), targetEdge, costEstimator); + abstractGraph, sourceEdge != null ? [sourceEdge.Value] : Array.Empty(), targetEdge, costEstimator); // Determine an abstract path in both directions, for use in a bidirectional search. var estimatedSearchSize = (abstractGraph.Count + 2) / 8; @@ -905,12 +905,12 @@ namespace OpenRA.Mods.Common.Pathfinder reverseAbstractSearch.ExpandToTarget(); using (var fromSrc = GetLocalPathSearch( - self, new[] { source }, target, customCost, ignoreActor, check, laneBias, null, heuristicWeightPercentage, + self, [source], target, customCost, ignoreActor, check, laneBias, null, heuristicWeightPercentage, Heuristic(reverseAbstractSearch, estimatedSearchSize, null, null), inReverse, pathFinderOverlay?.RecordLocalEdges(self))) using (var fromDest = GetLocalPathSearch( - self, new[] { target }, source, customCost, ignoreActor, check, laneBias, null, heuristicWeightPercentage, + self, [target], source, customCost, ignoreActor, check, laneBias, null, heuristicWeightPercentage, Heuristic(forwardAbstractSearch, estimatedSearchSize, null, null), !inReverse, pathFinderOverlay?.RecordLocalEdges(self))) diff --git a/OpenRA.Mods.Common/Pathfinder/PathSearch.cs b/OpenRA.Mods.Common/Pathfinder/PathSearch.cs index 24cb0258f2..d984b15d9d 100644 --- a/OpenRA.Mods.Common/Pathfinder/PathSearch.cs +++ b/OpenRA.Mods.Common/Pathfinder/PathSearch.cs @@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Pathfinder // PERF: Maintain a pool of layers used for paths searches for each world. These searches are performed often // so we wish to avoid the high cost of initializing a new search space every time by reusing the old ones. - static readonly ConditionalWeakTable LayerPoolTable = new(); + static readonly ConditionalWeakTable LayerPoolTable = []; static readonly ConditionalWeakTable.CreateValueCallback CreateLayerPool = world => new CellInfoLayerPool(world.Map); static CellInfoLayerPool LayerPoolForWorld(World world) diff --git a/OpenRA.Mods.Common/Pathfinder/SparsePathGraph.cs b/OpenRA.Mods.Common/Pathfinder/SparsePathGraph.cs index ae828259f8..68538f016f 100644 --- a/OpenRA.Mods.Common/Pathfinder/SparsePathGraph.cs +++ b/OpenRA.Mods.Common/Pathfinder/SparsePathGraph.cs @@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.Pathfinder public List GetConnections(CPos position, Func targetPredicate) { - return edges(position) ?? new List(); + return edges(position) ?? []; } public CellInfo this[CPos pos] diff --git a/OpenRA.Mods.Common/Projectiles/AreaBeam.cs b/OpenRA.Mods.Common/Projectiles/AreaBeam.cs index f49d702e8c..0f4fbb8964 100644 --- a/OpenRA.Mods.Common/Projectiles/AreaBeam.cs +++ b/OpenRA.Mods.Common/Projectiles/AreaBeam.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Projectiles public class AreaBeamInfo : IProjectileInfo { [Desc("Projectile speed in WDist / tick, two values indicate a randomly picked velocity per beam.")] - public readonly WDist[] Speed = { new(128) }; + public readonly WDist[] Speed = [new(128)]; [Desc("The maximum duration (in ticks) of each beam burst.")] public readonly int Duration = 10; @@ -46,10 +46,10 @@ namespace OpenRA.Mods.Common.Projectiles public readonly WDist MinDistance = WDist.Zero; [Desc("Damage modifier applied at each range step.")] - public readonly int[] Falloff = { 100, 100 }; + public readonly int[] Falloff = [100, 100]; [Desc("Ranges at which each Falloff step is defined.")] - public readonly WDist[] Range = { WDist.Zero, new(int.MaxValue) }; + public readonly WDist[] Range = [WDist.Zero, new(int.MaxValue)]; [Desc("The maximum/constant/incremental inaccuracy used in conjunction with the InaccuracyType property.")] public readonly WDist Inaccuracy = WDist.Zero; @@ -272,7 +272,7 @@ namespace OpenRA.Mods.Common.Projectiles if (!IsBeamComplete && info.RenderBeam && !(wr.World.FogObscures(tailPos) && wr.World.FogObscures(headPos))) { var beamRender = new BeamRenderable(headPos, info.ZOffset, tailPos - headPos, info.Shape, info.Width, color); - return new[] { (IRenderable)beamRender }; + return [beamRender]; } return SpriteRenderable.None; diff --git a/OpenRA.Mods.Common/Projectiles/Bullet.cs b/OpenRA.Mods.Common/Projectiles/Bullet.cs index c009c27196..ed1cc8b44a 100644 --- a/OpenRA.Mods.Common/Projectiles/Bullet.cs +++ b/OpenRA.Mods.Common/Projectiles/Bullet.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Projectiles public class BulletInfo : IProjectileInfo { [Desc("Projectile speed in WDist / tick, two values indicate variable velocity.")] - public readonly WDist[] Speed = { new(17) }; + public readonly WDist[] Speed = [new(17)]; [Desc("The maximum/constant/incremental inaccuracy used in conjunction with the InaccuracyType property.")] public readonly WDist Inaccuracy = WDist.Zero; @@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Projectiles [SequenceReference(nameof(Image), allowNullImage: true)] [Desc("Loop a randomly chosen sequence of Image from this list while this projectile is moving.")] - public readonly string[] Sequences = { "idle" }; + public readonly string[] Sequences = ["idle"]; [PaletteReference(nameof(IsPlayerPalette))] [Desc("The palette used to draw this projectile.")] @@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Projectiles [SequenceReference(nameof(TrailImage), allowNullImage: true)] [Desc("Loop a randomly chosen sequence of TrailImage from this list while this projectile is moving.")] - public readonly string[] TrailSequences = { "idle" }; + public readonly string[] TrailSequences = ["idle"]; [Desc("Interval in ticks between each spawned Trail animation.")] public readonly int TrailInterval = 2; @@ -83,7 +83,7 @@ namespace OpenRA.Mods.Common.Projectiles public readonly WDist Width = new(1); [Desc("Arc in WAngles, two values indicate variable arc.")] - public readonly WAngle[] LaunchAngle = { WAngle.Zero }; + public readonly WAngle[] LaunchAngle = [WAngle.Zero]; [Desc("Up to how many times does this bullet bounce when touching ground without hitting a target.", "0 implies exploding on contact with the originally targeted position.")] @@ -96,7 +96,7 @@ namespace OpenRA.Mods.Common.Projectiles public readonly string BounceSound = null; [Desc("Terrain where the projectile explodes instead of bouncing.")] - public readonly HashSet InvalidBounceTerrain = new(); + public readonly HashSet InvalidBounceTerrain = []; [Desc("Trigger the explosion if the projectile touches an actor thats owner has these player relationships.")] public readonly PlayerRelationship ValidBounceBlockerRelationships = PlayerRelationship.Enemy | PlayerRelationship.Neutral; diff --git a/OpenRA.Mods.Common/Projectiles/GravityBomb.cs b/OpenRA.Mods.Common/Projectiles/GravityBomb.cs index c6086a93a3..8fc1e77219 100644 --- a/OpenRA.Mods.Common/Projectiles/GravityBomb.cs +++ b/OpenRA.Mods.Common/Projectiles/GravityBomb.cs @@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Projectiles [SequenceReference(nameof(Image), allowNullImage: true)] [Desc("Loop a randomly chosen sequence of Image from this list while falling.")] - public readonly string[] Sequences = { "idle" }; + public readonly string[] Sequences = ["idle"]; [SequenceReference(nameof(Image), allowNullImage: true)] [Desc("Sequence to play when launched. Skipped if null or empty.")] diff --git a/OpenRA.Mods.Common/Projectiles/InstantHit.cs b/OpenRA.Mods.Common/Projectiles/InstantHit.cs index 1c2cd119c2..f8ec2e8a3c 100644 --- a/OpenRA.Mods.Common/Projectiles/InstantHit.cs +++ b/OpenRA.Mods.Common/Projectiles/InstantHit.cs @@ -10,7 +10,6 @@ #endregion using System.Collections.Generic; -using System.Linq; using OpenRA.GameRules; using OpenRA.Graphics; using OpenRA.Mods.Common.Traits; @@ -91,7 +90,7 @@ namespace OpenRA.Mods.Common.Projectiles public IEnumerable Render(WorldRenderer wr) { - return Enumerable.Empty(); + return []; } } } diff --git a/OpenRA.Mods.Common/Projectiles/Missile.cs b/OpenRA.Mods.Common/Projectiles/Missile.cs index a14ddc46e9..d28a16c28f 100644 --- a/OpenRA.Mods.Common/Projectiles/Missile.cs +++ b/OpenRA.Mods.Common/Projectiles/Missile.cs @@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Projectiles [SequenceReference(nameof(Image), allowNullImage: true)] [Desc("Loop a randomly chosen sequence of Image from this list while this projectile is moving.")] - public readonly string[] Sequences = { "idle" }; + public readonly string[] Sequences = ["idle"]; [PaletteReference(nameof(IsPlayerPalette))] [Desc("Palette used to render the projectile sequence.")] @@ -118,7 +118,7 @@ namespace OpenRA.Mods.Common.Projectiles [SequenceReference(nameof(TrailImage), allowNullImage: true)] [Desc("Loop a randomly chosen sequence of TrailImage from this list while this projectile is moving.")] - public readonly string[] TrailSequences = { "idle" }; + public readonly string[] TrailSequences = ["idle"]; [PaletteReference(nameof(TrailUsePlayerPalette))] [Desc("Palette used to render the trail sequence.")] diff --git a/OpenRA.Mods.Common/Projectiles/NukeLaunch.cs b/OpenRA.Mods.Common/Projectiles/NukeLaunch.cs index ea5e0a9817..90d35d89ef 100644 --- a/OpenRA.Mods.Common/Projectiles/NukeLaunch.cs +++ b/OpenRA.Mods.Common/Projectiles/NukeLaunch.cs @@ -10,7 +10,6 @@ #endregion using System.Collections.Generic; -using System.Linq; using OpenRA.Effects; using OpenRA.GameRules; using OpenRA.Graphics; @@ -163,7 +162,7 @@ namespace OpenRA.Mods.Common.Effects public IEnumerable Render(WorldRenderer wr) { if (!isLaunched || anim == null) - return Enumerable.Empty(); + return []; return anim.Render(pos, wr.Palette(weaponPalette)); } diff --git a/OpenRA.Mods.Common/Scripting/Global/ActorGlobal.cs b/OpenRA.Mods.Common/Scripting/Global/ActorGlobal.cs index e4a40d6c73..f69e30cf32 100644 --- a/OpenRA.Mods.Common/Scripting/Global/ActorGlobal.cs +++ b/OpenRA.Mods.Common/Scripting/Global/ActorGlobal.cs @@ -84,7 +84,7 @@ namespace OpenRA.Mods.Common.Scripting if (!value.TryGetClrValue(valueType, out var clrValue)) continue; - initializer.Invoke(init, new[] { clrValue }); + initializer.Invoke(init, [clrValue]); return init; } diff --git a/OpenRA.Mods.Common/Scripting/LuaScript.cs b/OpenRA.Mods.Common/Scripting/LuaScript.cs index 253b4b28cc..204863d1d6 100644 --- a/OpenRA.Mods.Common/Scripting/LuaScript.cs +++ b/OpenRA.Mods.Common/Scripting/LuaScript.cs @@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Scripting public class LuaScriptInfo : TraitInfo, Requires, NotBefore { [Desc("File names with location relative to the map.")] - public readonly HashSet Scripts = new(); + public readonly HashSet Scripts = []; public override object Create(ActorInitializer init) { return new LuaScript(this); } } diff --git a/OpenRA.Mods.Common/Scripting/Properties/HealthProperties.cs b/OpenRA.Mods.Common/Scripting/Properties/HealthProperties.cs index e7dc423ee8..891e47eb80 100644 --- a/OpenRA.Mods.Common/Scripting/Properties/HealthProperties.cs +++ b/OpenRA.Mods.Common/Scripting/Properties/HealthProperties.cs @@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Scripting { Damage damage; if (damageTypes is string d) - damage = new Damage(health.MaxHP, new BitSet(new[] { d })); + damage = new Damage(health.MaxHP, new BitSet([d])); else if (damageTypes is LuaTable t && t.TryGetClrValue(out string[] ds)) damage = new Damage(health.MaxHP, new BitSet(ds)); else diff --git a/OpenRA.Mods.Common/Scripting/Properties/ProductionProperties.cs b/OpenRA.Mods.Common/Scripting/Properties/ProductionProperties.cs index bdc4c3fc53..645ab4b521 100644 --- a/OpenRA.Mods.Common/Scripting/Properties/ProductionProperties.cs +++ b/OpenRA.Mods.Common/Scripting/Properties/ProductionProperties.cs @@ -92,7 +92,7 @@ namespace OpenRA.Mods.Common.Scripting return Self.Location; } - set => rp.Path = new List { value }; + set => rp.Path = [value]; } } @@ -211,9 +211,9 @@ namespace OpenRA.Mods.Common.Scripting public ClassicProductionQueueProperties(ScriptContext context, Player player) : base(context, player) { - productionHandlers = new Dictionary>(); + productionHandlers = []; - queues = new Dictionary(); + queues = []; foreach (var q in player.PlayerActor.TraitsImplementing().Where(q => q.Enabled)) queues.Add(q.Info.Type, q); diff --git a/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs b/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs index b07d439946..4270ac5cf0 100644 --- a/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs +++ b/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs @@ -221,7 +221,7 @@ namespace OpenRA.Mods.Common.Server if (server.State == ServerState.GameStarted) { - server.SendFluentMessageTo(conn, StateUnchangedGameStarted, new object[] { "command", command }); + server.SendFluentMessageTo(conn, StateUnchangedGameStarted, ["command", command]); return false; } else if (client.State == Session.ClientState.Ready && !(command.StartsWith("state", StringComparison.Ordinal) || command == "startgame")) @@ -300,7 +300,7 @@ namespace OpenRA.Mods.Common.Server { if (!Enum.TryParse(s, false, out var state)) { - server.SendFluentMessageTo(conn, MalformedCommand, new object[] { "command", "state" }); + server.SendFluentMessageTo(conn, MalformedCommand, ["command", "state"]); return true; } @@ -396,7 +396,7 @@ namespace OpenRA.Mods.Common.Server return true; } - server.SendFluentMessageTo(conn, MalformedCommand, new object[] { "command", "allow_spectate" }); + server.SendFluentMessageTo(conn, MalformedCommand, ["command", "allow_spectate"]); return true; } @@ -485,7 +485,7 @@ namespace OpenRA.Mods.Common.Server var parts = s.Split(' '); if (parts.Length < 3) { - server.SendFluentMessageTo(conn, MalformedCommand, new object[] { "command", "slot_bot" }); + server.SendFluentMessageTo(conn, MalformedCommand, ["command", "slot_bot"]); return true; } @@ -672,7 +672,7 @@ namespace OpenRA.Mods.Common.Server server.SendFluentMessageTo(conn, SearchingMap); var mapRepository = server.ModData.Manifest.Get().MapRepository; var reported = false; - server.ModData.MapCache.QueryRemoteMapDetails(mapRepository, new[] { s }, SelectMap, _ => + server.ModData.MapCache.QueryRemoteMapDetails(mapRepository, [s], SelectMap, _ => { if (!reported) QueryFailed(); @@ -718,7 +718,7 @@ namespace OpenRA.Mods.Common.Server if (option.IsLocked) { - server.SendFluentMessageTo(conn, OptionLocked, new object[] { "option", option.Name }); + server.SendFluentMessageTo(conn, OptionLocked, ["option", option.Name]); return true; } @@ -801,7 +801,7 @@ namespace OpenRA.Mods.Common.Server if (!Exts.TryParseInt32Invariant(raw, out var teamCount)) { - server.SendFluentMessageTo(conn, NumberTeams, new object[] { "raw", raw }); + server.SendFluentMessageTo(conn, NumberTeams, ["raw", raw]); return true; } @@ -846,7 +846,7 @@ namespace OpenRA.Mods.Common.Server var split = s.Split(' '); if (split.Length < 2) { - server.SendFluentMessageTo(conn, MalformedCommand, new object[] { "command", "kick" }); + server.SendFluentMessageTo(conn, MalformedCommand, ["command", "kick"]); return true; } @@ -898,7 +898,7 @@ namespace OpenRA.Mods.Common.Server var split = s.Split(' '); if (split.Length != 2) { - server.SendFluentMessageTo(conn, MalformedCommand, new object[] { "command", "vote_kick" }); + server.SendFluentMessageTo(conn, MalformedCommand, ["command", "vote_kick"]); return true; } @@ -926,7 +926,7 @@ namespace OpenRA.Mods.Common.Server if (!bool.TryParse(split[1], out var vote)) { - server.SendFluentMessageTo(conn, MalformedCommand, new object[] { "command", "vote_kick" }); + server.SendFluentMessageTo(conn, MalformedCommand, ["command", "vote_kick"]); return true; } @@ -1057,7 +1057,7 @@ namespace OpenRA.Mods.Common.Server if (!isValidFaction) { - server.SendFluentMessageTo(conn, InvalidFactionSelected, new object[] { "faction", faction }); + server.SendFluentMessageTo(conn, InvalidFactionSelected, ["faction", faction]); return true; } diff --git a/OpenRA.Mods.Common/ServerTraits/LobbySettingsNotification.cs b/OpenRA.Mods.Common/ServerTraits/LobbySettingsNotification.cs index 84e3f42b75..d8bf229031 100644 --- a/OpenRA.Mods.Common/ServerTraits/LobbySettingsNotification.cs +++ b/OpenRA.Mods.Common/ServerTraits/LobbySettingsNotification.cs @@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Server foreach (var kv in server.LobbyInfo.GlobalSettings.LobbyOptions) if (!defaults.LobbyOptions.TryGetValue(kv.Key, out var def) || kv.Value.Value != def.Value) if (options.TryGetValue(kv.Key, out var option)) - server.SendFluentMessageTo(conn, NotificationLobbyOption, new object[] { "name", option.Name, "value", option.Values[kv.Value.Value] }); + server.SendFluentMessageTo(conn, NotificationLobbyOption, ["name", option.Name, "value", option.Values[kv.Value.Value]]); } } } diff --git a/OpenRA.Mods.Common/ServerTraits/MasterServerPinger.cs b/OpenRA.Mods.Common/ServerTraits/MasterServerPinger.cs index 09a58acd5c..3d6d30c218 100644 --- a/OpenRA.Mods.Common/ServerTraits/MasterServerPinger.cs +++ b/OpenRA.Mods.Common/ServerTraits/MasterServerPinger.cs @@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.Server bool isInitialPing = true; volatile bool isBusy; - readonly Queue masterServerMessages = new(); + readonly Queue masterServerMessages = []; static MasterServerPinger() { diff --git a/OpenRA.Mods.Common/SpriteLoaders/DdsLoader.cs b/OpenRA.Mods.Common/SpriteLoaders/DdsLoader.cs index 100ed677ac..d5f1456979 100644 --- a/OpenRA.Mods.Common/SpriteLoaders/DdsLoader.cs +++ b/OpenRA.Mods.Common/SpriteLoaders/DdsLoader.cs @@ -75,7 +75,7 @@ namespace OpenRA.Mods.Common.SpriteLoaders public DdsSprite(Stream stream) { - Frames = new ISpriteFrame[] { new DdsFrame(stream) }; + Frames = [new DdsFrame(stream)]; } } } diff --git a/OpenRA.Mods.Common/SpriteLoaders/PngSheetLoader.cs b/OpenRA.Mods.Common/SpriteLoaders/PngSheetLoader.cs index 113b400d1d..9c08b7bc75 100644 --- a/OpenRA.Mods.Common/SpriteLoaders/PngSheetLoader.cs +++ b/OpenRA.Mods.Common/SpriteLoaders/PngSheetLoader.cs @@ -79,10 +79,10 @@ namespace OpenRA.Mods.Common.SpriteLoaders Array.Copy(png.Data, (frameStart + y * png.Width) * stride, frames[i].Data, y * frames[i].Size.Width * stride, frames[i].Size.Width * stride); } - metadata = new TypeDictionary - { + metadata = + [ new PngSheetMetadata(png.EmbeddedData), - }; + ]; if (png.Palette != null) metadata.Add(new EmbeddedSpritePalette(png.Palette.Select(x => x.ToArgb()).ToArray())); @@ -92,8 +92,8 @@ namespace OpenRA.Mods.Common.SpriteLoaders static void RegionsFromFrames(Png png, out List regions, out List offsets) { - regions = new List(); - offsets = new List(); + regions = []; + offsets = []; var pngRectangle = new Rectangle(0, 0, png.Width, png.Height); for (var i = 0; png.EmbeddedData.TryGetValue("Frame[" + i + "]", out var frame); i++) @@ -147,8 +147,8 @@ namespace OpenRA.Mods.Common.SpriteLoaders if (png.Width < frameSize.Width * frameAmount / rows || png.Height < frameSize.Height * rows) throw new InvalidDataException($"Invalid frame size {frameSize} and frame amount {frameAmount} defined."); - regions = new List(); - offsets = new List(); + regions = []; + offsets = []; for (var i = 0; i < frameAmount; i++) { diff --git a/OpenRA.Mods.Common/SpriteLoaders/TgaLoader.cs b/OpenRA.Mods.Common/SpriteLoaders/TgaLoader.cs index aab73e424d..7147a76b06 100644 --- a/OpenRA.Mods.Common/SpriteLoaders/TgaLoader.cs +++ b/OpenRA.Mods.Common/SpriteLoaders/TgaLoader.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -79,7 +78,7 @@ namespace OpenRA.Mods.Common.SpriteLoaders public TgaFrame() { - Data = Array.Empty(); + Data = []; } public TgaFrame(Stream stream) @@ -110,7 +109,7 @@ namespace OpenRA.Mods.Common.SpriteLoaders public TgaSprite(Stream stream) { - Frames = new ISpriteFrame[] { new TgaFrame(stream) }; + Frames = [new TgaFrame(stream)]; } } } diff --git a/OpenRA.Mods.Common/Terrain/DefaultTerrain.cs b/OpenRA.Mods.Common/Terrain/DefaultTerrain.cs index 36ea88c5d1..fb55922042 100644 --- a/OpenRA.Mods.Common/Terrain/DefaultTerrain.cs +++ b/OpenRA.Mods.Common/Terrain/DefaultTerrain.cs @@ -71,7 +71,7 @@ namespace OpenRA.Mods.Common.Terrain public readonly string Name; public readonly string Id; public readonly int SheetSize = 512; - public readonly Color[] HeightDebugColors = { Color.Red }; + public readonly Color[] HeightDebugColors = [Color.Red]; public readonly string[] EditorTemplateOrder; public readonly bool IgnoreTileSpriteOffsets; public readonly bool EnableDepth = false; @@ -88,7 +88,7 @@ namespace OpenRA.Mods.Common.Terrain [FieldLoader.Ignore] public readonly TerrainTypeInfo[] TerrainInfo; - readonly Dictionary terrainIndexByType = new(); + readonly Dictionary terrainIndexByType = []; readonly byte defaultWalkableTerrainIndex; public DefaultTerrain(IReadOnlyFileSystem fileSystem, string filepath) diff --git a/OpenRA.Mods.Common/Terrain/DefaultTileCache.cs b/OpenRA.Mods.Common/Terrain/DefaultTileCache.cs index fa024e2b06..50df31ba36 100644 --- a/OpenRA.Mods.Common/Terrain/DefaultTileCache.cs +++ b/OpenRA.Mods.Common/Terrain/DefaultTileCache.cs @@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Terrain public sealed class DefaultTileCache : IDisposable { - readonly Dictionary templates = new(); + readonly Dictionary templates = []; readonly Cache sheetBuilders; readonly MersenneTwister random; diff --git a/OpenRA.Mods.Common/Terrain/TerrainInfo.cs b/OpenRA.Mods.Common/Terrain/TerrainInfo.cs index c8fb7a1141..b9350fee9a 100644 --- a/OpenRA.Mods.Common/Terrain/TerrainInfo.cs +++ b/OpenRA.Mods.Common/Terrain/TerrainInfo.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using OpenRA.Mods.Common.MapGenerator; @@ -89,7 +88,7 @@ namespace OpenRA.Mods.Common.Terrain } else { - Segments = Array.Empty(); + Segments = []; } } diff --git a/OpenRA.Mods.Common/Traits/AcceptsDeliveredCash.cs b/OpenRA.Mods.Common/Traits/AcceptsDeliveredCash.cs index 8ae136b087..aa152e01f6 100644 --- a/OpenRA.Mods.Common/Traits/AcceptsDeliveredCash.cs +++ b/OpenRA.Mods.Common/Traits/AcceptsDeliveredCash.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using OpenRA.Traits; @@ -19,13 +18,13 @@ namespace OpenRA.Mods.Common.Traits public class AcceptsDeliveredCashInfo : TraitInfo { [Desc("Accepted `DeliversCash` types. Leave empty to accept all types.")] - public readonly HashSet ValidTypes = new(); + public readonly HashSet ValidTypes = []; [Desc("Player relationships the owner of the delivering actor needs.")] public readonly PlayerRelationship ValidRelationships = PlayerRelationship.Ally; [Desc("Play a randomly selected sound from this list when accepting cash.")] - public readonly string[] Sounds = Array.Empty(); + public readonly string[] Sounds = []; public override object Create(ActorInitializer init) { return new AcceptsDeliveredCash(this); } } diff --git a/OpenRA.Mods.Common/Traits/AcceptsDeliveredExperience.cs b/OpenRA.Mods.Common/Traits/AcceptsDeliveredExperience.cs index 2b159180fa..6d060affbf 100644 --- a/OpenRA.Mods.Common/Traits/AcceptsDeliveredExperience.cs +++ b/OpenRA.Mods.Common/Traits/AcceptsDeliveredExperience.cs @@ -18,7 +18,7 @@ namespace OpenRA.Mods.Common.Traits public class AcceptsDeliveredExperienceInfo : TraitInfo, Requires { [Desc("Accepted `DeliversExperience` types. Leave empty to accept all types.")] - public readonly HashSet ValidTypes = new(); + public readonly HashSet ValidTypes = []; [Desc("Player relationships the owner of the delivering actor needs.")] public readonly PlayerRelationship ValidRelationships = PlayerRelationship.Ally; diff --git a/OpenRA.Mods.Common/Traits/ActorSpawner.cs b/OpenRA.Mods.Common/Traits/ActorSpawner.cs index e71f4e11de..cb2477d613 100644 --- a/OpenRA.Mods.Common/Traits/ActorSpawner.cs +++ b/OpenRA.Mods.Common/Traits/ActorSpawner.cs @@ -17,7 +17,7 @@ namespace OpenRA.Mods.Common.Traits public class ActorSpawnerInfo : ConditionalTraitInfo { [Desc("Type of ActorSpawner with which it connects.")] - public readonly HashSet Types = new(); + public readonly HashSet Types = []; public override object Create(ActorInitializer init) { return new ActorSpawner(this); } } diff --git a/OpenRA.Mods.Common/Traits/AffectsShroud.cs b/OpenRA.Mods.Common/Traits/AffectsShroud.cs index a0e152dc60..226ba0ea03 100644 --- a/OpenRA.Mods.Common/Traits/AffectsShroud.cs +++ b/OpenRA.Mods.Common/Traits/AffectsShroud.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using System.Linq; using OpenRA.Traits; @@ -36,7 +35,7 @@ namespace OpenRA.Mods.Common.Traits public abstract class AffectsShroud : ConditionalTrait, ISync, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyMoving, INotifyCenterPositionChanged, ITick { - static readonly PPos[] NoCells = Array.Empty(); + static readonly PPos[] NoCells = []; readonly HashSet footprint; @@ -58,7 +57,7 @@ namespace OpenRA.Mods.Common.Traits : base(info) { if (Info.Type == VisibilityType.Footprint) - footprint = new HashSet(); + footprint = []; } PPos[] ProjectedCells(Actor self) diff --git a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs index e2afc98576..5bf03160c3 100644 --- a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs +++ b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs @@ -83,7 +83,7 @@ namespace OpenRA.Mods.Common.Traits [Desc("Minimum altitude where this aircraft is considered airborne.")] public readonly int MinAirborneAltitude = 1; - public readonly HashSet LandableTerrainTypes = new(); + public readonly HashSet LandableTerrainTypes = []; [Desc("Can the actor be ordered to move in to shroud?")] public readonly bool MoveIntoShroud = true; @@ -142,10 +142,10 @@ namespace OpenRA.Mods.Common.Traits public readonly WDist AltitudeVelocity = new(43); [Desc("Sounds to play when the actor is taking off.")] - public readonly string[] TakeoffSounds = Array.Empty(); + public readonly string[] TakeoffSounds = []; [Desc("Sounds to play when the actor is landing.")] - public readonly string[] LandingSounds = Array.Empty(); + public readonly string[] LandingSounds = []; [Desc("The distance of the resupply base that the aircraft will wait for its turn.")] public readonly WDist WaitDistanceFromResupplyBase = new(3072); @@ -284,7 +284,7 @@ namespace OpenRA.Mods.Common.Traits public bool MayYieldReservation { get; private set; } public bool ForceLanding { get; private set; } - (CPos, SubCell)[] landingCells = Array.Empty<(CPos, SubCell)>(); + (CPos, SubCell)[] landingCells = []; public bool RequireForceMove; readonly int creationActivityDelay; @@ -882,7 +882,7 @@ namespace OpenRA.Mods.Common.Traits public void AddInfluence(CPos landingCell) { - AddInfluence(new[] { (landingCell, SubCell.FullCell) }); + AddInfluence([(landingCell, SubCell.FullCell)]); } public void RemoveInfluence() @@ -890,7 +890,7 @@ namespace OpenRA.Mods.Common.Traits if (self.IsInWorld) self.World.ActorMap.RemoveInfluence(self, this); - landingCells = Array.Empty<(CPos, SubCell)>(); + landingCells = []; } public bool HasInfluence() diff --git a/OpenRA.Mods.Common/Traits/AmmoPool.cs b/OpenRA.Mods.Common/Traits/AmmoPool.cs index 415274d551..21a4591d99 100644 --- a/OpenRA.Mods.Common/Traits/AmmoPool.cs +++ b/OpenRA.Mods.Common/Traits/AmmoPool.cs @@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Traits public readonly string Name = "primary"; [Desc("Name(s) of armament(s) that use this pool.")] - public readonly string[] Armaments = { "primary", "secondary" }; + public readonly string[] Armaments = ["primary", "secondary"]; [Desc("How much ammo does this pool contain when fully loaded.")] public readonly int Ammo = 1; @@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits public class AmmoPool : INotifyCreated, INotifyAttack, ISync { public readonly AmmoPoolInfo Info; - readonly Stack tokens = new(); + readonly Stack tokens = []; // HACK: Temporarily needed until Rearm activity is gone for good [Sync] diff --git a/OpenRA.Mods.Common/Traits/Armament.cs b/OpenRA.Mods.Common/Traits/Armament.cs index 99c6dd9642..7552a08c2c 100644 --- a/OpenRA.Mods.Common/Traits/Armament.cs +++ b/OpenRA.Mods.Common/Traits/Armament.cs @@ -42,10 +42,10 @@ namespace OpenRA.Mods.Common.Traits [Desc("Muzzle position relative to turret or body, (forward, right, up) triples.", "If weapon Burst = 1, it cycles through all listed offsets, otherwise the offset corresponding to current burst is used.")] - public readonly WVec[] LocalOffset = Array.Empty(); + public readonly WVec[] LocalOffset = []; [Desc("Muzzle yaw relative to turret or body.")] - public readonly WAngle[] LocalYaw = Array.Empty(); + public readonly WAngle[] LocalYaw = []; [Desc("Move the turret backwards when firing.")] public readonly WDist Recoil = WDist.Zero; @@ -131,7 +131,7 @@ namespace OpenRA.Mods.Common.Traits int currentBarrel; readonly int barrelCount; - readonly List<(int Ticks, int Burst, Action Func)> delayedActions = new(); + readonly List<(int Ticks, int Burst, Action Func)> delayedActions = []; public WDist Recoil; public int FireDelay { get; protected set; } diff --git a/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs b/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs index f1640bee4e..bbd7ca72f0 100644 --- a/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs +++ b/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs @@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Traits public abstract class AttackBaseInfo : PausableConditionalTraitInfo { [Desc("Armament names")] - public readonly string[] Armaments = { "primary", "secondary" }; + public readonly string[] Armaments = ["primary", "secondary"]; [CursorReference] [Desc("Cursor to display when hovering over a valid target.")] @@ -366,7 +366,7 @@ namespace OpenRA.Mods.Common.Traits // If force-fire is not used, and the target requires force-firing or the target is // terrain or invalid, no armaments can be used if (!forceAttack && ((t.Type == TargetType.Terrain && !Info.TargetTerrainWithoutForceFire) || t.Type == TargetType.Invalid || t.RequiresForceFire)) - return Enumerable.Empty(); + return []; // Get target's owner; in case of terrain or invalid target there will be no problems // with owner == null since forceFire will have to be true in this part of the method diff --git a/OpenRA.Mods.Common/Traits/Attack/AttackGarrisoned.cs b/OpenRA.Mods.Common/Traits/Attack/AttackGarrisoned.cs index 3d0b7915b1..f62bea3ba0 100644 --- a/OpenRA.Mods.Common/Traits/Attack/AttackGarrisoned.cs +++ b/OpenRA.Mods.Common/Traits/Attack/AttackGarrisoned.cs @@ -91,11 +91,11 @@ namespace OpenRA.Mods.Common.Traits { Info = info; coords = Exts.Lazy(self.Trait); - armaments = new List(); - muzzles = new List(); - paxFacing = new Dictionary(); - paxPos = new Dictionary(); - paxRender = new Dictionary(); + armaments = []; + muzzles = []; + paxFacing = []; + paxPos = []; + paxRender = []; } protected override void Created(Actor self) diff --git a/OpenRA.Mods.Common/Traits/Attack/AttackTurreted.cs b/OpenRA.Mods.Common/Traits/Attack/AttackTurreted.cs index f7c87940fe..3ad0803b97 100644 --- a/OpenRA.Mods.Common/Traits/Attack/AttackTurreted.cs +++ b/OpenRA.Mods.Common/Traits/Attack/AttackTurreted.cs @@ -18,7 +18,7 @@ namespace OpenRA.Mods.Common.Traits public class AttackTurretedInfo : AttackFollowInfo, Requires { [Desc("Turret names")] - public readonly string[] Turrets = { "primary" }; + public readonly string[] Turrets = ["primary"]; public override object Create(ActorInitializer init) { return new AttackTurreted(init.Self, this); } } diff --git a/OpenRA.Mods.Common/Traits/AutoTarget.cs b/OpenRA.Mods.Common/Traits/AutoTarget.cs index a5b6002efc..8faf08d035 100644 --- a/OpenRA.Mods.Common/Traits/AutoTarget.cs +++ b/OpenRA.Mods.Common/Traits/AutoTarget.cs @@ -69,7 +69,7 @@ namespace OpenRA.Mods.Common.Traits public readonly string AttackAnythingCondition = null; [FieldLoader.Ignore] - public readonly Dictionary ConditionByStance = new(); + public readonly Dictionary ConditionByStance = []; [Desc("Allow the player to change the unit stance.")] public readonly bool EnableStances = true; diff --git a/OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs index 8f35138d52..74ac56a2c3 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs @@ -21,37 +21,37 @@ namespace OpenRA.Mods.Common.Traits public class BaseBuilderBotModuleInfo : ConditionalTraitInfo { [Desc("Tells the AI what building types are considered construction yards.")] - public readonly HashSet ConstructionYardTypes = new(); + public readonly HashSet ConstructionYardTypes = []; [Desc("Tells the AI what building types are considered vehicle production facilities.")] - public readonly HashSet VehiclesFactoryTypes = new(); + public readonly HashSet VehiclesFactoryTypes = []; [Desc("Tells the AI what building types are considered refineries.")] - public readonly HashSet RefineryTypes = new(); + public readonly HashSet RefineryTypes = []; [Desc("Tells the AI what building types are considered power plants.")] - public readonly HashSet PowerTypes = new(); + public readonly HashSet PowerTypes = []; [Desc("Tells the AI what building types are considered infantry production facilities.")] - public readonly HashSet BarracksTypes = new(); + public readonly HashSet BarracksTypes = []; [Desc("Tells the AI what building types are considered production facilities.")] - public readonly HashSet ProductionTypes = new(); + public readonly HashSet ProductionTypes = []; [Desc("Tells the AI what building types are considered naval production facilities.")] - public readonly HashSet NavalProductionTypes = new(); + public readonly HashSet NavalProductionTypes = []; [Desc("Tells the AI what building types are considered silos (resource storage).")] - public readonly HashSet SiloTypes = new(); + public readonly HashSet SiloTypes = []; [Desc("Tells the AI what building types are considered defenses.")] - public readonly HashSet DefenseTypes = new(); + public readonly HashSet DefenseTypes = []; [Desc("Production queues AI uses for buildings.")] - public readonly HashSet BuildingQueues = new() { "Building" }; + public readonly HashSet BuildingQueues = ["Building"]; [Desc("Production queues AI uses for defenses.")] - public readonly HashSet DefenseQueues = new() { "Defense" }; + public readonly HashSet DefenseQueues = ["Defense"]; [Desc("Minimum distance in cells from center of the base when checking for building placement.")] public readonly int MinBaseRadius = 2; @@ -122,7 +122,7 @@ namespace OpenRA.Mods.Common.Traits public readonly int CheckForWaterRadius = 8; [Desc("Terrain types which are considered water for base building purposes.")] - public readonly HashSet WaterTerrainTypes = new() { "Water" }; + public readonly HashSet WaterTerrainTypes = ["Water"]; [Desc("What buildings to the AI should build.", "What integer percentage of the total base must be this type of building.")] public readonly Dictionary BuildingFractions = null; @@ -156,7 +156,7 @@ namespace OpenRA.Mods.Common.Traits public CPos DefenseCenter { get; private set; } // Actor, ActorCount. - public Dictionary BuildingsBeingProduced = new(); + public Dictionary BuildingsBeingProduced = []; readonly World world; readonly Player player; @@ -167,7 +167,7 @@ namespace OpenRA.Mods.Common.Traits IBotPositionsUpdated[] positionsUpdatedModules; CPos initialBaseCenter; - readonly Stack> rallyPoints = new(); + readonly Stack> rallyPoints = []; int assignRallyPointsTicks; readonly BaseBuilderQueueManager[] builders; @@ -406,11 +406,11 @@ namespace OpenRA.Mods.Common.Traits if (IsTraitDisabled) return null; - return new List() - { + return + [ new("InitialBaseCenter", FieldSaver.FormatValue(initialBaseCenter)), new("DefenseCenter", FieldSaver.FormatValue(DefenseCenter)) - }; + ]; } void IGameSaveTraitData.ResolveTraitData(Actor self, MiniYaml data) diff --git a/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/BaseBuilderQueueManager.cs b/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/BaseBuilderQueueManager.cs index 0acbc22c93..e55242997f 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/BaseBuilderQueueManager.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/BaseBuilderQueueManager.cs @@ -346,7 +346,7 @@ namespace OpenRA.Mods.Common.Traits // Check the number of this structure and its variants var actorInfo = world.Map.Rules.Actors[name]; var buildingVariantInfo = actorInfo.TraitInfoOrDefault(); - var variants = buildingVariantInfo?.Actors ?? Array.Empty(); + var variants = buildingVariantInfo?.Actors ?? []; var count = playerBuildings.Count(a => a.Info.Name == name || variants.Contains(a.Info.Name)) + diff --git a/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/MinelayerBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/MinelayerBotModule.cs index 2b74474c33..4a26c18131 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/MinelayerBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/MinelayerBotModule.cs @@ -87,8 +87,8 @@ namespace OpenRA.Mods.Common.Traits player = self.Owner; unitCannotBeOrdered = a => a == null || a.IsDead || !a.IsInWorld || a.Owner != player; unitCannotBeOrderedOrIsBusy = a => unitCannotBeOrdered(a) || !a.IsIdle; - conflictPositionQueue = new CPos?[MaxPositionCacheLength] { null, null, null, null, null }; - favoritePositions = new CPos?[MaxPositionCacheLength] { null, null, null, null, null }; + conflictPositionQueue = new CPos?[MaxPositionCacheLength]; + favoritePositions = new CPos?[MaxPositionCacheLength]; } protected override void TraitEnabled(Actor self) @@ -149,7 +149,7 @@ namespace OpenRA.Mods.Common.Traits foreach (var minelayer in minelayers) { var cells = pathFinder.FindPathToTargetCell( - minelayer.Actor, new[] { minelayer.Actor.Location }, enemy.Location, BlockedByActor.Immovable, laneBias: false); + minelayer.Actor, [minelayer.Actor.Location], enemy.Location, BlockedByActor.Immovable, laneBias: false); if (cells != null && cells.Count != 0) { AIUtils.BotDebug($"{player}: try find a location to lay mine."); @@ -194,7 +194,7 @@ namespace OpenRA.Mods.Common.Traits foreach (var minelayer in minelayers) { var cells = pathFinder.FindPathToTargetCell( - minelayer.Actor, new[] { minelayer.Actor.Location }, minelayingPosition, BlockedByActor.Immovable, laneBias: false); + minelayer.Actor, [minelayer.Actor.Location], minelayingPosition, BlockedByActor.Immovable, laneBias: false); if (cells != null && cells.Count != 0) { orderedActors.Add(minelayer.Actor); diff --git a/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/SupportPowerDecision.cs b/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/SupportPowerDecision.cs index 7184b4a430..be2faee491 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/SupportPowerDecision.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/SupportPowerDecision.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits [FieldLoader.LoadUsing(nameof(LoadConsiderations))] [Desc("The decisions associated with this power")] - public readonly List Considerations = new(); + public readonly List Considerations = []; [Desc("Minimum ticks to wait until next Decision scan attempt.")] public readonly int MinimumScanTimeInterval = 250; diff --git a/OpenRA.Mods.Common/Traits/BotModules/CaptureManagerBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/CaptureManagerBotModule.cs index 351656e6d4..f5f04e1bac 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/CaptureManagerBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/CaptureManagerBotModule.cs @@ -22,11 +22,11 @@ namespace OpenRA.Mods.Common.Traits { [Desc("Actor types that can capture other actors (via `Captures`).", "Leave this empty to disable capturing.")] - public readonly HashSet CapturingActorTypes = new(); + public readonly HashSet CapturingActorTypes = []; [Desc("Actor types that can be targeted for capturing.", "Leave this empty to include all actors.")] - public readonly HashSet CapturableActorTypes = new(); + public readonly HashSet CapturableActorTypes = []; [Desc("Minimum delay (in ticks) between trying to capture with CapturingActorTypes.")] public readonly int MinimumCaptureDelay = 375; @@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.Traits int minCaptureDelayTicks; // Units that the bot already knows about and has given a capture order. Any unit not on this list needs to be given a new order. - readonly List activeCapturers = new(); + readonly List activeCapturers = []; readonly ActorIndex.OwnerAndNamesAndTrait capturingActors; diff --git a/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs index 447d9cd872..21cd31fad3 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs @@ -24,10 +24,10 @@ namespace OpenRA.Mods.Common.Traits { [Desc("Actor types that are considered harvesters. If harvester count drops below RefineryTypes count, a new harvester is built.", "Leave empty to disable harvester replacement. Currently only needed by harvester replacement system.")] - public readonly HashSet HarvesterTypes = new(); + public readonly HashSet HarvesterTypes = []; [Desc("Actor types that are counted as refineries. Currently only needed by harvester replacement system.")] - public readonly HashSet RefineryTypes = new(); + public readonly HashSet RefineryTypes = []; [Desc("Interval (in ticks) between giving out orders to idle harvesters.")] public readonly int ScanForIdleHarvestersInterval = 50; @@ -68,11 +68,11 @@ namespace OpenRA.Mods.Common.Traits readonly World world; readonly Player player; readonly Func unitCannotBeOrdered; - readonly Dictionary harvesters = new(); - readonly Stack harvestersNeedingOrders = new(); + readonly Dictionary harvesters = []; + readonly Stack harvestersNeedingOrders = []; readonly ActorIndex.OwnerAndNamesAndTrait refineries; readonly ActorIndex.OwnerAndNamesAndTrait harvestersIndex; - readonly Dictionary resourceTypesByCell = new(); + readonly Dictionary resourceTypesByCell = []; IResourceLayer resourceLayer; ResourceClaimLayer claimLayer; diff --git a/OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs index 7e46e8b062..9ab15c5f48 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs @@ -20,13 +20,13 @@ namespace OpenRA.Mods.Common.Traits public class McvManagerBotModuleInfo : ConditionalTraitInfo { [Desc("Actor types that are considered MCVs (deploy into base builders).")] - public readonly HashSet McvTypes = new(); + public readonly HashSet McvTypes = []; [Desc("Actor types that are considered construction yards (base builders).")] - public readonly HashSet ConstructionYardTypes = new(); + public readonly HashSet ConstructionYardTypes = []; [Desc("Actor types that are able to produce MCVs.")] - public readonly HashSet McvFactoryTypes = new(); + public readonly HashSet McvFactoryTypes = []; [Desc("Try to maintain at least this many ConstructionYardTypes, build an MCV if number is below this.")] public readonly int MinimumConstructionYardCount = 1; @@ -211,10 +211,10 @@ namespace OpenRA.Mods.Common.Traits if (IsTraitDisabled) return null; - return new List() - { + return + [ new("InitialBaseCenter", FieldSaver.FormatValue(initialBaseCenter)) - }; + ]; } void IGameSaveTraitData.ResolveTraitData(Actor self, MiniYaml data) diff --git a/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs index b6076d0037..e35e0119f2 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs @@ -24,27 +24,27 @@ namespace OpenRA.Mods.Common.Traits { [ActorReference] [Desc("Actor types that are valid for naval squads.")] - public readonly HashSet NavalUnitsTypes = new(); + public readonly HashSet NavalUnitsTypes = []; [ActorReference] [Desc("Actor types that are excluded from ground attacks.")] - public readonly HashSet AirUnitsTypes = new(); + public readonly HashSet AirUnitsTypes = []; [ActorReference] [Desc("Actor types that should generally be excluded from attack squads.")] - public readonly HashSet ExcludeFromSquadsTypes = new(); + public readonly HashSet ExcludeFromSquadsTypes = []; [ActorReference] [Desc("Actor types that are considered construction yards (base builders).")] - public readonly HashSet ConstructionYardTypes = new(); + public readonly HashSet ConstructionYardTypes = []; [ActorReference] [Desc("Enemy building types around which to scan for targets for naval squads.")] - public readonly HashSet NavalProductionTypes = new(); + public readonly HashSet NavalProductionTypes = []; [ActorReference] [Desc("Own actor types that are prioritized when defending.")] - public readonly HashSet ProtectionTypes = new(); + public readonly HashSet ProtectionTypes = []; [Desc("Target types are used for identifying aircraft.")] public readonly BitSet AircraftTargetType = new("Air"); @@ -119,13 +119,13 @@ namespace OpenRA.Mods.Common.Traits public readonly Player Player; readonly Predicate unitCannotBeOrdered; - readonly List unitsHangingAroundTheBase = new(); + readonly List unitsHangingAroundTheBase = []; // Units that the bot already knows about. Any unit not on this list needs to be given a role. - readonly HashSet activeUnits = new(); + readonly HashSet activeUnits = []; - public List Squads = new(); - readonly Stack squadsPendingUpdate = new(); + public List Squads = []; + readonly Stack squadsPendingUpdate = []; readonly ActorIndex.NamesAndTrait constructionYardBuildings; IBot bot; @@ -229,8 +229,8 @@ namespace OpenRA.Mods.Common.Traits { var range = ownActorsAndTheirAttackRanges[a].Length; var rangeDiag = Exts.MultiplyBySqrtTwoOverTwo(range); - return new[] - { + return + [ targetActor.CenterPosition, targetActor.CenterPosition + new WVec(range, 0, 0), targetActor.CenterPosition + new WVec(-range, 0, 0), @@ -240,7 +240,7 @@ namespace OpenRA.Mods.Common.Traits targetActor.CenterPosition + new WVec(-rangeDiag, rangeDiag, 0), targetActor.CenterPosition + new WVec(-rangeDiag, -rangeDiag, 0), targetActor.CenterPosition + new WVec(rangeDiag, -rangeDiag, 0), - }; + ]; }); } @@ -268,8 +268,8 @@ namespace OpenRA.Mods.Common.Traits { var range = enemiesAndSourceAttackRanges[a].Length; var rangeDiag = Exts.MultiplyBySqrtTwoOverTwo(range); - return new[] - { + return + [ WVec.Zero, new WVec(range, 0, 0), new WVec(-range, 0, 0), @@ -279,7 +279,7 @@ namespace OpenRA.Mods.Common.Traits new WVec(-rangeDiag, rangeDiag, 0), new WVec(-rangeDiag, -rangeDiag, 0), new WVec(rangeDiag, -rangeDiag, 0), - }; + ]; }) .Select(x => (x.Actor, x.ReachableOffsets.MinBy(o => o.LengthSquared))); } @@ -520,8 +520,8 @@ namespace OpenRA.Mods.Common.Traits if (IsTraitDisabled) return null; - return new List() - { + return + [ new("Squads", "", Squads.ConvertAll(s => new MiniYamlNode("Squad", s.Serialize()))), new("InitialBaseCenter", FieldSaver.FormatValue(initialBaseCenter)), new("UnitsHangingAroundTheBase", FieldSaver.FormatValue(unitsHangingAroundTheBase @@ -536,7 +536,7 @@ namespace OpenRA.Mods.Common.Traits new("AssignRolesTicks", FieldSaver.FormatValue(assignRolesTicks)), new("AttackForceTicks", FieldSaver.FormatValue(attackForceTicks)), new("MinAttackForceDelayTicks", FieldSaver.FormatValue(minAttackForceDelayTicks)), - }; + ]; } void IGameSaveTraitData.ResolveTraitData(Actor self, MiniYaml data) diff --git a/OpenRA.Mods.Common/Traits/BotModules/Squads/AttackOrFleeFuzzy.cs b/OpenRA.Mods.Common/Traits/BotModules/Squads/AttackOrFleeFuzzy.cs index 565601e349..92d1b3f9bc 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/Squads/AttackOrFleeFuzzy.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/Squads/AttackOrFleeFuzzy.cs @@ -20,17 +20,17 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads { sealed class AttackOrFleeFuzzy { - static readonly string[] DefaultRulesNormalOwnHealth = new[] - { + static readonly string[] DefaultRulesNormalOwnHealth = + [ "if ((OwnHealth is Normal) " + "and ((EnemyHealth is NearDead) or (EnemyHealth is Injured) or (EnemyHealth is Normal)) " + "and ((RelativeAttackPower is Weak) or (RelativeAttackPower is Equal) or (RelativeAttackPower is Strong)) " + "and ((RelativeSpeed is Slow) or (RelativeSpeed is Equal) or (RelativeSpeed is Fast))) " + "then AttackOrFlee is Attack" - }; + ]; - static readonly string[] DefaultRulesInjuredOwnHealth = new[] - { + static readonly string[] DefaultRulesInjuredOwnHealth = + [ "if ((OwnHealth is Injured) " + "and (EnemyHealth is NearDead) " + "and ((RelativeAttackPower is Weak) or (RelativeAttackPower is Equal) or (RelativeAttackPower is Strong)) " + @@ -60,10 +60,10 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads "and ((RelativeAttackPower is Weak) or (RelativeAttackPower is Equal) or (RelativeAttackPower is Strong)) " + "and (RelativeSpeed is Slow)) " + "then AttackOrFlee is Attack" - }; + ]; - static readonly string[] DefaultRulesNearDeadOwnHealth = new[] - { + static readonly string[] DefaultRulesNearDeadOwnHealth = + [ "if ((OwnHealth is NearDead) " + "and ((EnemyHealth is NearDead) or (EnemyHealth is Injured)) " + "and ((RelativeAttackPower is Equal) or (RelativeAttackPower is Strong)) " + @@ -93,11 +93,11 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads "and (RelativeAttackPower is Equal) " + "and (RelativeSpeed is Fast) " + "then AttackOrFlee is Flee" - }; + ]; public static readonly AttackOrFleeFuzzy Default = new(null, null, null); - public static readonly AttackOrFleeFuzzy Rush = new(new[] - { + public static readonly AttackOrFleeFuzzy Rush = new( + [ "if ((OwnHealth is Normal) " + "and ((EnemyHealth is NearDead) or (EnemyHealth is Injured) or (EnemyHealth is Normal)) " + "and (RelativeAttackPower is Strong) " + @@ -109,7 +109,7 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads "and ((RelativeAttackPower is Weak) or (RelativeAttackPower is Equal)) " + "and ((RelativeSpeed is Slow) or (RelativeSpeed is Equal) or (RelativeSpeed is Fast))) " + "then AttackOrFlee is Flee" - }, null, null); + ], null, null); readonly MamdaniFuzzySystem fuzzyEngine = new(); diff --git a/OpenRA.Mods.Common/Traits/BotModules/Squads/Squad.cs b/OpenRA.Mods.Common/Traits/BotModules/Squads/Squad.cs index 48660d98fa..c26db306db 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/Squads/Squad.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/Squads/Squad.cs @@ -20,7 +20,7 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads public class Squad { - public HashSet Units = new(); + public HashSet Units = []; public SquadType Type; internal IBot Bot; @@ -114,7 +114,7 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads // e.g. a ship targeting a land unit, but the land unit moved north. // We need to update our location to move north as well. // If we can reach the actor directly, we'll just target it directly. - var target = SquadManager.FindEnemies(new[] { TargetActor }, squadUnit).FirstOrDefault(); + var target = SquadManager.FindEnemies([TargetActor], squadUnit).FirstOrDefault(); SetActorToTarget(target); return target.Actor != null; } diff --git a/OpenRA.Mods.Common/Traits/BotModules/SupportPowerBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/SupportPowerBotModule.cs index ff61177d95..24feb72a7e 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/SupportPowerBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/SupportPowerBotModule.cs @@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Traits { [Desc("Tells the AI how to use its support powers.")] [FieldLoader.LoadUsing(nameof(LoadDecisions))] - public readonly List Decisions = new(); + public readonly List Decisions = []; static object LoadDecisions(MiniYaml yaml) { @@ -41,9 +41,9 @@ namespace OpenRA.Mods.Common.Traits { readonly World world; readonly Player player; - readonly Dictionary waitingPowers = new(); - readonly Dictionary powerDecisions = new(); - readonly List stalePowers = new(); + readonly Dictionary waitingPowers = []; + readonly Dictionary powerDecisions = []; + readonly List stalePowers = []; SupportPowerManager supportPowerManager; public SupportPowerBotModule(Actor self, SupportPowerBotModuleInfo info) @@ -153,7 +153,7 @@ namespace OpenRA.Mods.Common.Traits var wbr = world.Map.CenterOfCell(br.ToCPos(map)); var targets = world.ActorMap.ActorsInBox(wtl, wbr); - var frozenTargets = player.FrozenActorLayer != null ? player.FrozenActorLayer.FrozenActorsInRegion(region) : Enumerable.Empty(); + var frozenTargets = player.FrozenActorLayer != null ? player.FrozenActorLayer.FrozenActorsInRegion(region) : []; var consideredAttractiveness = powerDecision.GetAttractiveness(targets, player) + powerDecision.GetAttractiveness(frozenTargets, player); if (consideredAttractiveness < powerDecision.MinimumAttractiveness) continue; @@ -218,10 +218,10 @@ namespace OpenRA.Mods.Common.Traits .Select(kv => new MiniYamlNode(kv.Key.Key, FieldSaver.FormatValue(kv.Value))) .ToList(); - return new List() - { + return + [ new("WaitingPowers", "", waitingPowersNodes) - }; + ]; } void IGameSaveTraitData.ResolveTraitData(Actor self, MiniYaml data) diff --git a/OpenRA.Mods.Common/Traits/BotModules/UnitBuilderBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/UnitBuilderBotModule.cs index ca9ea03e18..25b804f698 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/UnitBuilderBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/UnitBuilderBotModule.cs @@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits public readonly int IdleBaseUnitsMaximum = -1; [Desc("Production queues AI uses for producing units.")] - public readonly string[] UnitQueues = { "Vehicle", "Infantry", "Plane", "Ship", "Aircraft" }; + public readonly string[] UnitQueues = ["Vehicle", "Infantry", "Plane", "Ship", "Aircraft"]; [Desc("What units to the AI should build.", "What relative share of the total army must be this type of unit.")] public readonly Dictionary UnitsToBuild = null; @@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.Traits readonly World world; readonly Player player; - readonly List queuedBuildRequests = new(); + readonly List queuedBuildRequests = []; readonly ActorIndex.OwnerAndNames unitsToBuild; IBotRequestPauseUnitProduction[] requestPause; @@ -237,11 +237,11 @@ namespace OpenRA.Mods.Common.Traits if (IsTraitDisabled) return null; - return new List() - { + return + [ new("QueuedBuildRequests", FieldSaver.FormatValue(queuedBuildRequests.ToArray())), new("IdleUnitCount", FieldSaver.FormatValue(idleUnitCount)) - }; + ]; } void IGameSaveTraitData.ResolveTraitData(Actor self, MiniYaml data) diff --git a/OpenRA.Mods.Common/Traits/Buildable.cs b/OpenRA.Mods.Common/Traits/Buildable.cs index 45ae494552..64e140b229 100644 --- a/OpenRA.Mods.Common/Traits/Buildable.cs +++ b/OpenRA.Mods.Common/Traits/Buildable.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using OpenRA.Traits; @@ -21,10 +20,10 @@ namespace OpenRA.Mods.Common.Traits "This can be prefixed with ! to invert the prerequisite (disabling production if the prerequisite is available)", "and/or ~ to hide the actor from the production palette if the prerequisite is not available.", "Prerequisites are granted by actors with the ProvidesPrerequisite trait.")] - public readonly string[] Prerequisites = Array.Empty(); + public readonly string[] Prerequisites = []; [Desc("Production queue(s) that can produce this.")] - public readonly HashSet Queue = new(); + public readonly HashSet Queue = []; [Desc("Override the production structure type (from the Production Produces list) that this unit should be built at.")] public readonly string BuildAtProductionType = null; diff --git a/OpenRA.Mods.Common/Traits/Buildings/Bridge.cs b/OpenRA.Mods.Common/Traits/Buildings/Bridge.cs index 3b748e75e2..353c657e05 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/Bridge.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/Bridge.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits public readonly ushort DestroyedPlusSouthTemplate = 0; public readonly ushort DestroyedPlusBothTemplate = 0; - public readonly string[] ShorePieces = { "br1", "br2" }; + public readonly string[] ShorePieces = ["br1", "br2"]; public readonly int[] NorthOffset = null; public readonly int[] SouthOffset = null; @@ -228,7 +228,7 @@ namespace OpenRA.Mods.Common.Traits if (!initialized) { var palette = wr.Palette(TileSet.TerrainPaletteInternalName); - renderables = new Dictionary(); + renderables = []; foreach (var t in info.Templates) renderables.Add(t.Template, TemplateRenderables(wr, palette, t.Template)); diff --git a/OpenRA.Mods.Common/Traits/Buildings/BridgeHut.cs b/OpenRA.Mods.Common/Traits/Buildings/BridgeHut.cs index 8e98725f02..868901e301 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/BridgeHut.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/BridgeHut.cs @@ -22,10 +22,10 @@ namespace OpenRA.Mods.Common.Traits public class BridgeHutInfo : TraitInfo, IDemolishableInfo { [Desc("Bridge types to act on")] - public readonly string[] Types = { "GroundLevelBridge" }; + public readonly string[] Types = ["GroundLevelBridge"]; [Desc("Offsets to look for adjacent bridges to act on")] - public readonly CVec[] NeighbourOffsets = Array.Empty(); + public readonly CVec[] NeighbourOffsets = []; [Desc("Delay between each segment repair step")] public readonly int RepairPropagationDelay = 20; @@ -47,11 +47,11 @@ namespace OpenRA.Mods.Common.Traits readonly BridgeLayer bridgeLayer; // Fixed at map load - readonly List segmentLocations = new(); + readonly List segmentLocations = []; // Changes as segments are killed and repaired - readonly Dictionary segments = new(); - readonly HashSet dirtyLocations = new(); + readonly Dictionary segments = []; + readonly HashSet dirtyLocations = []; // Enabled during a repair action int repairStep; diff --git a/OpenRA.Mods.Common/Traits/Buildings/BridgePlaceholder.cs b/OpenRA.Mods.Common/Traits/Buildings/BridgePlaceholder.cs index 0d9403c7cd..60f84e06cf 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/BridgePlaceholder.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/BridgePlaceholder.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using OpenRA.Primitives; using OpenRA.Traits; @@ -26,7 +25,7 @@ namespace OpenRA.Mods.Common.Traits [Desc("Actor type to replace with on repair.")] public readonly string ReplaceWithActor = null; - public readonly CVec[] NeighbourOffsets = Array.Empty(); + public readonly CVec[] NeighbourOffsets = []; public override object Create(ActorInitializer init) { return new BridgePlaceholder(init.Self, this); } } @@ -63,11 +62,11 @@ namespace OpenRA.Mods.Common.Traits { self.Dispose(); - w.CreateActor(Info.ReplaceWithActor, new TypeDictionary - { + w.CreateActor(Info.ReplaceWithActor, + [ new LocationInit(self.Location), new OwnerInit(self.Owner), - }); + ]); }); } diff --git a/OpenRA.Mods.Common/Traits/Buildings/Building.cs b/OpenRA.Mods.Common/Traits/Buildings/Building.cs index d209440e01..21b3813130 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/Building.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/Building.cs @@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits public class BuildingInfo : TraitInfo, IOccupySpaceInfo, IPlaceBuildingDecorationInfo { [Desc("Where you are allowed to place the building (Water, Clear, ...)")] - public readonly HashSet TerrainTypes = new(); + public readonly HashSet TerrainTypes = []; [Desc("x means cell is blocked, capital X means blocked but not counting as targetable, ", "= means part of the footprint but passable, _ means completely empty.")] @@ -56,16 +56,16 @@ namespace OpenRA.Mods.Common.Traits [Desc("Clear smudges from underneath the building footprint on transform.")] public readonly bool RemoveSmudgesOnTransform = true; - public readonly string[] BuildSounds = Array.Empty(); + public readonly string[] BuildSounds = []; - public readonly string[] UndeploySounds = Array.Empty(); + public readonly string[] UndeploySounds = []; public override object Create(ActorInitializer init) { return new Building(init, this); } protected static object LoadFootprint(MiniYaml yaml) { var footprintYaml = yaml.NodeWithKeyOrDefault("Footprint"); - var footprintChars = footprintYaml?.Value.Value.Where(x => !char.IsWhiteSpace(x)).ToArray() ?? new[] { 'x' }; + var footprintChars = footprintYaml?.Value.Value.Where(x => !char.IsWhiteSpace(x)).ToArray() ?? ['x']; var dimensionsYaml = yaml.NodeWithKeyOrDefault("Dimensions"); var dim = dimensionsYaml != null ? FieldLoader.GetValue("Dimensions", dimensionsYaml.Value.Value) : new CVec(1, 1); diff --git a/OpenRA.Mods.Common/Traits/Buildings/BuildingUtils.cs b/OpenRA.Mods.Common/Traits/Buildings/BuildingUtils.cs index 175c069558..4c003f5a5b 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/BuildingUtils.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/BuildingUtils.cs @@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.Traits if (r.IsTraitDisabled) continue; - acceptedReplacements ??= new HashSet(); + acceptedReplacements ??= []; acceptedReplacements.UnionWith(r.Info.Types); } @@ -101,8 +101,8 @@ namespace OpenRA.Mods.Common.Traits // Start at place location, search outwards // TODO: First make it work, then make it nice var vecs = new[] { new CVec(1, 0), new CVec(0, 1), new CVec(-1, 0), new CVec(0, -1) }; - int[] dirs = { 0, 0, 0, 0 }; - Actor[] connectors = { null, null, null, null }; + int[] dirs = [0, 0, 0, 0]; + Actor[] connectors = [null, null, null, null]; for (var d = 0; d < 4; d++) { diff --git a/OpenRA.Mods.Common/Traits/Buildings/Exit.cs b/OpenRA.Mods.Common/Traits/Buildings/Exit.cs index 78c7be6a4d..3f85616807 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/Exit.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/Exit.cs @@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Traits public readonly WAngle? Facing = null; [Desc("Type tags on this exit.")] - public readonly HashSet ProductionTypes = new(); + public readonly HashSet ProductionTypes = []; [Desc("Number of ticks to wait before moving into the world.")] public readonly int ExitDelay = 0; @@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.Traits public static IEnumerable Exits(this Actor actor, string productionType = null) { if (!actor.IsInWorld || actor.Disposed) - return Enumerable.Empty(); + return []; var all = actor.TraitsImplementing() .Where(t => !t.IsTraitDisabled); diff --git a/OpenRA.Mods.Common/Traits/Buildings/FreeActor.cs b/OpenRA.Mods.Common/Traits/Buildings/FreeActor.cs index 6ab2e642d9..245b7ca47a 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/FreeActor.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/FreeActor.cs @@ -10,7 +10,6 @@ #endregion using System.Collections.Generic; -using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -72,13 +71,13 @@ namespace OpenRA.Mods.Common.Traits self.World.AddFrameEndTask(w => { - w.CreateActor(Info.Actor, new TypeDictionary - { + w.CreateActor(Info.Actor, + [ new ParentActorInit(self), new LocationInit(self.Location + Info.SpawnOffset), new OwnerInit(self.Owner), new FacingInit(Info.Facing), - }); + ]); }); } } diff --git a/OpenRA.Mods.Common/Traits/Buildings/FreeActorWithDelivery.cs b/OpenRA.Mods.Common/Traits/Buildings/FreeActorWithDelivery.cs index 7dbc1b81bf..8919c2529f 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/FreeActorWithDelivery.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/FreeActorWithDelivery.cs @@ -10,7 +10,6 @@ #endregion using OpenRA.Mods.Common.Activities; -using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -91,19 +90,19 @@ namespace OpenRA.Mods.Common.Traits spawn += new WVec(0, 0, aircraftInfo.CruiseAltitude.Length); // Create delivery actor - carrier = self.World.CreateActor(false, deliveringActorName, new TypeDictionary - { + carrier = self.World.CreateActor(false, deliveringActorName, + [ new LocationInit(location), new CenterPositionInit(spawn), new OwnerInit(self.Owner), new FacingInit(initialFacing) - }); + ]); // Create delivered actor - cargo = self.World.CreateActor(false, actorName, new TypeDictionary - { + cargo = self.World.CreateActor(false, actorName, + [ new OwnerInit(self.Owner), - }); + ]); } } } diff --git a/OpenRA.Mods.Common/Traits/Buildings/Gate.cs b/OpenRA.Mods.Common/Traits/Buildings/Gate.cs index 0569cb354f..70ad221a31 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/Gate.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/Gate.cs @@ -126,7 +126,7 @@ namespace OpenRA.Mods.Common.Traits void INotifyRemovedFromWorld.RemovedFromWorld(Actor self) { - blockedPositions = Enumerable.Empty(); + blockedPositions = []; } bool CanRemoveBlockage(Actor self, Actor blocking) diff --git a/OpenRA.Mods.Common/Traits/Buildings/GivesBuildableArea.cs b/OpenRA.Mods.Common/Traits/Buildings/GivesBuildableArea.cs index b979c4bc52..7b8ffa54a0 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/GivesBuildableArea.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/GivesBuildableArea.cs @@ -18,7 +18,7 @@ namespace OpenRA.Mods.Common.Traits { [FieldLoader.Require] [Desc("Types of buildable area this actor gives.")] - public readonly HashSet AreaTypes = new(); + public readonly HashSet AreaTypes = []; public override object Create(ActorInitializer init) { return new GivesBuildableArea(this); } } @@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits public GivesBuildableArea(GivesBuildableAreaInfo info) : base(info) { } - readonly HashSet noAreaTypes = new(); + readonly HashSet noAreaTypes = []; public HashSet AreaTypes => !IsTraitDisabled ? Info.AreaTypes : noAreaTypes; } diff --git a/OpenRA.Mods.Common/Traits/Buildings/GroundLevelBridge.cs b/OpenRA.Mods.Common/Traits/Buildings/GroundLevelBridge.cs index 420dddbe32..af8c7c5fda 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/GroundLevelBridge.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/GroundLevelBridge.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using OpenRA.GameRules; using OpenRA.Primitives; @@ -24,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits public readonly string Type = "GroundLevelBridge"; - public readonly CVec[] NeighbourOffsets = Array.Empty(); + public readonly CVec[] NeighbourOffsets = []; [WeaponReference] [Desc("The name of the weapon to use when demolishing the bridge")] diff --git a/OpenRA.Mods.Common/Traits/Buildings/LineBuild.cs b/OpenRA.Mods.Common/Traits/Buildings/LineBuild.cs index 26b5858821..afe084e613 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/LineBuild.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/LineBuild.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using System.Linq; using OpenRA.Traits; @@ -28,7 +27,7 @@ namespace OpenRA.Mods.Common.Traits readonly Actor[] parents = null; public LineBuildParentInit(Actor[] value) - : base(Array.Empty()) + : base([]) { parents = value; } @@ -56,7 +55,7 @@ namespace OpenRA.Mods.Common.Traits public readonly int Range = 5; [Desc("LineBuildNode 'Types' to attach to.")] - public readonly HashSet NodeTypes = new() { "wall" }; + public readonly HashSet NodeTypes = ["wall"]; [ActorReference(typeof(LineBuildInfo))] [Desc("Actor type for line-built segments (defaults to same actor).")] @@ -71,7 +70,7 @@ namespace OpenRA.Mods.Common.Traits public class LineBuild : INotifyKilled, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyLineBuildSegmentsChanged { readonly LineBuildInfo info; - readonly Actor[] parentNodes = Array.Empty(); + readonly Actor[] parentNodes = []; HashSet segments; public LineBuild(ActorInitializer init, LineBuildInfo info) @@ -84,7 +83,7 @@ namespace OpenRA.Mods.Common.Traits void INotifyLineBuildSegmentsChanged.SegmentAdded(Actor self, Actor segment) { - segments ??= new HashSet(); + segments ??= []; segments.Add(segment); } diff --git a/OpenRA.Mods.Common/Traits/Buildings/LineBuildNode.cs b/OpenRA.Mods.Common/Traits/Buildings/LineBuildNode.cs index 64684df026..038d535ae6 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/LineBuildNode.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/LineBuildNode.cs @@ -18,10 +18,10 @@ namespace OpenRA.Mods.Common.Traits public class LineBuildNodeInfo : TraitInfo { [Desc("This actor is of LineBuild 'NodeType'...")] - public readonly HashSet Types = new() { "wall" }; + public readonly HashSet Types = ["wall"]; [Desc("Cells (outside the footprint) that contain cells that can connect to this actor.")] - public readonly CVec[] Connections = new[] { new CVec(1, 0), new CVec(0, 1), new CVec(-1, 0), new CVec(0, -1) }; + public readonly CVec[] Connections = [new CVec(1, 0), new CVec(0, 1), new CVec(-1, 0), new CVec(0, -1)]; } public class LineBuildNode { } diff --git a/OpenRA.Mods.Common/Traits/Buildings/PrimaryBuilding.cs b/OpenRA.Mods.Common/Traits/Buildings/PrimaryBuilding.cs index a1922cf36d..b1f086c2c2 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/PrimaryBuilding.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/PrimaryBuilding.cs @@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits [Desc("List of production queues for which the primary flag should be set.", "If empty, the list given in the `Produces` property of the `" + nameof(Production) + "` trait will be used.")] - public readonly string[] ProductionQueues = Array.Empty(); + public readonly string[] ProductionQueues = []; [CursorReference] [Desc("Cursor to display when setting the primary building.")] diff --git a/OpenRA.Mods.Common/Traits/Buildings/ProductionAirdrop.cs b/OpenRA.Mods.Common/Traits/Buildings/ProductionAirdrop.cs index 0007894235..a951472ace 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/ProductionAirdrop.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/ProductionAirdrop.cs @@ -104,15 +104,15 @@ namespace OpenRA.Mods.Common.Traits return; } - var actor = w.CreateActor(info.ActorType, new TypeDictionary - { + var actor = w.CreateActor(info.ActorType, + [ new CenterPositionInit(w.Map.CenterOfCell(startPos) + new WVec(WDist.Zero, WDist.Zero, aircraftInfo.CruiseAltitude)), new OwnerInit(owner), new FacingInit(spawnFacing) - }); + ]); var exitCell = self.Location + exit.ExitCell; - actor.QueueActivity(new Land(actor, Target.FromActor(self), WDist.Zero, info.LandOffset, info.Facing, clearCells: new CPos[1] { exitCell })); + actor.QueueActivity(new Land(actor, Target.FromActor(self), WDist.Zero, info.LandOffset, info.Facing, clearCells: [exitCell])); if (info.WaitTickBeforeProduce > 0) actor.QueueActivity(new Wait(info.WaitTickBeforeProduce)); actor.QueueActivity(new CallFunc(() => diff --git a/OpenRA.Mods.Common/Traits/Buildings/RallyPoint.cs b/OpenRA.Mods.Common/Traits/Buildings/RallyPoint.cs index 34ed96ca53..d0e5aaa054 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/RallyPoint.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/RallyPoint.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using System.Linq; using OpenRA.Mods.Common.Effects; @@ -43,7 +42,7 @@ namespace OpenRA.Mods.Common.Traits public readonly bool IsPlayerPalette = true; [Desc("A list of 0 or more offsets defining the initial rally point path.")] - public readonly CVec[] Path = Array.Empty(); + public readonly CVec[] Path = []; [NotificationReference("Speech")] [Desc("Speech notification to play when setting a new rallypoint.")] diff --git a/OpenRA.Mods.Common/Traits/Buildings/RepairableBuilding.cs b/OpenRA.Mods.Common/Traits/Buildings/RepairableBuilding.cs index 73de472272..6c95305e1c 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/RepairableBuilding.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/RepairableBuilding.cs @@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Traits public readonly BitSet RepairDamageTypes = default; [Desc("The percentage repair bonus applied with increasing numbers of repairers.")] - public readonly int[] RepairBonuses = { 100, 150, 175, 200, 220, 240, 260, 280, 300 }; + public readonly int[] RepairBonuses = [100, 150, 175, 200, 220, 240, 260, 280, 300]; // TODO: This should be replaced with a pause condition [Desc("Cancel the repair state when the trait is disabled.")] @@ -68,10 +68,10 @@ namespace OpenRA.Mods.Common.Traits { readonly IHealth health; readonly Predicate isNotActiveAlly; - readonly Stack repairTokens = new(); + readonly Stack repairTokens = []; int remainingTicks; - public readonly List Repairers = new(); + public readonly List Repairers = []; public bool RepairActive { get; private set; } public RepairableBuilding(Actor self, RepairableBuildingInfo info) diff --git a/OpenRA.Mods.Common/Traits/Buildings/RequiresBuildableArea.cs b/OpenRA.Mods.Common/Traits/Buildings/RequiresBuildableArea.cs index 29f1530013..f8d3e28d1d 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/RequiresBuildableArea.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/RequiresBuildableArea.cs @@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.Traits { [FieldLoader.Require] [Desc("Types of buildable are this actor requires.")] - public readonly HashSet AreaTypes = new(); + public readonly HashSet AreaTypes = []; [Desc("Maximum range from the actor with 'GivesBuildableArea' this can be placed at.")] public readonly int Adjacent = 2; diff --git a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoAircraft.cs b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoAircraft.cs index 7d4333c418..37b395281a 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoAircraft.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoAircraft.cs @@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits [ActorReference] [FieldLoader.Require] - public readonly HashSet DockActors = new(); + public readonly HashSet DockActors = []; [VoiceReference] public readonly string Voice = "Action"; diff --git a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoMobile.cs b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoMobile.cs index d04046245d..c3a0ba77af 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoMobile.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoMobile.cs @@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Traits [CursorReference(dictionaryReference: LintDictionaryReference.Values)] [Desc("Cursor overrides to display for specific terrain types.", "A dictionary of [terrain type]: [cursor name].")] - public readonly Dictionary TerrainCursors = new(); + public readonly Dictionary TerrainCursors = []; [CursorReference] [Desc("Cursor to display when a move order cannot be issued at target location.")] diff --git a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoRepairable.cs b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoRepairable.cs index e569dce002..8ccedb95eb 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoRepairable.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoRepairable.cs @@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits { [ActorReference] [FieldLoader.Require] - public readonly HashSet RepairActors = new(); + public readonly HashSet RepairActors = []; [VoiceReference] public readonly string Voice = "Action"; diff --git a/OpenRA.Mods.Common/Traits/CapturableProgressBar.cs b/OpenRA.Mods.Common/Traits/CapturableProgressBar.cs index 8145e4fceb..5afd884d34 100644 --- a/OpenRA.Mods.Common/Traits/CapturableProgressBar.cs +++ b/OpenRA.Mods.Common/Traits/CapturableProgressBar.cs @@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits sealed class CapturableProgressBar : ConditionalTrait, ISelectionBar, ICaptureProgressWatcher { - readonly Dictionary progress = new(); + readonly Dictionary progress = []; public CapturableProgressBar(CapturableProgressBarInfo info) : base(info) { } diff --git a/OpenRA.Mods.Common/Traits/CapturableProgressBlink.cs b/OpenRA.Mods.Common/Traits/CapturableProgressBlink.cs index 84f278f54f..73f15ee486 100644 --- a/OpenRA.Mods.Common/Traits/CapturableProgressBlink.cs +++ b/OpenRA.Mods.Common/Traits/CapturableProgressBlink.cs @@ -30,8 +30,8 @@ namespace OpenRA.Mods.Common.Traits sealed class CapturableProgressBlink : ConditionalTrait, ITick, ICaptureProgressWatcher { - readonly List captorOwners = new(); - readonly HashSet captors = new(); + readonly List captorOwners = []; + readonly HashSet captors = []; int tick = 0; public CapturableProgressBlink(CapturableProgressBlinkInfo info) diff --git a/OpenRA.Mods.Common/Traits/CaptureManager.cs b/OpenRA.Mods.Common/Traits/CaptureManager.cs index e55696b9cc..eccadf15fc 100644 --- a/OpenRA.Mods.Common/Traits/CaptureManager.cs +++ b/OpenRA.Mods.Common/Traits/CaptureManager.cs @@ -66,7 +66,7 @@ namespace OpenRA.Mods.Common.Traits int beingCapturedToken = Actor.InvalidConditionToken; bool enteringCurrentTarget; - readonly HashSet currentCaptors = new(); + readonly HashSet currentCaptors = []; public bool BeingCaptured { get; private set; } diff --git a/OpenRA.Mods.Common/Traits/Cargo.cs b/OpenRA.Mods.Common/Traits/Cargo.cs index 4ab82c10e7..f237e550e6 100644 --- a/OpenRA.Mods.Common/Traits/Cargo.cs +++ b/OpenRA.Mods.Common/Traits/Cargo.cs @@ -26,10 +26,10 @@ namespace OpenRA.Mods.Common.Traits public readonly int MaxWeight = 0; [Desc("`Passenger.CargoType`s that can be loaded into this actor.")] - public readonly HashSet Types = new(); + public readonly HashSet Types = []; [Desc("A list of actor types that are initially spawned into this actor.")] - public readonly string[] InitialUnits = Array.Empty(); + public readonly string[] InitialUnits = []; [Desc("When this actor is sold should all of its passengers be unloaded?")] public readonly bool EjectOnSell = true; @@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits public readonly bool EjectOnDeath = false; [Desc("Terrain types that this actor is allowed to eject actors onto. Leave empty for all terrain types.")] - public readonly HashSet UnloadTerrainTypes = new(); + public readonly HashSet UnloadTerrainTypes = []; [VoiceReference] [Desc("Voice to play when ordered to unload the passengers.")] @@ -79,7 +79,7 @@ namespace OpenRA.Mods.Common.Traits [ActorReference(dictionaryReference: LintDictionaryReference.Keys)] [Desc("Conditions to grant when specified actors are loaded inside the transport.", "A dictionary of [actor name]: [condition].")] - public readonly Dictionary PassengerConditions = new(); + public readonly Dictionary PassengerConditions = []; [GrantedConditionReference] public IEnumerable LinterPassengerConditions => PassengerConditions.Values; @@ -92,9 +92,9 @@ namespace OpenRA.Mods.Common.Traits INotifyCreated, INotifyKilled, ITransformActorInitModifier { readonly Actor self; - readonly List cargo = new(); - readonly HashSet reserves = new(); - readonly Dictionary> passengerTokens = new(); + readonly List cargo = []; + readonly HashSet reserves = []; + readonly Dictionary> passengerTokens = []; readonly Lazy facing; readonly bool checkTerrainType; @@ -102,7 +102,7 @@ namespace OpenRA.Mods.Common.Traits int reservedWeight = 0; Aircraft aircraft; int loadingToken = Actor.InvalidConditionToken; - readonly Stack loadedTokens = new(); + readonly Stack loadedTokens = []; bool takeOffAfterLoad; bool initialised; @@ -130,7 +130,7 @@ namespace OpenRA.Mods.Common.Traits foreach (var u in cargoInit.Value) { var unit = self.World.CreateActor(false, u.ToLowerInvariant(), - new TypeDictionary { new OwnerInit(self.Owner) }); + [new OwnerInit(self.Owner)]); cargo.Add(unit); } @@ -142,7 +142,7 @@ namespace OpenRA.Mods.Common.Traits foreach (var u in info.InitialUnits) { var unit = self.World.CreateActor(false, u.ToLowerInvariant(), - new TypeDictionary { new OwnerInit(self.Owner) }); + [new OwnerInit(self.Owner)]); cargo.Add(unit); } diff --git a/OpenRA.Mods.Common/Traits/Carryall.cs b/OpenRA.Mods.Common/Traits/Carryall.cs index eaa086d27d..b0effb5b15 100644 --- a/OpenRA.Mods.Common/Traits/Carryall.cs +++ b/OpenRA.Mods.Common/Traits/Carryall.cs @@ -69,7 +69,7 @@ namespace OpenRA.Mods.Common.Traits [ActorReference(dictionaryReference: LintDictionaryReference.Keys)] [Desc("Conditions to grant when a specified actor is being carried.", "A dictionary of [actor name]: [condition].")] - public readonly Dictionary CarryableConditions = new(); + public readonly Dictionary CarryableConditions = []; [VoiceReference] public readonly string Voice = "Action"; @@ -128,11 +128,11 @@ namespace OpenRA.Mods.Common.Traits if (!string.IsNullOrEmpty(info.InitialActor)) { - var cargo = self.World.CreateActor(false, info.InitialActor.ToLowerInvariant(), new TypeDictionary - { + var cargo = self.World.CreateActor(false, info.InitialActor.ToLowerInvariant(), + [ new ParentActorInit(self), new OwnerInit(self.Owner) - }); + ]); cargo.Trait().Attached(cargo, self); AttachCarryable(self, cargo); diff --git a/OpenRA.Mods.Common/Traits/CombatDebugOverlay.cs b/OpenRA.Mods.Common/Traits/CombatDebugOverlay.cs index 58f3ca5cf9..7d7fd65b84 100644 --- a/OpenRA.Mods.Common/Traits/CombatDebugOverlay.cs +++ b/OpenRA.Mods.Common/Traits/CombatDebugOverlay.cs @@ -52,7 +52,7 @@ namespace OpenRA.Mods.Common.Traits IEnumerable IRenderAnnotations.RenderAnnotations(Actor self, WorldRenderer wr) { if (debugVis == null || !debugVis.CombatGeometry || self.World.FogObscures(self)) - return Enumerable.Empty(); + return []; return RenderAnnotations(self, wr); } diff --git a/OpenRA.Mods.Common/Traits/Conditions/ExternalCondition.cs b/OpenRA.Mods.Common/Traits/Conditions/ExternalCondition.cs index 522770b1bd..087f677a88 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/ExternalCondition.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/ExternalCondition.cs @@ -55,10 +55,10 @@ namespace OpenRA.Mods.Common.Traits } public readonly ExternalConditionInfo Info; - readonly Dictionary> permanentTokens = new(); + readonly Dictionary> permanentTokens = []; // Tokens are sorted on insert/remove by ascending expiry time - readonly List timedTokens = new(); + readonly List timedTokens = []; IConditionTimerWatcher[] watchers; int duration; int expires; @@ -147,7 +147,7 @@ namespace OpenRA.Mods.Common.Traits } } else if (permanent == null) - permanentTokens.Add(source, new HashSet { token }); + permanentTokens.Add(source, [token]); else permanent.Add(token); diff --git a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnAttack.cs b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnAttack.cs index 8909d0a068..c875c4365e 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnAttack.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnAttack.cs @@ -22,11 +22,11 @@ namespace OpenRA.Mods.Common.Traits public readonly string Condition = null; [Desc("Name of the armaments that grant this condition.")] - public readonly HashSet ArmamentNames = new() { "primary" }; + public readonly HashSet ArmamentNames = ["primary"]; [Desc("Shots required to apply an instance of the condition. If there are more instances of the condition granted than values listed,", "the last value is used for all following instances beyond the defined range.")] - public readonly int[] RequiredShotsPerInstance = { 1 }; + public readonly int[] RequiredShotsPerInstance = [1]; [Desc("Maximum instances of the condition to grant.")] public readonly int MaximumInstances = 1; @@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Traits public class GrantConditionOnAttack : PausableConditionalTrait, INotifyCreated, ITick, INotifyAttack { - readonly Stack tokens = new(); + readonly Stack tokens = []; int cooldown = 0; int shotsFired = 0; diff --git a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnBotOwner.cs b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnBotOwner.cs index ac886714ec..3bcda48aee 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnBotOwner.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnBotOwner.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Traits [FieldLoader.Require] [Desc("Bot types that trigger the condition.")] - public readonly string[] Bots = Array.Empty(); + public readonly string[] Bots = []; public override object Create(ActorInitializer init) { return new GrantConditionOnBotOwner(this); } } diff --git a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnDamageState.cs b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnDamageState.cs index 18bb28b67b..2c230d840b 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnDamageState.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnDamageState.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -23,10 +22,10 @@ namespace OpenRA.Mods.Common.Traits public readonly string Condition = null; [Desc("Play a random sound from this list when enabled.")] - public readonly string[] EnabledSounds = Array.Empty(); + public readonly string[] EnabledSounds = []; [Desc("Play a random sound from this list when disabled.")] - public readonly string[] DisabledSounds = Array.Empty(); + public readonly string[] DisabledSounds = []; [Desc("Levels of damage at which to grant the condition.")] public readonly DamageState ValidDamageStates = DamageState.Heavy | DamageState.Critical; diff --git a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnDeploy.cs b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnDeploy.cs index 9a42a7073a..a63596461d 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnDeploy.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnDeploy.cs @@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.Traits public readonly string DeployedCondition = null; [Desc("The terrain types that this actor can deploy on. Leave empty to allow any.")] - public readonly HashSet AllowedTerrainTypes = new(); + public readonly HashSet AllowedTerrainTypes = []; [Desc("Can this actor deploy on slopes?")] public readonly bool CanDeployOnRamps = false; diff --git a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnFaction.cs b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnFaction.cs index ef4575b0f5..2831119bfd 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnFaction.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnFaction.cs @@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits public readonly string Condition = null; [Desc("Only grant this condition for certain factions.")] - public readonly HashSet Factions = new(); + public readonly HashSet Factions = []; [Desc("Should it recheck everything when it is captured?")] public readonly bool ResetOnOwnerChange = false; diff --git a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnHealth.cs b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnHealth.cs index 0be4372118..7620f67f7b 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnHealth.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnHealth.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -23,10 +22,10 @@ namespace OpenRA.Mods.Common.Traits public readonly string Condition = null; [Desc("Play a random sound from this list when enabled.")] - public readonly string[] EnabledSounds = Array.Empty(); + public readonly string[] EnabledSounds = []; [Desc("Play a random sound from this list when disabled.")] - public readonly string[] DisabledSounds = Array.Empty(); + public readonly string[] DisabledSounds = []; [Desc("Minimum level of health at which to grant the condition.")] public readonly int MinHP = 0; diff --git a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnPrerequisite.cs b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnPrerequisite.cs index a0dd02baf8..47c1457a64 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnPrerequisite.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnPrerequisite.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -24,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits [FieldLoader.Require] [Desc("List of required prerequisites.")] - public readonly string[] Prerequisites = Array.Empty(); + public readonly string[] Prerequisites = []; public override object Create(ActorInitializer init) { return new GrantConditionOnPrerequisite(this); } } diff --git a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnProduction.cs b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnProduction.cs index c587da20f2..0bdf10960d 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnProduction.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnProduction.cs @@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits [ActorReference] [Desc("The actors to grant condition for. If empty condition will be granted for all actors.")] - public readonly HashSet Actors = new(); + public readonly HashSet Actors = []; [Desc("How long condition is applies for. Use -1 for infinite.")] public readonly int Duration = -1; diff --git a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnTerrain.cs b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnTerrain.cs index 3595565fc5..45937f42ba 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnTerrain.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnTerrain.cs @@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Traits [FieldLoader.Require] [Desc("Terrain names to trigger the condition.")] - public readonly string[] TerrainTypes = Array.Empty(); + public readonly string[] TerrainTypes = []; public override object Create(ActorInitializer init) { return new GrantConditionOnTerrain(init, this); } } diff --git a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnTileSet.cs b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnTileSet.cs index 144a231faf..fa6d3aa987 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnTileSet.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnTileSet.cs @@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Traits [FieldLoader.Require] [Desc("Tile set IDs to trigger the condition.")] - public readonly string[] TileSets = Array.Empty(); + public readonly string[] TileSets = []; public override object Create(ActorInitializer init) { return new GrantConditionOnTileSet(this); } } diff --git a/OpenRA.Mods.Common/Traits/Conditions/LineBuildSegmentExternalCondition.cs b/OpenRA.Mods.Common/Traits/Conditions/LineBuildSegmentExternalCondition.cs index 448be153c1..b64fd39d9d 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/LineBuildSegmentExternalCondition.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/LineBuildSegmentExternalCondition.cs @@ -27,8 +27,8 @@ namespace OpenRA.Mods.Common.Traits public class LineBuildSegmentExternalCondition : ConditionalTrait, INotifyLineBuildSegmentsChanged { - readonly HashSet segments = new(); - readonly Dictionary tokens = new(); + readonly HashSet segments = []; + readonly Dictionary tokens = []; public LineBuildSegmentExternalCondition(LineBuildSegmentExternalConditionInfo info) : base(info) { } diff --git a/OpenRA.Mods.Common/Traits/Conditions/ProximityExternalCondition.cs b/OpenRA.Mods.Common/Traits/Conditions/ProximityExternalCondition.cs index a93608f172..a0f896defb 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/ProximityExternalCondition.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/ProximityExternalCondition.cs @@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Traits { readonly Actor self; - readonly Dictionary tokens = new(); + readonly Dictionary tokens = []; int proximityTrigger; WPos cachedPosition; diff --git a/OpenRA.Mods.Common/Traits/Crates/Crate.cs b/OpenRA.Mods.Common/Traits/Crates/Crate.cs index 6ba5cccc96..c2d8b01c04 100644 --- a/OpenRA.Mods.Common/Traits/Crates/Crate.cs +++ b/OpenRA.Mods.Common/Traits/Crates/Crate.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Traits public readonly int Duration = 0; [Desc("Allowed to land on.")] - public readonly HashSet TerrainTypes = new(); + public readonly HashSet TerrainTypes = []; [Desc("Define actors that can collect crates by setting this into the Crushes field from the Mobile trait.")] public readonly string CrushClass = "crate"; @@ -187,7 +187,7 @@ namespace OpenRA.Mods.Common.Traits } public CPos TopLeft => Location; - public (CPos, SubCell)[] OccupiedCells() { return new[] { (Location, SubCell.FullCell) }; } + public (CPos, SubCell)[] OccupiedCells() { return [(Location, SubCell.FullCell)]; } public WPos CenterPosition { get; private set; } diff --git a/OpenRA.Mods.Common/Traits/Crates/CrateAction.cs b/OpenRA.Mods.Common/Traits/Crates/CrateAction.cs index d75e7c65b6..2a4e839388 100644 --- a/OpenRA.Mods.Common/Traits/Crates/CrateAction.cs +++ b/OpenRA.Mods.Common/Traits/Crates/CrateAction.cs @@ -47,11 +47,11 @@ namespace OpenRA.Mods.Common.Traits public readonly int TimeDelay = 0; [Desc("Only allow this crate action when the collector has these prerequisites")] - public readonly string[] Prerequisites = Array.Empty(); + public readonly string[] Prerequisites = []; [ActorReference] [Desc("Actor types that this crate action will not occur for.")] - public readonly string[] ExcludedActorTypes = Array.Empty(); + public readonly string[] ExcludedActorTypes = []; public override object Create(ActorInitializer init) { return new CrateAction(init.Self, this); } } diff --git a/OpenRA.Mods.Common/Traits/Crates/DuplicateUnitCrateAction.cs b/OpenRA.Mods.Common/Traits/Crates/DuplicateUnitCrateAction.cs index 39f3c2fb07..40b89fa2c1 100644 --- a/OpenRA.Mods.Common/Traits/Crates/DuplicateUnitCrateAction.cs +++ b/OpenRA.Mods.Common/Traits/Crates/DuplicateUnitCrateAction.cs @@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits public readonly BitSet ValidTargets = new("Ground", "Water"); [Desc("Which factions this crate action can occur for.")] - public readonly HashSet ValidFactions = new(); + public readonly HashSet ValidFactions = []; [Desc("Is the new duplicates given to a specific owner, regardless of whom collected it?")] public readonly string Owner = null; @@ -117,11 +117,11 @@ namespace OpenRA.Mods.Common.Traits for (var i = 0; i < duplicates; i++) { - var actor = w.CreateActor(collector.Info.Name, new TypeDictionary - { + var actor = w.CreateActor(collector.Info.Name, + [ new LocationInit(shuffledCandidateCells[i]), new OwnerInit(info.Owner ?? collector.Owner.InternalName) - }); + ]); // Set the subcell and make sure to crush actors beneath. var positionable = actor.OccupiesSpace as IPositionable; diff --git a/OpenRA.Mods.Common/Traits/Crates/GiveUnitCrateAction.cs b/OpenRA.Mods.Common/Traits/Crates/GiveUnitCrateAction.cs index 2fa3dcb6fd..eb9927a787 100644 --- a/OpenRA.Mods.Common/Traits/Crates/GiveUnitCrateAction.cs +++ b/OpenRA.Mods.Common/Traits/Crates/GiveUnitCrateAction.cs @@ -9,10 +9,8 @@ */ #endregion -using System; using System.Collections.Generic; using System.Linq; -using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -23,10 +21,10 @@ namespace OpenRA.Mods.Common.Traits [ActorReference] [FieldLoader.Require] [Desc("The list of units to spawn.")] - public readonly string[] Units = Array.Empty(); + public readonly string[] Units = []; [Desc("Factions that are allowed to trigger this action.")] - public readonly HashSet ValidFactions = new(); + public readonly HashSet ValidFactions = []; [Desc("Override the owner of the newly spawned unit: e.g. Creeps or Neutral")] public readonly string Owner = null; @@ -89,11 +87,11 @@ namespace OpenRA.Mods.Common.Traits var location = ChooseEmptyCellNear(collector, unit, pathFinder, locomotorsByName); if (location != null) { - var actor = w.CreateActor(unit, new TypeDictionary - { + var actor = w.CreateActor(unit, + [ new LocationInit(location.Value), new OwnerInit(info.Owner ?? collector.Owner.InternalName) - }); + ]); // Set the subcell and make sure to crush actors beneath. var positionable = actor.OccupiesSpace as IPositionable; diff --git a/OpenRA.Mods.Common/Traits/Crates/SupportPowerCrateAction.cs b/OpenRA.Mods.Common/Traits/Crates/SupportPowerCrateAction.cs index 8d43bf2e7a..776de1e233 100644 --- a/OpenRA.Mods.Common/Traits/Crates/SupportPowerCrateAction.cs +++ b/OpenRA.Mods.Common/Traits/Crates/SupportPowerCrateAction.cs @@ -9,7 +9,6 @@ */ #endregion -using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -38,10 +37,10 @@ namespace OpenRA.Mods.Common.Traits // We want neither of these properties for crate power proxies. public override void Activate(Actor collector) { - collector.World.AddFrameEndTask(w => w.CreateActor(info.Proxy, new TypeDictionary - { + collector.World.AddFrameEndTask(w => w.CreateActor(info.Proxy, + [ new OwnerInit(collector.Owner) - })); + ])); base.Activate(collector); } diff --git a/OpenRA.Mods.Common/Traits/DamagedByTerrain.cs b/OpenRA.Mods.Common/Traits/DamagedByTerrain.cs index af0cbd41df..0ccb622743 100644 --- a/OpenRA.Mods.Common/Traits/DamagedByTerrain.cs +++ b/OpenRA.Mods.Common/Traits/DamagedByTerrain.cs @@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits [FieldLoader.Require] [Desc("Terrain types where the actor will take damage.")] - public readonly string[] Terrain = Array.Empty(); + public readonly string[] Terrain = []; public override object Create(ActorInitializer init) { return new DamagedByTerrain(this); } } diff --git a/OpenRA.Mods.Common/Traits/DeliversCash.cs b/OpenRA.Mods.Common/Traits/DeliversCash.cs index e1567acd1b..5fb65b3f50 100644 --- a/OpenRA.Mods.Common/Traits/DeliversCash.cs +++ b/OpenRA.Mods.Common/Traits/DeliversCash.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using OpenRA.Mods.Common.Activities; using OpenRA.Mods.Common.Orders; @@ -31,7 +30,7 @@ namespace OpenRA.Mods.Common.Traits public readonly string Type = null; [Desc("Sound to play when delivering cash")] - public readonly string[] Sounds = Array.Empty(); + public readonly string[] Sounds = []; [CursorReference] [Desc("Cursor to display when hovering over a valid actor to deliver cash to.")] diff --git a/OpenRA.Mods.Common/Traits/Demolishable.cs b/OpenRA.Mods.Common/Traits/Demolishable.cs index 8c929e7d69..067aa4148c 100644 --- a/OpenRA.Mods.Common/Traits/Demolishable.cs +++ b/OpenRA.Mods.Common/Traits/Demolishable.cs @@ -46,8 +46,8 @@ namespace OpenRA.Mods.Common.Traits } } - readonly List actions = new(); - readonly List removeActions = new(); + readonly List actions = []; + readonly List removeActions = []; IDamageModifier[] damageModifiers; public Demolishable(DemolishableInfo info) diff --git a/OpenRA.Mods.Common/Traits/DockHost.cs b/OpenRA.Mods.Common/Traits/DockHost.cs index 9a4ddace25..9a38feb041 100644 --- a/OpenRA.Mods.Common/Traits/DockHost.cs +++ b/OpenRA.Mods.Common/Traits/DockHost.cs @@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Traits public bool IsEnabledAndInWorld => !preventDock && !IsTraitDisabled && !self.IsDead && self.IsInWorld; public int ReservationCount => ReservedDockClients.Count; public bool CanBeReserved => ReservationCount < Info.MaxQueueLength; - protected readonly List ReservedDockClients = new(); + protected readonly List ReservedDockClients = []; public WPos DockPosition => self.CenterPosition + Info.DockOffset; diff --git a/OpenRA.Mods.Common/Traits/FireProjectilesOnDeath.cs b/OpenRA.Mods.Common/Traits/FireProjectilesOnDeath.cs index a4daa0c357..68baf2d379 100644 --- a/OpenRA.Mods.Common/Traits/FireProjectilesOnDeath.cs +++ b/OpenRA.Mods.Common/Traits/FireProjectilesOnDeath.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Linq; using OpenRA.GameRules; using OpenRA.Traits; @@ -22,13 +21,13 @@ namespace OpenRA.Mods.Common.Traits [WeaponReference] [FieldLoader.Require] [Desc("The weapons used for shrapnel.")] - public readonly string[] Weapons = Array.Empty(); + public readonly string[] Weapons = []; [Desc("The amount of pieces of shrapnel to expel. Two values indicate a range.")] - public readonly int[] Pieces = { 3, 10 }; + public readonly int[] Pieces = [3, 10]; [Desc("The minimum and maximum distances the shrapnel may travel.")] - public readonly WDist[] Range = { WDist.FromCells(2), WDist.FromCells(5) }; + public readonly WDist[] Range = [WDist.FromCells(2), WDist.FromCells(5)]; public WeaponInfo[] WeaponInfos { get; private set; } diff --git a/OpenRA.Mods.Common/Traits/FireWarheads.cs b/OpenRA.Mods.Common/Traits/FireWarheads.cs index be819967ac..be6fd8da7d 100644 --- a/OpenRA.Mods.Common/Traits/FireWarheads.cs +++ b/OpenRA.Mods.Common/Traits/FireWarheads.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Linq; using OpenRA.GameRules; using OpenRA.Traits; @@ -22,7 +21,7 @@ namespace OpenRA.Mods.Common.Traits [WeaponReference] [FieldLoader.Require] [Desc("Weapons to fire.")] - public readonly string[] Weapons = Array.Empty(); + public readonly string[] Weapons = []; [Desc("How long (in ticks) to wait before the first detonation.")] public readonly int StartCooldown = 0; diff --git a/OpenRA.Mods.Common/Traits/GainsExperience.cs b/OpenRA.Mods.Common/Traits/GainsExperience.cs index 0574aaf72d..3ea5c2593a 100644 --- a/OpenRA.Mods.Common/Traits/GainsExperience.cs +++ b/OpenRA.Mods.Common/Traits/GainsExperience.cs @@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Traits readonly GainsExperienceInfo info; readonly int initialExperience; - readonly List<(int RequiredExperience, string Condition)> nextLevel = new(); + readonly List<(int RequiredExperience, string Condition)> nextLevel = []; // Stored as a percentage of our value [Sync] diff --git a/OpenRA.Mods.Common/Traits/GivesBounty.cs b/OpenRA.Mods.Common/Traits/GivesBounty.cs index a3701e488f..be2e55cf01 100644 --- a/OpenRA.Mods.Common/Traits/GivesBounty.cs +++ b/OpenRA.Mods.Common/Traits/GivesBounty.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits sealed class GivesBounty : ConditionalTrait, INotifyKilled, INotifyPassengerEntered, INotifyPassengerExited { - readonly Dictionary passengerBounties = new(); + readonly Dictionary passengerBounties = []; public GivesBounty(GivesBountyInfo info) : base(info) { } diff --git a/OpenRA.Mods.Common/Traits/GivesExperience.cs b/OpenRA.Mods.Common/Traits/GivesExperience.cs index 6ba0f4efad..554f898f06 100644 --- a/OpenRA.Mods.Common/Traits/GivesExperience.cs +++ b/OpenRA.Mods.Common/Traits/GivesExperience.cs @@ -73,7 +73,7 @@ namespace OpenRA.Mods.Common.Traits } e.Attacker.Owner.PlayerActor.TraitOrDefault() - ?.GiveExperience(Util.ApplyPercentageModifiers(exp, new[] { info.PlayerExperienceModifier })); + ?.GiveExperience(Util.ApplyPercentageModifiers(exp, [info.PlayerExperienceModifier])); } } } diff --git a/OpenRA.Mods.Common/Traits/Harvester.cs b/OpenRA.Mods.Common/Traits/Harvester.cs index 455edc2013..d240eed1da 100644 --- a/OpenRA.Mods.Common/Traits/Harvester.cs +++ b/OpenRA.Mods.Common/Traits/Harvester.cs @@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Traits public readonly int HarvestFacings = 0; [Desc("Which resources it can harvest.")] - public readonly string[] Resources = Array.Empty(); + public readonly string[] Resources = []; [Desc("Percentage of maximum speed when fully loaded.")] public readonly int FullyLoadedSpeed = 85; diff --git a/OpenRA.Mods.Common/Traits/HitShape.cs b/OpenRA.Mods.Common/Traits/HitShape.cs index 00c5039fcf..b044e9f0a5 100644 --- a/OpenRA.Mods.Common/Traits/HitShape.cs +++ b/OpenRA.Mods.Common/Traits/HitShape.cs @@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits public readonly string Turret = null; [Desc("Create a targetable position for each offset listed here (relative to CenterPosition).")] - public readonly WVec[] TargetableOffsets = { WVec.Zero }; + public readonly WVec[] TargetableOffsets = [WVec.Zero]; [Desc("Create a targetable position at the center of each occupied cell. Stacks with TargetableOffsets.")] public readonly bool UseTargetableCellsOffsets = false; @@ -99,7 +99,7 @@ namespace OpenRA.Mods.Common.Traits IEnumerable ITargetablePositions.TargetablePositions(Actor self) { if (IsTraitDisabled) - return Enumerable.Empty(); + return []; // Check for changes in inputs that affect the result of the TargetablePositions method. // If the inputs have not changed we can cache and reuse the result for later calls. diff --git a/OpenRA.Mods.Common/Traits/Husk.cs b/OpenRA.Mods.Common/Traits/Husk.cs index da42c3c3b3..e95baaa4de 100644 --- a/OpenRA.Mods.Common/Traits/Husk.cs +++ b/OpenRA.Mods.Common/Traits/Husk.cs @@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Traits [Desc("Spawns remains of a husk actor with the correct facing.")] public class HuskInfo : TraitInfo, IPositionableInfo, IFacingInfo, IActorPreviewInitInfo, IRulesetLoaded { - public readonly HashSet AllowedTerrain = new(); + public readonly HashSet AllowedTerrain = []; [Desc("Facing to use for actor previews (map editor, color picker, etc)")] public readonly WAngle PreviewFacing = new(384); @@ -126,7 +126,7 @@ namespace OpenRA.Mods.Common.Traits return true; } - public (CPos, SubCell)[] OccupiedCells() { return new[] { (TopLeft, SubCell.FullCell) }; } + public (CPos, SubCell)[] OccupiedCells() { return [(TopLeft, SubCell.FullCell)]; } public bool IsLeavingCell(CPos location, SubCell subCell = SubCell.Any) { return false; } public SubCell GetValidSubCell(SubCell preferred = SubCell.Any) { return SubCell.FullCell; } public SubCell GetAvailableSubCell(CPos cell, SubCell preferredSubCell = SubCell.Any, Actor ignoreActor = null, BlockedByActor check = BlockedByActor.All) diff --git a/OpenRA.Mods.Common/Traits/Immobile.cs b/OpenRA.Mods.Common/Traits/Immobile.cs index 67a7ff06a0..996b545226 100644 --- a/OpenRA.Mods.Common/Traits/Immobile.cs +++ b/OpenRA.Mods.Common/Traits/Immobile.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using OpenRA.Traits; @@ -23,7 +22,7 @@ namespace OpenRA.Mods.Common.Traits public IReadOnlyDictionary OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any) { return OccupiesSpace ? new Dictionary() { { location, SubCell.FullCell } } : - new Dictionary(); + []; } bool IOccupySpaceInfo.SharesCell => false; @@ -39,9 +38,9 @@ namespace OpenRA.Mods.Common.Traits CenterPosition = init.World.Map.CenterOfCell(TopLeft); if (info.OccupiesSpace) - occupied = new[] { (TopLeft, SubCell.FullCell) }; + occupied = [(TopLeft, SubCell.FullCell)]; else - occupied = Array.Empty<(CPos, SubCell)>(); + occupied = []; } [Sync] diff --git a/OpenRA.Mods.Common/Traits/Infantry/ScaredyCat.cs b/OpenRA.Mods.Common/Traits/Infantry/ScaredyCat.cs index bc76baf00e..5d9b116c7f 100644 --- a/OpenRA.Mods.Common/Traits/Infantry/ScaredyCat.cs +++ b/OpenRA.Mods.Common/Traits/Infantry/ScaredyCat.cs @@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits public readonly int AttackPanicChance = 20; [Desc("The terrain types that this actor should avoid running on to while panicking.")] - public readonly HashSet AvoidTerrainTypes = new(); + public readonly HashSet AvoidTerrainTypes = []; [SequenceReference(prefix: true)] public readonly string PanicSequencePrefix = "panic-"; diff --git a/OpenRA.Mods.Common/Traits/Infantry/TakeCover.cs b/OpenRA.Mods.Common/Traits/Infantry/TakeCover.cs index e05c9e20d5..0c9d284eab 100644 --- a/OpenRA.Mods.Common/Traits/Infantry/TakeCover.cs +++ b/OpenRA.Mods.Common/Traits/Infantry/TakeCover.cs @@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits public readonly BitSet DamageTriggers = default; [Desc("Damage modifiers for each damage type (defined on the warheads) while the unit is prone.")] - public readonly Dictionary DamageModifiers = new(); + public readonly Dictionary DamageModifiers = []; [Desc("Muzzle offset modifier to apply while prone.")] public readonly WVec ProneOffset = new(500, 0, 0); diff --git a/OpenRA.Mods.Common/Traits/IsometricSelectable.cs b/OpenRA.Mods.Common/Traits/IsometricSelectable.cs index 7c1bb07b5c..d39b0aff42 100644 --- a/OpenRA.Mods.Common/Traits/IsometricSelectable.cs +++ b/OpenRA.Mods.Common/Traits/IsometricSelectable.cs @@ -116,10 +116,10 @@ namespace OpenRA.Mods.Common.Traits } if (height == 0) - return new Polygon(new[] { top, left, bottom, right }); + return new Polygon([top, left, bottom, right]); var h = new int2(0, height); - return new Polygon(new[] { top - h, left - h, left, bottom, right, right - h }); + return new Polygon([top - h, left - h, left, bottom, right, right - h]); } public Polygon Bounds(Actor self, WorldRenderer wr) diff --git a/OpenRA.Mods.Common/Traits/KillsSelf.cs b/OpenRA.Mods.Common/Traits/KillsSelf.cs index 76bdcdc98b..4134d78d6a 100644 --- a/OpenRA.Mods.Common/Traits/KillsSelf.cs +++ b/OpenRA.Mods.Common/Traits/KillsSelf.cs @@ -20,7 +20,7 @@ namespace OpenRA.Mods.Common.Traits public readonly bool RemoveInstead = false; [Desc("The amount of time (in ticks) before the actor dies. Two values indicate a range between which a random value is chosen.")] - public readonly int[] Delay = { 0 }; + public readonly int[] Delay = [0]; [Desc("Types of damage that this trait causes. Leave empty for no damage types.")] public readonly BitSet DamageTypes = default; diff --git a/OpenRA.Mods.Common/Traits/Minelayer.cs b/OpenRA.Mods.Common/Traits/Minelayer.cs index 9e2add2ff9..1f3c961a1b 100644 --- a/OpenRA.Mods.Common/Traits/Minelayer.cs +++ b/OpenRA.Mods.Common/Traits/Minelayer.cs @@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Traits public readonly string TileUnknownName = "build-unknown"; [Desc("Only allow laying mines on listed terrain types. Leave empty to allow all terrain types.")] - public readonly HashSet TerrainTypes = new(); + public readonly HashSet TerrainTypes = []; [CursorReference] [Desc("Cursor to display when able to lay a mine.")] @@ -229,7 +229,7 @@ namespace OpenRA.Mods.Common.Traits public MinefieldOrderGenerator(Actor a, CPos xy, bool queued) { - minelayers = new List() { a }; + minelayers = [a]; minefieldStart = xy; this.queued = queued; diff --git a/OpenRA.Mods.Common/Traits/Mobile.cs b/OpenRA.Mods.Common/Traits/Mobile.cs index d43ef4a5ff..6b055b7311 100644 --- a/OpenRA.Mods.Common/Traits/Mobile.cs +++ b/OpenRA.Mods.Common/Traits/Mobile.cs @@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits [CursorReference(dictionaryReference: LintDictionaryReference.Values)] [Desc("Cursor overrides to display for specific terrain types.", "A dictionary of [terrain type]: [cursor name].")] - public readonly Dictionary TerrainCursors = new(); + public readonly Dictionary TerrainCursors = []; [CursorReference] [Desc("Cursor to display when a move order cannot be issued at target location.")] @@ -255,13 +255,13 @@ namespace OpenRA.Mods.Common.Traits public (CPos, SubCell)[] OccupiedCells() { if (FromCell == ToCell) - return new[] { (FromCell, FromSubCell) }; + return [(FromCell, FromSubCell)]; // HACK: Should be fixed properly, see https://github.com/OpenRA/OpenRA/pull/17292 for an explanation if (Info.LocomotorInfo.SharesCell) - return new[] { (ToCell, ToSubCell) }; + return [(ToCell, ToSubCell)]; - return new[] { (FromCell, FromSubCell), (ToCell, ToSubCell) }; + return [(FromCell, FromSubCell), (ToCell, ToSubCell)]; } #endregion @@ -819,7 +819,7 @@ namespace OpenRA.Mods.Common.Traits return above; var path = PathFinder.FindPathToTargetCellByPredicate( - self, new[] { self.Location }, loc => loc.Layer == 0 && CanEnterCell(loc), BlockedByActor.All); + self, [self.Location], loc => loc.Layer == 0 && CanEnterCell(loc), BlockedByActor.All); if (path.Count > 0) return path[0]; diff --git a/OpenRA.Mods.Common/Traits/Modifiers/FrozenUnderFog.cs b/OpenRA.Mods.Common/Traits/Modifiers/FrozenUnderFog.cs index 4e325b70dd..ccbc2254fa 100644 --- a/OpenRA.Mods.Common/Traits/Modifiers/FrozenUnderFog.cs +++ b/OpenRA.Mods.Common/Traits/Modifiers/FrozenUnderFog.cs @@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Traits var exploredMap = init.World.LobbyInfo.GlobalSettings.OptionOrDefault("explored", shroudInfo.ExploredMapCheckboxEnabled); startsRevealed = exploredMap && init.Contains() && !init.Contains(); var buildingInfo = init.Self.Info.TraitInfoOrDefault(); - var footprintCells = buildingInfo?.FrozenUnderFogTiles(init.Self.Location).ToList() ?? new List() { init.Self.Location }; + var footprintCells = buildingInfo?.FrozenUnderFogTiles(init.Self.Location).ToList() ?? [init.Self.Location]; footprint = footprintCells.SelectMany(c => map.ProjectedCellsCovering(c.ToMPos(map))).ToArray(); } diff --git a/OpenRA.Mods.Common/Traits/Multipliers/ProductionCostMultiplier.cs b/OpenRA.Mods.Common/Traits/Multipliers/ProductionCostMultiplier.cs index 60f8606e34..8cc2209d00 100644 --- a/OpenRA.Mods.Common/Traits/Multipliers/ProductionCostMultiplier.cs +++ b/OpenRA.Mods.Common/Traits/Multipliers/ProductionCostMultiplier.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using OpenRA.Traits; @@ -22,10 +21,10 @@ namespace OpenRA.Mods.Common.Traits public readonly int Multiplier = 100; [Desc("Only apply this cost change if owner has these prerequisites.")] - public readonly string[] Prerequisites = Array.Empty(); + public readonly string[] Prerequisites = []; [Desc("Queues that this cost will apply.")] - public readonly HashSet Queue = new(); + public readonly HashSet Queue = []; int IProductionCostModifierInfo.GetProductionCostModifier(TechTree techTree, string queue) { diff --git a/OpenRA.Mods.Common/Traits/Multipliers/ProductionTimeMultiplier.cs b/OpenRA.Mods.Common/Traits/Multipliers/ProductionTimeMultiplier.cs index 597f0703fa..bd1240a714 100644 --- a/OpenRA.Mods.Common/Traits/Multipliers/ProductionTimeMultiplier.cs +++ b/OpenRA.Mods.Common/Traits/Multipliers/ProductionTimeMultiplier.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using OpenRA.Traits; @@ -22,10 +21,10 @@ namespace OpenRA.Mods.Common.Traits public readonly int Multiplier = 100; [Desc("Only apply this time change if owner has these prerequisites.")] - public readonly string[] Prerequisites = Array.Empty(); + public readonly string[] Prerequisites = []; [Desc("Queues that this time will apply.")] - public readonly HashSet Queue = new(); + public readonly HashSet Queue = []; int IProductionTimeModifierInfo.GetProductionTimeModifier(TechTree techTree, string queue) { diff --git a/OpenRA.Mods.Common/Traits/PaletteEffects/CloakPaletteEffect.cs b/OpenRA.Mods.Common/Traits/PaletteEffects/CloakPaletteEffect.cs index e28e233547..92dce8270f 100644 --- a/OpenRA.Mods.Common/Traits/PaletteEffects/CloakPaletteEffect.cs +++ b/OpenRA.Mods.Common/Traits/PaletteEffects/CloakPaletteEffect.cs @@ -25,12 +25,12 @@ namespace OpenRA.Mods.Common.Traits readonly string paletteName = "cloak"; readonly Color[] colors = - { + [ Color.FromArgb(55, 205, 205, 220), Color.FromArgb(120, 205, 205, 230), Color.FromArgb(192, 180, 180, 255), Color.FromArgb(178, 205, 250, 220), - }; + ]; void IPaletteModifier.AdjustPalette(IReadOnlyDictionary b) { diff --git a/OpenRA.Mods.Common/Traits/PaletteEffects/RotationPaletteEffect.cs b/OpenRA.Mods.Common/Traits/PaletteEffects/RotationPaletteEffect.cs index c2c0c4dfc5..d0937a6010 100644 --- a/OpenRA.Mods.Common/Traits/PaletteEffects/RotationPaletteEffect.cs +++ b/OpenRA.Mods.Common/Traits/PaletteEffects/RotationPaletteEffect.cs @@ -22,17 +22,17 @@ namespace OpenRA.Mods.Common.Traits { [Desc("Defines to which palettes this effect should be applied to.", "If none specified, it applies to all palettes not explicitly excluded.")] - public readonly HashSet Palettes = new(); + public readonly HashSet Palettes = []; [Desc("Defines for which tileset IDs this effect should be loaded.", "If none specified, it applies to all tileset IDs not explicitly excluded.")] - public readonly HashSet Tilesets = new(); + public readonly HashSet Tilesets = []; [Desc("Defines which palettes should be excluded from this effect.")] - public readonly HashSet ExcludePalettes = new(); + public readonly HashSet ExcludePalettes = []; [Desc("Don't apply the effect for these tileset IDs.")] - public readonly HashSet ExcludeTilesets = new(); + public readonly HashSet ExcludeTilesets = []; [Desc("Palette index of first RotationRange color.")] public readonly int RotationBase = 0x60; diff --git a/OpenRA.Mods.Common/Traits/Palettes/ColorPickerPalette.cs b/OpenRA.Mods.Common/Traits/Palettes/ColorPickerPalette.cs index 15f5c2c40e..f789c650b7 100644 --- a/OpenRA.Mods.Common/Traits/Palettes/ColorPickerPalette.cs +++ b/OpenRA.Mods.Common/Traits/Palettes/ColorPickerPalette.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using System.Linq; using OpenRA.Graphics; @@ -33,7 +32,7 @@ namespace OpenRA.Mods.Common.Traits public readonly string BasePalette = null; [Desc("Remap these indices to player colors.")] - public readonly int[] RemapIndex = Array.Empty(); + public readonly int[] RemapIndex = []; [Desc("Allow palette modifiers to change the palette.")] public readonly bool AllowModifiers = true; diff --git a/OpenRA.Mods.Common/Traits/Palettes/FixedColorPalette.cs b/OpenRA.Mods.Common/Traits/Palettes/FixedColorPalette.cs index 43642a53dd..8d82c0f6ea 100644 --- a/OpenRA.Mods.Common/Traits/Palettes/FixedColorPalette.cs +++ b/OpenRA.Mods.Common/Traits/Palettes/FixedColorPalette.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Linq; using OpenRA.Graphics; using OpenRA.Primitives; @@ -30,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits public readonly string Name = "resources"; [Desc("Remap these indices to pre-defined colors.")] - public readonly int[] RemapIndex = Array.Empty(); + public readonly int[] RemapIndex = []; [Desc("The fixed color to remap.")] public readonly Color Color; diff --git a/OpenRA.Mods.Common/Traits/Palettes/IndexedPalette.cs b/OpenRA.Mods.Common/Traits/Palettes/IndexedPalette.cs index 19b6e9f84c..1ce4e15ddf 100644 --- a/OpenRA.Mods.Common/Traits/Palettes/IndexedPalette.cs +++ b/OpenRA.Mods.Common/Traits/Palettes/IndexedPalette.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using System.IO; using OpenRA.Graphics; @@ -33,11 +32,11 @@ namespace OpenRA.Mods.Common.Traits [FieldLoader.Require] [Desc("Indices from BasePalette to be swapped with ReplaceIndex.")] - public readonly int[] Index = Array.Empty(); + public readonly int[] Index = []; [FieldLoader.Require] [Desc("Indices from BasePalette to replace from Index.")] - public readonly int[] ReplaceIndex = Array.Empty(); + public readonly int[] ReplaceIndex = []; [Desc("Allow palette modifiers to change the palette.")] public readonly bool AllowModifiers = true; @@ -70,7 +69,7 @@ namespace OpenRA.Mods.Common.Traits public class IndexedColorRemap : IPaletteRemap { - readonly Dictionary replacements = new(); + readonly Dictionary replacements = []; readonly IPalette basePalette; public IndexedColorRemap(IPalette basePalette, int[] ramp, int[] remap) diff --git a/OpenRA.Mods.Common/Traits/Palettes/IndexedPlayerPalette.cs b/OpenRA.Mods.Common/Traits/Palettes/IndexedPlayerPalette.cs index 50031bde87..72c3bbcd49 100644 --- a/OpenRA.Mods.Common/Traits/Palettes/IndexedPlayerPalette.cs +++ b/OpenRA.Mods.Common/Traits/Palettes/IndexedPlayerPalette.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using System.Linq; using OpenRA.Graphics; @@ -31,7 +30,7 @@ namespace OpenRA.Mods.Common.Traits public readonly string BaseName = "player"; [Desc("Remap these indices to player colors.")] - public readonly int[] RemapIndex = Array.Empty(); + public readonly int[] RemapIndex = []; [Desc("Allow palette modifiers to change the palette.")] public readonly bool AllowModifiers = true; diff --git a/OpenRA.Mods.Common/Traits/Palettes/PaletteFromFile.cs b/OpenRA.Mods.Common/Traits/Palettes/PaletteFromFile.cs index 8a86c80cbc..5fc25512a6 100644 --- a/OpenRA.Mods.Common/Traits/Palettes/PaletteFromFile.cs +++ b/OpenRA.Mods.Common/Traits/Palettes/PaletteFromFile.cs @@ -34,10 +34,10 @@ namespace OpenRA.Mods.Common.Traits public readonly string Filename = null; [Desc("Map listed indices to transparent. Ignores previous color.")] - public readonly int[] TransparentIndex = { 0 }; + public readonly int[] TransparentIndex = [0]; [Desc("Map listed indices to shadow. Ignores previous color.")] - public readonly int[] ShadowIndex = Array.Empty(); + public readonly int[] ShadowIndex = []; public readonly bool AllowModifiers = true; diff --git a/OpenRA.Mods.Common/Traits/Palettes/PaletteFromGimpOrJascFile.cs b/OpenRA.Mods.Common/Traits/Palettes/PaletteFromGimpOrJascFile.cs index 222b5263dc..dfc1885f70 100644 --- a/OpenRA.Mods.Common/Traits/Palettes/PaletteFromGimpOrJascFile.cs +++ b/OpenRA.Mods.Common/Traits/Palettes/PaletteFromGimpOrJascFile.cs @@ -30,10 +30,10 @@ namespace OpenRA.Mods.Common.Traits [Desc("Defines for which tileset IDs this palette should be loaded.", "If none specified, it applies to all tileset IDs not explicitly excluded.")] - public readonly HashSet Tilesets = new(); + public readonly HashSet Tilesets = []; [Desc("Don't load palette for these tileset IDs.")] - public readonly HashSet ExcludeTilesets = new(); + public readonly HashSet ExcludeTilesets = []; [FieldLoader.Require] [Desc("Name of the file to load.")] diff --git a/OpenRA.Mods.Common/Traits/Palettes/PaletteFromPng.cs b/OpenRA.Mods.Common/Traits/Palettes/PaletteFromPng.cs index 3f8fff0e5d..c775e08e73 100644 --- a/OpenRA.Mods.Common/Traits/Palettes/PaletteFromPng.cs +++ b/OpenRA.Mods.Common/Traits/Palettes/PaletteFromPng.cs @@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Traits public readonly string Filename = null; [Desc("Map listed indices to shadow. Ignores previous color.")] - public readonly int[] ShadowIndex = Array.Empty(); + public readonly int[] ShadowIndex = []; public readonly bool AllowModifiers = true; diff --git a/OpenRA.Mods.Common/Traits/Palettes/PlayerColorPalette.cs b/OpenRA.Mods.Common/Traits/Palettes/PlayerColorPalette.cs index b2712c7ab9..7cba8ecded 100644 --- a/OpenRA.Mods.Common/Traits/Palettes/PlayerColorPalette.cs +++ b/OpenRA.Mods.Common/Traits/Palettes/PlayerColorPalette.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Linq; using OpenRA.Graphics; using OpenRA.Primitives; @@ -30,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits public readonly string BaseName = "player"; [Desc("Remap these indices to player colors.")] - public readonly int[] RemapIndex = Array.Empty(); + public readonly int[] RemapIndex = []; [Desc("Allow palette modifiers to change the palette.")] public readonly bool AllowModifiers = true; diff --git a/OpenRA.Mods.Common/Traits/Parachutable.cs b/OpenRA.Mods.Common/Traits/Parachutable.cs index 922358d062..bf6b9fecb7 100644 --- a/OpenRA.Mods.Common/Traits/Parachutable.cs +++ b/OpenRA.Mods.Common/Traits/Parachutable.cs @@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.Traits public readonly string WaterCorpsePalette = "effect"; [Desc("Terrain types on which to display WaterCorpseSequence.")] - public readonly HashSet WaterTerrainTypes = new() { "Water" }; + public readonly HashSet WaterTerrainTypes = ["Water"]; public readonly string WaterImpactSound = null; diff --git a/OpenRA.Mods.Common/Traits/Passenger.cs b/OpenRA.Mods.Common/Traits/Passenger.cs index d1793f7911..557ebe587c 100644 --- a/OpenRA.Mods.Common/Traits/Passenger.cs +++ b/OpenRA.Mods.Common/Traits/Passenger.cs @@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Traits [ActorReference(dictionaryReference: LintDictionaryReference.Keys)] [Desc("Conditions to grant when this actor is loaded inside specified transport.", "A dictionary of [actor name]: [condition].")] - public readonly Dictionary CargoConditions = new(); + public readonly Dictionary CargoConditions = []; [GrantedConditionReference] public IEnumerable LinterCargoConditions => CargoConditions.Values; diff --git a/OpenRA.Mods.Common/Traits/Player/ClassicParallelProductionQueue.cs b/OpenRA.Mods.Common/Traits/Player/ClassicParallelProductionQueue.cs index 310ddd5e9d..1f3fc60bdf 100644 --- a/OpenRA.Mods.Common/Traits/Player/ClassicParallelProductionQueue.cs +++ b/OpenRA.Mods.Common/Traits/Player/ClassicParallelProductionQueue.cs @@ -30,17 +30,17 @@ namespace OpenRA.Mods.Common.Traits [Desc("Every time another production building of the same queue is", "constructed, the build times of all actors in the queue", "modified by a percentage of the original time.")] - public readonly int[] BuildingCountBuildTimeMultipliers = { 100, 86, 75, 67, 60, 55, 50 }; + public readonly int[] BuildingCountBuildTimeMultipliers = [100, 86, 75, 67, 60, 55, 50]; [Desc("Build time modifier multiplied by the number of parallel production for producing different actors at the same time.")] - public readonly int[] ParallelPenaltyBuildTimeMultipliers = { 100, 116, 133, 150, 166, 183, 200, 216, 233, 250 }; + public readonly int[] ParallelPenaltyBuildTimeMultipliers = [100, 116, 133, 150, 166, 183, 200, 216, 233, 250]; public override object Create(ActorInitializer init) { return new ClassicParallelProductionQueue(init, this); } } public class ClassicParallelProductionQueue : ProductionQueue { - static readonly ActorInfo[] NoItems = Array.Empty(); + static readonly ActorInfo[] NoItems = []; readonly Actor self; readonly ClassicParallelProductionQueueInfo info; diff --git a/OpenRA.Mods.Common/Traits/Player/ClassicProductionQueue.cs b/OpenRA.Mods.Common/Traits/Player/ClassicProductionQueue.cs index 5b338d7985..89c67126b4 100644 --- a/OpenRA.Mods.Common/Traits/Player/ClassicProductionQueue.cs +++ b/OpenRA.Mods.Common/Traits/Player/ClassicProductionQueue.cs @@ -29,14 +29,14 @@ namespace OpenRA.Mods.Common.Traits [Desc("Every time another production building of the same queue is", "constructed, the build times of all actors in the queue", "decreased by a percentage of the original time.")] - public readonly int[] BuildTimeSpeedReduction = { 100, 86, 75, 67, 60, 55, 50 }; + public readonly int[] BuildTimeSpeedReduction = [100, 86, 75, 67, 60, 55, 50]; public override object Create(ActorInitializer init) { return new ClassicProductionQueue(init, this); } } public class ClassicProductionQueue : ProductionQueue { - static readonly ActorInfo[] NoItems = Array.Empty(); + static readonly ActorInfo[] NoItems = []; readonly Actor self; readonly ClassicProductionQueueInfo info; diff --git a/OpenRA.Mods.Common/Traits/Player/EnemyWatcher.cs b/OpenRA.Mods.Common/Traits/Player/EnemyWatcher.cs index aaaba27200..04576464e2 100644 --- a/OpenRA.Mods.Common/Traits/Player/EnemyWatcher.cs +++ b/OpenRA.Mods.Common/Traits/Player/EnemyWatcher.cs @@ -43,8 +43,8 @@ namespace OpenRA.Mods.Common.Traits public EnemyWatcher(EnemyWatcherInfo info) { - lastKnownActorIds = new HashSet(); - discoveredPlayers = new HashSet(); + lastKnownActorIds = []; + discoveredPlayers = []; this.info = info; rescanInterval = 0; ticksBeforeNextNotification = 0; @@ -67,8 +67,8 @@ namespace OpenRA.Mods.Common.Traits rescanInterval = info.ScanInterval; announcedAny = false; - visibleActorIds = new HashSet(); - playedNotifications = new HashSet(); + visibleActorIds = []; + playedNotifications = []; foreach (var actor in self.World.ActorsWithTrait()) { diff --git a/OpenRA.Mods.Common/Traits/Player/GrantConditionOnPrerequisiteManager.cs b/OpenRA.Mods.Common/Traits/Player/GrantConditionOnPrerequisiteManager.cs index 6b03706515..9a22780723 100644 --- a/OpenRA.Mods.Common/Traits/Player/GrantConditionOnPrerequisiteManager.cs +++ b/OpenRA.Mods.Common/Traits/Player/GrantConditionOnPrerequisiteManager.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Traits public class GrantConditionOnPrerequisiteManager : ITechTreeElement { readonly Actor self; - readonly Dictionary> upgradables = new(); + readonly Dictionary> upgradables = []; readonly TechTree techTree; public GrantConditionOnPrerequisiteManager(ActorInitializer init) @@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.Traits var key = MakeKey(prerequisites); if (!upgradables.TryGetValue(key, out var list)) { - upgradables.Add(key, list = new List<(Actor, GrantConditionOnPrerequisite)>()); + upgradables.Add(key, list = []); techTree.Add(key, prerequisites, 0, this); } diff --git a/OpenRA.Mods.Common/Traits/Player/LobbyPrerequisiteCheckbox.cs b/OpenRA.Mods.Common/Traits/Player/LobbyPrerequisiteCheckbox.cs index 2a0e4cecce..80811fce55 100644 --- a/OpenRA.Mods.Common/Traits/Player/LobbyPrerequisiteCheckbox.cs +++ b/OpenRA.Mods.Common/Traits/Player/LobbyPrerequisiteCheckbox.cs @@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.Traits [FieldLoader.Require] [Desc("Prerequisites to grant when this checkbox is enabled.")] - public readonly HashSet Prerequisites = new(); + public readonly HashSet Prerequisites = []; IEnumerable ITechTreePrerequisiteInfo.Prerequisites(ActorInfo info) { return Prerequisites; } @@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Traits public class LobbyPrerequisiteCheckbox : INotifyCreated, ITechTreePrerequisite { readonly LobbyPrerequisiteCheckboxInfo info; - HashSet prerequisites = new(); + HashSet prerequisites = []; public LobbyPrerequisiteCheckbox(LobbyPrerequisiteCheckboxInfo info) { diff --git a/OpenRA.Mods.Common/Traits/Player/MissionObjectives.cs b/OpenRA.Mods.Common/Traits/Player/MissionObjectives.cs index ffe0edacff..e4af268b7c 100644 --- a/OpenRA.Mods.Common/Traits/Player/MissionObjectives.cs +++ b/OpenRA.Mods.Common/Traits/Player/MissionObjectives.cs @@ -75,7 +75,7 @@ namespace OpenRA.Mods.Common.Traits public class MissionObjectives : INotifyWinStateChanged, ISync, IResolveOrder, IWorldLoaded { public readonly MissionObjectivesInfo Info; - readonly List objectives = new(); + readonly List objectives = []; readonly Player player; public IReadOnlyList Objectives => objectives; diff --git a/OpenRA.Mods.Common/Traits/Player/ModularBot.cs b/OpenRA.Mods.Common/Traits/Player/ModularBot.cs index e466716068..3643dec619 100644 --- a/OpenRA.Mods.Common/Traits/Player/ModularBot.cs +++ b/OpenRA.Mods.Common/Traits/Player/ModularBot.cs @@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Traits readonly ModularBotInfo info; readonly World world; - readonly Queue orders = new(); + readonly Queue orders = []; Player player; diff --git a/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs b/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs index 874d0f9b44..e02f149ed0 100644 --- a/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs +++ b/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs @@ -10,7 +10,6 @@ #endregion using System.Linq; -using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -121,13 +120,13 @@ namespace OpenRA.Mods.Common.Traits if (os == "LineBuild") { // Build the parent actor first - var placed = w.CreateActor(actorInfo.Name, new TypeDictionary - { + var placed = w.CreateActor(actorInfo.Name, + [ new LocationInit(targetLocation), new OwnerInit(order.Player), new FactionInit(faction), new PlaceBuildingInit() - }); + ]); foreach (var s in buildingInfo.BuildSounds) Game.Sound.PlayToPlayer(SoundType.World, order.Player, s, placed.CenterPosition); @@ -152,15 +151,15 @@ namespace OpenRA.Mods.Common.Traits if (a.TraitsImplementing().Any(r => !r.IsTraitDisabled && r.Info.Types.Overlaps(replaceableSegments))) self.World.Remove(a); - w.CreateActor(segmentType, new TypeDictionary - { + w.CreateActor(segmentType, + [ new LocationInit(t.Cell), new OwnerInit(order.Player), new FactionInit(faction), new LineBuildDirectionInit(t.Cell.X == targetLocation.X ? LineBuildDirection.Y : LineBuildDirection.X), - new LineBuildParentInit(new[] { t.Actor, placed }), + new LineBuildParentInit([t.Actor, placed]), new PlaceBuildingInit() - }); + ]); } } else if (os == "PlacePlug") @@ -192,13 +191,13 @@ namespace OpenRA.Mods.Common.Traits || !buildingInfo.IsCloseEnoughToBase(self.World, order.Player, actorInfo, targetLocation)) return; - var building = w.CreateActor(actorInfo.Name, new TypeDictionary - { + var building = w.CreateActor(actorInfo.Name, + [ new LocationInit(targetLocation), new OwnerInit(order.Player), new FactionInit(faction), new PlaceBuildingInit() - }); + ]); foreach (var s in buildingInfo.BuildSounds) Game.Sound.PlayToPlayer(SoundType.World, order.Player, s, building.CenterPosition); diff --git a/OpenRA.Mods.Common/Traits/Player/PlayerResources.cs b/OpenRA.Mods.Common/Traits/Player/PlayerResources.cs index 4e1017771b..7391fcf3d9 100644 --- a/OpenRA.Mods.Common/Traits/Player/PlayerResources.cs +++ b/OpenRA.Mods.Common/Traits/Player/PlayerResources.cs @@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Traits public readonly string DefaultCashDropdownDescription = "The amount of cash that players start with"; [Desc("Starting cash options that are available in the lobby options.")] - public readonly int[] SelectableCash = { 2500, 5000, 10000, 20000 }; + public readonly int[] SelectableCash = [2500, 5000, 10000, 20000]; [Desc("Default starting cash option: should be one of the SelectableCash options.")] public readonly int DefaultCash = 5000; @@ -59,7 +59,7 @@ namespace OpenRA.Mods.Common.Traits public readonly string CashTickDownNotification = null; [Desc("Monetary value of each resource type.", "Dictionary of [resource type]: [value per unit].")] - public readonly Dictionary ResourceValues = new(); + public readonly Dictionary ResourceValues = []; IEnumerable ILobbyOptions.LobbyOptions(MapPreview map) { diff --git a/OpenRA.Mods.Common/Traits/Player/ProductionQueue.cs b/OpenRA.Mods.Common/Traits/Player/ProductionQueue.cs index e360247636..2ad507ca9f 100644 --- a/OpenRA.Mods.Common/Traits/Player/ProductionQueue.cs +++ b/OpenRA.Mods.Common/Traits/Player/ProductionQueue.cs @@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Traits public readonly string Group = null; [Desc("Only enable this queue for certain factions.")] - public readonly HashSet Factions = new(); + public readonly HashSet Factions = []; [Desc("Should the prerequisite remain enabled if the owner changes?")] public readonly bool Sticky = true; @@ -137,8 +137,8 @@ namespace OpenRA.Mods.Common.Traits public readonly ProductionQueueInfo Info; // A list of things we could possibly build - protected readonly Dictionary Producible = new(); - protected readonly List Queue = new(); + protected readonly Dictionary Producible = []; + protected readonly List Queue = []; readonly IEnumerable allProducibles; readonly IEnumerable buildableProducibles; @@ -297,7 +297,7 @@ namespace OpenRA.Mods.Common.Traits public virtual IEnumerable AllItems() { if (productionTraits.Length > 0 && productionTraits.All(p => p.IsTraitDisabled)) - return Enumerable.Empty(); + return []; if (developerMode.AllTech) return Producible.Keys; @@ -307,9 +307,9 @@ namespace OpenRA.Mods.Common.Traits public virtual IEnumerable BuildableItems() { if (productionTraits.Length > 0 && productionTraits.All(p => p.IsTraitDisabled)) - return Enumerable.Empty(); + return []; if (!Enabled) - return Enumerable.Empty(); + return []; if (!Info.PayUpFront && developerMode.AllTech) return Producible.Keys; if (Info.PayUpFront && developerMode.AllTech) diff --git a/OpenRA.Mods.Common/Traits/Player/ProvidesPrerequisite.cs b/OpenRA.Mods.Common/Traits/Player/ProvidesPrerequisite.cs index edf60d03c3..d39fff42c7 100644 --- a/OpenRA.Mods.Common/Traits/Player/ProvidesPrerequisite.cs +++ b/OpenRA.Mods.Common/Traits/Player/ProvidesPrerequisite.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using System.Linq; using OpenRA.Traits; @@ -22,17 +21,17 @@ namespace OpenRA.Mods.Common.Traits public readonly string Prerequisite = null; [Desc("Only grant this prerequisite when you have these prerequisites.")] - public readonly string[] RequiresPrerequisites = Array.Empty(); + public readonly string[] RequiresPrerequisites = []; [Desc("Only grant this prerequisite for certain factions.")] - public readonly HashSet Factions = new(); + public readonly HashSet Factions = []; [Desc("Should it recheck everything when it is captured?")] public readonly bool ResetOnOwnerChange = false; IEnumerable ITechTreePrerequisiteInfo.Prerequisites(ActorInfo info) { - return new string[] { Prerequisite ?? info.Name }; + return [Prerequisite ?? info.Name]; } public override object Create(ActorInitializer init) { return new ProvidesPrerequisite(init, this); } @@ -50,9 +49,9 @@ namespace OpenRA.Mods.Common.Traits : base(info) { if (string.IsNullOrEmpty(info.Prerequisite)) - prerequisites = new[] { init.Self.Info.Name }; + prerequisites = [init.Self.Info.Name]; else - prerequisites = new[] { info.Prerequisite }; + prerequisites = [info.Prerequisite]; faction = init.GetValue(init.Self.Owner.Faction.InternalName); } diff --git a/OpenRA.Mods.Common/Traits/Player/ProvidesTechPrerequisite.cs b/OpenRA.Mods.Common/Traits/Player/ProvidesTechPrerequisite.cs index 60f8b26ee2..f363f344f2 100644 --- a/OpenRA.Mods.Common/Traits/Player/ProvidesTechPrerequisite.cs +++ b/OpenRA.Mods.Common/Traits/Player/ProvidesTechPrerequisite.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using System.Linq; using OpenRA.Traits; @@ -27,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits public readonly string Name; [Desc("Prerequisites to grant when this tech level is active.")] - public readonly string[] Prerequisites = Array.Empty(); + public readonly string[] Prerequisites = []; IEnumerable ITechTreePrerequisiteInfo.Prerequisites(ActorInfo info) { return Prerequisites; } diff --git a/OpenRA.Mods.Common/Traits/Player/TechTree.cs b/OpenRA.Mods.Common/Traits/Player/TechTree.cs index c5b6ab3c1d..1489b56a95 100644 --- a/OpenRA.Mods.Common/Traits/Player/TechTree.cs +++ b/OpenRA.Mods.Common/Traits/Player/TechTree.cs @@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Traits public class TechTree { - readonly List watchers = new(); + readonly List watchers = []; public TechTree(ActorInitializer init) { diff --git a/OpenRA.Mods.Common/Traits/Pluggable.cs b/OpenRA.Mods.Common/Traits/Pluggable.cs index 94906a95a1..7b9d30ebcd 100644 --- a/OpenRA.Mods.Common/Traits/Pluggable.cs +++ b/OpenRA.Mods.Common/Traits/Pluggable.cs @@ -30,12 +30,12 @@ namespace OpenRA.Mods.Common.Traits [Desc("Requirements for accepting a plug type.", "Key is the plug type that the requirements applies to.", "Value is the condition expression defining the requirements to place the plug.")] - public readonly Dictionary Requirements = new(); + public readonly Dictionary Requirements = []; [Desc("Options to display in the map editor.", "Key is the plug type that the requirements applies to.", "Value is the label that is displayed in the actor editor dropdown.")] - public readonly Dictionary EditorOptions = new(); + public readonly Dictionary EditorOptions = []; [Desc("Label to use for an empty plug socket.")] public readonly string EmptyOption = "Empty"; @@ -95,7 +95,7 @@ namespace OpenRA.Mods.Common.Traits if (info.Requirements.Count > 0) { - plugTypesAvailability = new Dictionary(); + plugTypesAvailability = []; foreach (var plug in info.Requirements) plugTypesAvailability[plug.Key] = true; } diff --git a/OpenRA.Mods.Common/Traits/Power/Player/PowerManager.cs b/OpenRA.Mods.Common/Traits/Power/Player/PowerManager.cs index 7315f18094..a996b82f84 100644 --- a/OpenRA.Mods.Common/Traits/Power/Player/PowerManager.cs +++ b/OpenRA.Mods.Common/Traits/Power/Player/PowerManager.cs @@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits readonly PowerManagerInfo info; readonly DeveloperMode devMode; - readonly Dictionary powerDrain = new(); + readonly Dictionary powerDrain = []; [Sync] public int PowerProvided { get; private set; } diff --git a/OpenRA.Mods.Common/Traits/ProducibleWithLevel.cs b/OpenRA.Mods.Common/Traits/ProducibleWithLevel.cs index 2212ec2246..c7b5dc549c 100644 --- a/OpenRA.Mods.Common/Traits/ProducibleWithLevel.cs +++ b/OpenRA.Mods.Common/Traits/ProducibleWithLevel.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -18,7 +17,7 @@ namespace OpenRA.Mods.Common.Traits "this trait grants a level-up to newly spawned actors.")] public class ProducibleWithLevelInfo : TraitInfo, Requires { - public readonly string[] Prerequisites = Array.Empty(); + public readonly string[] Prerequisites = []; [Desc("Number of levels to give to the actor on creation.")] public readonly int InitialLevels = 1; diff --git a/OpenRA.Mods.Common/Traits/Production.cs b/OpenRA.Mods.Common/Traits/Production.cs index 73a9ac2281..2f9119e55f 100644 --- a/OpenRA.Mods.Common/Traits/Production.cs +++ b/OpenRA.Mods.Common/Traits/Production.cs @@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Traits { [FieldLoader.Require] [Desc("e.g. Infantry, Vehicles, Aircraft, Buildings")] - public readonly string[] Produces = Array.Empty(); + public readonly string[] Produces = []; [Desc("When owner is changed, should the Faction be updated to the new owner's faction?")] public readonly bool UpdateFactionOnOwnerChange = false; @@ -78,7 +78,7 @@ namespace OpenRA.Mods.Common.Traits else initialFacing = exitinfo.Facing.Value; - exitLocations = rp != null && rp.Path.Count > 0 ? rp.Path : new List { exit }; + exitLocations = rp != null && rp.Path.Count > 0 ? rp.Path : [exit]; td.Add(new LocationInit(exit)); td.Add(new CenterPositionInit(spawn)); diff --git a/OpenRA.Mods.Common/Traits/ProductionFromMapEdge.cs b/OpenRA.Mods.Common/Traits/ProductionFromMapEdge.cs index bbcf99ad82..3f1cd61797 100644 --- a/OpenRA.Mods.Common/Traits/ProductionFromMapEdge.cs +++ b/OpenRA.Mods.Common/Traits/ProductionFromMapEdge.cs @@ -9,7 +9,6 @@ */ #endregion -using System.Collections.Generic; using System.Linq; using OpenRA.Primitives; using OpenRA.Traits; @@ -53,7 +52,7 @@ namespace OpenRA.Mods.Common.Traits var aircraftInfo = producee.TraitInfoOrDefault(); var mobileInfo = producee.TraitInfoOrDefault(); - var destinations = rp != null && rp.Path.Count > 0 ? rp.Path : new List { self.Location }; + var destinations = rp != null && rp.Path.Count > 0 ? rp.Path : [self.Location]; var location = spawnLocation; if (!location.HasValue) diff --git a/OpenRA.Mods.Common/Traits/ProductionParadrop.cs b/OpenRA.Mods.Common/Traits/ProductionParadrop.cs index b8584564f0..43fdcb5ef6 100644 --- a/OpenRA.Mods.Common/Traits/ProductionParadrop.cs +++ b/OpenRA.Mods.Common/Traits/ProductionParadrop.cs @@ -79,12 +79,12 @@ namespace OpenRA.Mods.Common.Traits } var altitude = self.World.Map.Rules.Actors[actorType].TraitInfo().CruiseAltitude; - var actor = w.CreateActor(actorType, new TypeDictionary - { + var actor = w.CreateActor(actorType, + [ new CenterPositionInit(w.Map.CenterOfCell(startPos) + new WVec(WDist.Zero, WDist.Zero, altitude)), new OwnerInit(owner), new FacingInit(new WAngle(256)), - }); + ]); actor.QueueActivity(new Fly(actor, Target.FromCell(w, dropPos))); actor.QueueActivity(new CallFunc(() => @@ -137,7 +137,7 @@ namespace OpenRA.Mods.Common.Traits var initialFacing = (exitinfo != null && exitinfo.Facing.HasValue) ? exitinfo.Facing.Value : (to - spawn).Yaw; - exitLocations = rp.Value != null && rp.Value.Path.Count > 0 ? rp.Value.Path : new List { exit }; + exitLocations = rp.Value != null && rp.Value.Path.Count > 0 ? rp.Value.Path : [exit]; td.Add(new LocationInit(exit)); td.Add(new CenterPositionInit(spawn)); diff --git a/OpenRA.Mods.Common/Traits/ProximityCapturableBase.cs b/OpenRA.Mods.Common/Traits/ProximityCapturableBase.cs index e333b9b671..5f908ee002 100644 --- a/OpenRA.Mods.Common/Traits/ProximityCapturableBase.cs +++ b/OpenRA.Mods.Common/Traits/ProximityCapturableBase.cs @@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Traits public ProximityCapturableBaseInfo Info; public Actor Self; - readonly List actorsInRange = new(); + readonly List actorsInRange = []; protected int trigger; WPos prevPosition; bool skipTriggerUpdate; @@ -202,9 +202,9 @@ namespace OpenRA.Mods.Common.Traits IEnumerable IRenderAnnotations.RenderAnnotations(Actor self, WorldRenderer wr) { if (!self.IsInWorld || !Info.DrawDecoration) - return Enumerable.Empty(); + return []; - return new[] { GetRenderable(self, wr) }; + return [GetRenderable(self, wr)]; } bool IRenderAnnotations.SpatiallyPartitionable { get { return false; } } diff --git a/OpenRA.Mods.Common/Traits/Rearmable.cs b/OpenRA.Mods.Common/Traits/Rearmable.cs index f6b9ed9f66..d85aafc242 100644 --- a/OpenRA.Mods.Common/Traits/Rearmable.cs +++ b/OpenRA.Mods.Common/Traits/Rearmable.cs @@ -20,10 +20,10 @@ namespace OpenRA.Mods.Common.Traits [ActorReference] [FieldLoader.Require] [Desc("Actors that this actor can dock to and get rearmed by.")] - public readonly HashSet RearmActors = new(); + public readonly HashSet RearmActors = []; [Desc("Name(s) of AmmoPool(s) that use this trait to rearm.")] - public readonly HashSet AmmoPools = new() { "primary" }; + public readonly HashSet AmmoPools = ["primary"]; public override object Create(ActorInitializer init) { return new Rearmable(this); } } diff --git a/OpenRA.Mods.Common/Traits/RegionProximityCapturable.cs b/OpenRA.Mods.Common/Traits/RegionProximityCapturable.cs index c7b4841b5d..bf041d761d 100644 --- a/OpenRA.Mods.Common/Traits/RegionProximityCapturable.cs +++ b/OpenRA.Mods.Common/Traits/RegionProximityCapturable.cs @@ -9,8 +9,6 @@ */ #endregion -using System; -using System.Collections.Generic; using System.Linq; using OpenRA.Graphics; using OpenRA.Mods.Common.Graphics; @@ -24,7 +22,7 @@ namespace OpenRA.Mods.Common.Traits [Desc("Set of cell offsets (relative to the actor's Location) the " + nameof(ProximityCaptor) + " needs to be in to initiate the capture. ", "A 'Region' ActorInit can be used to override this value per actor. If either is empty or non-existent, ", "the immediately neighboring cells of the actor will be used.")] - public readonly CVec[] Region = Array.Empty(); + public readonly CVec[] Region = []; public override object Create(ActorInitializer init) { return new RegionProximityCapturable(init, this); } } @@ -45,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits region = offsets.Select(o => o + self.Location).ToArray(); if (region.Length == 0) - region = Util.ExpandFootprint(new List { self.Location }, true).ToArray(); + region = Util.ExpandFootprint([self.Location], true).ToArray(); return self.World.ActorMap.AddCellTrigger(region, ActorEntered, ActorLeft); } diff --git a/OpenRA.Mods.Common/Traits/RejectsOrders.cs b/OpenRA.Mods.Common/Traits/RejectsOrders.cs index fcc05de895..8dc34bd9a8 100644 --- a/OpenRA.Mods.Common/Traits/RejectsOrders.cs +++ b/OpenRA.Mods.Common/Traits/RejectsOrders.cs @@ -18,11 +18,11 @@ namespace OpenRA.Mods.Common.Traits public class RejectsOrdersInfo : ConditionalTraitInfo { [Desc("Explicit list of rejected orders. Leave empty to reject all minus those listed under Except.")] - public readonly HashSet Reject = new(); + public readonly HashSet Reject = []; [Desc("List of orders that should *not* be rejected.", "Also overrides other instances of this trait's Reject fields.")] - public readonly HashSet Except = new(); + public readonly HashSet Except = []; [Desc("Remove current and all queued orders from the actor when this trait is enabled.")] public readonly bool RemoveOrders = false; diff --git a/OpenRA.Mods.Common/Traits/Render/Contrail.cs b/OpenRA.Mods.Common/Traits/Render/Contrail.cs index 5332b79b33..698b0aecb9 100644 --- a/OpenRA.Mods.Common/Traits/Render/Contrail.cs +++ b/OpenRA.Mods.Common/Traits/Render/Contrail.cs @@ -10,7 +10,6 @@ #endregion using System.Collections.Generic; -using System.Linq; using OpenRA.Graphics; using OpenRA.Mods.Common.Graphics; using OpenRA.Primitives; @@ -98,9 +97,9 @@ namespace OpenRA.Mods.Common.Traits IEnumerable IRender.Render(Actor self, WorldRenderer wr) { if (IsTraitDisabled) - return Enumerable.Empty(); + return []; - return new IRenderable[] { trail }; + return [trail]; } IEnumerable IRender.ScreenBounds(Actor self, WorldRenderer wr) diff --git a/OpenRA.Mods.Common/Traits/Render/DrawLineToTarget.cs b/OpenRA.Mods.Common/Traits/Render/DrawLineToTarget.cs index 3af2d84a2e..932f51f4ad 100644 --- a/OpenRA.Mods.Common/Traits/Render/DrawLineToTarget.cs +++ b/OpenRA.Mods.Common/Traits/Render/DrawLineToTarget.cs @@ -10,7 +10,6 @@ #endregion using System.Collections.Generic; -using System.Linq; using OpenRA.Graphics; using OpenRA.Mods.Common.Orders; using OpenRA.Traits; @@ -45,7 +44,7 @@ namespace OpenRA.Mods.Common.Traits public class DrawLineToTarget : IRenderAboveShroud, IRenderAnnotationsWhenSelected, INotifySelected { readonly DrawLineToTargetInfo info; - readonly List renderableCache = new(); + readonly List renderableCache = []; long lifetime; public DrawLineToTarget(DrawLineToTargetInfo info) @@ -81,7 +80,7 @@ namespace OpenRA.Mods.Common.Traits IEnumerable IRenderAboveShroud.RenderAboveShroud(Actor self, WorldRenderer wr) { if (!ShouldRender(self)) - return Enumerable.Empty(); + return []; return RenderAboveShroud(self, wr); } @@ -102,7 +101,7 @@ namespace OpenRA.Mods.Common.Traits IEnumerable IRenderAnnotationsWhenSelected.RenderAnnotations(Actor self, WorldRenderer wr) { if (!ShouldRender(self)) - return Enumerable.Empty(); + return []; renderableCache.Clear(); var prev = self.CenterPosition; @@ -120,14 +119,14 @@ namespace OpenRA.Mods.Common.Traits var markerWidth = renderableCache.Count > 0 ? info.QueuedMarkerWidth : info.MarkerWidth; var pos = n.Target.CenterPosition; - renderableCache.Add(new TargetLineRenderable(new[] { prev, pos }, n.Color, lineWidth, markerWidth)); + renderableCache.Add(new TargetLineRenderable([prev, pos], n.Color, lineWidth, markerWidth)); prev = pos; } } } if (renderableCache.Count == 0) - return Enumerable.Empty(); + return []; // Reverse draw order so target markers are drawn on top of the next line renderableCache.Reverse(); diff --git a/OpenRA.Mods.Common/Traits/Render/FloatingSpriteEmitter.cs b/OpenRA.Mods.Common/Traits/Render/FloatingSpriteEmitter.cs index 1a8cb149b2..5148aae767 100644 --- a/OpenRA.Mods.Common/Traits/Render/FloatingSpriteEmitter.cs +++ b/OpenRA.Mods.Common/Traits/Render/FloatingSpriteEmitter.cs @@ -26,13 +26,13 @@ namespace OpenRA.Mods.Common.Traits public readonly int Duration = -1; [Desc("Randomised offset for the particle emitter.")] - public readonly WVec[] Offset = { WVec.Zero }; + public readonly WVec[] Offset = [WVec.Zero]; [Desc("Randomized particle forward movement.")] - public readonly WDist[] Speed = { WDist.Zero }; + public readonly WDist[] Speed = [WDist.Zero]; [Desc("Randomized particle gravity.")] - public readonly WDist[] Gravity = { WDist.Zero }; + public readonly WDist[] Gravity = [WDist.Zero]; [Desc("Randomize particle facing.")] public readonly bool RandomFacing = true; @@ -44,14 +44,14 @@ namespace OpenRA.Mods.Common.Traits public readonly int RandomRate = 4; [Desc("How many particles should spawn. Two values for a random range.")] - public readonly int[] SpawnFrequency = { 1 }; + public readonly int[] SpawnFrequency = [1]; [Desc("Which image to use.")] public readonly string Image = "smoke"; [Desc("Which sequence to use.")] [SequenceReference(nameof(Image))] - public readonly string[] Sequences = { "particles" }; + public readonly string[] Sequences = ["particles"]; [Desc("Which palette to use.")] [PaletteReference(nameof(IsPlayerPalette))] diff --git a/OpenRA.Mods.Common/Traits/Render/LeavesTrails.cs b/OpenRA.Mods.Common/Traits/Render/LeavesTrails.cs index 1e9a28a17f..526bdc3b18 100644 --- a/OpenRA.Mods.Common/Traits/Render/LeavesTrails.cs +++ b/OpenRA.Mods.Common/Traits/Render/LeavesTrails.cs @@ -24,13 +24,13 @@ namespace OpenRA.Mods.Common.Traits.Render public readonly string Image = null; [SequenceReference(nameof(Image))] - public readonly string[] Sequences = { "idle" }; + public readonly string[] Sequences = ["idle"]; [PaletteReference] public readonly string Palette = "effect"; [Desc("Only leave trail on listed terrain types. Leave empty to leave trail on all terrain types.")] - public readonly HashSet TerrainTypes = new(); + public readonly HashSet TerrainTypes = []; [Desc("Accepts values: Cell to draw the trail sprite in the center of the current cell,", "CenterPosition to draw the trail sprite at the current position.")] @@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Traits.Render public readonly int StartDelay = 0; [Desc("Trail spawn positions relative to actor position. (forward, right, up) triples")] - public readonly WVec[] Offsets = { WVec.Zero }; + public readonly WVec[] Offsets = [WVec.Zero]; [Desc("Should the trail spawn relative to last position or current position?")] public readonly bool SpawnAtLastPosition = true; diff --git a/OpenRA.Mods.Common/Traits/Render/ProductionIconOverlayManager.cs b/OpenRA.Mods.Common/Traits/Render/ProductionIconOverlayManager.cs index 1cf2f64d4f..a3b1bc3986 100644 --- a/OpenRA.Mods.Common/Traits/Render/ProductionIconOverlayManager.cs +++ b/OpenRA.Mods.Common/Traits/Render/ProductionIconOverlayManager.cs @@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Traits.Render // This makes sure that the keys are unique with respect to the registering ITechTreeElement. readonly string prefix; - readonly Dictionary overlayActive = new(); + readonly Dictionary overlayActive = []; public ProductionIconOverlayManager(ActorInitializer init, ProductionIconOverlayManagerInfo info) { diff --git a/OpenRA.Mods.Common/Traits/Render/ReloadArmamentsBar.cs b/OpenRA.Mods.Common/Traits/Render/ReloadArmamentsBar.cs index 520d4bf4bc..94f8f44e0e 100644 --- a/OpenRA.Mods.Common/Traits/Render/ReloadArmamentsBar.cs +++ b/OpenRA.Mods.Common/Traits/Render/ReloadArmamentsBar.cs @@ -20,7 +20,7 @@ namespace OpenRA.Mods.Common.Traits.Render sealed class ReloadArmamentsBarInfo : TraitInfo { [Desc("Armament names")] - public readonly string[] Armaments = { "primary", "secondary" }; + public readonly string[] Armaments = ["primary", "secondary"]; public readonly Color Color = Color.Red; diff --git a/OpenRA.Mods.Common/Traits/Render/RenderMouseBounds.cs b/OpenRA.Mods.Common/Traits/Render/RenderMouseBounds.cs index 9255bd9a49..71025c6ff4 100644 --- a/OpenRA.Mods.Common/Traits/Render/RenderMouseBounds.cs +++ b/OpenRA.Mods.Common/Traits/Render/RenderMouseBounds.cs @@ -10,7 +10,6 @@ #endregion using System.Collections.Generic; -using System.Linq; using OpenRA.Graphics; using OpenRA.Mods.Common.Graphics; using OpenRA.Primitives; @@ -44,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits.Render IEnumerable IRenderAnnotations.RenderAnnotations(Actor self, WorldRenderer wr) { if (self.World.FogObscures(self)) - return Enumerable.Empty(); + return []; return DrawDecorations(self, wr); } diff --git a/OpenRA.Mods.Common/Traits/Render/RenderShroudCircle.cs b/OpenRA.Mods.Common/Traits/Render/RenderShroudCircle.cs index 86d164caf5..d1cb2013da 100644 --- a/OpenRA.Mods.Common/Traits/Render/RenderShroudCircle.cs +++ b/OpenRA.Mods.Common/Traits/Render/RenderShroudCircle.cs @@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Traits public IEnumerable RenderAnnotations(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition) { if (!EnabledByDefault) - return Enumerable.Empty(); + return []; var localRange = ai.TraitInfos() .Where(csi => csi.EnabledByDefault) diff --git a/OpenRA.Mods.Common/Traits/Render/RenderSprites.cs b/OpenRA.Mods.Common/Traits/Render/RenderSprites.cs index 9913be451c..f693f208b7 100644 --- a/OpenRA.Mods.Common/Traits/Render/RenderSprites.cs +++ b/OpenRA.Mods.Common/Traits/Render/RenderSprites.cs @@ -81,12 +81,12 @@ namespace OpenRA.Mods.Common.Traits.Render public class RenderSprites : IRender, ITick, INotifyOwnerChanged, INotifyEffectiveOwnerChanged, IActorPreviewInitModifier { static readonly (DamageState DamageState, string Prefix)[] DamagePrefixes = - { + [ (DamageState.Critical, "critical-"), (DamageState.Heavy, "damaged-"), (DamageState.Medium, "scratched-"), (DamageState.Light, "scuffed-") - }; + ]; sealed class AnimationWrapper { @@ -141,7 +141,7 @@ namespace OpenRA.Mods.Common.Traits.Render public readonly RenderSpritesInfo Info; readonly string faction; - readonly List anims = new(); + readonly List anims = []; string cachedImage; public static Func MakeFacingFunc(Actor self) diff --git a/OpenRA.Mods.Common/Traits/Render/SelectionDecorationsBase.cs b/OpenRA.Mods.Common/Traits/Render/SelectionDecorationsBase.cs index c4cc242ed8..07fdd64b4b 100644 --- a/OpenRA.Mods.Common/Traits/Render/SelectionDecorationsBase.cs +++ b/OpenRA.Mods.Common/Traits/Render/SelectionDecorationsBase.cs @@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Traits.Render IEnumerable IRenderAnnotations.RenderAnnotations(Actor self, WorldRenderer wr) { if (self.World.FogObscures(self)) - return Enumerable.Empty(); + return []; return DrawDecorations(self, wr); } diff --git a/OpenRA.Mods.Common/Traits/Render/WithAircraftLandingEffect.cs b/OpenRA.Mods.Common/Traits/Render/WithAircraftLandingEffect.cs index b4c786cfe8..c872a1de23 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithAircraftLandingEffect.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithAircraftLandingEffect.cs @@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits.Render public readonly string Image = null; [SequenceReference(nameof(Image))] - public readonly string[] Sequences = { "idle" }; + public readonly string[] Sequences = ["idle"]; [PaletteReference] public readonly string Palette = "effect"; @@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Traits.Render public readonly WDist DistanceAboveTerrain = new(756); [Desc("Only play on these terrain types.")] - public readonly HashSet TerrainTypes = new(); + public readonly HashSet TerrainTypes = []; public override object Create(ActorInitializer init) { return new WithAircraftLandingEffect(this); } } diff --git a/OpenRA.Mods.Common/Traits/Render/WithAmmoPipsDecoration.cs b/OpenRA.Mods.Common/Traits/Render/WithAmmoPipsDecoration.cs index 9113e68b51..59ea604f70 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithAmmoPipsDecoration.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithAmmoPipsDecoration.cs @@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Traits.Render public readonly string Palette = "chrome"; [Desc("Name(s) of AmmoPool(s) that use this decoration. Leave empty to include all pools.")] - public readonly string[] AmmoPools = Array.Empty(); + public readonly string[] AmmoPools = []; public override object Create(ActorInitializer init) { return new WithAmmoPipsDecoration(init.Self, this); } } diff --git a/OpenRA.Mods.Common/Traits/Render/WithBridgeSpriteBody.cs b/OpenRA.Mods.Common/Traits/Render/WithBridgeSpriteBody.cs index c5524487cc..6155c173e2 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithBridgeSpriteBody.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithBridgeSpriteBody.cs @@ -28,16 +28,16 @@ namespace OpenRA.Mods.Common.Traits.Render [SequenceReference] [Desc("Sequences to use when both neighbours are alive.")] - public readonly string[] Sequences = { "idle" }; + public readonly string[] Sequences = ["idle"]; [SequenceReference] - public readonly string[] ADestroyedSequences = { "adestroyed" }; + public readonly string[] ADestroyedSequences = ["adestroyed"]; [SequenceReference] - public readonly string[] BDestroyedSequences = { "bdestroyed" }; + public readonly string[] BDestroyedSequences = ["bdestroyed"]; [SequenceReference] - public readonly string[] ABDestroyedSequences = { "abdestroyed" }; + public readonly string[] ABDestroyedSequences = ["abdestroyed"]; public override object Create(ActorInitializer init) { return new WithBridgeSpriteBody(init, this); } diff --git a/OpenRA.Mods.Common/Traits/Render/WithCargoPipsDecoration.cs b/OpenRA.Mods.Common/Traits/Render/WithCargoPipsDecoration.cs index a8a11b2a99..a55f388834 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithCargoPipsDecoration.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithCargoPipsDecoration.cs @@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits.Render [SequenceReference(nameof(Image), dictionaryReference: LintDictionaryReference.Values)] [Desc("Pip sequence to use for specific passenger actors.")] - public readonly Dictionary CustomPipSequences = new(); + public readonly Dictionary CustomPipSequences = []; [PaletteReference] public readonly string Palette = "chrome"; diff --git a/OpenRA.Mods.Common/Traits/Render/WithCrateBody.cs b/OpenRA.Mods.Common/Traits/Render/WithCrateBody.cs index 8af987a513..59787aae62 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithCrateBody.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithCrateBody.cs @@ -21,10 +21,10 @@ namespace OpenRA.Mods.Common.Traits.Render sealed class WithCrateBodyInfo : TraitInfo, Requires, IRenderActorPreviewSpritesInfo { [Desc("Easteregg sequences to use in December.")] - public readonly string[] XmasImages = Array.Empty(); + public readonly string[] XmasImages = []; [Desc("Terrain types on which to display WaterSequence.")] - public readonly HashSet WaterTerrainTypes = new() { "Water" }; + public readonly HashSet WaterTerrainTypes = ["Water"]; [SequenceReference] public readonly string IdleSequence = "idle"; @@ -58,7 +58,7 @@ namespace OpenRA.Mods.Common.Traits.Render var rs = self.Trait(); var image = rs.GetImage(self); - var images = info.XmasImages.Length > 0 && DateTime.Today.Month == 12 ? info.XmasImages : new[] { image }; + var images = info.XmasImages.Length > 0 && DateTime.Today.Month == 12 ? info.XmasImages : [image]; anim = new Animation(self.World, images.Random(Game.CosmeticRandom)); anim.Play(info.IdleSequence); diff --git a/OpenRA.Mods.Common/Traits/Render/WithDeadBridgeSpriteBody.cs b/OpenRA.Mods.Common/Traits/Render/WithDeadBridgeSpriteBody.cs index 5a38bbc35f..8b9e70e3d4 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithDeadBridgeSpriteBody.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithDeadBridgeSpriteBody.cs @@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Traits.Render sealed class WithDeadBridgeSpriteBodyInfo : WithSpriteBodyInfo { [ActorReference] - public readonly string[] RampActors = Array.Empty(); + public readonly string[] RampActors = []; [Desc("Offset to search for the 'A' neighbour")] public readonly CVec AOffset = CVec.Zero; @@ -30,13 +30,13 @@ namespace OpenRA.Mods.Common.Traits.Render public readonly CVec BOffset = CVec.Zero; [SequenceReference] - public readonly string[] ARampSequences = { "aramp" }; + public readonly string[] ARampSequences = ["aramp"]; [SequenceReference] - public readonly string[] BRampSequences = { "bramp" }; + public readonly string[] BRampSequences = ["bramp"]; [SequenceReference] - public readonly string[] ABRampSequences = { "abramp" }; + public readonly string[] ABRampSequences = ["abramp"]; [SequenceReference] [Desc("Placeholder sequence to use in the map editor.")] diff --git a/OpenRA.Mods.Common/Traits/Render/WithDeathAnimation.cs b/OpenRA.Mods.Common/Traits/Render/WithDeathAnimation.cs index 58c1f21b5b..f79ef11ff3 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithDeathAnimation.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithDeathAnimation.cs @@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Traits.Render [Desc("Death animations to use for each damage type (defined on the warheads).", "Is only used if UseDeathTypeSuffix is `True`.")] - public readonly Dictionary DeathTypes = new(); + public readonly Dictionary DeathTypes = []; [SequenceReference] [Desc("Sequence to use when the actor is killed by some non-standard means (e.g. suicide).")] diff --git a/OpenRA.Mods.Common/Traits/Render/WithDecoration.cs b/OpenRA.Mods.Common/Traits/Render/WithDecoration.cs index 862fc708f9..aa3227a487 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithDecoration.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithDecoration.cs @@ -10,7 +10,6 @@ #endregion using System.Collections.Generic; -using System.Linq; using OpenRA.Graphics; using OpenRA.Traits; @@ -58,12 +57,12 @@ namespace OpenRA.Mods.Common.Traits.Render protected override IEnumerable RenderDecoration(Actor self, WorldRenderer wr, int2 screenPos) { if (anim == null) - return Enumerable.Empty(); + return []; - return new IRenderable[] - { + return + [ new UISpriteRenderable(anim.Image, self.CenterPosition, screenPos - (0.5f * anim.Image.Size.XY).ToInt2(), 0, GetPalette(self, wr)) - }; + ]; } void ITick.Tick(Actor self) { anim.Tick(); } diff --git a/OpenRA.Mods.Common/Traits/Render/WithDecorationBase.cs b/OpenRA.Mods.Common/Traits/Render/WithDecorationBase.cs index 6e5e6aca8e..e7e755692f 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithDecorationBase.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithDecorationBase.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using System.Linq; using OpenRA.Graphics; @@ -36,17 +35,17 @@ namespace OpenRA.Mods.Common.Traits.Render [Desc("Screen-space offsets to apply when defined conditions are enabled.", "A dictionary of [condition string]: [x, y offset].")] - public readonly Dictionary Offsets = new(); + public readonly Dictionary Offsets = []; [Desc("The number of ticks that each step in the blink pattern in active.")] public readonly int BlinkInterval = 5; [Desc("A pattern of ticks (BlinkInterval long) where the decoration is visible or hidden.")] - public readonly BlinkState[] BlinkPattern = Array.Empty(); + public readonly BlinkState[] BlinkPattern = []; [Desc("Override blink conditions to use when defined conditions are enabled.", "A dictionary of [condition string]: [pattern].")] - public readonly Dictionary BlinkPatterns = new(); + public readonly Dictionary BlinkPatterns = []; [ConsumedConditionReference] public IEnumerable ConsumedConditions @@ -97,7 +96,7 @@ namespace OpenRA.Mods.Common.Traits.Render IEnumerable IDecoration.RenderDecoration(Actor self, WorldRenderer wr, ISelectionDecorations container) { if (IsTraitDisabled || self.IsDead || !self.IsInWorld || !ShouldRender(self)) - return Enumerable.Empty(); + return []; var screenPos = container.GetDecorationOrigin(self, wr, Info.Position, Info.Margin) + conditionalOffset; return RenderDecoration(self, wr, screenPos); diff --git a/OpenRA.Mods.Common/Traits/Render/WithGateSpriteBody.cs b/OpenRA.Mods.Common/Traits/Render/WithGateSpriteBody.cs index 55de51945d..98d936ae36 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithGateSpriteBody.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithGateSpriteBody.cs @@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Traits.Render sealed class WithGateSpriteBodyInfo : WithSpriteBodyInfo, IWallConnectorInfo, Requires { [Desc("Cells (outside the gate footprint) that contain wall cells that can connect to the gate")] - public readonly CVec[] WallConnections = Array.Empty(); + public readonly CVec[] WallConnections = []; [Desc("Wall type for connections")] public readonly string Type = "wall"; diff --git a/OpenRA.Mods.Common/Traits/Render/WithIdleAnimation.cs b/OpenRA.Mods.Common/Traits/Render/WithIdleAnimation.cs index 895c8d22ff..84efee86df 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithIdleAnimation.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithIdleAnimation.cs @@ -19,10 +19,10 @@ namespace OpenRA.Mods.Common.Traits.Render { [SequenceReference] [Desc("Sequence names to use.")] - public readonly string[] Sequences = { "active" }; + public readonly string[] Sequences = ["active"]; [Desc("The amount of time (in ticks) between animations. Two values indicate a range between which a random value is chosen.")] - public readonly int[] Interval = { 750 }; + public readonly int[] Interval = [750]; [Desc("Which sprite body to play the animation on.")] public readonly string Body = "body"; diff --git a/OpenRA.Mods.Common/Traits/Render/WithInfantryBody.cs b/OpenRA.Mods.Common/Traits/Render/WithInfantryBody.cs index 7fe352db6f..975a6a01d8 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithInfantryBody.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithInfantryBody.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using OpenRA.Graphics; using OpenRA.Mods.Common.Graphics; @@ -32,13 +31,13 @@ namespace OpenRA.Mods.Common.Traits.Render [Desc("Attack sequence to use for each armament.", "A dictionary of [armament name]: [sequence name(s)].", "Multiple sequence names can be defined to specify per-burst animations.")] - public readonly Dictionary AttackSequences = new(); + public readonly Dictionary AttackSequences = []; [SequenceReference] - public readonly string[] IdleSequences = Array.Empty(); + public readonly string[] IdleSequences = []; [SequenceReference] - public readonly string[] StandSequences = { "stand" }; + public readonly string[] StandSequences = ["stand"]; [PaletteReference(nameof(IsPlayerPalette))] [Desc("Custom palette name")] diff --git a/OpenRA.Mods.Common/Traits/Render/WithMakeAnimation.cs b/OpenRA.Mods.Common/Traits/Render/WithMakeAnimation.cs index c469ee8dda..aeee08c57d 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithMakeAnimation.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithMakeAnimation.cs @@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits.Render public readonly string Condition = null; [Desc("Apply to sprite bodies with these names.")] - public readonly string[] BodyNames = { "body" }; + public readonly string[] BodyNames = ["body"]; public override object Create(ActorInitializer init) { return new WithMakeAnimation(init, this); } } diff --git a/OpenRA.Mods.Common/Traits/Render/WithMuzzleOverlay.cs b/OpenRA.Mods.Common/Traits/Render/WithMuzzleOverlay.cs index c0c9a5f8e2..9498feb91e 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithMuzzleOverlay.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithMuzzleOverlay.cs @@ -29,8 +29,8 @@ namespace OpenRA.Mods.Common.Traits.Render sealed class WithMuzzleOverlay : ConditionalTrait, INotifyAttack, IRender, ITick { - readonly Dictionary visible = new(); - readonly Dictionary anims = new(); + readonly Dictionary visible = []; + readonly Dictionary anims = []; readonly Func getFacing; readonly Armament[] armaments; diff --git a/OpenRA.Mods.Common/Traits/Render/WithNameTagDecoration.cs b/OpenRA.Mods.Common/Traits/Render/WithNameTagDecoration.cs index e97e0d1953..6c6d222291 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithNameTagDecoration.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithNameTagDecoration.cs @@ -10,7 +10,6 @@ #endregion using System.Collections.Generic; -using System.Linq; using OpenRA.Graphics; using OpenRA.Mods.Common.Graphics; using OpenRA.Primitives; @@ -62,13 +61,13 @@ namespace OpenRA.Mods.Common.Traits.Render protected override IEnumerable RenderDecoration(Actor self, WorldRenderer wr, int2 screenPos) { if (IsTraitDisabled || self.IsDead || !self.IsInWorld || !ShouldRender(self)) - return Enumerable.Empty(); + return []; var size = font.Measure(name); - return new IRenderable[] - { + return + [ new UITextRenderable(font, self.CenterPosition, screenPos - size / 2, 0, info.UsePlayerColor ? self.OwnerColor() : info.Color, name) - }; + ]; } void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) diff --git a/OpenRA.Mods.Common/Traits/Render/WithParachute.cs b/OpenRA.Mods.Common/Traits/Render/WithParachute.cs index cce94336df..990fefeeb5 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithParachute.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithParachute.cs @@ -11,7 +11,6 @@ using System; using System.Collections.Generic; -using System.Linq; using OpenRA.Graphics; using OpenRA.Mods.Common.Graphics; using OpenRA.Primitives; @@ -169,39 +168,39 @@ namespace OpenRA.Mods.Common.Traits.Render IEnumerable IRender.Render(Actor self, WorldRenderer wr) { if (info.ShadowImage == null) - return Enumerable.Empty(); + return []; if (IsTraitDisabled || self.IsDead || !self.IsInWorld) - return Enumerable.Empty(); + return []; if (self.World.FogObscures(self)) - return Enumerable.Empty(); + return []; var dat = self.World.Map.DistanceAboveTerrain(self.CenterPosition); var pos = self.CenterPosition - new WVec(0, 0, dat.Length); var palette = wr.Palette(info.Palette); var alpha = shadow.CurrentSequence.GetAlpha(shadow.CurrentFrame); var tintModifiers = shadow.CurrentSequence.IgnoreWorldTint ? TintModifiers.ReplaceColor | TintModifiers.IgnoreWorldTint : TintModifiers.ReplaceColor; - return new IRenderable[] - { + return + [ new SpriteRenderable(shadow.Image, pos, info.ShadowOffset, info.ShadowZOffset, palette, 1, shadowAlpha * alpha, shadowColor, tintModifiers, true) - }; + ]; } IEnumerable IRender.ScreenBounds(Actor self, WorldRenderer wr) { if (info.ShadowImage == null) - return Enumerable.Empty(); + return []; if (IsTraitDisabled || self.IsDead || !self.IsInWorld) - return Enumerable.Empty(); + return []; if (self.World.FogObscures(self)) - return Enumerable.Empty(); + return []; var dat = self.World.Map.DistanceAboveTerrain(self.CenterPosition); var pos = self.CenterPosition - new WVec(0, 0, dat.Length); - return new Rectangle[] { shadow.ScreenBounds(wr, pos, info.ShadowOffset) }; + return [shadow.ScreenBounds(wr, pos, info.ShadowOffset)]; } } } diff --git a/OpenRA.Mods.Common/Traits/Render/WithProductionIconOverlay.cs b/OpenRA.Mods.Common/Traits/Render/WithProductionIconOverlay.cs index 9aa88c838d..f73865216f 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithProductionIconOverlay.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithProductionIconOverlay.cs @@ -19,9 +19,9 @@ namespace OpenRA.Mods.Common.Traits.Render public class WithProductionIconOverlayInfo : TraitInfo, IRulesetLoaded { [FieldLoader.Require] - public readonly string[] Types = Array.Empty(); + public readonly string[] Types = []; - public readonly string[] Prerequisites = Array.Empty(); + public readonly string[] Prerequisites = []; public virtual void RulesetLoaded(Ruleset rules, ActorInfo ai) { diff --git a/OpenRA.Mods.Common/Traits/Render/WithProductionOverlay.cs b/OpenRA.Mods.Common/Traits/Render/WithProductionOverlay.cs index 2cabc01f53..a8621fd53a 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithProductionOverlay.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithProductionOverlay.cs @@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Traits.Render public class WithProductionOverlayInfo : PausableConditionalTraitInfo, Requires, Requires, Requires { [Desc("Queues that should be producing for this overlay to render.")] - public readonly HashSet Queues = new(); + public readonly HashSet Queues = []; [SequenceReference] [Desc("Sequence name to use")] diff --git a/OpenRA.Mods.Common/Traits/Render/WithSpriteControlGroupDecoration.cs b/OpenRA.Mods.Common/Traits/Render/WithSpriteControlGroupDecoration.cs index 4f4bc0610d..32b7dc3758 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithSpriteControlGroupDecoration.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithSpriteControlGroupDecoration.cs @@ -10,7 +10,6 @@ #endregion using System.Collections.Generic; -using System.Linq; using OpenRA.Graphics; using OpenRA.Traits; @@ -54,16 +53,16 @@ namespace OpenRA.Mods.Common.Traits.Render { var group = self.World.ControlGroups.GetControlGroupForActor(self); if (group == null) - return Enumerable.Empty(); + return []; anim.PlayFetchIndex(Info.GroupSequence, () => (int)group); var screenPos = container.GetDecorationOrigin(self, wr, Info.Position, Info.Margin) - (0.5f * anim.Image.Size.XY).ToInt2(); var palette = wr.Palette(Info.Palette); - return new IRenderable[] - { + return + [ new UISpriteRenderable(anim.Image, self.CenterPosition, screenPos, 0, palette) - }; + ]; } } } diff --git a/OpenRA.Mods.Common/Traits/Render/WithStoresResourcesPipsDecoration.cs b/OpenRA.Mods.Common/Traits/Render/WithStoresResourcesPipsDecoration.cs index 167578f662..63bfd0a21a 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithStoresResourcesPipsDecoration.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithStoresResourcesPipsDecoration.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits.Render [SequenceReference(nameof(Image), dictionaryReference: LintDictionaryReference.Values)] [Desc("Pip sequence to use for specific resource types.")] - public readonly Dictionary ResourceSequences = new(); + public readonly Dictionary ResourceSequences = []; [PaletteReference] public readonly string Palette = "chrome"; diff --git a/OpenRA.Mods.Common/Traits/Render/WithTextControlGroupDecoration.cs b/OpenRA.Mods.Common/Traits/Render/WithTextControlGroupDecoration.cs index 2f69fe0cdd..29b65a7816 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithTextControlGroupDecoration.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithTextControlGroupDecoration.cs @@ -10,7 +10,6 @@ #endregion using System.Collections.Generic; -using System.Linq; using OpenRA.Graphics; using OpenRA.Mods.Common.Graphics; using OpenRA.Primitives; @@ -63,14 +62,14 @@ namespace OpenRA.Mods.Common.Traits.Render { var group = self.World.ControlGroups.GetControlGroupForActor(self); if (group == null) - return Enumerable.Empty(); + return []; var text = label.Update(group.Value); var screenPos = container.GetDecorationOrigin(self, wr, info.Position, info.Margin); - return new IRenderable[] - { + return + [ new UITextRenderable(font, self.CenterPosition, screenPos, 0, info.UsePlayerColor ? self.OwnerColor() : info.Color, text) - }; + ]; } } } diff --git a/OpenRA.Mods.Common/Traits/Render/WithTextDecoration.cs b/OpenRA.Mods.Common/Traits/Render/WithTextDecoration.cs index 046616762e..4ad093fc1f 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithTextDecoration.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithTextDecoration.cs @@ -10,7 +10,6 @@ #endregion using System.Collections.Generic; -using System.Linq; using OpenRA.Graphics; using OpenRA.Mods.Common.Graphics; using OpenRA.Primitives; @@ -58,13 +57,13 @@ namespace OpenRA.Mods.Common.Traits.Render protected override IEnumerable RenderDecoration(Actor self, WorldRenderer wr, int2 screenPos) { if (IsTraitDisabled || self.IsDead || !self.IsInWorld || !ShouldRender(self)) - return Enumerable.Empty(); + return []; var size = font.Measure(Info.Text); - return new IRenderable[] - { + return + [ new UITextRenderable(font, self.CenterPosition, screenPos - size / 2, 0, color, Info.Text) - }; + ]; } void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) diff --git a/OpenRA.Mods.Common/Traits/Repairable.cs b/OpenRA.Mods.Common/Traits/Repairable.cs index ca00f98720..37e40e495c 100644 --- a/OpenRA.Mods.Common/Traits/Repairable.cs +++ b/OpenRA.Mods.Common/Traits/Repairable.cs @@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits { [ActorReference] [FieldLoader.Require] - public readonly HashSet RepairActors = new(); + public readonly HashSet RepairActors = []; [VoiceReference] public readonly string Voice = "Action"; diff --git a/OpenRA.Mods.Common/Traits/RepairableNear.cs b/OpenRA.Mods.Common/Traits/RepairableNear.cs index 616b67739f..c75f5a7678 100644 --- a/OpenRA.Mods.Common/Traits/RepairableNear.cs +++ b/OpenRA.Mods.Common/Traits/RepairableNear.cs @@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Traits { [ActorReference] [FieldLoader.Require] - public readonly HashSet RepairActors = new(); + public readonly HashSet RepairActors = []; public readonly WDist CloseEnough = WDist.FromCells(4); diff --git a/OpenRA.Mods.Common/Traits/Replaceable.cs b/OpenRA.Mods.Common/Traits/Replaceable.cs index fc4b2fa948..22147c604f 100644 --- a/OpenRA.Mods.Common/Traits/Replaceable.cs +++ b/OpenRA.Mods.Common/Traits/Replaceable.cs @@ -17,7 +17,7 @@ namespace OpenRA.Mods.Common.Traits { [FieldLoader.Require] [Desc("Replacement types this Replaceable actor accepts.")] - public readonly HashSet Types = new(); + public readonly HashSet Types = []; public override object Create(ActorInitializer init) { return new Replaceable(this); } } diff --git a/OpenRA.Mods.Common/Traits/Replacement.cs b/OpenRA.Mods.Common/Traits/Replacement.cs index 1e4e1d35b7..82e939ccc5 100644 --- a/OpenRA.Mods.Common/Traits/Replacement.cs +++ b/OpenRA.Mods.Common/Traits/Replacement.cs @@ -18,7 +18,7 @@ namespace OpenRA.Mods.Common.Traits { [FieldLoader.Require] [Desc("Replacement type (matched against Types in Replaceable).")] - public readonly HashSet ReplaceableTypes = new(); + public readonly HashSet ReplaceableTypes = []; } public class Replacement { } diff --git a/OpenRA.Mods.Common/Traits/RequiresSpecificOwners.cs b/OpenRA.Mods.Common/Traits/RequiresSpecificOwners.cs index 9f85e5cfb1..41ed1174f3 100644 --- a/OpenRA.Mods.Common/Traits/RequiresSpecificOwners.cs +++ b/OpenRA.Mods.Common/Traits/RequiresSpecificOwners.cs @@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.Traits { [Desc("Only allow players listed here as owners.")] [FieldLoader.Require] - public readonly HashSet ValidOwnerNames = new(); + public readonly HashSet ValidOwnerNames = []; } public class RequiresSpecificOwners { } diff --git a/OpenRA.Mods.Common/Traits/RevealOnFire.cs b/OpenRA.Mods.Common/Traits/RevealOnFire.cs index 85e5351685..1c3ee94f2e 100644 --- a/OpenRA.Mods.Common/Traits/RevealOnFire.cs +++ b/OpenRA.Mods.Common/Traits/RevealOnFire.cs @@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.Traits public class RevealOnFireInfo : ConditionalTraitInfo { [Desc("The armament types which trigger revealing.")] - public readonly string[] ArmamentNames = { "primary", "secondary" }; + public readonly string[] ArmamentNames = ["primary", "secondary"]; [Desc("Player relationships relative to the target player this actor will be revealed to during firing.")] public readonly PlayerRelationship RevealForRelationships = PlayerRelationship.Ally; diff --git a/OpenRA.Mods.Common/Traits/ScriptTags.cs b/OpenRA.Mods.Common/Traits/ScriptTags.cs index bb3d9c73ab..36651a1cda 100644 --- a/OpenRA.Mods.Common/Traits/ScriptTags.cs +++ b/OpenRA.Mods.Common/Traits/ScriptTags.cs @@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Traits public class ScriptTags { - readonly HashSet tags = new(); + readonly HashSet tags = []; public ScriptTags(ActorInitializer init, ScriptTagsInfo info) { diff --git a/OpenRA.Mods.Common/Traits/Sellable.cs b/OpenRA.Mods.Common/Traits/Sellable.cs index 7290d5dba3..d96322e61e 100644 --- a/OpenRA.Mods.Common/Traits/Sellable.cs +++ b/OpenRA.Mods.Common/Traits/Sellable.cs @@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Traits public readonly int RefundPercent = 50; [Desc("List of audio clips to play when the actor is being sold.")] - public readonly string[] SellSounds = Array.Empty(); + public readonly string[] SellSounds = []; [NotificationReference("Speech")] [Desc("Speech notification to play.")] diff --git a/OpenRA.Mods.Common/Traits/Sound/AmbientSound.cs b/OpenRA.Mods.Common/Traits/Sound/AmbientSound.cs index 7efd75e6ad..904a93fa4d 100644 --- a/OpenRA.Mods.Common/Traits/Sound/AmbientSound.cs +++ b/OpenRA.Mods.Common/Traits/Sound/AmbientSound.cs @@ -22,11 +22,11 @@ namespace OpenRA.Mods.Common.Traits.Sound [Desc("Initial delay (in ticks) before playing the sound for the first time.", "Two values indicate a random delay range.")] - public readonly int[] Delay = { 0 }; + public readonly int[] Delay = [0]; [Desc("Interval between playing the sound (in ticks).", "Two values indicate a random delay range.")] - public readonly int[] Interval = { 0 }; + public readonly int[] Interval = [0]; public override object Create(ActorInitializer init) { return new AmbientSound(init.Self, this); } } @@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.Traits.Sound sealed class AmbientSound : ConditionalTrait, ITick, INotifyRemovedFromWorld { readonly bool loop; - readonly HashSet currentSounds = new(); + readonly HashSet currentSounds = []; WPos cachedPosition; int delay; diff --git a/OpenRA.Mods.Common/Traits/Sound/AttackSounds.cs b/OpenRA.Mods.Common/Traits/Sound/AttackSounds.cs index 735b9e68d7..ca190bb58d 100644 --- a/OpenRA.Mods.Common/Traits/Sound/AttackSounds.cs +++ b/OpenRA.Mods.Common/Traits/Sound/AttackSounds.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits.Sound @@ -18,7 +17,7 @@ namespace OpenRA.Mods.Common.Traits.Sound public class AttackSoundsInfo : ConditionalTraitInfo { [Desc("Play a randomly selected sound from this list when preparing for an attack or attacking.")] - public readonly string[] Sounds = Array.Empty(); + public readonly string[] Sounds = []; [Desc("Delay in ticks before sound starts, either relative to attack preparation or attack.")] public readonly int Delay = 0; diff --git a/OpenRA.Mods.Common/Traits/Sound/SoundOnDamageTransition.cs b/OpenRA.Mods.Common/Traits/Sound/SoundOnDamageTransition.cs index 5d85345aaa..131119b883 100644 --- a/OpenRA.Mods.Common/Traits/Sound/SoundOnDamageTransition.cs +++ b/OpenRA.Mods.Common/Traits/Sound/SoundOnDamageTransition.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using OpenRA.Primitives; using OpenRA.Traits; @@ -18,10 +17,10 @@ namespace OpenRA.Mods.Common.Traits.Sound public class SoundOnDamageTransitionInfo : TraitInfo { [Desc("Play a random sound from this list when damaged.")] - public readonly string[] DamagedSounds = Array.Empty(); + public readonly string[] DamagedSounds = []; [Desc("Play a random sound from this list when destroyed.")] - public readonly string[] DestroyedSounds = Array.Empty(); + public readonly string[] DestroyedSounds = []; [Desc("DamageType(s) that trigger the sounds. Leave empty to always trigger a sound.")] public readonly BitSet DamageTypes = default; diff --git a/OpenRA.Mods.Common/Traits/SpawnActorsOnSell.cs b/OpenRA.Mods.Common/Traits/SpawnActorsOnSell.cs index 968425422c..e4d02c87f8 100644 --- a/OpenRA.Mods.Common/Traits/SpawnActorsOnSell.cs +++ b/OpenRA.Mods.Common/Traits/SpawnActorsOnSell.cs @@ -9,10 +9,8 @@ */ #endregion -using System; using System.Collections.Generic; using System.Linq; -using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -30,11 +28,11 @@ namespace OpenRA.Mods.Common.Traits [ActorReference] [Desc("Actors to spawn on sell. Be sure to use lowercase.")] - public readonly string[] GuaranteedActorTypes = Array.Empty(); + public readonly string[] GuaranteedActorTypes = []; [Desc("Spawns actors only if the selling player's faction is in this list. " + "Leave empty to allow all factions by default.")] - public readonly HashSet Factions = new(); + public readonly HashSet Factions = []; public override object Create(ActorInitializer init) { return new SpawnActorsOnSell(init.Self, this); } } @@ -102,11 +100,11 @@ namespace OpenRA.Mods.Common.Traits guaranteedActorTypes.Remove(at); dudesValue -= at.Cost; - self.World.AddFrameEndTask(w => w.CreateActor(at.Name, new TypeDictionary - { + self.World.AddFrameEndTask(w => w.CreateActor(at.Name, + [ new LocationInit(loc), new OwnerInit(self.Owner), - })); + ])); } if (eligibleLocations.Count == 0) @@ -131,11 +129,11 @@ namespace OpenRA.Mods.Common.Traits eligibleLocations.Remove(loc); dudesValue -= at.Cost; - self.World.AddFrameEndTask(w => w.CreateActor(at.Name, new TypeDictionary - { + self.World.AddFrameEndTask(w => w.CreateActor(at.Name, + [ new LocationInit(loc), new OwnerInit(self.Owner), - })); + ])); } } diff --git a/OpenRA.Mods.Common/Traits/StoresResources.cs b/OpenRA.Mods.Common/Traits/StoresResources.cs index 9fbba002b2..16f4069ae3 100644 --- a/OpenRA.Mods.Common/Traits/StoresResources.cs +++ b/OpenRA.Mods.Common/Traits/StoresResources.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Traits public readonly int Capacity = 28; [Desc("Which resources can be stored.")] - public readonly string[] Resources = Array.Empty(); + public readonly string[] Resources = []; string[] IStoresResourcesInfo.ResourceTypes => Resources; @@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.Traits public class StoresResources : IStoresResources, ISync { - readonly Dictionary contents = new(); + readonly Dictionary contents = []; readonly StoresResourcesInfo info; [Sync] diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs b/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs index 41fd226ee5..6290fd3b68 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs @@ -14,7 +14,6 @@ using System.Collections.Generic; using System.Linq; using OpenRA.Mods.Common.Activities; using OpenRA.Mods.Common.Effects; -using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -93,11 +92,11 @@ namespace OpenRA.Mods.Common.Traits { self.World.AddFrameEndTask(w => { - camera = w.CreateActor(info.CameraActor, new TypeDictionary - { + camera = w.CreateActor(info.CameraActor, + [ new LocationInit(self.World.Map.CellContaining(target)), new OwnerInit(self.Owner), - }); + ]); }); } @@ -140,12 +139,12 @@ namespace OpenRA.Mods.Common.Traits var so = info.SquadOffset; var spawnOffset = new WVec(i * so.Y, -Math.Abs(i) * so.X, 0).Rotate(attackRotation); var targetOffset = new WVec(i * so.Y, 0, 0).Rotate(attackRotation); - var a = self.World.CreateActor(false, info.UnitType, new TypeDictionary - { + var a = self.World.CreateActor(false, info.UnitType, + [ new CenterPositionInit(startEdge + spawnOffset), new OwnerInit(self.Owner), new FacingInit(facing.Value), - }); + ]); aircraft.Add(a); aircraftInRange.Add(a, false); diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/DirectionalSupportPower.cs b/OpenRA.Mods.Common/Traits/SupportPowers/DirectionalSupportPower.cs index 27986a510c..58ea95c58c 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/DirectionalSupportPower.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/DirectionalSupportPower.cs @@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.Traits public readonly bool UseDirectionalTarget = false; [SequenceReference(nameof(DirectionArrowAnimation), allowNullImage: true)] - public readonly string[] Arrows = { "arrow-t", "arrow-tl", "arrow-l", "arrow-bl", "arrow-b", "arrow-br", "arrow-r", "arrow-tr" }; + public readonly string[] Arrows = ["arrow-t", "arrow-tl", "arrow-l", "arrow-bl", "arrow-b", "arrow-br", "arrow-r", "arrow-tr"]; [Desc("Animation used to render the direction arrows.")] public readonly string DirectionArrowAnimation = null; diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/NukePower.cs b/OpenRA.Mods.Common/Traits/SupportPowers/NukePower.cs index a7a3307622..e25126d98f 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/NukePower.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/NukePower.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using OpenRA.GameRules; using OpenRA.Graphics; @@ -63,7 +62,7 @@ namespace OpenRA.Mods.Common.Traits [SequenceReference(nameof(TrailImage), allowNullImage: true)] [Desc("Loop a randomly chosen sequence of TrailImage from this list while this projectile is moving.")] - public readonly string[] TrailSequences = Array.Empty(); + public readonly string[] TrailSequences = []; [Desc("Interval in ticks between each spawned Trail animation.")] public readonly int TrailInterval = 1; diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/ParatroopersPower.cs b/OpenRA.Mods.Common/Traits/SupportPowers/ParatroopersPower.cs index 83278b7646..d9b7aacea7 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/ParatroopersPower.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/ParatroopersPower.cs @@ -14,7 +14,6 @@ using System.Collections.Generic; using System.Linq; using OpenRA.Mods.Common.Activities; using OpenRA.Mods.Common.Effects; -using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -48,7 +47,7 @@ namespace OpenRA.Mods.Common.Traits [ActorReference(typeof(PassengerInfo))] [Desc("Troops to be delivered. They will be distributed between the planes if SquadSize > 1.")] - public readonly string[] DropItems = Array.Empty(); + public readonly string[] DropItems = []; [Desc("Risks stuck units when they don't have the Paratrooper trait.")] public readonly bool AllowImpassableCells = false; @@ -114,11 +113,11 @@ namespace OpenRA.Mods.Common.Traits { self.World.AddFrameEndTask(w => { - camera = w.CreateActor(info.CameraActor, new TypeDictionary - { + camera = w.CreateActor(info.CameraActor, + [ new LocationInit(self.World.Map.CellContaining(target)), new OwnerInit(self.Owner), - }); + ]); }); } @@ -169,20 +168,20 @@ namespace OpenRA.Mods.Common.Traits var so = info.SquadOffset; var spawnOffset = new WVec(i * so.Y, -Math.Abs(i) * so.X, 0).Rotate(dropRotation); - aircraft.Add(self.World.CreateActor(false, info.UnitType, new TypeDictionary - { + aircraft.Add(self.World.CreateActor(false, info.UnitType, + [ new CenterPositionInit(startEdge + spawnOffset), new OwnerInit(self.Owner), new FacingInit(facing.Value), - })); + ])); } foreach (var p in info.DropItems) { - units.Add(self.World.CreateActor(false, p.ToLowerInvariant(), new TypeDictionary - { + units.Add(self.World.CreateActor(false, p.ToLowerInvariant(), + [ new OwnerInit(self.Owner) - })); + ])); } self.World.AddFrameEndTask(w => diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/SpawnActorPower.cs b/OpenRA.Mods.Common/Traits/SupportPowers/SpawnActorPower.cs index 6ee3cf88a1..535e68d7fe 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/SpawnActorPower.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/SpawnActorPower.cs @@ -15,7 +15,6 @@ using OpenRA.Graphics; using OpenRA.Mods.Common.Activities; using OpenRA.Mods.Common.Effects; using OpenRA.Mods.Common.Orders; -using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -81,11 +80,11 @@ namespace OpenRA.Mods.Common.Traits w.Add(new SpriteEffect(position, w, info.EffectImage, info.EffectSequence, palette)); } - var actor = w.CreateActor(info.Actor, new TypeDictionary - { + var actor = w.CreateActor(info.Actor, + [ new LocationInit(cell), new OwnerInit(self.Owner), - }); + ]); if (info.LifeTime > -1) { diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/SupportPower.cs b/OpenRA.Mods.Common/Traits/SupportPowers/SupportPower.cs index 6eabeb150e..c6528aa13f 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/SupportPower.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/SupportPower.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using OpenRA.Traits; @@ -54,7 +53,7 @@ namespace OpenRA.Mods.Common.Traits "Normal rules apply for subsequent charges.")] public readonly bool StartFullyCharged = false; - public readonly string[] Prerequisites = Array.Empty(); + public readonly string[] Prerequisites = []; public readonly string DetectedSound = null; diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs b/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs index 33929a0669..00d281121e 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs @@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits public class SupportPowerManager : ITick, IResolveOrder, ITechTreeElement { public readonly Actor Self; - public readonly Dictionary Powers = new(); + public readonly Dictionary Powers = []; public readonly DeveloperMode DevMode; public readonly TechTree TechTree; @@ -106,7 +106,7 @@ namespace OpenRA.Mods.Common.Traits sp.Activate(order); } - static readonly SupportPowerInstance[] NoInstances = Array.Empty(); + static readonly SupportPowerInstance[] NoInstances = []; public IEnumerable GetPowersForActor(Actor a) { @@ -144,7 +144,7 @@ namespace OpenRA.Mods.Common.Traits public readonly string Key; - public readonly List Instances = new(); + public readonly List Instances = []; public readonly int TotalTicks; protected int remainingSubTicks; diff --git a/OpenRA.Mods.Common/Traits/Targetable.cs b/OpenRA.Mods.Common/Traits/Targetable.cs index 991fb2bbf4..65c4a29059 100644 --- a/OpenRA.Mods.Common/Traits/Targetable.cs +++ b/OpenRA.Mods.Common/Traits/Targetable.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Linq; using OpenRA.Primitives; using OpenRA.Traits; @@ -30,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits public class Targetable : ConditionalTrait, ITargetable { - protected static readonly string[] None = Array.Empty(); + protected static readonly string[] None = []; protected Cloak[] cloaks; public Targetable(TargetableInfo info) diff --git a/OpenRA.Mods.Common/Traits/Transforms.cs b/OpenRA.Mods.Common/Traits/Transforms.cs index 888cd096b6..d23d17968f 100644 --- a/OpenRA.Mods.Common/Traits/Transforms.cs +++ b/OpenRA.Mods.Common/Traits/Transforms.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using System.Linq; using OpenRA.Activities; @@ -34,10 +33,10 @@ namespace OpenRA.Mods.Common.Traits public readonly WAngle Facing = new(384); [Desc("Sounds to play when transforming.")] - public readonly string[] TransformSounds = Array.Empty(); + public readonly string[] TransformSounds = []; [Desc("Sounds to play when the transformation is blocked.")] - public readonly string[] NoTransformSounds = Array.Empty(); + public readonly string[] NoTransformSounds = []; [NotificationReference("Speech")] [Desc("Speech notification to play when transforming.")] diff --git a/OpenRA.Mods.Common/Traits/Wanders.cs b/OpenRA.Mods.Common/Traits/Wanders.cs index 47d5f7bda0..6bb003aacb 100644 --- a/OpenRA.Mods.Common/Traits/Wanders.cs +++ b/OpenRA.Mods.Common/Traits/Wanders.cs @@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits public readonly int MaxMoveDelay = 0; [Desc("The terrain types that this actor should avoid wandering on to.")] - public readonly HashSet AvoidTerrainTypes = new(); + public readonly HashSet AvoidTerrainTypes = []; public override object Create(ActorInitializer init) { return new Wanders(init.Self, this); } } diff --git a/OpenRA.Mods.Common/Traits/World/ActorMap.cs b/OpenRA.Mods.Common/Traits/World/ActorMap.cs index 010b3dc775..de7b9d3eef 100644 --- a/OpenRA.Mods.Common/Traits/World/ActorMap.cs +++ b/OpenRA.Mods.Common/Traits/World/ActorMap.cs @@ -38,8 +38,8 @@ namespace OpenRA.Mods.Common.Traits sealed class Bin { - public readonly List Actors = new(); - public readonly List ProximityTriggers = new(); + public readonly List Actors = []; + public readonly List ProximityTriggers = []; } sealed class CellTrigger @@ -49,8 +49,8 @@ namespace OpenRA.Mods.Common.Traits readonly Action onActorEntered; readonly Action onActorExited; - readonly HashSet oldActors = new(); - readonly HashSet currentActors = new(); + readonly HashSet oldActors = []; + readonly HashSet currentActors = []; public CellTrigger(CPos[] footprint, Action onActorEntered, Action onActorExited) { @@ -98,8 +98,8 @@ namespace OpenRA.Mods.Common.Traits readonly Action onActorEntered; readonly Action onActorExited; - readonly HashSet oldActors = new(); - readonly HashSet currentActors = new(); + readonly HashSet oldActors = []; + readonly HashSet currentActors = []; WPos position; WDist range; @@ -166,23 +166,23 @@ namespace OpenRA.Mods.Common.Traits readonly ActorMapInfo info; readonly Map map; - readonly Dictionary cellTriggers = new(); - readonly Dictionary> cellTriggerInfluence = new(); - readonly Dictionary proximityTriggers = new(); + readonly Dictionary cellTriggers = []; + readonly Dictionary> cellTriggerInfluence = []; + readonly Dictionary proximityTriggers = []; int nextTriggerId; CellLayer[] influence; // Index 0 is kept null as layer 0 is used for the ground layer. - public ICustomMovementLayer[] CustomMovementLayers = new ICustomMovementLayer[] { null }; + public ICustomMovementLayer[] CustomMovementLayers = [null]; public event Action CellUpdated; readonly Bin[] bins; readonly int rows, cols; // Position updates are done in one pass // to ensure consistency during a tick - readonly HashSet addActorPosition = new(); - readonly HashSet removeActorPosition = new(); + readonly HashSet addActorPosition = []; + readonly HashSet removeActorPosition = []; readonly Predicate actorShouldBeRemoved; public WDist LargestActorRadius { get; } @@ -192,7 +192,7 @@ namespace OpenRA.Mods.Common.Traits { this.info = info; map = world.Map; - influence = new[] { new CellLayer(world.Map) }; + influence = [new CellLayer(world.Map)]; cols = CellCoordToBinIndex(world.Map.MapSize.X) + 1; rows = CellCoordToBinIndex(world.Map.MapSize.Y) + 1; @@ -268,7 +268,7 @@ namespace OpenRA.Mods.Common.Traits var uv = a.ToMPos(map); var layer = influence[a.Layer]; if (!layer.Contains(uv)) - return Enumerable.Empty(); + return []; return new ActorsAtEnumerable(layer[uv]); } @@ -521,7 +521,7 @@ namespace OpenRA.Mods.Common.Traits continue; if (!cellTriggerInfluence.ContainsKey(c)) - cellTriggerInfluence.Add(c, new List()); + cellTriggerInfluence.Add(c, []); cellTriggerInfluence[c].Add(t); } diff --git a/OpenRA.Mods.Common/Traits/World/ActorSpawnManager.cs b/OpenRA.Mods.Common/Traits/World/ActorSpawnManager.cs index a691dd9363..4d233ea177 100644 --- a/OpenRA.Mods.Common/Traits/World/ActorSpawnManager.cs +++ b/OpenRA.Mods.Common/Traits/World/ActorSpawnManager.cs @@ -9,10 +9,8 @@ */ #endregion -using System; using System.Collections.Generic; using System.Linq; -using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -32,17 +30,17 @@ namespace OpenRA.Mods.Common.Traits [Desc("Time (in ticks) between actor spawn. Supports 1 or 2 values.", "If 2 values are provided they are used as a range from which a value is randomly selected.")] - public readonly int[] SpawnInterval = { 6000 }; + public readonly int[] SpawnInterval = [6000]; [FieldLoader.Require] [ActorReference] [Desc("Name of the actor that will be randomly picked to spawn.")] - public readonly string[] Actors = Array.Empty(); + public readonly string[] Actors = []; public readonly string Owner = "Creeps"; [Desc("Type of ActorSpawner with which it connects.")] - public readonly HashSet Types = new(); + public readonly HashSet Types = []; public override void RulesetLoaded(Ruleset rules, ActorInfo ai) { @@ -123,11 +121,11 @@ namespace OpenRA.Mods.Common.Traits WPos SpawnActor(Actor self, Actor spawnPoint) { - self.World.AddFrameEndTask(w => w.CreateActor(info.Actors.Random(self.World.SharedRandom), new TypeDictionary - { + self.World.AddFrameEndTask(w => w.CreateActor(info.Actors.Random(self.World.SharedRandom), + [ new OwnerInit(w.Players.First(x => x.PlayerName == info.Owner)), new LocationInit(spawnPoint.Location) - })); + ])); actorsPresent++; diff --git a/OpenRA.Mods.Common/Traits/World/AutoSave.cs b/OpenRA.Mods.Common/Traits/World/AutoSave.cs index a2f4077867..fdd22fb6b7 100644 --- a/OpenRA.Mods.Common/Traits/World/AutoSave.cs +++ b/OpenRA.Mods.Common/Traits/World/AutoSave.cs @@ -86,7 +86,7 @@ namespace OpenRA.Mods.Common.Traits var autoSaveDirectoryInfo = new DirectoryInfo(saveFolderPath); if (!autoSaveDirectoryInfo.Exists) - return Array.Empty(); + return []; return autoSaveDirectoryInfo.EnumerateFiles($"{AutoSavePattern}*{SaveFileExtension}"); } diff --git a/OpenRA.Mods.Common/Traits/World/CellTriggerOverlay.cs b/OpenRA.Mods.Common/Traits/World/CellTriggerOverlay.cs index 8d16dbd66d..f162941983 100644 --- a/OpenRA.Mods.Common/Traits/World/CellTriggerOverlay.cs +++ b/OpenRA.Mods.Common/Traits/World/CellTriggerOverlay.cs @@ -10,6 +10,7 @@ #endregion using System.Collections.Generic; +using System.Linq; using OpenRA.Graphics; using OpenRA.Mods.Common.Commands; using OpenRA.Mods.Common.Graphics; diff --git a/OpenRA.Mods.Common/Traits/World/ClearMapGenerator.cs b/OpenRA.Mods.Common/Traits/World/ClearMapGenerator.cs index 6ae977ff4b..f6d5f89552 100644 --- a/OpenRA.Mods.Common/Traits/World/ClearMapGenerator.cs +++ b/OpenRA.Mods.Common/Traits/World/ClearMapGenerator.cs @@ -11,7 +11,6 @@ using System; using System.Collections.Generic; -using System.Collections.Immutable; using OpenRA.Mods.Common.MapGenerator; using OpenRA.Mods.Common.Terrain; using OpenRA.Support; @@ -95,7 +94,7 @@ namespace OpenRA.Mods.Common.Traits } map.PlayerDefinitions = new MapPlayers(map.Rules, 0).ToMiniYaml(); - map.ActorDefinitions = ImmutableArray.Empty; + map.ActorDefinitions = []; } } diff --git a/OpenRA.Mods.Common/Traits/World/ColorPickerManager.cs b/OpenRA.Mods.Common/Traits/World/ColorPickerManager.cs index c50a063421..09a18edce5 100644 --- a/OpenRA.Mods.Common/Traits/World/ColorPickerManager.cs +++ b/OpenRA.Mods.Common/Traits/World/ColorPickerManager.cs @@ -34,16 +34,16 @@ namespace OpenRA.Mods.Common.Traits const string InvalidPlayerColor = "notification-invalid-player-color"; [Desc("Minimum and maximum saturation levels that are valid for use.")] - public readonly float[] HsvSaturationRange = { 0.3f, 0.95f }; + public readonly float[] HsvSaturationRange = [0.3f, 0.95f]; [Desc("Minimum and maximum value levels that are valid for use.")] - public readonly float[] HsvValueRange = { 0.3f, 0.95f }; + public readonly float[] HsvValueRange = [0.3f, 0.95f]; [Desc("Perceptual color threshold for determining whether two colors are too similar.")] public readonly int SimilarityThreshold = 0x50; [Desc("List of colors to be displayed in the palette tab.")] - public readonly Color[] PresetColors = Array.Empty(); + public readonly Color[] PresetColors = []; [ActorReference] [Desc("Actor type to show in the color picker. This can be overridden for specific factions with FactionPreviewActors.")] @@ -52,7 +52,7 @@ namespace OpenRA.Mods.Common.Traits [SequenceReference(dictionaryReference: LintDictionaryReference.Values)] [Desc("Actor type to show in the color picker for specific factions. Overrides PreviewActor.", "A dictionary of [faction name]: [actor name].")] - public readonly Dictionary FactionPreviewActors = new(); + public readonly Dictionary FactionPreviewActors = []; public bool IsInvalidColor(Color color, IEnumerable candidateBlockers) { diff --git a/OpenRA.Mods.Common/Traits/World/ControlGroups.cs b/OpenRA.Mods.Common/Traits/World/ControlGroups.cs index cf3e9d614d..8a4e332c26 100644 --- a/OpenRA.Mods.Common/Traits/World/ControlGroups.cs +++ b/OpenRA.Mods.Common/Traits/World/ControlGroups.cs @@ -18,7 +18,7 @@ namespace OpenRA.Mods.Common.Traits { public class ControlGroupsInfo : TraitInfo, IControlGroupsInfo { - public readonly string[] Groups = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" }; + public readonly string[] Groups = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]; public override object Create(ActorInitializer init) { return new ControlGroups(init.World, this); } @@ -127,10 +127,10 @@ namespace OpenRA.Mods.Common.Traits } } - return new List() - { + return + [ new("Groups", new MiniYaml("", groups)) - }; + ]; } void IGameSaveTraitData.ResolveTraitData(Actor self, MiniYaml data) diff --git a/OpenRA.Mods.Common/Traits/World/CrateSpawner.cs b/OpenRA.Mods.Common/Traits/World/CrateSpawner.cs index 070457ce53..1a748193c6 100644 --- a/OpenRA.Mods.Common/Traits/World/CrateSpawner.cs +++ b/OpenRA.Mods.Common/Traits/World/CrateSpawner.cs @@ -13,7 +13,6 @@ using System; using System.Collections.Generic; using System.Linq; using OpenRA.Mods.Common.Activities; -using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -54,20 +53,20 @@ namespace OpenRA.Mods.Common.Traits public readonly int InitialSpawnDelay = 0; [Desc("Which terrain types can we drop on?")] - public readonly HashSet ValidGround = new() { "Clear", "Rough", "Road", "Ore", "Beach" }; + public readonly HashSet ValidGround = ["Clear", "Rough", "Road", "Ore", "Beach"]; [Desc("Which terrain types count as water?")] - public readonly HashSet ValidWater = new() { "Water" }; + public readonly HashSet ValidWater = ["Water"]; [Desc("Chance of generating a water crate instead of a land crate.")] public readonly int WaterChance = 20; [ActorReference] [Desc("Crate actors to drop.")] - public readonly string[] CrateActors = { "crate" }; + public readonly string[] CrateActors = ["crate"]; [Desc("Chance of each crate actor spawning.")] - public readonly int[] CrateActorShares = { 10 }; + public readonly int[] CrateActorShares = [10]; [ActorReference] [Desc("If a DeliveryAircraft: is specified, then this actor will deliver crates.")] @@ -142,7 +141,7 @@ namespace OpenRA.Mods.Common.Traits { if (info.DeliveryAircraft != null) { - var crate = w.CreateActor(false, crateActor, new TypeDictionary { new OwnerInit(w.WorldActor.Owner) }); + var crate = w.CreateActor(false, crateActor, [new OwnerInit(w.WorldActor.Owner)]); var dropFacing = new WAngle(1024 * self.World.SharedRandom.Next(info.QuantizedFacings) / info.QuantizedFacings); var delta = new WVec(0, -1024, 0).Rotate(WRot.FromYaw(dropFacing)); @@ -151,12 +150,12 @@ namespace OpenRA.Mods.Common.Traits var startEdge = target - (self.World.Map.DistanceToEdge(target, -delta) + info.Cordon).Length * delta / 1024; var finishEdge = target + (self.World.Map.DistanceToEdge(target, delta) + info.Cordon).Length * delta / 1024; - var plane = w.CreateActor(info.DeliveryAircraft, new TypeDictionary - { + var plane = w.CreateActor(info.DeliveryAircraft, + [ new CenterPositionInit(startEdge), new OwnerInit(self.Owner), new FacingInit(dropFacing), - }); + ]); var drop = plane.Trait(); drop.SetLZ(p, true); @@ -166,7 +165,7 @@ namespace OpenRA.Mods.Common.Traits plane.QueueActivity(new RemoveSelf()); } else - w.CreateActor(crateActor, new TypeDictionary { new OwnerInit(w.WorldActor.Owner), new LocationInit(p) }); + w.CreateActor(crateActor, [new OwnerInit(w.WorldActor.Owner), new LocationInit(p)]); }); } diff --git a/OpenRA.Mods.Common/Traits/World/EditorActionManager.cs b/OpenRA.Mods.Common/Traits/World/EditorActionManager.cs index 77f551938b..a1399cab28 100644 --- a/OpenRA.Mods.Common/Traits/World/EditorActionManager.cs +++ b/OpenRA.Mods.Common/Traits/World/EditorActionManager.cs @@ -21,8 +21,8 @@ namespace OpenRA.Mods.Common.Traits public class EditorActionManager : IWorldLoaded { - readonly Stack undoStack = new(); - readonly Stack redoStack = new(); + readonly Stack undoStack = []; + readonly Stack redoStack = []; public event Action ItemAdded; public event Action ItemRemoved; diff --git a/OpenRA.Mods.Common/Traits/World/EditorActorLayer.cs b/OpenRA.Mods.Common/Traits/World/EditorActorLayer.cs index eef1b53b88..032a1649b5 100644 --- a/OpenRA.Mods.Common/Traits/World/EditorActorLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/EditorActorLayer.cs @@ -42,7 +42,7 @@ namespace OpenRA.Mods.Common.Traits public class EditorActorLayer : IWorldLoaded, ITickRender, IRender, IRadarSignature, ICreatePlayers, IRenderAnnotations { public readonly EditorActorLayerInfo Info; - readonly List previews = new(); + readonly List previews = []; int2 cellOffset; SpatiallyPartitioned cellMap; @@ -106,7 +106,7 @@ namespace OpenRA.Mods.Common.Traits p.Tick(); } - static readonly IEnumerable NoRenderables = Enumerable.Empty(); + static readonly IEnumerable NoRenderables = []; public virtual IEnumerable Render(Actor self, WorldRenderer wr) { if (wr.World.Type != WorldType.Editor) @@ -176,7 +176,7 @@ namespace OpenRA.Mods.Common.Traits { // Fallback to the actor's CenterPosition for the ActorMap if it has no Footprint if (preview.Footprint.Count == 0) - return new[] { worldRenderer.World.Map.CellContaining(preview.CenterPosition) }; + return [worldRenderer.World.Map.CellContaining(preview.CenterPosition)]; return preview.Footprint.Keys; } @@ -238,7 +238,7 @@ namespace OpenRA.Mods.Common.Traits Name = $"Multi{index}", Faction = "Random", Playable = true, - Enemies = new[] { "Creeps" } + Enemies = ["Creeps"] }; Players.Players.Add(pr.Name, pr); diff --git a/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs b/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs index 7e85d70ac9..4abf3d19ac 100644 --- a/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs +++ b/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs @@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.Traits readonly WorldRenderer worldRenderer; readonly TooltipInfoBase tooltip; readonly ActorReference reference; - readonly Dictionary editorData = new(); + readonly Dictionary editorData = []; readonly Action onCellEntryChanged; SelectionBoxAnnotationRenderable selectionBox; diff --git a/OpenRA.Mods.Common/Traits/World/EditorCursorLayer.cs b/OpenRA.Mods.Common/Traits/World/EditorCursorLayer.cs index 3bc8c7c6b2..c1291aaf15 100644 --- a/OpenRA.Mods.Common/Traits/World/EditorCursorLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/EditorCursorLayer.cs @@ -10,7 +10,6 @@ #endregion using System.Collections.Generic; -using System.Linq; using OpenRA.Graphics; using OpenRA.Mods.Common.Widgets; using OpenRA.Traits; @@ -25,7 +24,7 @@ namespace OpenRA.Mods.Common.Traits { IEditorBrush brush; - static readonly IEnumerable NoRenderables = Enumerable.Empty(); + static readonly IEnumerable NoRenderables = []; public void SetBrush(IEditorBrush brush) { diff --git a/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs b/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs index e73d8e1c6d..f79a0cb80f 100644 --- a/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs @@ -115,7 +115,7 @@ namespace OpenRA.Mods.Common.Traits return; var playerResourcesInfo = w.Map.Rules.Actors[SystemActors.Player].TraitInfoOrDefault(); - resourceValues = playerResourcesInfo?.ResourceValues ?? new Dictionary(); + resourceValues = playerResourcesInfo?.ResourceValues ?? []; foreach (var cell in Map.AllCells) UpdateCell(cell); diff --git a/OpenRA.Mods.Common/Traits/World/ElevatedBridgeLayer.cs b/OpenRA.Mods.Common/Traits/World/ElevatedBridgeLayer.cs index 63472024a5..db04581e5f 100644 --- a/OpenRA.Mods.Common/Traits/World/ElevatedBridgeLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/ElevatedBridgeLayer.cs @@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits readonly Map map; readonly CellLayer cellCenters; readonly CellLayer terrainIndices; - readonly HashSet ends = new(); + readonly HashSet ends = []; bool enabled; public ElevatedBridgeLayer(Actor self, ElevatedBridgeLayerInfo info) diff --git a/OpenRA.Mods.Common/Traits/World/ExperimentalMapGenerator.cs b/OpenRA.Mods.Common/Traits/World/ExperimentalMapGenerator.cs index 18c0757d0d..43ee401f19 100644 --- a/OpenRA.Mods.Common/Traits/World/ExperimentalMapGenerator.cs +++ b/OpenRA.Mods.Common/Traits/World/ExperimentalMapGenerator.cs @@ -1292,7 +1292,7 @@ namespace OpenRA.Mods.Common.Traits CellLayerUtils.WalkingDistances( resourceSpawnPreferences, zoneable, - new[] { chosenMPos.ToCPos(gridType) }, + [chosenMPos.ToCPos(gridType)], param.SpawnRegionSize * 1024); foreach (var mpos in map.AllCells.MapCoords) { diff --git a/OpenRA.Mods.Common/Traits/World/HierarchicalPathFinderOverlay.cs b/OpenRA.Mods.Common/Traits/World/HierarchicalPathFinderOverlay.cs index 013bda56ee..b0b8a24736 100644 --- a/OpenRA.Mods.Common/Traits/World/HierarchicalPathFinderOverlay.cs +++ b/OpenRA.Mods.Common/Traits/World/HierarchicalPathFinderOverlay.cs @@ -93,7 +93,7 @@ namespace OpenRA.Mods.Common.Traits .Select(a => a.TraitOrDefault()?.Locomotor) .Where(l => l != null) .Distinct() - : new[] { Locomotor }; + : [Locomotor]; foreach (var locomotor in locomotors) { var (abstractGraph, abstractDomains) = pathFinder.GetOverlayDataForLocomotor(locomotor, Check); diff --git a/OpenRA.Mods.Common/Traits/World/LegacyBridgeLayer.cs b/OpenRA.Mods.Common/Traits/World/LegacyBridgeLayer.cs index 6b84e75618..12bf8723e3 100644 --- a/OpenRA.Mods.Common/Traits/World/LegacyBridgeLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/LegacyBridgeLayer.cs @@ -14,7 +14,6 @@ using System.IO; using System.Linq; using OpenRA.Graphics; using OpenRA.Mods.Common.Terrain; -using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -23,7 +22,7 @@ namespace OpenRA.Mods.Common.Traits public class LegacyBridgeLayerInfo : TraitInfo { [ActorReference] - public readonly string[] Bridges = { "bridge1", "bridge2" }; + public readonly string[] Bridges = ["bridge1", "bridge2"]; public override object Create(ActorInitializer init) { return new LegacyBridgeLayer(init.Self, this); } } @@ -31,7 +30,7 @@ namespace OpenRA.Mods.Common.Traits public class LegacyBridgeLayer : IWorldLoaded { readonly LegacyBridgeLayerInfo info; - readonly Dictionary bridgeTypes = new(); + readonly Dictionary bridgeTypes = []; readonly ITemplatedTerrainInfo terrainInfo; CellLayer bridges; @@ -80,12 +79,12 @@ namespace OpenRA.Mods.Common.Traits var nj = cell.Y - index / template.Size.X; // Create a new actor for this bridge and keep track of which subtiles this bridge includes - var bridge = w.CreateActor(bridgeTypes[tile].Template, new TypeDictionary - { + var bridge = w.CreateActor(bridgeTypes[tile].Template, + [ new LocationInit(new CPos(ni, nj)), new OwnerInit(w.WorldActor.Owner), new HealthInit(bridgeTypes[tile].Health, true), - }).Trait(); + ]).Trait(); var subTiles = new Dictionary(); var mapTiles = w.Map.Tiles; diff --git a/OpenRA.Mods.Common/Traits/World/LoadWidgetAtGameStart.cs b/OpenRA.Mods.Common/Traits/World/LoadWidgetAtGameStart.cs index a4ccf08ab3..49af18d809 100644 --- a/OpenRA.Mods.Common/Traits/World/LoadWidgetAtGameStart.cs +++ b/OpenRA.Mods.Common/Traits/World/LoadWidgetAtGameStart.cs @@ -67,7 +67,7 @@ namespace OpenRA.Mods.Common.Traits var widget = world.Type == WorldType.Shellmap ? info.ShellmapRoot : world.Type == WorldType.Editor ? info.EditorRoot : info.IngameRoot; - root = Game.LoadWidget(world, widget, Ui.Root, new WidgetArgs()); + root = Game.LoadWidget(world, widget, Ui.Root, []); // The Lua API requires the UI to available, so hide it instead if (world.IsLoadingGameSave) diff --git a/OpenRA.Mods.Common/Traits/World/Locomotor.cs b/OpenRA.Mods.Common/Traits/World/Locomotor.cs index a254d631f2..987c4c080f 100644 --- a/OpenRA.Mods.Common/Traits/World/Locomotor.cs +++ b/OpenRA.Mods.Common/Traits/World/Locomotor.cs @@ -153,7 +153,7 @@ namespace OpenRA.Mods.Common.Traits readonly LocomotorInfo.TerrainInfo[] terrainInfos; readonly World world; - readonly HashSet dirtyCells = new(); + readonly HashSet dirtyCells = []; readonly bool sharesCell; CellLayer[] cellsCost; @@ -395,8 +395,8 @@ namespace OpenRA.Mods.Common.Traits map.Tiles.CellEntryChanged += UpdateCellCost; actorMap.CellUpdated += CellUpdated; - cellsCost = new[] { new CellLayer(map) }; - blockingCache = new[] { new CellLayer(map) }; + cellsCost = [new CellLayer(map)]; + blockingCache = [new CellLayer(map)]; foreach (var cell in map.AllCells) { diff --git a/OpenRA.Mods.Common/Traits/World/MapStartingLocations.cs b/OpenRA.Mods.Common/Traits/World/MapStartingLocations.cs index 3492bda0e3..9850f4d612 100644 --- a/OpenRA.Mods.Common/Traits/World/MapStartingLocations.cs +++ b/OpenRA.Mods.Common/Traits/World/MapStartingLocations.cs @@ -64,7 +64,7 @@ namespace OpenRA.Mods.Common.Traits { public CPos[] SpawnLocations; public List AvailableSpawnPoints; - public readonly Dictionary OccupiedSpawnPoints = new(); + public readonly Dictionary OccupiedSpawnPoints = []; } object IAssignSpawnPointsInfo.InitializeState(MapPreview map, Session lobbyInfo) @@ -112,7 +112,7 @@ namespace OpenRA.Mods.Common.Traits public class MapStartingLocations : IWorldLoaded, INotifyCreated, IAssignSpawnPoints { readonly MapStartingLocationsInfo info; - readonly Dictionary occupiedSpawnPoints = new(); + readonly Dictionary occupiedSpawnPoints = []; bool separateTeamSpawns; CPos[] spawnLocations; List availableSpawnPoints; diff --git a/OpenRA.Mods.Common/Traits/World/MapStartingUnits.cs b/OpenRA.Mods.Common/Traits/World/MapStartingUnits.cs index 5303087b0a..0a1d6b5ea1 100644 --- a/OpenRA.Mods.Common/Traits/World/MapStartingUnits.cs +++ b/OpenRA.Mods.Common/Traits/World/MapStartingUnits.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using OpenRA.Traits; @@ -27,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits public readonly string ClassName = "Unlabeled"; [Desc("Only available when selecting one of these factions.", "Leave empty for no restrictions.")] - public readonly HashSet Factions = new(); + public readonly HashSet Factions = []; [Desc("The actor at the center, usually the mobile construction vehicle.")] [ActorReference] @@ -38,7 +37,7 @@ namespace OpenRA.Mods.Common.Traits [Desc("A group of units ready to defend or scout.")] [ActorReference] - public readonly string[] SupportActors = Array.Empty(); + public readonly string[] SupportActors = []; [Desc("Inner radius for spawning support actors")] public readonly int InnerSupportRadius = 2; diff --git a/OpenRA.Mods.Common/Traits/World/MarkerLayerOverlay.cs b/OpenRA.Mods.Common/Traits/World/MarkerLayerOverlay.cs index 5ed0ca9d9d..e8b10b4a1a 100644 --- a/OpenRA.Mods.Common/Traits/World/MarkerLayerOverlay.cs +++ b/OpenRA.Mods.Common/Traits/World/MarkerLayerOverlay.cs @@ -25,8 +25,8 @@ namespace OpenRA.Mods.Common.Traits public class MarkerLayerOverlayInfo : TraitInfo { [Desc("A list of colors to be used for drawing.")] - public readonly Color[] Colors = new[] - { + public readonly Color[] Colors = + [ Color.FromArgb(255, 0, 0), Color.FromArgb(255, 127, 0), Color.FromArgb(255, 238, 70), @@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Traits Color.FromArgb(0, 42, 255), Color.FromArgb(165, 0, 255), Color.FromArgb(255, 0, 220), - }; + ]; [Desc("Default alpha blend.")] public readonly int Alpha = 85; @@ -62,7 +62,7 @@ namespace OpenRA.Mods.Common.Traits const double DegreesToRadians = Math.PI / 180; - readonly int[] validFlipModeSides = { 2, 4 }; + readonly int[] validFlipModeSides = [2, 4]; public enum MarkerTileMirrorMode { @@ -76,7 +76,7 @@ namespace OpenRA.Mods.Common.Traits readonly Color[] alphaBlendColors; public readonly CellLayer CellLayer; - public readonly Dictionary> Tiles = new(); + public readonly Dictionary> Tiles = []; public bool Enabled = true; public MarkerTileMirrorMode MirrorMode { get; private set; } = MarkerTileMirrorMode.None; @@ -362,7 +362,7 @@ namespace OpenRA.Mods.Common.Traits if (Tiles.TryGetValue(tileType.Value, out set)) set.Add(target); else - Tiles.Add(tileType.Value, new HashSet { target }); + Tiles.Add(tileType.Value, [target]); CellLayer[target] = tileType; } diff --git a/OpenRA.Mods.Common/Traits/World/PathFinder.cs b/OpenRA.Mods.Common/Traits/World/PathFinder.cs index 5dd524b5cf..c9ee4a60fc 100644 --- a/OpenRA.Mods.Common/Traits/World/PathFinder.cs +++ b/OpenRA.Mods.Common/Traits/World/PathFinder.cs @@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.Traits public class PathFinder : IPathFinder, IWorldLoaded { - public static readonly List NoPath = new(0); + public static readonly List NoPath = []; /// /// When searching for paths, use a default weight of 125% to reduce @@ -196,7 +196,7 @@ namespace OpenRA.Mods.Common.Traits // Unlike the destination cell, the source cell is allowed to have an unreachable movement cost. if (!PathSearch.CellAllowsMovement(self.World, locomotor, source, customCost)) return NoPath; - return new List(2) { target, source }; + return [target, source]; } // Use a hierarchical path search, which performs a guided bidirectional search. diff --git a/OpenRA.Mods.Common/Traits/World/PathFinderOverlay.cs b/OpenRA.Mods.Common/Traits/World/PathFinderOverlay.cs index 6b81138963..39deb195bf 100644 --- a/OpenRA.Mods.Common/Traits/World/PathFinderOverlay.cs +++ b/OpenRA.Mods.Common/Traits/World/PathFinderOverlay.cs @@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Traits sealed class Record : PathSearch.IRecorder, IEnumerable<(CPos Source, CPos Destination, int CostSoFar, int EstimatedRemainingCost)> { - readonly Dictionary edges = new(); + readonly Dictionary edges = []; public void Add(CPos source, CPos destination, int costSoFar, int estimatedRemainingCost) { @@ -160,11 +160,11 @@ namespace OpenRA.Mods.Common.Traits var visibleRegion = wr.Viewport.AllVisibleCells; foreach (var sourceCell in sourceCells) - yield return new TargetLineRenderable(new[] - { + yield return new TargetLineRenderable( + [ self.World.Map.CenterOfSubCell(sourceCell, SubCell.FullCell), self.World.Map.CenterOfSubCell(targetCell ?? sourceCell, SubCell.FullCell), - }, info.TargetLineColor, 8, 8); + ], info.TargetLineColor, 8, 8); foreach (var line in RenderEdges(self, abstractEdges1, 8, 6, info.AbstractColor1, null)) yield return line; @@ -210,11 +210,11 @@ namespace OpenRA.Mods.Common.Traits if (visibleRegion != null && !visibleRegion.Contains(srcUv) && !visibleRegion.Contains(dstUv)) continue; - yield return new TargetLineRenderable(new[] - { + yield return new TargetLineRenderable( + [ self.World.Map.CenterOfSubCell(source, SubCell.FullCell) + CustomLayerOffset(source), self.World.Map.CenterOfSubCell(destination, SubCell.FullCell) + CustomLayerOffset(destination), - }, destination.Layer == 0 ? color : customColor, edgeSize, nodeSize); + ], destination.Layer == 0 ? color : customColor, edgeSize, nodeSize); } } diff --git a/OpenRA.Mods.Common/Traits/World/RadarPings.cs b/OpenRA.Mods.Common/Traits/World/RadarPings.cs index 9c927fa410..3e9eedf4dc 100644 --- a/OpenRA.Mods.Common/Traits/World/RadarPings.cs +++ b/OpenRA.Mods.Common/Traits/World/RadarPings.cs @@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits public class RadarPings : ITick { - public readonly List Pings = new(); + public readonly List Pings = []; readonly RadarPingsInfo info; public WPos? LastPingPosition; diff --git a/OpenRA.Mods.Common/Traits/World/ResourceClaimLayer.cs b/OpenRA.Mods.Common/Traits/World/ResourceClaimLayer.cs index 86bf6bd76e..2d50e15d48 100644 --- a/OpenRA.Mods.Common/Traits/World/ResourceClaimLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/ResourceClaimLayer.cs @@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.Traits lastClaimers.Remove(claimer); if (claimers == null) - claimByCell.Add(cell, claimers = new List()); + claimByCell.Add(cell, claimers = []); claimByActor[claimer] = cell; return true; } diff --git a/OpenRA.Mods.Common/Traits/World/ResourceRenderer.cs b/OpenRA.Mods.Common/Traits/World/ResourceRenderer.cs index 32aeea4f4d..732ee7b141 100644 --- a/OpenRA.Mods.Common/Traits/World/ResourceRenderer.cs +++ b/OpenRA.Mods.Common/Traits/World/ResourceRenderer.cs @@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits [FieldLoader.Require] [SequenceReference(nameof(Image))] [Desc("Randomly chosen image sequences.")] - public readonly string[] Sequences = Array.Empty(); + public readonly string[] Sequences = []; [PaletteReference] [Desc("Palette used for rendering the resource sprites.")] @@ -99,11 +99,11 @@ namespace OpenRA.Mods.Common.Traits protected readonly ResourceRendererInfo Info; protected readonly IResourceLayer ResourceLayer; protected readonly CellLayer RenderContents; - protected readonly Dictionary> Variants = new(); + protected readonly Dictionary> Variants = []; protected readonly World World; - readonly HashSet dirty = new(); - readonly Queue cleanDirty = new(); + readonly HashSet dirty = []; + readonly Queue cleanDirty = []; TerrainSpriteLayer shadowLayer; TerrainSpriteLayer spriteLayer; bool disposed; diff --git a/OpenRA.Mods.Common/Traits/World/Selection.cs b/OpenRA.Mods.Common/Traits/World/Selection.cs index c09381c752..fd50229e0a 100644 --- a/OpenRA.Mods.Common/Traits/World/Selection.cs +++ b/OpenRA.Mods.Common/Traits/World/Selection.cs @@ -26,8 +26,8 @@ namespace OpenRA.Mods.Common.Traits public int Hash { get; private set; } public IReadOnlyCollection Actors => actors; - readonly HashSet actors = new(); - readonly List rolloverActors = new(); + readonly HashSet actors = []; + readonly List rolloverActors = []; World world; INotifySelection[] worldNotifySelection; @@ -179,10 +179,10 @@ namespace OpenRA.Mods.Common.Traits List IGameSaveTraitData.IssueTraitData(Actor self) { - return new List() - { + return + [ new("Selection", FieldSaver.FormatValue(Actors.Select(a => a.ActorID).ToArray())) - }; + ]; } void IGameSaveTraitData.ResolveTraitData(Actor self, MiniYaml data) diff --git a/OpenRA.Mods.Common/Traits/World/ShroudRenderer.cs b/OpenRA.Mods.Common/Traits/World/ShroudRenderer.cs index 0855da3aad..d657466dfd 100644 --- a/OpenRA.Mods.Common/Traits/World/ShroudRenderer.cs +++ b/OpenRA.Mods.Common/Traits/World/ShroudRenderer.cs @@ -24,10 +24,10 @@ namespace OpenRA.Mods.Common.Traits { public readonly string Sequence = "shroud"; [SequenceReference(nameof(Sequence))] - public readonly string[] ShroudVariants = { "shroud" }; + public readonly string[] ShroudVariants = ["shroud"]; [SequenceReference(nameof(Sequence))] - public readonly string[] FogVariants = { "fog" }; + public readonly string[] FogVariants = ["fog"]; [PaletteReference] public readonly string ShroudPalette = "shroud"; @@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Traits [Desc("Bitfield of shroud directions for each frame. Lower four bits are", "corners clockwise from TL; upper four are edges clockwise from top")] - public readonly int[] Index = { 12, 9, 8, 3, 1, 6, 4, 2, 13, 11, 7, 14 }; + public readonly int[] Index = [12, 9, 8, 3, 1, 6, 4, 2, 13, 11, 7, 14]; [Desc("Use the upper four bits when calculating frame")] public readonly bool UseExtendedIndex = false; diff --git a/OpenRA.Mods.Common/Traits/World/SmudgeLayer.cs b/OpenRA.Mods.Common/Traits/World/SmudgeLayer.cs index 853ef7cd3d..c17af678d3 100644 --- a/OpenRA.Mods.Common/Traits/World/SmudgeLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/SmudgeLayer.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -47,7 +46,7 @@ namespace OpenRA.Mods.Common.Traits [SequenceReference(nameof(SmokeImage), allowNullImage: true)] [Desc("Smoke sprite sequences randomly chosen from")] - public readonly string[] SmokeSequences = Array.Empty(); + public readonly string[] SmokeSequences = []; [PaletteReference] public readonly string SmokePalette = "effect"; @@ -94,9 +93,9 @@ namespace OpenRA.Mods.Common.Traits } public readonly SmudgeLayerInfo Info; - readonly Dictionary tiles = new(); - readonly Dictionary dirty = new(); - readonly Dictionary smudges = new(); + readonly Dictionary tiles = []; + readonly Dictionary dirty = []; + readonly Dictionary smudges = []; readonly World world; readonly bool hasSmoke; diff --git a/OpenRA.Mods.Common/Traits/World/SpawnMapActors.cs b/OpenRA.Mods.Common/Traits/World/SpawnMapActors.cs index 7616563b76..91a5ad6cca 100644 --- a/OpenRA.Mods.Common/Traits/World/SpawnMapActors.cs +++ b/OpenRA.Mods.Common/Traits/World/SpawnMapActors.cs @@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Traits public class SpawnMapActors : IWorldLoaded { - public Dictionary Actors = new(); + public Dictionary Actors = []; public uint LastMapActorID { get; private set; } public void WorldLoaded(World world, WorldRenderer wr) diff --git a/OpenRA.Mods.Common/Traits/World/SpawnStartingUnits.cs b/OpenRA.Mods.Common/Traits/World/SpawnStartingUnits.cs index 74ee1fb031..84cf28b5a9 100644 --- a/OpenRA.Mods.Common/Traits/World/SpawnStartingUnits.cs +++ b/OpenRA.Mods.Common/Traits/World/SpawnStartingUnits.cs @@ -13,7 +13,6 @@ using System; using System.Collections.Generic; using System.Linq; using OpenRA.Graphics; -using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -90,20 +89,20 @@ namespace OpenRA.Mods.Common.Traits if (unitGroup.BaseActor != null) { var facing = unitGroup.BaseActorFacing ?? new WAngle(w.SharedRandom.Next(1024)); - var baseActor = w.CreateActor(unitGroup.BaseActor.ToLowerInvariant(), new TypeDictionary - { + var baseActor = w.CreateActor(unitGroup.BaseActor.ToLowerInvariant(), + [ new LocationInit(p.HomeLocation + unitGroup.BaseActorOffset), new OwnerInit(p), new SkipMakeAnimsInit(), new FacingInit(facing), new SpawnedByMapInit(), - }); + ]); var baseActorIsMovable = baseActor.OccupiesSpace is Mobile mobile && !mobile.IsTraitDisabled && !mobile.IsTraitPaused && !mobile.IsImmovable; if (baseActorIsMovable) { // If the base is movable, we want support actors to be able to path to its location. - homeLocations = new[] { baseActor.Location }; + homeLocations = [baseActor.Location]; } else { @@ -116,7 +115,7 @@ namespace OpenRA.Mods.Common.Traits else { // If there is no base actor, we want support actors to be able to path to the home location. - homeLocations = new[] { p.HomeLocation }; + homeLocations = [p.HomeLocation]; } if (unitGroup.SupportActors.Length == 0) @@ -155,14 +154,14 @@ namespace OpenRA.Mods.Common.Traits var subCell = ip.SharesCell ? w.ActorMap.FreeSubCell(validCell) : 0; var facing = unitGroup.SupportActorsFacing ?? new WAngle(w.SharedRandom.Next(1024)); - w.CreateActor(s.ToLowerInvariant(), new TypeDictionary - { + w.CreateActor(s.ToLowerInvariant(), + [ new OwnerInit(p), new LocationInit(validCell), new SubCellInit(subCell), new FacingInit(facing), new SpawnedByMapInit(), - }); + ]); } } } diff --git a/OpenRA.Mods.Common/Traits/World/SubterraneanLocomotor.cs b/OpenRA.Mods.Common/Traits/World/SubterraneanLocomotor.cs index 783090d754..9e6bde653d 100644 --- a/OpenRA.Mods.Common/Traits/World/SubterraneanLocomotor.cs +++ b/OpenRA.Mods.Common/Traits/World/SubterraneanLocomotor.cs @@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Traits public readonly short SubterraneanTransitionCost = 0; [Desc("The terrain types that this actor can transition on. Leave empty to allow any.")] - public readonly HashSet SubterraneanTransitionTerrainTypes = new(); + public readonly HashSet SubterraneanTransitionTerrainTypes = []; [Desc("Can this actor transition on slopes?")] public readonly bool SubterraneanTransitionOnRamps = false; diff --git a/OpenRA.Mods.Common/Traits/World/TerrainLighting.cs b/OpenRA.Mods.Common/Traits/World/TerrainLighting.cs index a612e5b3be..ea63f7c835 100644 --- a/OpenRA.Mods.Common/Traits/World/TerrainLighting.cs +++ b/OpenRA.Mods.Common/Traits/World/TerrainLighting.cs @@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Traits readonly TerrainLightingInfo info; readonly Map map; - readonly Dictionary lightSources = new(); + readonly Dictionary lightSources = []; readonly SpatiallyPartitioned partitionedLightSources; readonly float3 globalTint; int nextLightSourceToken = 1; diff --git a/OpenRA.Mods.Common/Traits/World/TerrainTunnelLayer.cs b/OpenRA.Mods.Common/Traits/World/TerrainTunnelLayer.cs index 26359cf5c7..967afcb339 100644 --- a/OpenRA.Mods.Common/Traits/World/TerrainTunnelLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/TerrainTunnelLayer.cs @@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.Traits readonly Map map; readonly CellLayer cellCenters; readonly CellLayer terrainIndices; - readonly HashSet portals = new(); + readonly HashSet portals = []; bool enabled; public TerrainTunnelLayer(Actor self, TerrainTunnelLayerInfo info) diff --git a/OpenRA.Mods.Common/Traits/World/TimeLimitManager.cs b/OpenRA.Mods.Common/Traits/World/TimeLimitManager.cs index f5716857a8..58142c2522 100644 --- a/OpenRA.Mods.Common/Traits/World/TimeLimitManager.cs +++ b/OpenRA.Mods.Common/Traits/World/TimeLimitManager.cs @@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits public readonly string TimeLimitDescription = "dropdown-time-limit.description"; [Desc("Time Limit options that will be shown in the lobby dropdown. Values are in minutes.")] - public readonly int[] TimeLimitOptions = { 0, 10, 20, 30, 40, 60, 90 }; + public readonly int[] TimeLimitOptions = [0, 10, 20, 30, 40, 60, 90]; [Desc("List of remaining minutes of game time when a text and optional speech notification should be made to players.")] public readonly Dictionary TimeLimitWarnings = new() diff --git a/OpenRA.Mods.Common/Traits/World/WarheadDebugOverlay.cs b/OpenRA.Mods.Common/Traits/World/WarheadDebugOverlay.cs index 7d8f2a1a02..a138e7c689 100644 --- a/OpenRA.Mods.Common/Traits/World/WarheadDebugOverlay.cs +++ b/OpenRA.Mods.Common/Traits/World/WarheadDebugOverlay.cs @@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Traits } readonly WarheadDebugOverlayInfo info; - readonly List impacts = new(); + readonly List impacts = []; public WarheadDebugOverlay(WarheadDebugOverlayInfo info) { diff --git a/OpenRA.Mods.Common/Traits/World/WeatherOverlay.cs b/OpenRA.Mods.Common/Traits/World/WeatherOverlay.cs index e6d2894db6..1812c1b2f3 100644 --- a/OpenRA.Mods.Common/Traits/World/WeatherOverlay.cs +++ b/OpenRA.Mods.Common/Traits/World/WeatherOverlay.cs @@ -28,10 +28,10 @@ namespace OpenRA.Mods.Common.Traits public readonly bool ChangingWindLevel = true; [Desc("The levels of wind intensity (particles x-axis movement in px/tick).")] - public readonly int[] WindLevels = { -12, -7, -5, 0, 5, 7, 12 }; + public readonly int[] WindLevels = [-12, -7, -5, 0, 5, 7, 12]; [Desc("Works only if ChangingWindLevel is enabled. Min. and max. ticks needed to change the WindLevel.")] - public readonly int[] WindTick = { 150, 550 }; + public readonly int[] WindTick = [150, 550]; [Desc("Hard or soft fading between the WindLevels.")] public readonly bool InstantWindChanges = false; @@ -40,31 +40,31 @@ namespace OpenRA.Mods.Common.Traits public readonly bool UseSquares = true; [Desc("Size / width of the particle in px.")] - public readonly int[] ParticleSize = { 1, 3 }; + public readonly int[] ParticleSize = [1, 3]; [Desc("Scatters falling direction on the x-axis. Scatter min. and max. value in px/tick.")] - public readonly int[] ScatterDirection = { -1, 1 }; + public readonly int[] ScatterDirection = [-1, 1]; [Desc("Min. and max. speed at which particles fall in px/tick.")] - public readonly float[] Gravity = { 2.5f, 5f }; + public readonly float[] Gravity = [2.5f, 5f]; [Desc("The current offset value for the swing movement. SwingOffset min. and max. value in px/tick.")] - public readonly float[] SwingOffset = { 2.5f, 3.5f }; + public readonly float[] SwingOffset = [2.5f, 3.5f]; [Desc("The value that particles swing to the side each update. SwingSpeed min. and max. value in px/tick.")] - public readonly float[] SwingSpeed = { 0.0025f, 0.06f }; + public readonly float[] SwingSpeed = [0.0025f, 0.06f]; [Desc("The value range that can be swung to the left or right. SwingAmplitude min. and max. value in px/tick.")] - public readonly float[] SwingAmplitude = { 1.0f, 1.5f }; + public readonly float[] SwingAmplitude = [1.0f, 1.5f]; [Desc("The randomly selected rgb(a) hex colors for the particles. Use this order: rrggbb[aa], rrggbb[aa], ...")] public readonly Color[] ParticleColors = - { + [ Color.FromArgb(236, 236, 236), Color.FromArgb(228, 228, 228), Color.FromArgb(208, 208, 208), Color.FromArgb(188, 188, 188) - }; + ]; [Desc("Works only with line enabled and can be used to fade out the tail of the line like a contrail.")] public readonly byte LineTailAlphaValue = 200; diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20210321/ConvertBoundsToWDist.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20210321/ConvertBoundsToWDist.cs index 05ef197fb4..9e9e9d4122 100644 --- a/OpenRA.Mods.Common/UpdateRules/Rules/20210321/ConvertBoundsToWDist.cs +++ b/OpenRA.Mods.Common/UpdateRules/Rules/20210321/ConvertBoundsToWDist.cs @@ -21,8 +21,8 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules "The Bounds and DecorationBounds fields on Interactable and Selectable have been converted from pixels to WDist.\n" + "All bounds must be scaled by 1024 (Rectangular map grid) or 1448 (Isometric map grid) divided by your mod tile size."; - readonly string[] traits = { "Interactable", "Selectable", "IsometricSelectable" }; - readonly string[] fields = { "Bounds", "DecorationBounds" }; + readonly string[] traits = ["Interactable", "Selectable", "IsometricSelectable"]; + readonly string[] fields = ["Bounds", "DecorationBounds"]; public override IEnumerable UpdateActorNode(ModData modData, MiniYamlNodeBuilder actorNode) { diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20210321/RemovePlaceBuildingPalette.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20210321/RemovePlaceBuildingPalette.cs index 90c233edee..88d554762a 100644 --- a/OpenRA.Mods.Common/UpdateRules/Rules/20210321/RemovePlaceBuildingPalette.cs +++ b/OpenRA.Mods.Common/UpdateRules/Rules/20210321/RemovePlaceBuildingPalette.cs @@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules "SequencePlaceBuildingPreview, and D2kActorPreviewPlaceBuildingPreview traits have been removed.\n" + "New Alpha and LineBuildSegmentAlpha properties have been added in their place."; - readonly List locations = new(); + readonly List locations = []; public override IEnumerable AfterUpdate(ModData modData) { diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20210321/RemoveSmokeTrailWhenDamaged.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20210321/RemoveSmokeTrailWhenDamaged.cs index 17cbd82dc6..b3ebc6af36 100644 --- a/OpenRA.Mods.Common/UpdateRules/Rules/20210321/RemoveSmokeTrailWhenDamaged.cs +++ b/OpenRA.Mods.Common/UpdateRules/Rules/20210321/RemoveSmokeTrailWhenDamaged.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules } } - readonly Dictionary> locations = new(); + readonly Dictionary> locations = []; public override IEnumerable AfterUpdate(ModData modData) { diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20210321/ReplaceShadowPalette.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20210321/ReplaceShadowPalette.cs index 309af60a35..0630a50bb9 100644 --- a/OpenRA.Mods.Common/UpdateRules/Rules/20210321/ReplaceShadowPalette.cs +++ b/OpenRA.Mods.Common/UpdateRules/Rules/20210321/ReplaceShadowPalette.cs @@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules "The ShadowPalette field has been replaced by ShadowColor on projectiles.\n" + "The Palette field on WithShadow and ShadowPalette on WithParachute have similarly been replaced with ShadowColor."; - readonly List locations = new(); + readonly List locations = []; public override IEnumerable AfterUpdate(ModData modData) { diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20210321/ReplaceWithColoredOverlayPalette.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20210321/ReplaceWithColoredOverlayPalette.cs index 26949bc861..f4c07388d7 100644 --- a/OpenRA.Mods.Common/UpdateRules/Rules/20210321/ReplaceWithColoredOverlayPalette.cs +++ b/OpenRA.Mods.Common/UpdateRules/Rules/20210321/ReplaceWithColoredOverlayPalette.cs @@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules public override string Description => "The Palette field has been removed from WithColoredOverlay. You must now specify the Color directly."; - readonly List locations = new(); + readonly List locations = []; public override IEnumerable AfterUpdate(ModData modData) { diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20210321/UnhardcodeBaseBuilderBotModule.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20210321/UnhardcodeBaseBuilderBotModule.cs index adf8f6c9c6..55949dd605 100644 --- a/OpenRA.Mods.Common/UpdateRules/Rules/20210321/UnhardcodeBaseBuilderBotModule.cs +++ b/OpenRA.Mods.Common/UpdateRules/Rules/20210321/UnhardcodeBaseBuilderBotModule.cs @@ -20,7 +20,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules // Excludes AttackBomber and AttackTDGunboatTurreted as actors with these AttackBase traits aren't supposed to be controlled. readonly string[] attackBase = - { + [ "AttackLeap", "AttackPopupTurreted", "AttackAircraft", @@ -32,8 +32,8 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules "AttackGarrisoned", "AttackOmni", "AttackSwallow" - }; - readonly string[] buildings = { "Building", "EnergyWall", "D2kBuilding" }; + ]; + readonly string[] buildings = ["Building", "EnergyWall", "D2kBuilding"]; bool anyAdded; diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20210321/UnhardcodeSquadManager.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20210321/UnhardcodeSquadManager.cs index 5bc62d7554..5fee507534 100644 --- a/OpenRA.Mods.Common/UpdateRules/Rules/20210321/UnhardcodeSquadManager.cs +++ b/OpenRA.Mods.Common/UpdateRules/Rules/20210321/UnhardcodeSquadManager.cs @@ -16,11 +16,11 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules { public class UnhardcodeSquadManager : UpdateRule, IBeforeUpdateActors { - readonly List addNodes = new(); + readonly List addNodes = []; // Excludes AttackBomber and AttackTDGunboatTurreted as actors with these AttackBase traits aren't supposed to be controlled. readonly string[] attackBase = - { + [ "AttackLeap", "AttackPopupTurreted", "AttackAircraft", @@ -32,10 +32,10 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules "AttackGarrisoned", "AttackOmni", "AttackSwallow" - }; - readonly string[] vipsNames = { "Harvester", "BaseBuilding" }; - readonly string[] buildings = { "Building", "EnergyWall", "D2kBuilding" }; - readonly string[] excludedBuildings = { "LineBuild", "Plug" }; + ]; + readonly string[] vipsNames = ["Harvester", "BaseBuilding"]; + readonly string[] buildings = ["Building", "EnergyWall", "D2kBuilding"]; + readonly string[] excludedBuildings = ["LineBuild", "Plug"]; public override string Name => "SquadManagerBotModule got new fields to configure ground attacks and defensive actions."; diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20210321/UnhardcodeVeteranProductionIconOverlay.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20210321/UnhardcodeVeteranProductionIconOverlay.cs index 614869ec03..5c10a9d89a 100644 --- a/OpenRA.Mods.Common/UpdateRules/Rules/20210321/UnhardcodeVeteranProductionIconOverlay.cs +++ b/OpenRA.Mods.Common/UpdateRules/Rules/20210321/UnhardcodeVeteranProductionIconOverlay.cs @@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules public override string Description => "ProductionIconOverlayManager now works with the new WithProductionIconOverlay trait, instead of ProducibleWithLevel."; - readonly List locations = new(); + readonly List locations = []; public override IEnumerable AfterUpdate(ModData modData) { diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20230225/ExplicitSequenceFilenames.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20230225/ExplicitSequenceFilenames.cs index dfc5ab7f8a..9f2ca7a8b3 100644 --- a/OpenRA.Mods.Common/UpdateRules/Rules/20230225/ExplicitSequenceFilenames.cs +++ b/OpenRA.Mods.Common/UpdateRules/Rules/20230225/ExplicitSequenceFilenames.cs @@ -27,8 +27,8 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules string defaultSpriteExtension = ".shp"; List resolvedImagesNodes; - readonly Dictionary tilesetExtensions = new(); - readonly Dictionary tilesetCodes = new(); + readonly Dictionary tilesetExtensions = []; + readonly Dictionary tilesetCodes = []; bool parseModYaml = true; bool reportModYamlChanges; bool disabled; @@ -103,32 +103,32 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules { case "cnc": fromBackup = true; - tilesetExtensionsNode = new List() - { + tilesetExtensionsNode = + [ new("TEMPERAT", ".tem"), new("SNOW", ".sno"), new("INTERIOR", ".int"), new("DESERT", ".des"), new("JUNGLE", ".jun"), - }; + ]; break; case "ra": fromBackup = true; - tilesetExtensionsNode = new List() - { + tilesetExtensionsNode = + [ new("TEMPERAT", ".tem"), new("SNOW", ".sno"), new("INTERIOR", ".int"), new("DESERT", ".des"), - }; + ]; break; case "ts": fromBackup = true; - tilesetExtensionsNode = new List() - { + tilesetExtensionsNode = + [ new("TEMPERATE", ".tem"), new("SNOW", ".sno"), - }; + ]; break; } } @@ -148,11 +148,11 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules if (tilesetCodesNode == null && modData.Manifest.Id == "ts") { fromBackup = true; - tilesetCodesNode = new List() - { + tilesetCodesNode = + [ new("TEMPERATE", "t"), new("SNOW", "a"), - }; + ]; } if (tilesetCodesNode != null) @@ -210,11 +210,11 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules if (resolvedSequenceNode == resolvedDefaultsNode) continue; - resolvedSequenceNode.Value.Nodes = MiniYaml.Merge(new[] - { + resolvedSequenceNode.Value.Nodes = MiniYaml.Merge( + [ resolvedDefaultsNode.Value.Nodes.Select(n => n.Build()).ToArray(), resolvedSequenceNode.Value.Nodes.Select(n => n.Build()).ToArray() - }).ConvertAll(n => new MiniYamlNodeBuilder(n)); + ]).ConvertAll(n => new MiniYamlNodeBuilder(n)); resolvedSequenceNode.Value.Value ??= resolvedDefaultsNode.Value.Value; } } diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20230225/RemoveExperienceFromInfiltrates.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20230225/RemoveExperienceFromInfiltrates.cs index ae30b77dad..3850ae2e1d 100644 --- a/OpenRA.Mods.Common/UpdateRules/Rules/20230225/RemoveExperienceFromInfiltrates.cs +++ b/OpenRA.Mods.Common/UpdateRules/Rules/20230225/RemoveExperienceFromInfiltrates.cs @@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules "Infiltrates property PlayerExperience was removed, " + "it was replaced by adding PlayerExperience to all InfiltrateFor* Traits."; - readonly List locations = new(); + readonly List locations = []; public override IEnumerable AfterUpdate(ModData modData) { diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20230225/RemoveNegativeSequenceLength.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20230225/RemoveNegativeSequenceLength.cs index 673a020eec..a7002f3fa3 100644 --- a/OpenRA.Mods.Common/UpdateRules/Rules/20230225/RemoveNegativeSequenceLength.cs +++ b/OpenRA.Mods.Common/UpdateRules/Rules/20230225/RemoveNegativeSequenceLength.cs @@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules yield break; } - readonly Queue actionQueue = new(); + readonly Queue actionQueue = []; static MiniYamlNodeBuilder GetNode(string key, MiniYamlNodeBuilder node, MiniYamlNodeBuilder defaultNode) { diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20230225/RemoveSequenceHasEmbeddedPalette.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20230225/RemoveSequenceHasEmbeddedPalette.cs index 53b8f66511..559da54992 100644 --- a/OpenRA.Mods.Common/UpdateRules/Rules/20230225/RemoveSequenceHasEmbeddedPalette.cs +++ b/OpenRA.Mods.Common/UpdateRules/Rules/20230225/RemoveSequenceHasEmbeddedPalette.cs @@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules "The PaletteFromEmbeddedSpritePalette trait no longer references a sequence.\n" + "Image and Sequence are replaced by Filename and Frame."; - readonly HashSet locations = new(); + readonly HashSet locations = []; public override IEnumerable AfterUpdate(ModData modData) { diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20231010/AbstractDocking.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20231010/AbstractDocking.cs index 9b69258ce3..daec80b914 100644 --- a/OpenRA.Mods.Common/UpdateRules/Rules/20231010/AbstractDocking.cs +++ b/OpenRA.Mods.Common/UpdateRules/Rules/20231010/AbstractDocking.cs @@ -16,9 +16,9 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules { public class AbstractDocking : UpdateRule, IBeforeUpdateActors { - readonly string[] moveRefineyValues = { "DockAngle", "IsDragRequired", "DragOffset", "DragLength" }; - readonly string[] moveHarvesterValues = { "EnterCursor", "EnterBlockedCursor" }; - readonly string[] buildings = { "Building", "D2kBuilding" }; + readonly string[] moveRefineyValues = ["DockAngle", "IsDragRequired", "DragOffset", "DragLength"]; + readonly string[] moveHarvesterValues = ["EnterCursor", "EnterBlockedCursor"]; + readonly string[] buildings = ["Building", "D2kBuilding"]; readonly string[,] moveAndRenameHarvesterValues = new string[4, 2] { { "DeliverVoice", "Voice" }, @@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules { "SearchForDeliveryBuildingDelay", "SearchForDockDelay" } }; - readonly Dictionary> refineryNodes = new(); + readonly Dictionary> refineryNodes = []; public override string Name => "Docking was abstracted from Refinery & Harvester."; public override string Description => @@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules var harvesterNode = actorNode.ChildrenMatching("Harvester", includeRemovals: false).FirstOrDefault(); if (harvesterNode != null) harvesters[actorNode.Key] = harvesterNode.ChildrenMatching("DeliveryBuildings", includeRemovals: false) - .FirstOrDefault()?.NodeValue>() ?? new HashSet(); + .FirstOrDefault()?.NodeValue>() ?? []; if (actorNode.ChildrenMatching("Refinery", includeRemovals: false).Any()) refineries.Add(actorNode.Key.ToLowerInvariant()); @@ -59,7 +59,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules if (refinery == deliveryBuilding) { if (!refineryNodes.ContainsKey(refinery)) - refineryNodes[refinery] = new List(); + refineryNodes[refinery] = []; var node = new MiniYamlNodeBuilder("Type", deliveryBuilding.ToString()); if (!refineryNodes[refinery].Any(n => n.Key == node.Key)) diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20231010/RemoveValidRelationsFromCapturable.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20231010/RemoveValidRelationsFromCapturable.cs index 27003bfd74..846071057f 100644 --- a/OpenRA.Mods.Common/UpdateRules/Rules/20231010/RemoveValidRelationsFromCapturable.cs +++ b/OpenRA.Mods.Common/UpdateRules/Rules/20231010/RemoveValidRelationsFromCapturable.cs @@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules public override string Description => "ValidRelations has been moved from Capturable to Captures to match weapon definitions."; - readonly List locations = new(); + readonly List locations = []; public override IEnumerable AfterUpdate(ModData modData) { diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20231010/ReplaceCloakPalette.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20231010/ReplaceCloakPalette.cs index 9772d05be0..900ace0580 100644 --- a/OpenRA.Mods.Common/UpdateRules/Rules/20231010/ReplaceCloakPalette.cs +++ b/OpenRA.Mods.Common/UpdateRules/Rules/20231010/ReplaceCloakPalette.cs @@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules "Cloak has gained several new rendering modes\n" + "and its default behaviour has changed from using a palette to native alpha."; - readonly List<(string, string)> actorsWithDefault = new(); + readonly List<(string, string)> actorsWithDefault = []; IEnumerable IBeforeUpdateActors.BeforeUpdateActors(ModData modData, List resolvedActors) { foreach (var actor in resolvedActors) diff --git a/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs b/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs index d4a50a31e5..f171be8f7d 100644 --- a/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs +++ b/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs @@ -30,9 +30,9 @@ namespace OpenRA.Mods.Common.UpdateRules // with the prep playtest-to-playtest-to-release paths and finally a new/modified // release-to-bleed path. static readonly UpdatePath[] Paths = - { - new("release-20210321", "release-20230225", new UpdateRule[] - { + [ + new("release-20210321", "release-20230225", + [ new RenameMPTraits(), new RemovePlayerHighlightPalette(), new ReplaceWithColoredOverlayPalette(), @@ -59,10 +59,10 @@ namespace OpenRA.Mods.Common.UpdateRules // Execute these rules last to avoid premature yaml merge crashes. new UnhardcodeSquadManager(), new UnhardcodeBaseBuilderBotModule(), - }), + ]), - new("release-20230225", "release-20231010", new UpdateRule[] - { + new("release-20230225", "release-20231010", + [ new TextNotificationsDisplayWidgetRemoveTime(), new RenameEngineerRepair(), new ProductionTabsWidgetAddTabButtonCollection(), @@ -76,10 +76,11 @@ namespace OpenRA.Mods.Common.UpdateRules new ExplicitSequenceFilenames(), new RemoveSequenceHasEmbeddedPalette(), new RemoveNegativeSequenceLength(), - }), + ]), + + new("release-20231010", + [ - new("release-20231010", new UpdateRule[] - { // bleed only changes here. new RemoveValidRelationsFromCapturable(), new ExtractResourceStorageFromHarvester(), @@ -96,15 +97,15 @@ namespace OpenRA.Mods.Common.UpdateRules // Execute these rules last to avoid premature yaml merge crashes. new ReplaceCloakPalette(), new AbstractDocking(), - }), - }; + ]), + ]; public static IReadOnlyCollection FromSource(ObjectCreator objectCreator, string source, bool chain = true) { // Use reflection to identify types var namedType = objectCreator.FindType(source); if (namedType != null && namedType.IsSubclassOf(typeof(UpdateRule))) - return new[] { (UpdateRule)objectCreator.CreateBasic(namedType) }; + return [(UpdateRule)objectCreator.CreateBasic(namedType)]; return Paths.FirstOrDefault(p => p.source == source)?.Rules(chain); } diff --git a/OpenRA.Mods.Common/UpdateRules/UpdateUtils.cs b/OpenRA.Mods.Common/UpdateRules/UpdateUtils.cs index 7916956688..43d7d25c98 100644 --- a/OpenRA.Mods.Common/UpdateRules/UpdateUtils.cs +++ b/OpenRA.Mods.Common/UpdateRules/UpdateUtils.cs @@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.UpdateRules { return FieldLoader.GetValue("value", yaml.Value) .Where(f => f.Contains('|')) - .SelectMany(f => LoadModYaml(modData, FilterExternalFiles(modData, new[] { f }, externalFilenames))) + .SelectMany(f => LoadModYaml(modData, FilterExternalFiles(modData, [f], externalFilenames))) .ToList(); } @@ -100,12 +100,12 @@ namespace OpenRA.Mods.Common.UpdateRules if (mapStream == null) { // Not a valid map - files = new YamlFileSet(); + files = []; return manualSteps; } var yaml = new MiniYamlBuilder(null, MiniYaml.FromStream(mapStream, $"{mapPackage.Name}:map.yaml", false)); - files = new YamlFileSet() { (mapPackage, "map.yaml", yaml.Nodes) }; + files = [(mapPackage, "map.yaml", yaml.Nodes)]; manualSteps.AddRange(rule.BeforeUpdate(modData)); diff --git a/OpenRA.Mods.Common/UtilityCommands/ConvertSpriteToPngCommand.cs b/OpenRA.Mods.Common/UtilityCommands/ConvertSpriteToPngCommand.cs index d2d1fa4f1f..058682315f 100644 --- a/OpenRA.Mods.Common/UtilityCommands/ConvertSpriteToPngCommand.cs +++ b/OpenRA.Mods.Common/UtilityCommands/ConvertSpriteToPngCommand.cs @@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.UtilityCommands shadowIndex[^3] = 4; } - var palette = new ImmutablePalette(args[2], new[] { 0 }, shadowIndex); + var palette = new ImmutablePalette(args[2], [0], shadowIndex); var palColors = new Color[Palette.Size]; for (var i = 0; i < Palette.Size; i++) palColors[i] = palette.GetColor(i); diff --git a/OpenRA.Mods.Common/UtilityCommands/CreateManPage.cs b/OpenRA.Mods.Common/UtilityCommands/CreateManPage.cs index 9866a2edde..0ce1822068 100644 --- a/OpenRA.Mods.Common/UtilityCommands/CreateManPage.cs +++ b/OpenRA.Mods.Common/UtilityCommands/CreateManPage.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.UtilityCommands Console.WriteLine(".SH OPTIONS"); var sections = Game.Settings.Sections; - sections.Add("Launch", new LaunchArguments(new Arguments(Array.Empty()))); + sections.Add("Launch", new LaunchArguments(new Arguments([]))); foreach (var section in sections.OrderBy(s => s.Key)) { var fields = Utility.GetFields(section.Value.GetType()); diff --git a/OpenRA.Mods.Common/UtilityCommands/DebugChromeRegions.cs b/OpenRA.Mods.Common/UtilityCommands/DebugChromeRegions.cs index 038500cb79..7a59dc5617 100644 --- a/OpenRA.Mods.Common/UtilityCommands/DebugChromeRegions.cs +++ b/OpenRA.Mods.Common/UtilityCommands/DebugChromeRegions.cs @@ -79,12 +79,12 @@ namespace OpenRA.Mods.Common.UtilityCommands Convert.ToBase64String(modData.ModFiles.Open(image).ReadAllBytes()), "[" + regions.JoinWith(",") + "]"); var outputPath = Path.ChangeExtension(image, ".html"); - File.WriteAllLines(outputPath, new[] { output }); + File.WriteAllLines(outputPath, [output]); Console.WriteLine("Saved {0}", outputPath); } static readonly string[] HtmlTemplate = - { + [ "", "", "", @@ -137,6 +137,6 @@ namespace OpenRA.Mods.Common.UtilityCommands "", "", "", - }; + ]; } } diff --git a/OpenRA.Mods.Common/UtilityCommands/Documentation/ExtractSettingsDocsCommand.cs b/OpenRA.Mods.Common/UtilityCommands/Documentation/ExtractSettingsDocsCommand.cs index e0666380d6..b9f11badfa 100644 --- a/OpenRA.Mods.Common/UtilityCommands/Documentation/ExtractSettingsDocsCommand.cs +++ b/OpenRA.Mods.Common/UtilityCommands/Documentation/ExtractSettingsDocsCommand.cs @@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.UtilityCommands.Documentation Console.WriteLine(); var sections = new Settings(null, new Arguments()).Sections; - sections.Add("Launch", new LaunchArguments(new Arguments(Array.Empty()))); + sections.Add("Launch", new LaunchArguments(new Arguments([]))); foreach (var section in sections.OrderBy(s => s.Key)) { var fields = Utility.GetFields(section.Value.GetType()); diff --git a/OpenRA.Mods.Common/UtilityCommands/DumpSequenceSheetsCommand.cs b/OpenRA.Mods.Common/UtilityCommands/DumpSequenceSheetsCommand.cs index 1d81cfde7f..6efc04107c 100644 --- a/OpenRA.Mods.Common/UtilityCommands/DumpSequenceSheetsCommand.cs +++ b/OpenRA.Mods.Common/UtilityCommands/DumpSequenceSheetsCommand.cs @@ -17,7 +17,7 @@ namespace OpenRA.Mods.Common.UtilityCommands { sealed class DumpSequenceSheetsCommand : IUtilityCommand { - static readonly int[] ChannelMasks = { 2, 1, 0, 3 }; + static readonly int[] ChannelMasks = [2, 1, 0, 3]; string IUtilityCommand.Name => "--dump-sequence-sheets"; @@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.UtilityCommands // HACK: The engine code assumes that Game.modData is set. var modData = Game.ModData = utility.ModData; - var palette = new ImmutablePalette(args[1], new[] { 0 }, Array.Empty()); + var palette = new ImmutablePalette(args[1], [0], []); SequenceSet sequences; var tilesetUpper = args[2].ToUpperInvariant(); diff --git a/OpenRA.Mods.Common/UtilityCommands/ExtractChromeStrings.cs b/OpenRA.Mods.Common/UtilityCommands/ExtractChromeStrings.cs index eb2fef6d2d..3f189b6434 100644 --- a/OpenRA.Mods.Common/UtilityCommands/ExtractChromeStrings.cs +++ b/OpenRA.Mods.Common/UtilityCommands/ExtractChromeStrings.cs @@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.UtilityCommands if (extractionCandidates.Count > 0) { var chromeFilename = chrome.Split('/').Last(); - groupedCandidates[new HashSet() { chromeFilename }] = new List(); + groupedCandidates[[chromeFilename]] = []; for (var i = 0; i < extractionCandidates.Count; i++) { var candidate = extractionCandidates[i]; @@ -126,7 +126,7 @@ namespace OpenRA.Mods.Common.UtilityCommands if (nHash.Key != null) groupedCandidates[nHash.Key].Add(candidate); else - groupedCandidates[newHash] = new List() { candidate }; + groupedCandidates[newHash] = [candidate]; } var startWithNewline = File.Exists(fluentPath); @@ -214,7 +214,7 @@ namespace OpenRA.Mods.Common.UtilityCommands Key = key; Type = type; Value = value; - Nodes = new List() { node }; + Nodes = [node]; } } @@ -300,7 +300,7 @@ namespace OpenRA.Mods.Common.UtilityCommands if (!string.IsNullOrEmpty(nodeId)) { nodeId = string.Join('-', nodeId.Split('_') - .Except(string.IsNullOrEmpty(container) ? new string[] { widgetType } : container.Split('_').Append(widgetType)) + .Except(string.IsNullOrEmpty(container) ? [widgetType] : container.Split('_').Append(widgetType)) .Where(s => !string.IsNullOrEmpty(s))); if (!string.IsNullOrEmpty(nodeId)) diff --git a/OpenRA.Mods.Common/UtilityCommands/ExtractYamlStrings.cs b/OpenRA.Mods.Common/UtilityCommands/ExtractYamlStrings.cs index e36757a196..f62313f170 100644 --- a/OpenRA.Mods.Common/UtilityCommands/ExtractYamlStrings.cs +++ b/OpenRA.Mods.Common/UtilityCommands/ExtractYamlStrings.cs @@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.UtilityCommands .Where(t => t.Value.Length > 0) .ToDictionary(t => t.Key, t => t.Value); - var modRules = UpdateUtils.LoadModYaml(modData, UpdateUtils.FilterExternalFiles(modData, modData.Manifest.Rules, new HashSet())); + var modRules = UpdateUtils.LoadModYaml(modData, UpdateUtils.FilterExternalFiles(modData, modData.Manifest.Rules, [])); // Include files referenced in maps. foreach (var package in modData.MapCache.EnumerateMapPackagesWithoutCaching()) @@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.UtilityCommands var yaml = new MiniYamlBuilder(null, MiniYaml.FromStream(mapStream, $"{package.Name}:map.yaml", false)); var mapRulesNode = yaml.NodeWithKeyOrDefault("Rules"); if (mapRulesNode != null) - modRules.AddRange(UpdateUtils.LoadExternalMapYaml(modData, mapRulesNode.Value, new HashSet())); + modRules.AddRange(UpdateUtils.LoadExternalMapYaml(modData, mapRulesNode.Value, [])); } } @@ -81,7 +81,7 @@ namespace OpenRA.Mods.Common.UtilityCommands var mapRulesNode = yaml.NodeWithKeyOrDefault("Rules"); if (mapRulesNode != null) - mapRules.AddRange(UpdateUtils.LoadInternalMapYaml(modData, package, mapRulesNode.Value, new HashSet())); + mapRules.AddRange(UpdateUtils.LoadInternalMapYaml(modData, package, mapRulesNode.Value, [])); const string Mapftl = "map.ftl"; ExtractFromFile(Path.Combine(package.Name, Mapftl), mapRules, traitInfos, () => @@ -91,7 +91,7 @@ namespace OpenRA.Mods.Common.UtilityCommands { var value = node.NodeValue(); if (!value.Contains(Mapftl)) - node.Value.Value = string.Join(", ", value.Concat(new string[] { Mapftl }).ToArray()); + node.Value.Value = string.Join(", ", value.Concat([Mapftl]).ToArray()); } else yaml.Nodes.Add(new MiniYamlNodeBuilder("FluentMessages", Mapftl)); @@ -118,7 +118,7 @@ namespace OpenRA.Mods.Common.UtilityCommands if (candidates.Count > 0) { var ruleFilename = file.Split('/').Last(); - groupedCandidates[new HashSet() { ruleFilename }] = new List(); + groupedCandidates[[ruleFilename]] = []; for (var i = 0; i < candidates.Count; i++) { var candidate = candidates[i]; @@ -167,7 +167,7 @@ namespace OpenRA.Mods.Common.UtilityCommands if (nHash.Key != null) groupedCandidates[nHash.Key].Add(candidate); else - groupedCandidates[newHash] = new List() { candidate }; + groupedCandidates[newHash] = [candidate]; } addAction?.Invoke(); @@ -243,7 +243,7 @@ namespace OpenRA.Mods.Common.UtilityCommands Actor = actor; Key = key; Value = value; - Nodes = new List() { node }; + Nodes = [node]; } } diff --git a/OpenRA.Mods.Common/Warheads/ChangeOwnerWarhead.cs b/OpenRA.Mods.Common/Warheads/ChangeOwnerWarhead.cs index 16deb0bfb5..8ea3105c1c 100644 --- a/OpenRA.Mods.Common/Warheads/ChangeOwnerWarhead.cs +++ b/OpenRA.Mods.Common/Warheads/ChangeOwnerWarhead.cs @@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Warheads public override void DoImpact(in Target target, WarheadArgs args) { var firedBy = args.SourceActor; - var actors = target.Type == TargetType.Actor ? new[] { target.Actor } : + var actors = target.Type == TargetType.Actor ? [target.Actor] : firedBy.World.FindActorsInCircle(target.CenterPosition, Range); foreach (var a in actors) diff --git a/OpenRA.Mods.Common/Warheads/CreateEffectWarhead.cs b/OpenRA.Mods.Common/Warheads/CreateEffectWarhead.cs index 664398e729..8ff0444325 100644 --- a/OpenRA.Mods.Common/Warheads/CreateEffectWarhead.cs +++ b/OpenRA.Mods.Common/Warheads/CreateEffectWarhead.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Linq; using OpenRA.GameRules; using OpenRA.Mods.Common.Effects; @@ -24,7 +23,7 @@ namespace OpenRA.Mods.Common.Warheads { [SequenceReference(nameof(Image), allowNullImage: true)] [Desc("List of explosion sequences that can be used.")] - public readonly string[] Explosions = Array.Empty(); + public readonly string[] Explosions = []; [Desc("Image containing explosion effect sequence.")] public readonly string Image = "explosion"; @@ -40,7 +39,7 @@ namespace OpenRA.Mods.Common.Warheads public readonly bool ForceDisplayAtGroundLevel = false; [Desc("List of sounds that can be played on impact.")] - public readonly string[] ImpactSounds = Array.Empty(); + public readonly string[] ImpactSounds = []; [Desc("Chance of impact sound to play.")] public readonly int ImpactSoundChance = 100; diff --git a/OpenRA.Mods.Common/Warheads/CreateResourceWarhead.cs b/OpenRA.Mods.Common/Warheads/CreateResourceWarhead.cs index d404a25a94..a089788a44 100644 --- a/OpenRA.Mods.Common/Warheads/CreateResourceWarhead.cs +++ b/OpenRA.Mods.Common/Warheads/CreateResourceWarhead.cs @@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.Warheads public class CreateResourceWarhead : Warhead { [Desc("Size of the area. The resources are seeded within this area.", "Provide 2 values for a ring effect (outer/inner).")] - public readonly int[] Size = { 0, 0 }; + public readonly int[] Size = [0, 0]; [Desc("Will this splatter resources and which?")] [FieldLoader.Require] diff --git a/OpenRA.Mods.Common/Warheads/DamageWarhead.cs b/OpenRA.Mods.Common/Warheads/DamageWarhead.cs index 4ecb16898d..2fbe65413a 100644 --- a/OpenRA.Mods.Common/Warheads/DamageWarhead.cs +++ b/OpenRA.Mods.Common/Warheads/DamageWarhead.cs @@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Warheads public readonly BitSet DamageTypes = default; [Desc("Damage percentage versus each armor type.")] - public readonly Dictionary Versus = new(); + public readonly Dictionary Versus = []; public override bool IsValidAgainst(Actor victim, Actor firedBy) { diff --git a/OpenRA.Mods.Common/Warheads/DestroyResourceWarhead.cs b/OpenRA.Mods.Common/Warheads/DestroyResourceWarhead.cs index b0b464bca3..b8b069a01a 100644 --- a/OpenRA.Mods.Common/Warheads/DestroyResourceWarhead.cs +++ b/OpenRA.Mods.Common/Warheads/DestroyResourceWarhead.cs @@ -20,13 +20,13 @@ namespace OpenRA.Mods.Common.Warheads public class DestroyResourceWarhead : Warhead { [Desc("Size of the area. The resources are removed within this area.", "Provide 2 values for a ring effect (outer/inner).")] - public readonly int[] Size = { 0, 0 }; + public readonly int[] Size = [0, 0]; [Desc("Amount of resources to be removed. If negative or zero, all resources within the area will be removed.")] public readonly int ResourceAmount = 0; [Desc("Resource types to remove with this warhead.", "If empty, all resource types will be removed.")] - public readonly HashSet ResourceTypes = new(); + public readonly HashSet ResourceTypes = []; public override void DoImpact(in Target target, WarheadArgs args) { diff --git a/OpenRA.Mods.Common/Warheads/FireClusterWarhead.cs b/OpenRA.Mods.Common/Warheads/FireClusterWarhead.cs index b80ae5e0db..9e5b8f9d93 100644 --- a/OpenRA.Mods.Common/Warheads/FireClusterWarhead.cs +++ b/OpenRA.Mods.Common/Warheads/FireClusterWarhead.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using System.Linq; using OpenRA.GameRules; @@ -82,8 +81,8 @@ namespace OpenRA.Mods.Common.Warheads CurrentMuzzleFacing = () => (map.CenterOfCell(targetCell) - target.CenterPosition).Yaw, DamageModifiers = args.DamageModifiers, - InaccuracyModifiers = Array.Empty(), - RangeModifiers = Array.Empty(), + InaccuracyModifiers = [], + RangeModifiers = [], Source = target.CenterPosition, CurrentSource = () => target.CenterPosition, diff --git a/OpenRA.Mods.Common/Warheads/FlashTargetsInRadiusWarhead.cs b/OpenRA.Mods.Common/Warheads/FlashTargetsInRadiusWarhead.cs index 9f34db1b8c..9291afccaf 100644 --- a/OpenRA.Mods.Common/Warheads/FlashTargetsInRadiusWarhead.cs +++ b/OpenRA.Mods.Common/Warheads/FlashTargetsInRadiusWarhead.cs @@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.Warheads { var targetActor = target.Actor; var firedBy = args.SourceActor; - var victims = Radius == WDist.Zero && targetActor != null ? new Actor[] { targetActor } : firedBy.World.FindActorsInCircle(target.CenterPosition, Radius); + var victims = Radius == WDist.Zero && targetActor != null ? [targetActor] : firedBy.World.FindActorsInCircle(target.CenterPosition, Radius); foreach (var victim in victims) { diff --git a/OpenRA.Mods.Common/Warheads/GrantExternalConditionWarhead.cs b/OpenRA.Mods.Common/Warheads/GrantExternalConditionWarhead.cs index 753812cbd2..1c65637d1e 100644 --- a/OpenRA.Mods.Common/Warheads/GrantExternalConditionWarhead.cs +++ b/OpenRA.Mods.Common/Warheads/GrantExternalConditionWarhead.cs @@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Warheads if (target.Type == TargetType.Invalid) return; - var actors = target.Type == TargetType.Actor ? new[] { target.Actor } : + var actors = target.Type == TargetType.Actor ? [target.Actor] : firedBy.World.FindActorsInCircle(target.CenterPosition, Range); foreach (var a in actors) diff --git a/OpenRA.Mods.Common/Warheads/LeaveSmudgeWarhead.cs b/OpenRA.Mods.Common/Warheads/LeaveSmudgeWarhead.cs index c40e79302f..623e093681 100644 --- a/OpenRA.Mods.Common/Warheads/LeaveSmudgeWarhead.cs +++ b/OpenRA.Mods.Common/Warheads/LeaveSmudgeWarhead.cs @@ -22,10 +22,10 @@ namespace OpenRA.Mods.Common.Warheads public class LeaveSmudgeWarhead : Warhead { [Desc("Size of the area. A smudge will be created in each tile.", "Provide 2 values for a ring effect (outer/inner).")] - public readonly int[] Size = { 0, 0 }; + public readonly int[] Size = [0, 0]; [Desc("Type of smudge to apply to terrain.")] - public readonly HashSet SmudgeType = new(); + public readonly HashSet SmudgeType = []; [Desc("Percentage chance the smudge is created.")] public readonly int Chance = 100; diff --git a/OpenRA.Mods.Common/Warheads/SpreadDamageWarhead.cs b/OpenRA.Mods.Common/Warheads/SpreadDamageWarhead.cs index d635ef4a4b..0ebb258168 100644 --- a/OpenRA.Mods.Common/Warheads/SpreadDamageWarhead.cs +++ b/OpenRA.Mods.Common/Warheads/SpreadDamageWarhead.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Warheads public readonly WDist Spread = new(43); [Desc("Damage percentage at each range step")] - public readonly int[] Falloff = { 100, 37, 14, 5, 0 }; + public readonly int[] Falloff = [100, 37, 14, 5, 0]; [Desc("Ranges at which each Falloff step is defined. Overrides Spread.")] public readonly WDist[] Range = null; diff --git a/OpenRA.Mods.Common/Warheads/TargetDamageWarhead.cs b/OpenRA.Mods.Common/Warheads/TargetDamageWarhead.cs index ea53b1a1f5..1814a97003 100644 --- a/OpenRA.Mods.Common/Warheads/TargetDamageWarhead.cs +++ b/OpenRA.Mods.Common/Warheads/TargetDamageWarhead.cs @@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Warheads var debugVis = firedBy.World.WorldActor.TraitOrDefault(); if (debugVis != null && debugVis.CombatGeometry) - firedBy.World.WorldActor.Trait().AddImpact(pos, new[] { WDist.Zero, Spread }, DebugOverlayColor); + firedBy.World.WorldActor.Trait().AddImpact(pos, [WDist.Zero, Spread], DebugOverlayColor); foreach (var victim in firedBy.World.FindActorsOnCircle(pos, Spread)) { diff --git a/OpenRA.Mods.Common/Widgets/ActorPreviewWidget.cs b/OpenRA.Mods.Common/Widgets/ActorPreviewWidget.cs index 1084e979ad..719f17141b 100644 --- a/OpenRA.Mods.Common/Widgets/ActorPreviewWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ActorPreviewWidget.cs @@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Widgets readonly WorldRenderer worldRenderer; readonly WorldViewportSizes viewportSizes; - IActorPreview[] preview = Array.Empty(); + IActorPreview[] preview = []; public int2 PreviewOffset { get; private set; } public int2 IdealPreviewSize { get; private set; } diff --git a/OpenRA.Mods.Common/Widgets/HotkeyEntryWidget.cs b/OpenRA.Mods.Common/Widgets/HotkeyEntryWidget.cs index 9da9f297fe..ba0f2ff081 100644 --- a/OpenRA.Mods.Common/Widgets/HotkeyEntryWidget.cs +++ b/OpenRA.Mods.Common/Widgets/HotkeyEntryWidget.cs @@ -76,13 +76,13 @@ namespace OpenRA.Mods.Common.Widgets return true; } - static readonly Keycode[] IgnoreKeys = new Keycode[] - { + static readonly Keycode[] IgnoreKeys = + [ Keycode.RSHIFT, Keycode.LSHIFT, Keycode.RCTRL, Keycode.LCTRL, Keycode.RALT, Keycode.LALT, Keycode.RGUI, Keycode.LGUI, - }; + ]; public override bool HandleKeyPress(KeyInput e) { diff --git a/OpenRA.Mods.Common/Widgets/LineGraphWidget.cs b/OpenRA.Mods.Common/Widgets/LineGraphWidget.cs index 74561ea3ca..b1249fa648 100644 --- a/OpenRA.Mods.Common/Widgets/LineGraphWidget.cs +++ b/OpenRA.Mods.Common/Widgets/LineGraphWidget.cs @@ -119,7 +119,7 @@ namespace OpenRA.Mods.Common.Widgets var graphBottomOffset = Padding * 2 + xAxisLabelSize.Y + xAxisPointLabelHeight; var height = rect.Height - (graphBottomOffset + Padding); - var maxValue = series.Select(p => p.Points).SelectMany(d => d).Concat(new[] { 0f }).Max(); + var maxValue = series.Select(p => p.Points).SelectMany(d => d).Concat([0f]).Max(); var longestName = series.Select(s => s.Key).OrderByDescending(s => s.Length).FirstOrDefault() ?? ""; var scale = 200 / Math.Max(5000, (float)Math.Ceiling(maxValue / 1000) * 1000); diff --git a/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs index d4440b85ff..d9f7c6ce6f 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs @@ -431,7 +431,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic currentFrame = currentSprites.Length - 1; } - readonly Dictionary assetVisByName = new(); + readonly Dictionary assetVisByName = []; bool FilterAsset(string filename) { @@ -621,7 +621,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (assetSource != null) foreach (var content in assetSource.Contents) - files.Add(content, new List { assetSource }); + files.Add(content, [assetSource]); else { foreach (var mountedPackage in modData.ModFiles.MountedPackages) @@ -629,7 +629,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic foreach (var content in mountedPackage.Contents) { if (!files.TryGetValue(content, out var list)) - files.Add(content, new List { mountedPackage }); + files.Add(content, [mountedPackage]); else list.Add(mountedPackage); } @@ -738,7 +738,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic Widget CreateAssetTypesPanel() { - var assetTypesPanel = Ui.LoadWidget("ASSET_TYPES_PANEL", null, new WidgetArgs()); + var assetTypesPanel = Ui.LoadWidget("ASSET_TYPES_PANEL", null, []); var assetTypeTemplate = assetTypesPanel.Get("ASSET_TYPE_TEMPLATE"); var allAssetTypes = new[] { AssetType.Sprite, AssetType.Model, AssetType.Audio, AssetType.Video, AssetType.Unknown }; diff --git a/OpenRA.Mods.Common/Widgets/Logic/ColorPickerLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ColorPickerLogic.cs index d5f3001f35..70ce972ab0 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/ColorPickerLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/ColorPickerLogic.cs @@ -137,7 +137,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var colorIndex = j * paletteCols + i; var newSwatch = customColorTemplate.Clone(); - var getColor = new CachedTransform(c => colorManager.MakeValid(c, world.LocalRandom, Array.Empty(), Array.Empty())); + var getColor = new CachedTransform(c => colorManager.MakeValid(c, world.LocalRandom, [], [])); newSwatch.GetColor = () => getColor.Update(Game.Settings.Player.CustomColors[colorIndex]); newSwatch.IsVisible = () => Game.Settings.Player.CustomColors.Length > colorIndex; diff --git a/OpenRA.Mods.Common/Widgets/Logic/ConnectionLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ConnectionLogic.cs index 953edd7c28..b15b469e1b 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/ConnectionLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/ConnectionLogic.cs @@ -199,7 +199,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic switchButton.OnClick = () => { var launchCommand = $"Launch.URI={new UriBuilder("tcp", connection.EndPoint.Address.ToString(), connection.EndPoint.Port)}"; - Game.SwitchToExternalMod(CurrentServerSettings.ServerExternalMod, new[] { launchCommand }, () => + Game.SwitchToExternalMod(CurrentServerSettings.ServerExternalMod, [launchCommand], () => { orderManager.ServerError = ModSwitchFailed; Ui.CloseWindow(); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs index e5d1ad63e6..199553fb0a 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs @@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic readonly Widget actorEditPanel; readonly LabelWidget typeLabel; readonly TextFieldWidget actorIDField; - readonly HashSet typableFields = new(); + readonly HashSet typableFields = []; readonly LabelWidget actorIDErrorLabel; readonly Widget initContainer; @@ -485,7 +485,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic sealed class EditActorPreview { readonly SetActorIdAction setActorIdAction; - readonly List handles = new(); + readonly List handles = []; EditorActorPreview actor; public EditActorPreview(ActorEditLogic logic, EditorViewportControllerWidget editor, EditorActorLayer editorActorLayer, EditorActorPreview actor) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/CommonSelectorLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/CommonSelectorLogic.cs index ac5faf8dbe..1cb60f29eb 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/CommonSelectorLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/CommonSelectorLogic.cs @@ -40,8 +40,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic protected readonly ScrollPanelWidget Panel; protected readonly ScrollItemWidget ItemTemplate; - protected readonly HashSet SelectedCategories = new(); - protected readonly List FilteredCategories = new(); + protected readonly HashSet SelectedCategories = []; + protected readonly List FilteredCategories = []; protected string[] allCategories; protected string searchFilter; @@ -119,7 +119,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic protected Widget CreateCategoriesPanel(ScrollPanelWidget panel) { - var categoriesPanel = Ui.LoadWidget("CATEGORY_FILTER_PANEL", null, new WidgetArgs()); + var categoriesPanel = Ui.LoadWidget("CATEGORY_FILTER_PANEL", null, []); var categoryTemplate = categoriesPanel.Get("CATEGORY_TEMPLATE"); var selectButtons = categoriesPanel.Get("SELECT_CATEGORIES_BUTTONS"); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/HistoryLogLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/HistoryLogLogic.cs index 5a79c7b3ef..ccaa1dc65a 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/HistoryLogLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/HistoryLogLogic.cs @@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic readonly EditorActionManager editorActionManager; readonly ScrollItemWidget template; - readonly Dictionary states = new(); + readonly Dictionary states = []; [ObjectCreator.UseCtor] public HistoryLogLogic(Widget widget, World world) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/MapGeneratorToolLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/MapGeneratorToolLogic.cs index e59706a1f9..49288c35f4 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/MapGeneratorToolLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/MapGeneratorToolLogic.cs @@ -61,8 +61,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic this.modData = modData; selectedGenerator = null; - generatorsToSettings = new Dictionary(); - generatorsToSettingsChoices = new Dictionary>(); + generatorsToSettings = []; + generatorsToSettingsChoices = []; var mapGenerators = new List(); var terrainInfo = modData.DefaultTerrainInfo[world.Map.Tileset]; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/MapOverlaysLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/MapOverlaysLogic.cs index d4bdf6d672..b274af89c3 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/MapOverlaysLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/MapOverlaysLogic.cs @@ -95,10 +95,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic Widget CreateOverlaysPanel() { - var categoriesPanel = Ui.LoadWidget("OVERLAY_PANEL", null, new WidgetArgs()); + var categoriesPanel = Ui.LoadWidget("OVERLAY_PANEL", null, []); var categoryTemplate = categoriesPanel.Get("CATEGORY_TEMPLATE"); - MapOverlays[] allCategories = { MapOverlays.Grid, MapOverlays.Buildable, MapOverlays.Marker }; + MapOverlays[] allCategories = [MapOverlays.Grid, MapOverlays.Buildable, MapOverlays.Marker]; foreach (var cat in allCategories) { var category = categoryTemplate.Clone(); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/MapToolsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/MapToolsLogic.cs index 239e542d27..158eb76d31 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/MapToolsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/MapToolsLogic.cs @@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { MapTool.MapGenerator, MapGenerator } }; - readonly Dictionary toolPanels = new(); + readonly Dictionary toolPanels = []; MapTool selectedTool = MapTool.MarkerTiles; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs index 4af4cc4ae4..7d5593ba6c 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs @@ -87,7 +87,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var author = widget.Get("AUTHOR"); author.Text = map.Author; - var visibilityPanel = Ui.LoadWidget("MAP_SAVE_VISIBILITY_PANEL", null, new WidgetArgs()); + var visibilityPanel = Ui.LoadWidget("MAP_SAVE_VISIBILITY_PANEL", null, []); var visOptionTemplate = visibilityPanel.Get("VISIBILITY_TEMPLATE"); visibilityPanel.RemoveChildren(); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/TileSelectorLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/TileSelectorLogic.cs index 9887e738fe..34703c947a 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/TileSelectorLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/TileSelectorLogic.cs @@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic Template = template; Categories = template.Categories; Tooltip = template.Id.ToString(NumberFormatInfo.CurrentInfo); - SearchTerms = new[] { Tooltip }; + SearchTerms = [Tooltip]; } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/EncyclopediaLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/EncyclopediaLogic.cs index 1cf1a95513..c728bb1d4d 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/EncyclopediaLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/EncyclopediaLogic.cs @@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic readonly World world; readonly ModData modData; - readonly Dictionary info = new(); + readonly Dictionary info = []; readonly ScrollPanelWidget descriptionPanel; readonly LabelWidget titleLabel; @@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic readonly LabelWidget productionTime; readonly Widget productionPowerIcon; readonly LabelWidget productionPower; - readonly List sheets = new(); + readonly List sheets = []; ActorInfo selectedActor; ScrollItemWidget firstItem; diff --git a/OpenRA.Mods.Common/Widgets/Logic/GameSaveBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/GameSaveBrowserLogic.cs index a410da7223..bd860b42ba 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/GameSaveBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/GameSaveBrowserLogic.cs @@ -63,7 +63,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic readonly Widget panel; readonly ScrollPanelWidget gameList; readonly TextFieldWidget saveTextField; - readonly List games = new(); + readonly List games = []; readonly Action onStart; readonly Action onExit; readonly ModData modData; @@ -173,7 +173,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic ConfirmationDialogs.ButtonPrompt(modData, title: DeleteSaveTitle, text: DeleteSavePrompt, - textArguments: new object[] { "save", Path.GetFileNameWithoutExtension(selectedSave) }, + textArguments: ["save", Path.GetFileNameWithoutExtension(selectedSave)], onConfirm: () => { Delete(selectedSave); @@ -197,7 +197,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic ConfirmationDialogs.ButtonPrompt(modData, title: DeleteAllSavesTitle, text: DeleteAllSavesPrompt, - textArguments: new object[] { "count", games.Count }, + textArguments: ["count", games.Count], onConfirm: () => { foreach (var s in games.ToList()) @@ -373,7 +373,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic ConfirmationDialogs.ButtonPrompt(modData, title: OverwriteSaveTitle, text: OverwriteSavePrompt, - textArguments: new object[] { "file", saveTextField.Text }, + textArguments: ["file", saveTextField.Text], onConfirm: Inner, confirmText: OverwriteSaveAccept, onCancel: () => { }); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/CommandBarLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/CommandBarLogic.cs index 3bb4fe70ae..7f060026be 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/CommandBarLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/CommandBarLogic.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Widgets readonly World world; int selectionHash; - Actor[] selectedActors = Array.Empty(); + Actor[] selectedActors = []; bool attackMoveDisabled = true; bool forceMoveDisabled = true; bool forceAttackDisabled = true; @@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Widgets int scatterHighlighted; int stopHighlighted; - TraitPair[] selectedDeploys = Array.Empty>(); + TraitPair[] selectedDeploys = []; [ObjectCreator.UseCtor] public CommandBarLogic(Widget widget, World world, Dictionary logicArgs) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoLogic.cs index 0abd27c7ec..70b909562f 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoLogic.cs @@ -150,7 +150,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic void SetupMapPanel(ButtonWidget mapTabButton, Widget mapPanelContainer) { - Game.LoadWidget(world, "MAP_PANEL", mapPanelContainer, new WidgetArgs()); + Game.LoadWidget(world, "MAP_PANEL", mapPanelContainer, []); } void SetupLobbyOptionsPanel(ButtonWidget mapTabButton, Widget optionsPanelContainer) @@ -167,7 +167,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (debugTabButton != null) debugTabButton.IsDisabled = () => world.IsGameOver; - Game.LoadWidget(world, "DEBUG_PANEL", debugPanelContainer, new WidgetArgs()); + Game.LoadWidget(world, "DEBUG_PANEL", debugPanelContainer, []); if (activePanel == IngameInfoPanel.AutoSelect) activePanel = IngameInfoPanel.Debug; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs index 7a6abb3830..16d2aa09f2 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs @@ -160,8 +160,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic ConfirmationDialogs.ButtonPrompt(modData, title: VoteKickTitle, text: botsCount > 0 ? VoteKickPromptBreakBots : VoteKickPrompt, - titleArguments: new object[] { "player", client.Name }, - textArguments: new object[] { "bots", botsCount }, + titleArguments: ["player", client.Name], + textArguments: ["bots", botsCount], onConfirm: () => { orderManager.IssueOrder(Order.Command($"vote_kick {client.Index} {true}")); @@ -176,8 +176,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic ConfirmationDialogs.ButtonPrompt(modData, title: VoteKickTitle, text: botsCount > 0 ? VoteKickPromptBreakBots : VoteKickPrompt, - titleArguments: new object[] { "player", client.Name }, - textArguments: new object[] { "bots", botsCount }, + titleArguments: ["player", client.Name], + textArguments: ["bots", botsCount], onConfirm: () => { orderManager.IssueOrder(Order.Command($"vote_kick {client.Index} {true}")); @@ -201,7 +201,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic ConfirmationDialogs.ButtonPrompt(modData, title: KickTitle, text: KickPrompt, - titleArguments: new object[] { "player", client.Name }, + titleArguments: ["player", client.Name], onConfirm: () => { orderManager.IssueOrder(Order.Command($"kick {client.Index} {false}")); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleBasesHotkeyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleBasesHotkeyLogic.cs index 57b5c3f68c..20d863acc3 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleBasesHotkeyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleBasesHotkeyLogic.cs @@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic.Ingame if (building == null) return true; - selection.Combine(world, new Actor[] { building }, false, true); + selection.Combine(world, [building], false, true); viewport.Center(selection.Actors); return true; } @@ -67,7 +67,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic.Ingame next ??= bases[0]; - selection.Combine(world, new Actor[] { next }, false, true); + selection.Combine(world, [next], false, true); viewport.Center(selection.Actors); return true; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleHarvestersHotkeyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleHarvestersHotkeyLogic.cs index c2ada7cf8d..a074af577e 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleHarvestersHotkeyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleHarvestersHotkeyLogic.cs @@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic.Ingame next ??= harvesters[0]; - selection.Combine(world, new Actor[] { next }, false, true); + selection.Combine(world, [next], false, true); viewport.Center(selection.Actors); return true; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleProductionActorsHotkeyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleProductionActorsHotkeyLogic.cs index 86d3129351..3337487c38 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleProductionActorsHotkeyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleProductionActorsHotkeyLogic.cs @@ -62,7 +62,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic.Ingame Game.Sound.PlayNotification(world.Map.Rules, null, "Sounds", clickSound, null); - selection.Combine(world, new Actor[] { next }, false, true); + selection.Combine(world, [next], false, true); viewport.Center(selection.Actors); return true; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleStatusBarsHotkeyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleStatusBarsHotkeyLogic.cs index 00d618be43..3ef8e28e8c 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleStatusBarsHotkeyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleStatusBarsHotkeyLogic.cs @@ -18,7 +18,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic.Ingame [ChromeLogicArgsHotkeys("CycleStatusBarsKey")] public class CycleStatusBarsHotkeyLogic : SingleHotkeyBaseLogic { - readonly StatusBarsType[] options = { StatusBarsType.Standard, StatusBarsType.DamageShow, StatusBarsType.AlwaysShow }; + readonly StatusBarsType[] options = [StatusBarsType.Standard, StatusBarsType.DamageShow, StatusBarsType.AlwaysShow]; [ObjectCreator.UseCtor] public CycleStatusBarsHotkeyLogic(Widget widget, ModData modData, Dictionary logicArgs) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs index 64a8192b03..a4a36cf50c 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs @@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic readonly TextFieldWidget chatText; readonly CachedTransform chatAvailableIn; readonly string chatDisabled; - readonly Dictionary templates = new(); + readonly Dictionary templates = []; readonly TabCompletionLogic tabCompletion = new(); @@ -88,7 +88,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic foreach (var item in templateIds.Nodes) { var key = FieldLoader.GetValue("key", item.Key); - templates[key] = Ui.LoadWidget(item.Value.Value, null, new WidgetArgs()); + templates[key] = Ui.LoadWidget(item.Value.Value, null, []); } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs index 147980b86b..ea94b62244 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs @@ -142,7 +142,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic readonly Widget buttonContainer; readonly ButtonWidget buttonTemplate; readonly int2 buttonStride; - readonly List buttons = new(); + readonly List buttons = []; readonly ModData modData; readonly Action onExit; @@ -494,7 +494,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic ConfirmationDialogs.ButtonPrompt(modData, title: ErrorMaxPlayerTitle, text: ErrorMaxPlayerPrompt, - textArguments: new object[] { "players", playerCount, "max", MapPlayers.MaximumPlayerCount }, + textArguments: ["players", playerCount, "max", MapPlayers.MaximumPlayerCount], onConfirm: ShowMenu, confirmText: ErrorMaxPlayerAccept); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/LoadIngameHierarchicalPathFinderOverlayLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/LoadIngameHierarchicalPathFinderOverlayLogic.cs index a8c3ecfa1a..cb3d461047 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/LoadIngameHierarchicalPathFinderOverlayLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/LoadIngameHierarchicalPathFinderOverlayLogic.cs @@ -18,7 +18,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic [ObjectCreator.UseCtor] public LoadIngameHierarchicalPathFinderOverlayLogic(Widget widget, World world) { - Game.LoadWidget(world, "HPF_OVERLAY", widget, new WidgetArgs()); + Game.LoadWidget(world, "HPF_OVERLAY", widget, []); } } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/LoadIngamePerfLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/LoadIngamePerfLogic.cs index 0e1a63adc0..0b9b94bdea 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/LoadIngamePerfLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/LoadIngamePerfLogic.cs @@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic public LoadIngamePerfLogic(Widget widget, World world) { var perfRoot = widget.Get("PERF_ROOT"); - Game.LoadWidget(world, "PERF_WIDGETS", perfRoot, new WidgetArgs()); + Game.LoadWidget(world, "PERF_WIDGETS", perfRoot, []); } } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/LoadIngamePlayerOrObserverUILogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/LoadIngamePlayerOrObserverUILogic.cs index 7fd05d02a4..c13e9204dc 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/LoadIngamePlayerOrObserverUILogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/LoadIngamePlayerOrObserverUILogic.cs @@ -28,10 +28,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic var playerRoot = worldRoot.Get("PLAYER_ROOT"); if (world.LocalPlayer == null) - Game.LoadWidget(world, "OBSERVER_WIDGETS", playerRoot, new WidgetArgs()); + Game.LoadWidget(world, "OBSERVER_WIDGETS", playerRoot, []); else { - var playerWidgets = Game.LoadWidget(world, "PLAYER_WIDGETS", playerRoot, new WidgetArgs()); + var playerWidgets = Game.LoadWidget(world, "PLAYER_WIDGETS", playerRoot, []); var sidebarTicker = playerWidgets.Get("SIDEBAR_TICKER"); var objectives = world.LocalPlayer.PlayerActor.Info.TraitInfoOrDefault(); @@ -47,14 +47,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic return; playerRoot.RemoveChildren(); - Game.LoadWidget(world, "OBSERVER_WIDGETS", playerRoot, new WidgetArgs()); + Game.LoadWidget(world, "OBSERVER_WIDGETS", playerRoot, []); }); } }; } - Game.LoadWidget(world, "DEBUG_WIDGETS", worldRoot, new WidgetArgs()); - Game.LoadWidget(world, "TRANSIENTS_PANEL", worldRoot, new WidgetArgs()); + Game.LoadWidget(world, "DEBUG_WIDGETS", worldRoot, []); + Game.LoadWidget(world, "TRANSIENTS_PANEL", worldRoot, []); world.GameOver += () => { diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/LoadMapEditorLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/LoadMapEditorLogic.cs index de26f77601..a0f5f01b6e 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/LoadMapEditorLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/LoadMapEditorLogic.cs @@ -19,8 +19,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic public LoadMapEditorLogic(Widget widget, World world) { var editorRoot = widget.Get("WORLD_ROOT"); - Game.LoadWidget(world, "EDITOR_WORLD_ROOT", editorRoot, new WidgetArgs()); - Game.LoadWidget(world, "TRANSIENTS_PANEL", editorRoot, new WidgetArgs()); + Game.LoadWidget(world, "EDITOR_WORLD_ROOT", editorRoot, []); + Game.LoadWidget(world, "TRANSIENTS_PANEL", editorRoot, []); } } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/MenuButtonsChromeLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/MenuButtonsChromeLogic.cs index e2875b533a..65ceb769d5 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/MenuButtonsChromeLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/MenuButtonsChromeLogic.cs @@ -101,7 +101,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (button.DisableWorldSounds) Game.Sound.DisableWorldSounds = true; - widgetArgs ??= new WidgetArgs(); + widgetArgs ??= []; widgetArgs.Add("onExit", () => { if (button.HideIngameUI) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverShroudSelectorLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverShroudSelectorLogic.cs index 5acd8e931d..25a1c51002 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverShroudSelectorLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverShroudSelectorLogic.cs @@ -107,7 +107,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic combined = new CameraOption(this, world, FluentProvider.GetMessage(CameraOptionAllPlayers), world.Players.First(p => p.InternalName == "Everyone")); disableShroud = new CameraOption(this, world, FluentProvider.GetMessage(CameraOptionDisableShroud), null); if (!limitViews) - groups.Add(FluentProvider.GetMessage(CameraOptionOther), new List() { combined, disableShroud }); + groups.Add(FluentProvider.GetMessage(CameraOptionOther), [combined, disableShroud]); teams = world.Players.Where(p => !p.NonCombatant && p.Playable) .Select(p => new CameraOption(this, p)) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/StanceSelectorLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/StanceSelectorLogic.cs index 263f2982cf..de8c81f472 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/StanceSelectorLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/StanceSelectorLogic.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Linq; using OpenRA.Mods.Common.Traits; using OpenRA.Widgets; @@ -21,7 +20,7 @@ namespace OpenRA.Mods.Common.Widgets readonly World world; int selectionHash; - TraitPair[] actorStances = Array.Empty>(); + TraitPair[] actorStances = []; [ObjectCreator.UseCtor] public StanceSelectorLogic(Widget widget, World world) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Installation/DownloadPackageLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Installation/DownloadPackageLogic.cs index 56eca67cc2..869b37dab2 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Installation/DownloadPackageLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Installation/DownloadPackageLogic.cs @@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic [FluentReference] const string MirrorSelectionFailed = "label-mirror-selection-failed"; - static readonly string[] SizeSuffixes = { "bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" }; + static readonly string[] SizeSuffixes = ["bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]; readonly ModData modData; readonly ModContent.ModDownload download; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentLogic.cs index 0bc6477446..1ea51f3848 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentLogic.cs @@ -62,8 +62,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic readonly ScrollPanelWidget scrollPanel; readonly Widget template; - readonly Dictionary sources = new(); - readonly Dictionary downloads = new(); + readonly Dictionary sources = []; + readonly Dictionary downloads = []; bool sourceAvailable; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs index ceeaaa9899..afb7c562d5 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs @@ -82,14 +82,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic readonly Widget newSpectatorTemplate; readonly ScrollPanelWidget lobbyChatPanel; - readonly Dictionary chatTemplates = new(); + readonly Dictionary chatTemplates = []; readonly TextFieldWidget chatTextField; readonly CachedTransform chatAvailableIn; readonly string chatDisabled; readonly ScrollPanelWidget players; - readonly Dictionary factions = new(); + readonly Dictionary factions = []; readonly IColorPickerManagerInfo colorManager; @@ -104,7 +104,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic bool teamChat; bool updateDiscordStatus = true; bool resetOptionsButtonEnabled; - Dictionary spawnOccupants = new(); + Dictionary spawnOccupants = []; readonly string chatLineSound; readonly string playerJoinedSound; @@ -207,7 +207,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic UpdateCurrentMap(); - var playerBin = Ui.LoadWidget("LOBBY_PLAYER_BIN", lobby.Get("TOP_PANELS_ROOT"), new WidgetArgs()); + var playerBin = Ui.LoadWidget("LOBBY_PLAYER_BIN", lobby.Get("TOP_PANELS_ROOT"), []); playerBin.IsVisible = () => panel == PanelType.Players; players = playerBin.Get("LOBBY_PLAYERS"); @@ -464,7 +464,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic }; } - var forceStartBin = Ui.LoadWidget("FORCE_START_DIALOG", lobby.Get("TOP_PANELS_ROOT"), new WidgetArgs()); + var forceStartBin = Ui.LoadWidget("FORCE_START_DIALOG", lobby.Get("TOP_PANELS_ROOT"), []); forceStartBin.IsVisible = () => panel == PanelType.ForceStart; forceStartBin.Get("KICK_WARNING").IsVisible = () => orderManager.LobbyInfo.Clients.Any(c => c.IsInvalid); var forceStartButton = forceStartBin.Get("OK_BUTTON"); @@ -492,7 +492,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic foreach (var item in templateIds.Nodes) { var key = FieldLoader.GetValue("key", item.Key); - chatTemplates[key] = Ui.LoadWidget(item.Value.Value, null, new WidgetArgs()); + chatTemplates[key] = Ui.LoadWidget(item.Value.Value, null, []); } } @@ -655,7 +655,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic // We don't have the map else if (map.Status != MapStatus.DownloadAvailable && Game.Settings.Game.AllowDownloading) - modData.MapCache.QueryRemoteMapDetails(services.MapRepository, new[] { uid }); + modData.MapCache.QueryRemoteMapDetails(services.MapRepository, [uid]); } void UpdatePlayerList() diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/MapPreviewLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/MapPreviewLogic.cs index dfef5130e7..2121836bcf 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/MapPreviewLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/MapPreviewLogic.cs @@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic const string CreatedBy = "label-created-by"; readonly int blinkTickLength = 10; - readonly Dictionary previewWidgets = new(); + readonly Dictionary previewWidgets = []; readonly Func<(MapPreview Map, Session.MapStatus Status)> getMap; enum PreviewStatus @@ -195,7 +195,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic }); } else if (map.Status == MapStatus.Unavailable) - modData.MapCache.QueryRemoteMapDetails(mapRepository, new[] { map.Uid }); + modData.MapCache.QueryRemoteMapDetails(mapRepository, [map.Uid]); }; var retryInstall = FluentProvider.GetMessage(RetryInstall); @@ -207,27 +207,27 @@ namespace OpenRA.Mods.Common.Widgets.Logic // Widgets to be made visible. previewWidgets[PreviewStatus.Unknown] = - new Widget[] { previewLarge }; + [previewLarge]; previewWidgets[PreviewStatus.Playable] = - new Widget[] { previewLarge, SetupAuthorAndMapType(widget.Get("MAP_AVAILABLE")) }; + [previewLarge, SetupAuthorAndMapType(widget.Get("MAP_AVAILABLE"))]; previewWidgets[PreviewStatus.Incompatible] = - new Widget[] { previewLarge, widget.Get("MAP_INCOMPATIBLE") }; + [previewLarge, widget.Get("MAP_INCOMPATIBLE")]; previewWidgets[PreviewStatus.Validating] = - new Widget[] { previewSmall, widget.Get("MAP_VALIDATING") }; + [previewSmall, widget.Get("MAP_VALIDATING")]; previewWidgets[PreviewStatus.UpdateAvailable] = - new Widget[] { previewSmall, widget.Get("MAP_UPDATE_AVAILABLE"), updateButton }; + [previewSmall, widget.Get("MAP_UPDATE_AVAILABLE"), updateButton]; previewWidgets[PreviewStatus.DownloadAvailable] = - new Widget[] { previewSmall, SetUpInstallButton(SetupAuthorAndMapType(widget.Get("MAP_DOWNLOAD_AVAILABLE"))) }; + [previewSmall, SetUpInstallButton(SetupAuthorAndMapType(widget.Get("MAP_DOWNLOAD_AVAILABLE")))]; previewWidgets[PreviewStatus.UpdateDownloadAvailable] = - new Widget[] { previewSmall, SetUpInstallButton(widget.Get("MAP_UPDATE_DOWNLOAD_AVAILABLE")), updateButton }; + [previewSmall, SetUpInstallButton(widget.Get("MAP_UPDATE_DOWNLOAD_AVAILABLE")), updateButton]; previewWidgets[PreviewStatus.Searching] = - new Widget[] { previewSmall, widget.Get("MAP_SEARCHING") }; + [previewSmall, widget.Get("MAP_SEARCHING")]; previewWidgets[PreviewStatus.Downloading] = - new Widget[] { previewSmall, SetUpDownloadProgress(widget.Get("MAP_DOWNLOADING")) }; + [previewSmall, SetUpDownloadProgress(widget.Get("MAP_DOWNLOADING"))]; previewWidgets[PreviewStatus.Unavailable] = - new Widget[] { previewSmall, widget.Get("MAP_UNAVAILABLE"), retryButton }; + [previewSmall, widget.Get("MAP_UNAVAILABLE"), retryButton]; previewWidgets[PreviewStatus.DownloadError] = - new Widget[] { previewSmall, widget.Get("MAP_ERROR"), retryButton }; + [previewSmall, widget.Get("MAP_ERROR"), retryButton]; // Hide all widgets. foreach (var preview in previewWidgets) @@ -235,7 +235,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic p.IsVisible = () => false; } - Widget[] visibleWidgets = Array.Empty(); + Widget[] visibleWidgets = []; void UpdateVisibility() { diff --git a/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs index 84101a31e9..686ee3407d 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs @@ -228,7 +228,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { newsBG.IsVisible = () => Game.Settings.Game.FetchNews && menuType != MenuType.None && menuType != MenuType.StartupPrompts; - newsPanel = Ui.LoadWidget("NEWS_PANEL", null, new WidgetArgs()); + newsPanel = Ui.LoadWidget("NEWS_PANEL", null, []); newsTemplate = newsPanel.Get("NEWS_ITEM_TEMPLATE"); newsPanel.RemoveChild(newsTemplate); maxNewsHeight = newsPanel.Bounds.Height; diff --git a/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs index 79695d51f6..28023d6dbc 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs @@ -95,9 +95,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic int remoteSearching = 0; int remoteUnavailable = 0; - readonly Dictionary scrollpanels = new(); + readonly Dictionary scrollpanels = []; - readonly Dictionary tabMaps = new(); + readonly Dictionary tabMaps = []; string[] visibleMaps; string selectedUid; @@ -291,7 +291,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic } } else - tabMaps[tab] = Array.Empty(); + tabMaps[tab] = []; } void SetupMapTab(MapClassification tab, MapVisibility filter, string tabButtonName, string tabContainerName) @@ -514,7 +514,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic ConfirmationDialogs.ButtonPrompt(modData, title: DeleteMapTitle, text: DeleteMapPrompt, - textArguments: new object[] { "title", modData.MapCache[map].Title }, + textArguments: ["title", modData.MapCache[map].Title], onConfirm: () => { var newUid = DeleteMap(map); diff --git a/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs index 0a3c2a7edb..1d10fb84d3 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs @@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic bool minifiedOptions = true; MapPreview selectedMap; PlayingVideo playingVideo; - readonly Dictionary missionOptions = new(); + readonly Dictionary missionOptions = []; PanelType panel = PanelType.MissionInfo; [ObjectCreator.UseCtor] diff --git a/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs index 3e310fe58d..d80aeb7d1c 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs @@ -109,8 +109,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic readonly Widget panel; readonly ScrollPanelWidget replayList, playerList; readonly ScrollItemWidget playerTemplate, playerHeader; - readonly List replays = new(); - readonly Dictionary replayState = new(); + readonly List replays = []; + readonly Dictionary replayState = []; readonly Action onStart; readonly ModData modData; readonly WebServices services; @@ -507,7 +507,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic ConfirmationDialogs.ButtonPrompt(modData, title: DeleteReplayTitle, text: DeleteReplayPrompt, - textArguments: new object[] { "replay", Path.GetFileNameWithoutExtension(r.FilePath) }, + textArguments: ["replay", Path.GetFileNameWithoutExtension(r.FilePath)], onConfirm: () => { DeleteReplay(r); @@ -545,7 +545,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic ConfirmationDialogs.ButtonPrompt(modData, title: DeleteAllReplaysTitle, text: DeleteAllReplaysPrompt, - textArguments: new object[] { "count", list.Count }, + textArguments: ["count", list.Count], onConfirm: () => { foreach (var replayMetadata in list) @@ -713,7 +713,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic try { if (map.Status == MapStatus.Unavailable && Game.Settings.Game.AllowDownloading) - modData.MapCache.QueryRemoteMapDetails(services.MapRepository, new[] { map.Uid }); + modData.MapCache.QueryRemoteMapDetails(services.MapRepository, [map.Uid]); var players = replay.GameInfo.Players .GroupBy(p => p.Team) diff --git a/OpenRA.Mods.Common/Widgets/Logic/ServerListLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ServerListLogic.cs index 24e3ba6b55..32d5d61733 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/ServerListLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/ServerListLogic.cs @@ -248,7 +248,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic // HACK: MULTIPLAYER_FILTER_PANEL doesn't follow our normal procedure for dropdown creation // but we still need to be able to set the dropdown width based on the parent // The yaml should use PARENT_WIDTH instead of DROPDOWN_WIDTH - var filtersPanel = Ui.LoadWidget("MULTIPLAYER_FILTER_PANEL", filtersButton, new WidgetArgs()); + var filtersPanel = Ui.LoadWidget("MULTIPLAYER_FILTER_PANEL", filtersButton, []); filtersButton.Children.Remove(filtersPanel); var showWaitingCheckbox = filtersPanel.GetOrNull("WAITING_FOR_PLAYERS"); @@ -398,14 +398,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic clientContainer = widget.GetOrNull("CLIENT_LIST_CONTAINER"); if (clientContainer != null) { - clientList = Ui.LoadWidget("MULTIPLAYER_CLIENT_LIST", clientContainer, new WidgetArgs()) as ScrollPanelWidget; + clientList = Ui.LoadWidget("MULTIPLAYER_CLIENT_LIST", clientContainer, []) as ScrollPanelWidget; clientList.IsVisible = () => currentServer != null && currentServer.Clients.Length > 0; clientHeader = clientList.Get("HEADER"); clientTemplate = clientList.Get("TEMPLATE"); clientList.RemoveChildren(); } - lanGameLocations = new List(); + lanGameLocations = []; try { lanGameProbe = new Probe("OpenRALANGame"); @@ -461,7 +461,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var result = await httpResponseMessage.Content.ReadAsStreamAsync(); var yaml = MiniYaml.FromStream(result, queryURL); - games = new List(); + games = []; foreach (var node in yaml) { try diff --git a/OpenRA.Mods.Common/Widgets/Logic/Settings/GamePlaySettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Settings/GamePlaySettingsLogic.cs index f9b085e9db..b36888f96d 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Settings/GamePlaySettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Settings/GamePlaySettingsLogic.cs @@ -28,9 +28,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic [FluentReference] const string AutoSaveMaxFileNumber = "auto-save-max-file-number"; - readonly int[] autoSaveSeconds = { 0, 10, 30, 45, 60, 120, 180, 300, 600 }; + readonly int[] autoSaveSeconds = [0, 10, 30, 45, 60, 120, 180, 300, 600]; - readonly int[] autoSaveFileNumbers = { 3, 5, 10, 20, 50, 100 }; + readonly int[] autoSaveFileNumbers = [3, 5, 10, 20, 50, 100]; [ObjectCreator.UseCtor] public GameplaySettingsLogic(Action>, Func> registerPanel, string panelID, string label) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Settings/HotkeysSettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Settings/HotkeysSettingsLogic.cs index 27e86b1703..3061a6cb9e 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Settings/HotkeysSettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Settings/HotkeysSettingsLogic.cs @@ -41,8 +41,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic bool isHotkeyDefault; string currentContext = AnyContext; - readonly HashSet contexts = new() { AnyContext }; - readonly Dictionary> hotkeyGroups = new(); + readonly HashSet contexts = [AnyContext]; + readonly Dictionary> hotkeyGroups = []; TextFieldWidget filterInput; Widget headerTemplate; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Settings/SettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Settings/SettingsLogic.cs index e819d24e77..eca56a13ea 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Settings/SettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Settings/SettingsLogic.cs @@ -52,14 +52,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic [FluentReference] const string ResetCancel = "dialog-settings-reset.cancel"; - readonly Dictionary> leavePanelActions = new(); - readonly Dictionary resetPanelActions = new(); + readonly Dictionary> leavePanelActions = []; + readonly Dictionary resetPanelActions = []; readonly Widget panelContainer, tabContainer; readonly ButtonWidget tabTemplate; readonly int2 buttonStride; - readonly List buttons = new(); - readonly Dictionary panels = new(); + readonly List buttons = []; + readonly Dictionary panels = []; string activePanel; bool needsRestart = false; @@ -143,7 +143,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic ConfirmationDialogs.ButtonPrompt(modData, title: ResetTitle, text: ResetPrompt, - titleArguments: new object[] { "panel", panels[activePanel] }, + titleArguments: ["panel", panels[activePanel]], onConfirm: Reset, confirmText: ResetAccept, onCancel: () => { }, diff --git a/OpenRA.Mods.Common/Widgets/Logic/TabCompletionLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/TabCompletionLogic.cs index d31ebc4c69..24afc69fc7 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/TabCompletionLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/TabCompletionLogic.cs @@ -18,7 +18,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { public class TabCompletionLogic : ChromeLogic { - IList candidates = new List(); + IList candidates = []; int currentCandidateIndex = 0; string lastCompleted; string prefix; diff --git a/OpenRA.Mods.Common/Widgets/LogicKeyListenerWidget.cs b/OpenRA.Mods.Common/Widgets/LogicKeyListenerWidget.cs index d218b6fffb..d6413a67f8 100644 --- a/OpenRA.Mods.Common/Widgets/LogicKeyListenerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/LogicKeyListenerWidget.cs @@ -17,7 +17,7 @@ namespace OpenRA.Mods.Common.Widgets { public class LogicKeyListenerWidget : Widget { - readonly List> handlers = new(); + readonly List> handlers = []; public override bool HandleKeyPress(KeyInput e) { diff --git a/OpenRA.Mods.Common/Widgets/MapPreviewWidget.cs b/OpenRA.Mods.Common/Widgets/MapPreviewWidget.cs index 2ce62d1c26..1958c465f8 100644 --- a/OpenRA.Mods.Common/Widgets/MapPreviewWidget.cs +++ b/OpenRA.Mods.Common/Widgets/MapPreviewWidget.cs @@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Widgets public class MapPreviewWidget : Widget { - static readonly int[] NoDisabledSpawnPoints = Array.Empty(); + static readonly int[] NoDisabledSpawnPoints = []; public readonly bool IgnoreMouseInput = false; public readonly bool ShowSpawnPoints = true; @@ -72,7 +72,7 @@ namespace OpenRA.Mods.Common.Widgets readonly int2 spawnLabelOffset; public Func Preview = () => null; - public Func> SpawnOccupants = () => new Dictionary(); + public Func> SpawnOccupants = () => []; public Func> DisabledSpawnPoints = () => NoDisabledSpawnPoints; public Action OnMouseDown = _ => { }; public int TooltipSpawnIndex = -1; diff --git a/OpenRA.Mods.Common/Widgets/ObserverArmyIconsWidget.cs b/OpenRA.Mods.Common/Widgets/ObserverArmyIconsWidget.cs index d36111c911..ef3387565c 100644 --- a/OpenRA.Mods.Common/Widgets/ObserverArmyIconsWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ObserverArmyIconsWidget.cs @@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Widgets public readonly string TooltipContainer; readonly Lazy tooltipContainer; - readonly List armyIcons = new(); + readonly List armyIcons = []; readonly CachedTransform stats = new(player => player.PlayerActor.TraitOrDefault()); diff --git a/OpenRA.Mods.Common/Widgets/ObserverProductionIconsWidget.cs b/OpenRA.Mods.Common/Widgets/ObserverProductionIconsWidget.cs index 91c9bd0ab2..779dac6eef 100644 --- a/OpenRA.Mods.Common/Widgets/ObserverProductionIconsWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ObserverProductionIconsWidget.cs @@ -42,8 +42,8 @@ namespace OpenRA.Mods.Common.Widgets readonly Dictionary clocks; readonly Lazy tooltipContainer; - readonly List productionIcons = new(); - readonly List productionIconsBounds = new(); + readonly List productionIcons = []; + readonly List productionIconsBounds = []; readonly float2 iconSize; int lastIconIdx; @@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Widgets { this.world = world; this.worldRenderer = worldRenderer; - clocks = new Dictionary(); + clocks = []; GetTooltipIcon = () => TooltipIcon; tooltipContainer = Exts.Lazy(() => Ui.Root.Get(TooltipContainer)); diff --git a/OpenRA.Mods.Common/Widgets/ObserverSupportPowerIconsWidget.cs b/OpenRA.Mods.Common/Widgets/ObserverSupportPowerIconsWidget.cs index 9367288295..879b73447f 100644 --- a/OpenRA.Mods.Common/Widgets/ObserverSupportPowerIconsWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ObserverSupportPowerIconsWidget.cs @@ -41,8 +41,8 @@ namespace OpenRA.Mods.Common.Widgets public string ClockPalette = "chrome"; public Func GetPlayer; - readonly List supportPowerIconsIcons = new(); - readonly List supportPowerIconsBounds = new(); + readonly List supportPowerIconsIcons = []; + readonly List supportPowerIconsBounds = []; Animation icon; int lastIconIdx; int currentTooltipToken; @@ -52,7 +52,7 @@ namespace OpenRA.Mods.Common.Widgets { this.world = world; this.worldRenderer = worldRenderer; - clocks = new Dictionary(); + clocks = []; tooltipContainer = Exts.Lazy(() => Ui.Root.Get(TooltipContainer)); diff --git a/OpenRA.Mods.Common/Widgets/PerfGraphWidget.cs b/OpenRA.Mods.Common/Widgets/PerfGraphWidget.cs index 9972e06874..007d0f1116 100644 --- a/OpenRA.Mods.Common/Widgets/PerfGraphWidget.cs +++ b/OpenRA.Mods.Common/Widgets/PerfGraphWidget.cs @@ -25,12 +25,12 @@ namespace OpenRA.Mods.Common.Widgets var origin = new float2(rect.Right, rect.Bottom); var basis = new float2(-rect.Width / 100, -rect.Height / 100); - cr.DrawLine(new[] - { + cr.DrawLine( + [ new float3(rect.Left, rect.Top, 0), new float3(rect.Left, rect.Bottom, 0), new float3(rect.Right, rect.Bottom, 0) - }, 1, Color.White); + ], 1, Color.White); cr.DrawLine(origin + new float2(100, 0) * basis, origin + new float2(100, 100) * basis, 1, Color.White); diff --git a/OpenRA.Mods.Common/Widgets/ProductionPaletteWidget.cs b/OpenRA.Mods.Common/Widgets/ProductionPaletteWidget.cs index aec024f60f..c58b822125 100644 --- a/OpenRA.Mods.Common/Widgets/ProductionPaletteWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ProductionPaletteWidget.cs @@ -117,7 +117,7 @@ namespace OpenRA.Mods.Common.Widgets } public override Rectangle EventBounds => eventBounds; - Dictionary icons = new(); + Dictionary icons = []; Animation cantBuild; Animation clock; Rectangle eventBounds = Rectangle.Empty; @@ -144,7 +144,7 @@ namespace OpenRA.Mods.Common.Widgets count = FieldLoader.GetValue("HotkeyCount", countNode.Value.Value); if (count == 0) - return Array.Empty(); + return []; if (string.IsNullOrEmpty(prefix)) emitError($"{widgetNode.Location} must define HotkeyPrefix if HotkeyCount > 0."); @@ -223,7 +223,7 @@ namespace OpenRA.Mods.Common.Widgets get { if (CurrentQueue == null) - return Enumerable.Empty(); + return []; return CurrentQueue.AllItems().OrderBy(a => a.TraitInfo().BuildPaletteOrder); } @@ -452,7 +452,7 @@ namespace OpenRA.Mods.Common.Widgets if (selection.Actors.Count == 1 && selection.Contains(facility)) viewport.Center(selection.Actors); else - selection.Combine(World, new[] { facility }, false, true); + selection.Combine(World, [facility], false, true); Game.Sound.PlayNotification(World.Map.Rules, null, "Sounds", ClickSound, null); return true; @@ -466,7 +466,7 @@ namespace OpenRA.Mods.Common.Widgets public void RefreshIcons() { - icons = new Dictionary(); + icons = []; var producer = CurrentQueue != null ? CurrentQueue.MostLikelyProducer() : default; if (CurrentQueue == null || producer.Trait == null) { diff --git a/OpenRA.Mods.Common/Widgets/ProductionTabsWidget.cs b/OpenRA.Mods.Common/Widgets/ProductionTabsWidget.cs index 867f5f515b..fbad20ee1a 100644 --- a/OpenRA.Mods.Common/Widgets/ProductionTabsWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ProductionTabsWidget.cs @@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Widgets public class ProductionTabGroup { - public List Tabs = new(); + public List Tabs = []; public string Group; public int NextQueueName = 1; public bool Alert { get { return Tabs.Any(t => t.Queue.AllQueued().Any(i => i.Done)); } } @@ -105,7 +105,7 @@ namespace OpenRA.Mods.Common.Widgets readonly Lazy paletteWidget; string queueGroup; - readonly List<(ProductionQueue Queue, bool Enabled)> cachedProductionQueueEnabledStates = new(); + readonly List<(ProductionQueue Queue, bool Enabled)> cachedProductionQueueEnabledStates = []; [ObjectCreator.UseCtor] public ProductionTabsWidget(World world) diff --git a/OpenRA.Mods.Common/Widgets/SelectionUtils.cs b/OpenRA.Mods.Common/Widgets/SelectionUtils.cs index 5666319d01..e035869de9 100644 --- a/OpenRA.Mods.Common/Widgets/SelectionUtils.cs +++ b/OpenRA.Mods.Common/Widgets/SelectionUtils.cs @@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Widgets var isShroudDisabled = viewer == null || (world.RenderPlayer == null && world.LocalPlayer.Spectating); var isEveryone = viewer != null && viewer.NonCombatant && viewer.Spectating; - return isShroudDisabled || isEveryone ? world.Players : new[] { viewer }; + return isShroudDisabled || isEveryone ? world.Players : [viewer]; } } } diff --git a/OpenRA.Mods.Common/Widgets/SupportPowersWidget.cs b/OpenRA.Mods.Common/Widgets/SupportPowersWidget.cs index 8337733ad1..a556c79ac7 100644 --- a/OpenRA.Mods.Common/Widgets/SupportPowersWidget.cs +++ b/OpenRA.Mods.Common/Widgets/SupportPowersWidget.cs @@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Widgets Animation icon; Animation clock; - Dictionary icons = new(); + Dictionary icons = []; public SupportPowerIcon TooltipIcon { get; private set; } public Func GetTooltipIcon; @@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Widgets count = FieldLoader.GetValue("HotkeyCount", countNode.Value.Value); if (count == 0) - return Array.Empty(); + return []; if (string.IsNullOrEmpty(prefix)) emitError($"{widgetNode.Location} must define HotkeyPrefix if HotkeyCount > 0."); @@ -132,7 +132,7 @@ namespace OpenRA.Mods.Common.Widgets public void RefreshIcons() { - icons = new Dictionary(); + icons = []; var powers = spm.Powers.Values.Where(p => !p.Disabled) .OrderBy(p => p.Info.SupportPowerPaletteOrder); diff --git a/OpenRA.Mods.Common/Widgets/TextNotificationsDisplayWidget.cs b/OpenRA.Mods.Common/Widgets/TextNotificationsDisplayWidget.cs index f9e03cae9e..9f6ed38725 100644 --- a/OpenRA.Mods.Common/Widgets/TextNotificationsDisplayWidget.cs +++ b/OpenRA.Mods.Common/Widgets/TextNotificationsDisplayWidget.cs @@ -29,9 +29,9 @@ namespace OpenRA.Mods.Common.Widgets public string MissionTemplate = "CHAT_LINE_TEMPLATE"; public string FeedbackTemplate = "TRANSIENT_LINE_TEMPLATE"; public string TransientsTemplate = "TRANSIENT_LINE_TEMPLATE"; - readonly Dictionary templates = new(); + readonly Dictionary templates = []; - readonly List expirations = new(); + readonly List expirations = []; Rectangle overflowDrawBounds = Rectangle.Empty; public override Rectangle EventBounds => Rectangle.Empty; @@ -40,11 +40,11 @@ namespace OpenRA.Mods.Common.Widgets { base.Initialize(args); - templates.Add(TextNotificationPool.Chat, Ui.LoadWidget(ChatTemplate, null, new WidgetArgs())); - templates.Add(TextNotificationPool.System, Ui.LoadWidget(SystemTemplate, null, new WidgetArgs())); - templates.Add(TextNotificationPool.Mission, Ui.LoadWidget(MissionTemplate, null, new WidgetArgs())); - templates.Add(TextNotificationPool.Feedback, Ui.LoadWidget(FeedbackTemplate, null, new WidgetArgs())); - templates.Add(TextNotificationPool.Transients, Ui.LoadWidget(TransientsTemplate, null, new WidgetArgs())); + templates.Add(TextNotificationPool.Chat, Ui.LoadWidget(ChatTemplate, null, [])); + templates.Add(TextNotificationPool.System, Ui.LoadWidget(SystemTemplate, null, [])); + templates.Add(TextNotificationPool.Mission, Ui.LoadWidget(MissionTemplate, null, [])); + templates.Add(TextNotificationPool.Feedback, Ui.LoadWidget(FeedbackTemplate, null, [])); + templates.Add(TextNotificationPool.Transients, Ui.LoadWidget(TransientsTemplate, null, [])); // HACK: Assume that all templates use the same font var lineHeight = Game.Renderer.Fonts[templates[TextNotificationPool.Chat].Get("TEXT").Font].Measure("").Y; diff --git a/OpenRA.Mods.Common/WorldExtensions.cs b/OpenRA.Mods.Common/WorldExtensions.cs index 1a7add10ba..2046bcf206 100644 --- a/OpenRA.Mods.Common/WorldExtensions.cs +++ b/OpenRA.Mods.Common/WorldExtensions.cs @@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common return actors.Select(a => (a, targetOffsets(a))); var mobile = sourceActor.TraitOrDefault(); if (mobile == null) - return Enumerable.Empty<(Actor Actor, WVec[] ReachableOffsets)>(); + return []; var pathFinder = sourceActor.World.WorldActor.Trait(); var locomotor = mobile.Locomotor; @@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common /// public static IEnumerable WithPathFrom(this IEnumerable actors, Actor sourceActor) { - return actors.WithPathFrom(sourceActor, _ => new[] { WVec.Zero }).Select(x => x.Actor); + return actors.WithPathFrom(sourceActor, _ => [WVec.Zero]).Select(x => x.Actor); } /// @@ -71,7 +71,7 @@ namespace OpenRA.Mods.Common this IEnumerable actors, Actor sourceActor, Func targetOffsets = null) { return actors - .WithPathFrom(sourceActor, targetOffsets ?? (_ => new[] { WVec.Zero })) + .WithPathFrom(sourceActor, targetOffsets ?? (_ => [WVec.Zero])) .Select(x => x.Actor) .ClosestToIgnoringPath(sourceActor); } diff --git a/OpenRA.Mods.D2k/Graphics/SonicBlastRenderable.cs b/OpenRA.Mods.D2k/Graphics/SonicBlastRenderable.cs index 406f700b63..64a55215a2 100644 --- a/OpenRA.Mods.D2k/Graphics/SonicBlastRenderable.cs +++ b/OpenRA.Mods.D2k/Graphics/SonicBlastRenderable.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using OpenRA.Graphics; using OpenRA.Mods.D2k.Traits; @@ -19,7 +18,7 @@ namespace OpenRA.Mods.D2k.Graphics { public class SonicBlastRenderable : IRenderable, IFinalizedRenderable { - public static readonly IEnumerable None = Array.Empty(); + public static readonly IEnumerable None = []; readonly SonicBlastRenderer renderer; readonly float3 r; diff --git a/OpenRA.Mods.D2k/PackageLoaders/D2kSoundResources.cs b/OpenRA.Mods.D2k/PackageLoaders/D2kSoundResources.cs index 44cf1aae35..fdd3e86e6b 100644 --- a/OpenRA.Mods.D2k/PackageLoaders/D2kSoundResources.cs +++ b/OpenRA.Mods.D2k/PackageLoaders/D2kSoundResources.cs @@ -37,7 +37,7 @@ namespace OpenRA.Mods.D2k.PackageLoaders public IEnumerable Contents => index.Keys; readonly Stream s; - readonly Dictionary index = new(); + readonly Dictionary index = []; public D2kSoundResources(Stream s, string filename) { diff --git a/OpenRA.Mods.D2k/Projectiles/SonicBlast.cs b/OpenRA.Mods.D2k/Projectiles/SonicBlast.cs index 2d32591f8e..11de6d1538 100644 --- a/OpenRA.Mods.D2k/Projectiles/SonicBlast.cs +++ b/OpenRA.Mods.D2k/Projectiles/SonicBlast.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.D2k.Projectiles public class SonicBlastInfo : IProjectileInfo { [Desc("Projectile speed in WDist / tick, two values indicate a randomly picked velocity per blast.")] - public readonly WDist[] Speed = { new(128) }; + public readonly WDist[] Speed = [new(128)]; [Desc("The number of ticks between the blast causing warhead impacts in its area of effect.")] public readonly int DamageInterval = 1; @@ -37,10 +37,10 @@ namespace OpenRA.Mods.D2k.Projectiles public readonly WDist Width = new(650); [Desc("Damage modifier applied at each range step.")] - public readonly int[] Falloff = { 100, 100 }; + public readonly int[] Falloff = [100, 100]; [Desc("Ranges at which each Falloff step is defined.")] - public readonly WDist[] Range = { WDist.Zero, new(int.MaxValue) }; + public readonly WDist[] Range = [WDist.Zero, new(int.MaxValue)]; [Desc("The maximum/constant/incremental inaccuracy used in conjunction with the InaccuracyType property.")] public readonly WDist Inaccuracy = WDist.Zero; @@ -148,7 +148,7 @@ namespace OpenRA.Mods.D2k.Projectiles public IEnumerable Render(WorldRenderer wr) { if (!wr.World.FogObscures(pos)) - return new[] { (IRenderable)new SonicBlastRenderable(renderer, pos) }; + return [(new SonicBlastRenderable(renderer, pos))]; return SpriteRenderable.None; } diff --git a/OpenRA.Mods.D2k/Traits/AttractsWorms.cs b/OpenRA.Mods.D2k/Traits/AttractsWorms.cs index 0ff996383f..f0c690355f 100644 --- a/OpenRA.Mods.D2k/Traits/AttractsWorms.cs +++ b/OpenRA.Mods.D2k/Traits/AttractsWorms.cs @@ -20,7 +20,7 @@ namespace OpenRA.Mods.D2k.Traits public readonly int Intensity = 0; [Desc("Noise percentage at Range step away from the actor.")] - public readonly int[] Falloff = { 100, 100, 25, 11, 6, 4, 3, 2, 1, 0 }; + public readonly int[] Falloff = [100, 100, 25, 11, 6, 4, 3, 2, 1, 0]; [Desc("Range between falloff steps.")] public readonly WDist Spread = new(3072); diff --git a/OpenRA.Mods.D2k/Traits/Buildings/D2kActorPreviewPlaceBuildingPreview.cs b/OpenRA.Mods.D2k/Traits/Buildings/D2kActorPreviewPlaceBuildingPreview.cs index e0f0d77081..ddf55ebd67 100644 --- a/OpenRA.Mods.D2k/Traits/Buildings/D2kActorPreviewPlaceBuildingPreview.cs +++ b/OpenRA.Mods.D2k/Traits/Buildings/D2kActorPreviewPlaceBuildingPreview.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using System.Linq; using OpenRA.Graphics; @@ -24,10 +23,10 @@ namespace OpenRA.Mods.D2k.Traits public class D2kActorPreviewPlaceBuildingPreviewInfo : ActorPreviewPlaceBuildingPreviewInfo { [Desc("Terrain types that should show the 'unsafe' footprint tile.")] - public readonly HashSet UnsafeTerrainTypes = new() { "Rock" }; + public readonly HashSet UnsafeTerrainTypes = ["Rock"]; [Desc("Only check for 'unsafe' footprint tiles when you have these prerequisites.")] - public readonly string[] RequiresPrerequisites = Array.Empty(); + public readonly string[] RequiresPrerequisites = []; [Desc("Sprite image to use for the overlay.")] public readonly string Image = "overlay"; diff --git a/OpenRA.Mods.D2k/Traits/Buildings/D2kBuilding.cs b/OpenRA.Mods.D2k/Traits/Buildings/D2kBuilding.cs index b6b33f2557..ca892e6e78 100644 --- a/OpenRA.Mods.D2k/Traits/Buildings/D2kBuilding.cs +++ b/OpenRA.Mods.D2k/Traits/Buildings/D2kBuilding.cs @@ -31,7 +31,7 @@ namespace OpenRA.Mods.D2k.Traits.Buildings public readonly BitSet DamageTypes = default; [Desc("Terrain types where the actor will take damage.")] - public readonly string[] DamageTerrainTypes = { "Rock" }; + public readonly string[] DamageTerrainTypes = ["Rock"]; [Desc("Percentage health below which the actor will not receive further damage.")] public readonly int DamageThreshold = 50; @@ -44,7 +44,7 @@ namespace OpenRA.Mods.D2k.Traits.Buildings public readonly ushort ConcreteTemplate = 88; [Desc("List of required prerequisites to place a terrain template.")] - public readonly string[] ConcretePrerequisites = Array.Empty(); + public readonly string[] ConcretePrerequisites = []; public override object Create(ActorInitializer init) { return new D2kBuilding(init, this); } } diff --git a/OpenRA.Mods.D2k/Traits/SpiceBloom.cs b/OpenRA.Mods.D2k/Traits/SpiceBloom.cs index 340e1ea228..3379c921d9 100644 --- a/OpenRA.Mods.D2k/Traits/SpiceBloom.cs +++ b/OpenRA.Mods.D2k/Traits/SpiceBloom.cs @@ -25,28 +25,28 @@ namespace OpenRA.Mods.D2k.Traits public class SpiceBloomInfo : TraitInfo, IRenderActorPreviewSpritesInfo, Requires { [SequenceReference] - public readonly string[] GrowthSequences = { "grow1", "grow2", "grow3" }; + public readonly string[] GrowthSequences = ["grow1", "grow2", "grow3"]; [SequenceReference] public readonly string SpurtSequence = "spurt"; [Desc("The range of time (in ticks) that the spicebloom will take to grow until it blows up.")] - public readonly int[] Lifetime = { 2000, 3000 }; + public readonly int[] Lifetime = [2000, 3000]; public readonly string ResourceType = "Spice"; [Desc("Spice blooms only grow on these terrain types.")] - public readonly HashSet GrowthTerrainTypes = new(); + public readonly HashSet GrowthTerrainTypes = []; [Desc("The weapon to use for spice creation.")] [WeaponReference] public readonly string Weapon = null; [Desc("The number of times to fire Weapon at the minimum and maximum actor age.")] - public readonly int[] Bursts = { 4, 12 }; + public readonly int[] Bursts = [4, 12]; [Desc("The minimum and maximum distance in cells that spice may be expelled.")] - public readonly int[] Range = { 3, 5 }; + public readonly int[] Range = [3, 5]; [Desc("Delay between each burst. (in Ticks)")] public readonly int BurstInterval = 1; @@ -167,7 +167,7 @@ namespace OpenRA.Mods.D2k.Traits public class FireProjectilesEffect : IEffect { - readonly Stack projectiles = new(); + readonly Stack projectiles = []; int delay = 1; readonly int delayInfo = 1; public FireProjectilesEffect(Stack projectiles, int delayInfo) diff --git a/OpenRA.Mods.D2k/Traits/World/BuildableTerrainLayer.cs b/OpenRA.Mods.D2k/Traits/World/BuildableTerrainLayer.cs index d8c4cf405f..fa12a34407 100644 --- a/OpenRA.Mods.D2k/Traits/World/BuildableTerrainLayer.cs +++ b/OpenRA.Mods.D2k/Traits/World/BuildableTerrainLayer.cs @@ -35,7 +35,7 @@ namespace OpenRA.Mods.D2k.Traits public class BuildableTerrainLayer : IRenderOverlay, IWorldLoaded, ITickRender, IRadarTerrainLayer, INotifyActorDisposing { readonly BuildableTerrainLayerInfo info; - readonly Dictionary dirty = new(); + readonly Dictionary dirty = []; readonly ITiledTerrainRenderer terrainRenderer; readonly World world; readonly CellLayer strength; diff --git a/OpenRA.Mods.D2k/Traits/World/SonicBlastRenderer.cs b/OpenRA.Mods.D2k/Traits/World/SonicBlastRenderer.cs index 23514ea043..1bc3288180 100644 --- a/OpenRA.Mods.D2k/Traits/World/SonicBlastRenderer.cs +++ b/OpenRA.Mods.D2k/Traits/World/SonicBlastRenderer.cs @@ -35,7 +35,7 @@ namespace OpenRA.Mods.D2k.Traits readonly Renderer renderer; readonly IShader shader; readonly IVertexBuffer buffer; - readonly List positions = new(); + readonly List positions = []; public SonicBlastRenderer(SonicBlastRendererInfo info) { diff --git a/OpenRA.Mods.D2k/UtilityCommands/D2kMapImporter.cs b/OpenRA.Mods.D2k/UtilityCommands/D2kMapImporter.cs index f3c43a6abd..758c437d71 100644 --- a/OpenRA.Mods.D2k/UtilityCommands/D2kMapImporter.cs +++ b/OpenRA.Mods.D2k/UtilityCommands/D2kMapImporter.cs @@ -439,12 +439,12 @@ namespace OpenRA.Mods.D2k.UtilityCommands if (tileIndex == indices[i]) return new TerrainTile(474, (byte)i); - indices = new[] { 369, 370, 389, 390 }; + indices = [369, 370, 389, 390]; for (var i = 0; i < 4; i++) if (tileIndex == indices[i]) return new TerrainTile(117, (byte)i); - indices = new[] { 661, 662, 681, 682 }; + indices = [661, 662, 681, 682]; for (var i = 0; i < 4; i++) if (tileIndex == indices[i]) return new TerrainTile(251, (byte)i); @@ -493,12 +493,12 @@ namespace OpenRA.Mods.D2k.UtilityCommands if (tileIndex == indices[i]) return new TerrainTile(308, (byte)i); - indices = new[] { 660, 661, 662, 680, 681, 682 }; + indices = [660, 661, 662, 680, 681, 682]; for (var i = 0; i < 6; i++) if (tileIndex == indices[i]) return new TerrainTile(443, (byte)i); - indices = new[] { 609, 610, 629, 630 }; + indices = [609, 610, 629, 630]; for (var i = 0; i < 4; i++) if (tileIndex == indices[i]) return new TerrainTile(251, (byte)i); diff --git a/OpenRA.Platforms.Default/OpenAlSoundEngine.cs b/OpenRA.Platforms.Default/OpenAlSoundEngine.cs index ef20e13640..cd2ac0d13c 100644 --- a/OpenRA.Platforms.Default/OpenAlSoundEngine.cs +++ b/OpenRA.Platforms.Default/OpenAlSoundEngine.cs @@ -69,7 +69,7 @@ namespace OpenRA.Platforms.Default if (devicesPtr == IntPtr.Zero || AL10.alGetError() != AL10.AL_NO_ERROR) { Log.Write("sound", $"Failed to query OpenAL device list using {label}"); - return Array.Empty(); + return []; } var devices = new List(); @@ -103,7 +103,7 @@ namespace OpenRA.Platforms.Default if (ALC11.alcIsExtensionPresent(IntPtr.Zero, "ALC_ENUMERATION_EXT")) return QueryDevices("ALC_ENUMERATION_EXT", ALC10.ALC_DEVICE_SPECIFIER); - return Array.Empty(); + return []; } internal static int MakeALFormat(int channels, int bits) diff --git a/OpenRA.Platforms.Default/Shader.cs b/OpenRA.Platforms.Default/Shader.cs index 4e0c0223aa..88d8a05ed9 100644 --- a/OpenRA.Platforms.Default/Shader.cs +++ b/OpenRA.Platforms.Default/Shader.cs @@ -19,10 +19,10 @@ namespace OpenRA.Platforms.Default { sealed class Shader : ThreadAffine, IShader { - readonly Dictionary samplers = new(); - readonly Dictionary uniformCache = new(); - readonly Dictionary textures = new(); - readonly Queue unbindTextures = new(); + readonly Dictionary samplers = []; + readonly Dictionary uniformCache = []; + readonly Dictionary textures = []; + readonly Queue unbindTextures = []; readonly IShaderBindings bindings; readonly uint program; @@ -37,7 +37,7 @@ namespace OpenRA.Platforms.Default unsafe { var length = code.Length; - OpenGL.glShaderSource(shader, 1, new string[] { code }, new IntPtr(&length)); + OpenGL.glShaderSource(shader, 1, [code], new IntPtr(&length)); } OpenGL.CheckGLError(); diff --git a/OpenRA.Platforms.Default/ThreadedGraphicsContext.cs b/OpenRA.Platforms.Default/ThreadedGraphicsContext.cs index 5244ad680f..2d5cbf5494 100644 --- a/OpenRA.Platforms.Default/ThreadedGraphicsContext.cs +++ b/OpenRA.Platforms.Default/ThreadedGraphicsContext.cs @@ -24,9 +24,9 @@ namespace OpenRA.Platforms.Default sealed class ThreadedGraphicsContext : IGraphicsContext { // PERF: Maintain several object pools to reduce allocations. - readonly Dictionary vertexBufferPools = new(); - readonly Stack messagePool = new(); - readonly Queue messages = new(); + readonly Dictionary vertexBufferPools = []; + readonly Stack messagePool = []; + readonly Queue messages = []; public readonly int VertexBatchSize; public readonly int IndexBatchSize; @@ -100,8 +100,8 @@ namespace OpenRA.Platforms.Default tuple => { (object t, var type) = ((int, Type))tuple; - var vertexBuffer = context.GetType().GetMethod(nameof(CreateVertexBuffer)).MakeGenericMethod(type).Invoke(context, new[] { t }); - return typeof(ThreadedVertexBuffer<>).MakeGenericType(type).GetConstructors()[0].Invoke(new[] { this, vertexBuffer }); + var vertexBuffer = context.GetType().GetMethod(nameof(CreateVertexBuffer)).MakeGenericMethod(type).Invoke(context, [t]); + return typeof(ThreadedVertexBuffer<>).MakeGenericType(type).GetConstructors()[0].Invoke([this, vertexBuffer]); }; getCreateIndexBuffer = indices => new ThreadedIndexBuffer(this, context.CreateIndexBuffer((uint[])indices)); doDrawPrimitives = diff --git a/OpenRA.Server/Program.cs b/OpenRA.Server/Program.cs index 6e27bef7dc..2f76d0d0ed 100644 --- a/OpenRA.Server/Program.cs +++ b/OpenRA.Server/Program.cs @@ -64,7 +64,7 @@ namespace OpenRA.Server var explicitModPaths = Array.Empty(); if (modID != null && (File.Exists(modID) || Directory.Exists(modID))) { - explicitModPaths = new[] { modID }; + explicitModPaths = [modID]; modID = Path.GetFileNameWithoutExtension(modID); } @@ -81,7 +81,7 @@ namespace OpenRA.Server var envModSearchPaths = Environment.GetEnvironmentVariable("MOD_SEARCH_PATHS"); var modSearchPaths = !string.IsNullOrWhiteSpace(envModSearchPaths) ? FieldLoader.GetValue("MOD_SEARCH_PATHS", envModSearchPaths) : - new[] { Path.Combine(Platform.EngineDir, "mods") }; + [Path.Combine(Platform.EngineDir, "mods")]; var mods = new InstalledMods(modSearchPaths, explicitModPaths); diff --git a/OpenRA.Test/OpenRA.Game/ActionQueueTest.cs b/OpenRA.Test/OpenRA.Game/ActionQueueTest.cs index 09c7e01cbc..1fd95c62d1 100644 --- a/OpenRA.Test/OpenRA.Game/ActionQueueTest.cs +++ b/OpenRA.Test/OpenRA.Game/ActionQueueTest.cs @@ -36,7 +36,7 @@ namespace OpenRA.Test queue.PerformActions(1); queue.PerformActions(2); queue.PerformActions(3); - if (!list.SequenceEqual(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 })) + if (!list.SequenceEqual([1, 2, 3, 4, 5, 6, 7, 8, 9])) Assert.Fail("Actions were not performed in the correct order. Actual order was: " + string.Join(", ", list)); } } diff --git a/OpenRA.Test/OpenRA.Game/FluentTest.cs b/OpenRA.Test/OpenRA.Game/FluentTest.cs index de029cbdc0..f36a7d4031 100644 --- a/OpenRA.Test/OpenRA.Game/FluentTest.cs +++ b/OpenRA.Test/OpenRA.Game/FluentTest.cs @@ -28,9 +28,9 @@ label-players = {$player -> public void TestOne() { var bundle = new FluentBundle("en", pluralForms, e => Console.WriteLine(e.Message)); - var label = bundle.GetMessage("label-players", new object[] { "player", 1 }); + var label = bundle.GetMessage("label-players", ["player", 1]); Assert.That("One player", Is.EqualTo(label)); - label = bundle.GetMessage("label-players", new object[] { "player", 2 }); + label = bundle.GetMessage("label-players", ["player", 2]); Assert.That("2 players", Is.EqualTo(label)); } } diff --git a/OpenRA.Test/OpenRA.Game/MiniYamlTest.cs b/OpenRA.Test/OpenRA.Game/MiniYamlTest.cs index 12e8f168b7..4eec2f24c4 100644 --- a/OpenRA.Test/OpenRA.Game/MiniYamlTest.cs +++ b/OpenRA.Test/OpenRA.Game/MiniYamlTest.cs @@ -172,7 +172,7 @@ Parent: const string ResultString = "Parent:\n\tChild:\n"; var baseYaml = MiniYaml.FromString(BaseString, ""); - var resultYaml = MiniYaml.Merge(new[] { baseYaml }); + var resultYaml = MiniYaml.Merge([baseYaml]); Assert.That(ResultString, Is.EqualTo(resultYaml.WriteToString())); } @@ -195,7 +195,7 @@ Parent: var baseYaml = MiniYaml.FromString(BaseString, ""); var mergeYaml = MiniYaml.FromString(MergeString, ""); - var resultYaml = MiniYaml.Merge(new[] { baseYaml, mergeYaml }); + var resultYaml = MiniYaml.Merge([baseYaml, mergeYaml]); Assert.That(ResultString, Is.EqualTo(resultYaml.WriteToString())); } @@ -220,7 +220,7 @@ Parent: var baseYaml = MiniYaml.FromString(BaseString, ""); var mergeYaml = MiniYaml.FromString(MergeString, ""); - var resultYaml = MiniYaml.Merge(new[] { baseYaml, mergeYaml }); + var resultYaml = MiniYaml.Merge([baseYaml, mergeYaml]); Assert.That(ResultString, Is.EqualTo(resultYaml.WriteToString())); } @@ -453,7 +453,7 @@ Parent: var baseYaml = MiniYaml.FromString(BaseYaml, ""); var mergeYaml = MiniYaml.FromString(ExtendedYaml, ""); - var resultYaml = MiniYaml.Merge(new[] { baseYaml, mergeYaml }); + var resultYaml = MiniYaml.Merge([baseYaml, mergeYaml]); Assert.That(ResultString, Is.EqualTo(resultYaml.WriteToString())); } diff --git a/OpenRA.Test/OpenRA.Game/PngTest.cs b/OpenRA.Test/OpenRA.Game/PngTest.cs index a453a81def..9bb5f633ef 100644 --- a/OpenRA.Test/OpenRA.Game/PngTest.cs +++ b/OpenRA.Test/OpenRA.Game/PngTest.cs @@ -86,7 +86,7 @@ namespace OpenRA.Test public void PngConstructor_InvalidSignature_ThrowsInvalidDataException() { // Arrange - byte[] invalidSignature = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }; + byte[] invalidSignature = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07]; // Act & Assert var exception = Assert.Throws(() => new Png(new MemoryStream(invalidSignature))); diff --git a/OpenRA.Test/OpenRA.Mods.Common/ShapeTest.cs b/OpenRA.Test/OpenRA.Mods.Common/ShapeTest.cs index de8698b1de..9c731c0d38 100644 --- a/OpenRA.Test/OpenRA.Mods.Common/ShapeTest.cs +++ b/OpenRA.Test/OpenRA.Mods.Common/ShapeTest.cs @@ -98,7 +98,7 @@ namespace OpenRA.Test { // Rectangle like above, // Note: The calculations don't match for all, but do have a tolerance of 1. - shape = new PolygonShape(new int2[] { new(-123, -456), new(100, -456), new(100, 100), new(-123, 100) }); + shape = new PolygonShape([new(-123, -456), new(100, -456), new(100, 100), new(-123, 100)]); shape.Initialize(); Assert.That(shape.DistanceFromEdge(new WVec(10, 10, 0)).Length, @@ -121,7 +121,7 @@ namespace OpenRA.Test // Rectangle like above but reverse order // Note: The calculations don't match for all, but do have a tolerance of 1. - shape = new PolygonShape(new int2[] { new(-123, 100), new(100, 100), new(100, -456), new(-123, -456) }); + shape = new PolygonShape([new(-123, 100), new(100, 100), new(100, -456), new(-123, -456)]); shape.Initialize(); Assert.That(shape.DistanceFromEdge(new WVec(10, 10, 0)).Length, @@ -143,7 +143,7 @@ namespace OpenRA.Test Is.EqualTo(877)); // Right triangle taken from above by removing a point - shape = new PolygonShape(new int2[] { new(-123, -456), new(100, -456), new(100, 100) }); + shape = new PolygonShape([new(-123, -456), new(100, -456), new(100, 100)]); shape.Initialize(); Assert.That(shape.DistanceFromEdge(new WVec(10, 10, 0)).Length, @@ -171,7 +171,7 @@ namespace OpenRA.Test Is.EqualTo(878)); // Right triangle taken from above but reverse order - shape = new PolygonShape(new int2[] { new(100, 100), new(100, -456), new(-123, -456) }); + shape = new PolygonShape([new(100, 100), new(100, -456), new(-123, -456)]); shape.Initialize(); Assert.That(shape.DistanceFromEdge(new WVec(10, 10, 0)).Length, @@ -199,12 +199,12 @@ namespace OpenRA.Test Is.EqualTo(878)); // Plus shaped dodecagon - shape = new PolygonShape(new[] - { + shape = new PolygonShape( + [ new int2(-511, -1535), new int2(511, -1535), new int2(511, -511), new int2(1535, -511), new int2(1535, 511), new int2(511, 511), new int2(511, 1535), new int2(-511, 1535), new int2(-511, 511), new int2(-1535, 511), new int2(-1535, -511), new int2(-511, -511) - }); + ]); shape.Initialize(); Assert.That(shape.DistanceFromEdge(new WVec(10, 10, 0)).Length, diff --git a/OpenRA.Utility/Program.cs b/OpenRA.Utility/Program.cs index 4095ed90d0..af2ee20360 100644 --- a/OpenRA.Utility/Program.cs +++ b/OpenRA.Utility/Program.cs @@ -63,11 +63,11 @@ namespace OpenRA var envModSearchPaths = Environment.GetEnvironmentVariable("MOD_SEARCH_PATHS"); var modSearchPaths = !string.IsNullOrWhiteSpace(envModSearchPaths) ? FieldLoader.GetValue("MOD_SEARCH_PATHS", envModSearchPaths) : - new[] { Path.Combine(Platform.EngineDir, "mods") }; + [Path.Combine(Platform.EngineDir, "mods")]; if (args.Length == 0) { - PrintUsage(new InstalledMods(modSearchPaths, Array.Empty()), null); + PrintUsage(new InstalledMods(modSearchPaths, []), null); return; } @@ -75,7 +75,7 @@ namespace OpenRA var explicitModPaths = Array.Empty(); if (File.Exists(modId) || Directory.Exists(modId)) { - explicitModPaths = new[] { modId }; + explicitModPaths = [modId]; modId = Path.GetFileNameWithoutExtension(modId); } diff --git a/OpenRA.WindowsLauncher/Program.cs b/OpenRA.WindowsLauncher/Program.cs index 29e4f6553f..0018a2f753 100644 --- a/OpenRA.WindowsLauncher/Program.cs +++ b/OpenRA.WindowsLauncher/Program.cs @@ -144,7 +144,7 @@ namespace OpenRA.WindowsLauncher flags = SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_ERROR, title = "Fatal Error", message = displayName + " has encountered a fatal error and must close.\nRefer to the crash logs and FAQ for more information.", - buttons = new[] { quit, viewFaq, viewLogs }, + buttons = [quit, viewFaq, viewLogs], numbuttons = 3 };