Add a lint test for running update rules

This commit is contained in:
Gustas
2025-08-20 13:43:21 +03:00
committed by Gustas Kažukauskas
parent bd53aa734e
commit 89a4823a83
6 changed files with 93 additions and 8 deletions

View File

@@ -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
{
/// <summary>
/// Checks the loading of YAML files for mods without ignoring comments and whitespace.
/// </summary>
sealed class CheckRunningUpdateRule : ILintRulesPass
{
void ILintRulesPass.Run(Action<string> emitError, Action<string> emitWarning, ModData modData, Ruleset rules)
{
try
{
var externalFilenames = new HashSet<string>();
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}");
}
}
}
}

View File

@@ -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<string> BeforeUpdateActors(ModData modData, List<MiniYamlNodeBuilder> resolvedActors) { yield break; }
}
public interface IBeforeUpdateWeapons
{
IEnumerable<string> BeforeUpdateWeapons(ModData modData, List<MiniYamlNodeBuilder> resolvedWeapons) { yield break; }
}
public interface IBeforeUpdateSequences
{
IEnumerable<string> BeforeUpdateSequences(ModData modData, List<MiniYamlNodeBuilder> resolvedImages) { yield break; }
}
}
}

View File

@@ -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

View File

@@ -780,7 +780,7 @@
MapEditorData:
Categories: Destroyed Tiles
^DamagedBuildingEffects :
^DamagedBuildingEffects:
GrantConditionOnFaction@atreidesVFX:
Condition: atreidesVFX
Factions: atreides, fremen

View File

@@ -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

View File

@@ -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