From 89a4823a8330eeee54131f5a06dfcdf110460385 Mon Sep 17 00:00:00 2001 From: Gustas <37534529+PunkPun@users.noreply.github.com> Date: Wed, 20 Aug 2025 13:43:21 +0300 Subject: [PATCH] Add a lint test for running update rules --- .../Lint/CheckRunningUpdateRule.cs | 49 +++++++++++++++++++ .../UpdateRules/MockUpdateRule.cs | 36 ++++++++++++++ mods/cnc/rules/campaign-palettes.yaml | 6 +-- mods/d2k/rules/defaults.yaml | 2 +- mods/d2k/rules/map-generators.yaml | 4 +- mods/ts/rules/ai.yaml | 4 +- 6 files changed, 93 insertions(+), 8 deletions(-) create mode 100644 OpenRA.Mods.Common/Lint/CheckRunningUpdateRule.cs create mode 100644 OpenRA.Mods.Common/UpdateRules/MockUpdateRule.cs diff --git a/OpenRA.Mods.Common/Lint/CheckRunningUpdateRule.cs b/OpenRA.Mods.Common/Lint/CheckRunningUpdateRule.cs new file mode 100644 index 0000000000..8d46c82a1e --- /dev/null +++ b/OpenRA.Mods.Common/Lint/CheckRunningUpdateRule.cs @@ -0,0 +1,49 @@ +#region Copyright & License Information +/* + * Copyright (c) The OpenRA Developers and Contributors + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using OpenRA.Mods.Common.UpdateRules; +using OpenRA.Mods.Common.UpdateRules.Rules; + +namespace OpenRA.Mods.Common.Lint +{ + /// + /// Checks the loading of YAML files for mods without ignoring comments and whitespace. + /// + sealed class CheckRunningUpdateRule : ILintRulesPass + { + void ILintRulesPass.Run(Action emitError, Action emitWarning, ModData modData, Ruleset rules) + { + try + { + var externalFilenames = new HashSet(); + UpdateUtils.UpdateMod(modData, new MockUpdateRule(), out var allFiles, externalFilenames); + + foreach (var (package, file, nodes) in allFiles) + { + if (package == null) + continue; + + var textData = Encoding.UTF8.GetBytes(nodes.WriteToString()); + if (!Enumerable.SequenceEqual(textData, package.GetStream(file).ReadAllBytes())) + emitError($"Mock update rule has tried to modify file {file}. Syntax mismatch detected."); + } + } + catch (Exception ex) + { + emitError($"Mock update rule failed with message: {ex.Message}"); + } + } + } +} diff --git a/OpenRA.Mods.Common/UpdateRules/MockUpdateRule.cs b/OpenRA.Mods.Common/UpdateRules/MockUpdateRule.cs new file mode 100644 index 0000000000..eb25ad1997 --- /dev/null +++ b/OpenRA.Mods.Common/UpdateRules/MockUpdateRule.cs @@ -0,0 +1,36 @@ +#region Copyright & License Information +/* + * Copyright (c) The OpenRA Developers and Contributors + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System.Collections.Generic; + +namespace OpenRA.Mods.Common.UpdateRules.Rules +{ + public class MockUpdateRule : UpdateRule, IBeforeUpdateActors, IBeforeUpdateWeapons, IBeforeUpdateSequences + { + public override string Name => "Mock Update Rule"; + public override string Description => "A mock update rule that allows to test YAML loading and can be used to correct YAML syntax."; + + public interface IBeforeUpdateActors + { + IEnumerable BeforeUpdateActors(ModData modData, List resolvedActors) { yield break; } + } + + public interface IBeforeUpdateWeapons + { + IEnumerable BeforeUpdateWeapons(ModData modData, List resolvedWeapons) { yield break; } + } + + public interface IBeforeUpdateSequences + { + IEnumerable BeforeUpdateSequences(ModData modData, List resolvedImages) { yield break; } + } + } +} diff --git a/mods/cnc/rules/campaign-palettes.yaml b/mods/cnc/rules/campaign-palettes.yaml index 3fda231745..bf3e100a12 100644 --- a/mods/cnc/rules/campaign-palettes.yaml +++ b/mods/cnc/rules/campaign-palettes.yaml @@ -21,10 +21,10 @@ IndexedPlayerPalette@derricks: BasePalette: terrain BaseName: derrick - RemapIndex: 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 171, 173, 144, 145 + RemapIndex: 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 171, 173, 144, 145 PlayerIndex: - GDI: 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 179, 180, 188, 180 - Nod: 127, 126, 125, 124, 122, 46, 120, 47, 125, 124, 123, 122, 42, 121, 120, 120, 124, 122, 42, 122 + GDI: 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 179, 180, 188, 180 + Nod: 127, 126, 125, 124, 122, 46, 120, 47, 125, 124, 123, 122, 42, 121, 120, 120, 124, 122, 42, 122 Neutral: 192, 164, 132, 155, 133, 197, 112, 12, 163, 132, 155, 133, 134, 197, 154, 198, 155, 133, 134, 133 FixedPlayerColorShift: BasePalette: player diff --git a/mods/d2k/rules/defaults.yaml b/mods/d2k/rules/defaults.yaml index aaa6a1a212..4eab468eaf 100644 --- a/mods/d2k/rules/defaults.yaml +++ b/mods/d2k/rules/defaults.yaml @@ -780,7 +780,7 @@ MapEditorData: Categories: Destroyed Tiles -^DamagedBuildingEffects : +^DamagedBuildingEffects: GrantConditionOnFaction@atreidesVFX: Condition: atreidesVFX Factions: atreides, fremen diff --git a/mods/d2k/rules/map-generators.yaml b/mods/d2k/rules/map-generators.yaml index 799f51aeda..ab01222e0a 100644 --- a/mods/d2k/rules/map-generators.yaml +++ b/mods/d2k/rules/map-generators.yaml @@ -37,7 +37,7 @@ SandDetailClumpiness: 1 SandDetailCutout: 2 MaximumSandDetailCutoutSpacing: 12 - + # CreateEntities: True AreaEntityBonus: 0 PlayerCountEntityBonus: 1000000 @@ -58,7 +58,7 @@ WormSpawn: wormspawner WormSpawns: 1 WormSpawnReservation: 12 - + # SandTile: 0 RockTile: 266 PlayableTerrain: Clear,Concrete,Dune,Rock,Rough,Sand,Spice,SpiceSand,Transition diff --git a/mods/ts/rules/ai.yaml b/mods/ts/rules/ai.yaml index cfcf5d0b15..786a271a21 100644 --- a/mods/ts/rules/ai.yaml +++ b/mods/ts/rules/ai.yaml @@ -11,10 +11,10 @@ Player: RefineryTypes: proc PowerDownBotModule: RequiresCondition: enable-test-ai - PowerDownTypes: garadr, naradr, gavulc,garock,gacsam,gactwr,naobel,nalasr,nasam + PowerDownTypes: garadr, naradr, gavulc,garock,gacsam,gactwr,naobel,nalasr,nasam ResourceMapBotModule: RequiresCondition: enable-test-ai - ResourceCreatorTypes: tibtre01, tibtre02, tibtre03, bigblue, bigblue3 + ResourceCreatorTypes: tibtre01, tibtre02, tibtre03, bigblue, bigblue3 ValuableResourceTypes: Tiberium, BlueTiberium HarvesterTypes: harv RefineryTypes: proc