Skip to content

Commit 84cd691

Browse files
committed
refactorings and new some new verifications
1 parent 1b613db commit 84cd691

14 files changed

Lines changed: 256 additions & 108 deletions
Lines changed: 12 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
1-
using System;
2-
using System.Linq;
3-
using AET.ModVerify.Reporting;
1+
using AET.ModVerify.Reporting;
42
using PG.StarWarsGame.Engine.CommandBar;
5-
using PG.StarWarsGame.Engine.CommandBar.Components;
3+
using System.Linq;
4+
using System.Threading;
65

76
namespace AET.ModVerify.Verifiers.CommandBar;
87

98
partial class CommandBarVerifier
109
{
11-
private void VerifyCommandBarComponents()
10+
private void VerifyCommandBarComponents(CancellationToken token, double startProgress)
1211
{
1312
var occupiedComponentIds = SupportedCommandBarComponentData
1413
.GetComponentIdsForEngine(Repository.EngineType).Keys
1514
.ToDictionary(value => value, _ => false);
1615

16+
var counter = 0;
17+
var numEntities = GameEngine.CommandBar.Components.Count;
18+
var num = 1 - startProgress;
19+
1720
foreach (var component in GameEngine.CommandBar.Components)
1821
{
22+
var progress = num + (++counter / (double)numEntities) * startProgress;
23+
OnProgress(progress, $"CommandBarComponent - '{component.Name}'");
24+
1925
if (!occupiedComponentIds.TryGetValue(component.Id, out var alreadyOccupied))
2026
{
2127
AddError(VerificationError.Create(
@@ -39,49 +45,7 @@ private void VerifyCommandBarComponents()
3945
component.Name));
4046
}
4147

42-
VerifySingleComponent(component);
43-
}
44-
}
45-
46-
private void VerifySingleComponent(CommandBarBaseComponent component)
47-
{
48-
VerifyCommandBarModel(component);
49-
VerifyComponentBone(component);
50-
}
51-
52-
private void VerifyCommandBarModel(CommandBarBaseComponent component)
53-
{
54-
if (component is not CommandBarShellComponent shellComponent)
55-
return;
56-
57-
if (shellComponent.ModelPath is null)
58-
{
59-
AddError(VerificationError.Create(this,
60-
CommandBarShellNoModel, $"The CommandBarShellComponent '{component.Name}' has no model specified.",
61-
VerificationSeverity.Error, shellComponent.Name));
62-
return;
63-
}
64-
65-
var model = GameEngine.PGRender.LoadModelAndAnimations(shellComponent.ModelPath.AsSpan(), null);
66-
if (model is null)
67-
{
68-
AddError(VerificationError.Create(this,
69-
CommandBarShellNoModel, $"Could not find model '{shellComponent.ModelPath}' for CommandBarShellComponent '{component.Name}'.",
70-
VerificationSeverity.Error, [shellComponent.Name], shellComponent.ModelPath));
71-
return;
72-
}
73-
}
74-
75-
private void VerifyComponentBone(CommandBarBaseComponent component)
76-
{
77-
if (component is CommandBarShellComponent)
78-
return;
79-
80-
if (component.Bone == -1)
81-
{
82-
AddError(VerificationError.Create(this,
83-
CommandBarShellNoModel, $"The CommandBar component '{component.Name}' is not connected to a shell component.",
84-
VerificationSeverity.Warning, component.Name));
48+
VerifySingleComponent(component, token);
8549
}
8650
}
8751
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System.Threading;
2+
using AET.ModVerify.Reporting;
3+
using AET.ModVerify.Verifiers.Commons;
4+
using AET.ModVerify.Verifiers.Utilities;
5+
using PG.StarWarsGame.Engine.CommandBar;
6+
7+
namespace AET.ModVerify.Verifiers.CommandBar;
8+
9+
partial class CommandBarVerifier
10+
{
11+
private void VerifyMegaTexture(CancellationToken token)
12+
{
13+
if (CommandBar.MtdFile is null)
14+
{
15+
AddError(VerificationError.Create(this, VerifierErrorCodes.FileNotFound,
16+
$"Cannot find CommandBar MegaTextureDirectory '{CommandBarConstants.MegaTextureBaseName}.mtd'",
17+
VerificationSeverity.Critical, $"{CommandBarConstants.MegaTextureBaseName}.mtd"));
18+
}
19+
else
20+
{
21+
var dupVerifier = new DuplicateVerifier(this);
22+
dupVerifier.Verify(IDuplicateVerificationContext.CreateForMtd(CommandBar.MtdFile), [], token);
23+
24+
foreach (var duplicateError in dupVerifier.VerifyErrors)
25+
AddError(duplicateError);
26+
}
27+
28+
if (CommandBar.MegaTextureFileName is null)
29+
{
30+
AddError(VerificationError.Create(this, VerifierErrorCodes.FileNotFound,
31+
$"Cannot find CommandBar MegaTexture '{CommandBarConstants.MegaTextureBaseName}.tga'",
32+
VerificationSeverity.Critical, $"{CommandBarConstants.MegaTextureBaseName}.tga"));
33+
}
34+
else if (!GameEngine.GameRepository.TextureRepository.FileExists(CommandBar.MegaTextureFileName))
35+
{
36+
AddError(VerificationError.Create(this, VerifierErrorCodes.FileNotFound,
37+
$"Cannot find CommandBar MegaTexture '{CommandBarConstants.MegaTextureBaseName}.tga'",
38+
VerificationSeverity.Critical, $"{CommandBarConstants.MegaTextureBaseName}.tga"));
39+
}
40+
}
41+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using AET.ModVerify.Reporting;
2+
using PG.StarWarsGame.Engine.CommandBar.Components;
3+
using System;
4+
using System.Threading;
5+
6+
namespace AET.ModVerify.Verifiers.CommandBar;
7+
8+
partial class CommandBarVerifier
9+
{
10+
private void VerifySingleComponent(CommandBarBaseComponent component, CancellationToken token)
11+
{
12+
VerifyCommandBarModel(component, token);
13+
VerifyComponentBone(component);
14+
15+
// TODO: Textures
16+
}
17+
18+
private void VerifyCommandBarModel(CommandBarBaseComponent component, CancellationToken token)
19+
{
20+
if (component is not CommandBarShellComponent shellComponent)
21+
return;
22+
23+
if (shellComponent.ModelPath is null)
24+
{
25+
AddError(VerificationError.Create(this,
26+
CommandBarShellNoModel, $"The CommandBarShellComponent '{component.Name}' has no model specified.",
27+
VerificationSeverity.Error, [shellComponent.Name], shellComponent.Name));
28+
return;
29+
}
30+
31+
using var model = GameEngine.PGRender.LoadModelAndAnimations(shellComponent.ModelPath.AsSpan(), null);
32+
if (model is null)
33+
{
34+
AddError(VerificationError.Create(this,
35+
CommandBarShellNoModel, $"Could not find model '{shellComponent.ModelPath}' for CommandBarShellComponent '{component.Name}'.",
36+
VerificationSeverity.Error, [shellComponent.Name], shellComponent.ModelPath));
37+
return;
38+
}
39+
40+
_modelVerifier.VerifyModelOrParticle(model.File, [shellComponent.Name], token);
41+
42+
if (model.Animations.Cout == 0)
43+
return;
44+
45+
// TODO: Verify Animations
46+
47+
}
48+
49+
private void VerifyComponentBone(CommandBarBaseComponent component)
50+
{
51+
if (component is CommandBarShellComponent)
52+
return;
53+
54+
if (component.Bone == -1)
55+
{
56+
AddError(VerificationError.Create(this,
57+
CommandBarShellNoModel, $"The CommandBar component '{component.Name}' is not connected to a shell component.",
58+
VerificationSeverity.Warning, component.Name));
59+
}
60+
}
61+
}
Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,52 @@
11
using System;
2+
using System.Linq;
23
using System.Threading;
34
using AET.ModVerify.Settings;
5+
using AET.ModVerify.Verifiers.Commons;
46
using PG.StarWarsGame.Engine;
7+
using PG.StarWarsGame.Engine.CommandBar;
58

69
namespace AET.ModVerify.Verifiers.CommandBar;
710

8-
public partial class CommandBarVerifier(IStarWarsGameEngine gameEngine, GameVerifySettings settings, IServiceProvider serviceProvider)
9-
: GameVerifier(gameEngine, settings, serviceProvider)
10-
{
11+
public partial class CommandBarVerifier : GameVerifier
12+
{
1113
public const string CommandBarNoShellsGroup = "CMDBAR00";
1214
public const string CommandBarManyShellsGroup = "CMDBAR01";
1315
public const string CommandBarNoShellsComponentInShellGroup = "CMDBAR02";
1416
public const string CommandBarUnsupportedComponent = "CMDBAR03";
1517
public const string CommandBarShellNoModel = "CMDBAR04";
1618

19+
private readonly SingleModelVerifier _modelVerifier;
20+
private readonly TextureVerifier _textureVerifier;
21+
1722
public override string FriendlyName => "CommandBar";
1823

24+
public ICommandBarGameManager CommandBar { get; }
25+
26+
public CommandBarVerifier(IStarWarsGameEngine gameEngine, GameVerifySettings settings, IServiceProvider serviceProvider)
27+
: base(gameEngine, settings, serviceProvider)
28+
{
29+
CommandBar = gameEngine.CommandBar;
30+
_modelVerifier = new SingleModelVerifier(this);
31+
_textureVerifier = new TextureVerifier(this);
32+
}
33+
1934
public override void Verify(CancellationToken token)
2035
{
21-
OnProgress(0.0, "Verifying CommandBar Shell");
36+
var progress = 0.0d;
37+
OnProgress(progress, "Verifying MegaTexture");
38+
VerifyMegaTexture(token);
39+
progress = 1 / 3.0;
40+
OnProgress(progress, "Verifying CommandBar Shell");
2241
VerifyCommandBarShellsGroups();
23-
OnProgress(0.5d, "Verifying CommandBar components");
24-
VerifyCommandBarComponents();
25-
OnProgress(1.0d, null);
42+
progress = 2 / 3.0;
43+
OnProgress(progress, "Verifying CommandBar components");
44+
VerifyCommandBarComponents(token, progress);
45+
46+
foreach (var subError in _modelVerifier.VerifyErrors.Concat(_textureVerifier.VerifyErrors))
47+
AddError(subError);
48+
49+
progress = 1.0;
50+
OnProgress(progress, null);
2651
}
2752
}

src/ModVerify/Verifiers/Commons/DuplicateVerifier.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace AET.ModVerify.Verifiers.Commons;
99

1010
public sealed class DuplicateVerifier : GameVerifier<IDuplicateVerificationContext>
1111
{
12+
public override string FriendlyName => "Duplicate Verifier";
13+
1214
public DuplicateVerifier(GameVerifierBase parent) : base(parent)
1315
{
1416
}
@@ -22,8 +24,6 @@ public DuplicateVerifier(
2224
{
2325
}
2426

25-
public override string FriendlyName => "Duplicates";
26-
2727
public override void Verify(IDuplicateVerificationContext toVerify, IReadOnlyCollection<string> contextInfo, CancellationToken token)
2828
{
2929
foreach (var crc32 in toVerify.GetCrcs())

src/ModVerify/Verifiers/Commons/ModelVerifier.cs renamed to src/ModVerify/Verifiers/Commons/SingleModelVerifier.cs

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ public sealed class SingleModelVerifier : GameVerifier<string>
2222
{
2323
private const string ProxyAltIdentifier = "_ALT";
2424

25-
private readonly TextureVeifier _textureVerifier;
25+
private readonly TextureVerifier _textureVerifier;
2626
private readonly IAlreadyVerifiedCache? _cache;
2727

2828
public SingleModelVerifier(GameVerifierBase parent) : base(parent)
2929
{
30-
_textureVerifier = new TextureVeifier(this);
30+
_textureVerifier = new TextureVerifier(this);
3131
_cache = Services.GetService<IAlreadyVerifiedCache>();
3232
}
3333

@@ -37,28 +37,18 @@ public SingleModelVerifier(
3737
GameVerifySettings settings,
3838
IServiceProvider serviceProvider) : base(parent, engine, settings, serviceProvider)
3939
{
40-
_textureVerifier = new TextureVeifier(this);
40+
_textureVerifier = new TextureVerifier(this);
4141
_cache = serviceProvider.GetService<IAlreadyVerifiedCache>();
4242
}
4343

4444
public override void Verify(string modelName, IReadOnlyCollection<string> contextInfo, CancellationToken token)
4545
{
46-
try
47-
{
48-
_textureVerifier.Error += OnTextureError;
4946

50-
var modelPath = BuildModelPath(modelName);
51-
VerifyAlamoFile(modelPath, contextInfo, token);
52-
}
53-
finally
54-
{
55-
_textureVerifier.Error -= OnTextureError;
56-
}
57-
}
47+
var modelPath = BuildModelPath(modelName);
48+
VerifyAlamoFile(modelPath, contextInfo, token);
5849

59-
private void OnTextureError(object sender, VerificationErrorEventArgs e)
60-
{
61-
AddError(e.Error);
50+
foreach (var textureError in _textureVerifier.VerifyErrors)
51+
AddError(textureError);
6252
}
6353

6454
private void VerifyAlamoFile(string modelPath, IReadOnlyCollection<string> contextInfo, CancellationToken token)
@@ -111,10 +101,7 @@ private void VerifyAlamoFile(string modelPath, IReadOnlyCollection<string> conte
111101
}
112102
}
113103

114-
private void VerifyModelOrParticle(
115-
IAloFile<IAloDataContent, AloFileInformation> aloFile,
116-
IReadOnlyCollection<string> contextInfo,
117-
CancellationToken token)
104+
public void VerifyModelOrParticle(IAloFile<IAloDataContent, AloFileInformation> aloFile, IReadOnlyCollection<string> contextInfo, CancellationToken token)
118105
{
119106
switch (aloFile)
120107
{

src/ModVerify/Verifiers/Commons/TextureVeifier.cs renamed to src/ModVerify/Verifiers/Commons/TextureVerifier.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99
namespace AET.ModVerify.Verifiers.Commons;
1010

11-
public sealed class TextureVeifier : GameVerifier<string>
11+
public sealed class TextureVerifier : GameVerifier<string>
1212
{
13-
public TextureVeifier(GameVerifierBase parent) : base(parent)
13+
public TextureVerifier(GameVerifierBase parent) : base(parent)
1414
{
1515
}
1616

17-
public TextureVeifier(
17+
public TextureVerifier(
1818
IGameVerifierInfo? parent,
1919
IStarWarsGameEngine gameEngine,
2020
GameVerifySettings settings,

src/ModVerify/Verifiers/GuiDialogs/GuiDialogsVerifier.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ sealed class GuiDialogsVerifier : GameVerifier
2020
Enum.GetValues(typeof(GuiComponentType)).OfType<GuiComponentType>().ToArray();
2121

2222
private readonly IAlreadyVerifiedCache? _cache;
23-
private readonly TextureVeifier _textureVerifier;
23+
private readonly TextureVerifier _textureVerifier;
2424

2525
public GuiDialogsVerifier(
2626
IStarWarsGameEngine gameEngine,
@@ -29,21 +29,16 @@ public GuiDialogsVerifier(
2929
: base(gameEngine, settings, serviceProvider)
3030
{
3131
_cache = serviceProvider.GetService<IAlreadyVerifiedCache>();
32-
_textureVerifier = new TextureVeifier(this);
32+
_textureVerifier = new TextureVerifier(this);
3333
}
3434

3535
public override void Verify(CancellationToken token)
3636
{
37-
try
38-
{
39-
_textureVerifier.Error += OnTextureError;
40-
VerifyMegaTexturesExist(token);
41-
VerifyGuiTextures();
42-
}
43-
finally
44-
{
45-
_textureVerifier.Error -= OnTextureError;
46-
}
37+
VerifyMegaTexturesExist(token);
38+
VerifyGuiTextures();
39+
40+
foreach (var textureError in _textureVerifier.VerifyErrors)
41+
AddError(textureError);
4742
}
4843

4944
private void VerifyGuiTextures()

0 commit comments

Comments
 (0)