Skip to content

Commit 59675e7

Browse files
committed
refactorings of verifiers
1 parent a3364ef commit 59675e7

19 files changed

Lines changed: 322 additions & 250 deletions

src/ModVerify/DefaultGameVerifiersProvider.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using AET.ModVerify.Settings;
44
using AET.ModVerify.Verifiers;
5+
using AET.ModVerify.Verifiers.Commons;
56
using AET.ModVerify.Verifiers.GuiDialogs;
67
using PG.StarWarsGame.Engine;
78

@@ -14,9 +15,9 @@ public IEnumerable<GameVerifier> GetVerifiers(
1415
GameVerifySettings settings,
1516
IServiceProvider serviceProvider)
1617
{
17-
yield break;
18+
//yield break;
1819
yield return new ReferencedModelsVerifier(database, settings, serviceProvider);
19-
yield return new DuplicateNameFinder(database, settings, serviceProvider);
20+
//yield return new DuplicateNameFinder(database, settings, serviceProvider);
2021
yield return new AudioFilesVerifier(database, settings, serviceProvider);
2122
yield return new GuiDialogsVerifier(database, settings, serviceProvider);
2223
yield return new CommandBarVerifier(database, settings, serviceProvider);

src/ModVerify/GameVerifyPipeline.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using AET.ModVerify.Settings;
1212
using AET.ModVerify.Utilities;
1313
using AET.ModVerify.Verifiers;
14+
using AET.ModVerify.Verifiers.Utilities;
1415
using AnakinRaW.CommonUtilities.SimplePipeline;
1516
using AnakinRaW.CommonUtilities.SimplePipeline.Runners;
1617
using Microsoft.Extensions.DependencyInjection;

src/ModVerify/ModVerify.csproj.DotSettings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=reporting_005Creporters_005Ctext/@EntryIndexedValue">True</s:Boolean>
66
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=reporting_005Csuppressions_005Cjson/@EntryIndexedValue">False</s:Boolean>
77
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=verifiers_005Ccommandbar/@EntryIndexedValue">True</s:Boolean>
8+
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=verifiers_005Ccommons_005Cduplicates/@EntryIndexedValue">True</s:Boolean>
89
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=verifiers_005Cdatabaseerror/@EntryIndexedValue">True</s:Boolean>
910
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=verifiers_005Cengine/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

src/ModVerify/Reporting/Engine/GameAssertErrorReporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ private static string GetIdFromError(EngineAssertKind assertKind)
4646
EngineAssertKind.ValueOutOfRange => VerifierErrorCodes.AssertValueOutOfRange,
4747
EngineAssertKind.InvalidValue => VerifierErrorCodes.AssertValueInvalid,
4848
EngineAssertKind.FileNotFound => VerifierErrorCodes.FileNotFound,
49-
EngineAssertKind.DuplicateEntry => VerifierErrorCodes.DuplicateFound,
49+
EngineAssertKind.DuplicateEntry => VerifierErrorCodes.Duplicate,
5050
_ => throw new ArgumentOutOfRangeException(nameof(assertKind), assertKind, null)
5151
};
5252
}

src/ModVerify/Reporting/VerifierChainEqualityComparer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using AET.ModVerify.Verifiers;
4+
using AET.ModVerify.Verifiers.Utilities;
45

56
namespace AET.ModVerify.Reporting;
67

Lines changed: 0 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
using System;
2-
using System.Linq;
32
using System.Threading;
4-
using AET.ModVerify.Reporting;
53
using AET.ModVerify.Settings;
6-
using AnakinRaW.CommonUtilities.Collections;
74
using PG.StarWarsGame.Engine;
8-
using PG.StarWarsGame.Engine.CommandBar;
9-
using PG.StarWarsGame.Engine.CommandBar.Components;
105

116
namespace AET.ModVerify.Verifiers;
127

@@ -27,135 +22,4 @@ public override void Verify(CancellationToken token)
2722
VerifyCommandBarShellsGroups();
2823
VerifyCommandBarComponents();
2924
}
30-
31-
private void VerifySingleComponent(CommandBarBaseComponent component)
32-
{
33-
VerifyCommandBarModel(component);
34-
VerifyComponentBone(component);
35-
}
36-
}
37-
38-
partial class CommandBarVerifier
39-
{
40-
private void VerifyCommandBarModel(CommandBarBaseComponent component)
41-
{
42-
if (component is not CommandBarShellComponent shellComponent)
43-
return;
44-
45-
if (shellComponent.ModelPath is null)
46-
{
47-
AddError(VerificationError.Create(VerifierChain,
48-
CommandBarShellNoModel, $"The CommandBarShellComponent '{component.Name}' has no model specified.",
49-
VerificationSeverity.Error, shellComponent.Name));
50-
return;
51-
}
52-
53-
var model = GameEngine.PGRender.LoadModelAndAnimations(shellComponent.ModelPath.AsSpan(), null);
54-
if (model is null)
55-
{
56-
AddError(VerificationError.Create(VerifierChain,
57-
CommandBarShellNoModel, $"Could not find model '{shellComponent.ModelPath}' for CommandBarShellComponent '{component.Name}'.",
58-
VerificationSeverity.Error, [shellComponent.Name], shellComponent.ModelPath));
59-
return;
60-
}
61-
}
62-
63-
private void VerifyComponentBone(CommandBarBaseComponent component)
64-
{
65-
if (component is CommandBarShellComponent)
66-
return;
67-
68-
if (component.Bone == -1)
69-
{
70-
AddError(VerificationError.Create(VerifierChain,
71-
CommandBarShellNoModel, $"The CommandBar component '{component.Name}' is not connected to a shell component.",
72-
VerificationSeverity.Warning, component.Name));
73-
}
74-
}
75-
}
76-
77-
partial class CommandBarVerifier
78-
{
79-
private void VerifyCommandBarComponents()
80-
{
81-
var occupiedComponentIds = SupportedCommandBarComponentData.GetComponentIdsForEngine(Repository.EngineType).Keys
82-
.ToDictionary(value => value, _ => false);
83-
84-
foreach (var component in GameEngine.CommandBar.Components)
85-
{
86-
if (!occupiedComponentIds.TryGetValue(component.Id, out var alreadyOccupied))
87-
{
88-
AddError(VerificationError.Create(
89-
VerifierChain,
90-
CommandBarUnsupportedComponent,
91-
$"The CommandBar component '{component.Name}' is not supported by the game.",
92-
VerificationSeverity.Information,
93-
component.Name));
94-
}
95-
else
96-
{
97-
occupiedComponentIds[component.Id] = true;
98-
}
99-
100-
if (alreadyOccupied)
101-
{
102-
AddError(VerificationError.Create(VerifierChain,
103-
CommandBarDuplicateComponent,
104-
$"The CommandBar component '{component.Name}' with ID '{component.Id}' already exists.",
105-
VerificationSeverity.Warning,
106-
component.Name));
107-
}
108-
109-
VerifySingleComponent(component);
110-
}
111-
}
112-
}
113-
114-
partial class CommandBarVerifier
115-
{
116-
private void VerifyCommandBarShellsGroups()
117-
{
118-
var shellGroups = new FrugalList<string>();
119-
foreach (var groupPair in GameEngine.CommandBar.Groups)
120-
{
121-
if (groupPair.Key == CommandBarConstants.ShellGroupName)
122-
{
123-
shellGroups.Add(groupPair.Key);
124-
VerifyShellGroup(groupPair.Value);
125-
}
126-
else if (groupPair.Key.Equals(CommandBarConstants.ShellGroupName, StringComparison.OrdinalIgnoreCase))
127-
{
128-
shellGroups.Add(groupPair.Key);
129-
}
130-
}
131-
132-
if (shellGroups.Count == 0)
133-
AddError(VerificationError.Create(VerifierChain,
134-
CommandBarNoShellsGroup,
135-
$"No CommandBarGroup '{CommandBarConstants.ShellGroupName}' found.",
136-
VerificationSeverity.Error,
137-
"GameCommandBar"));
138-
139-
if (shellGroups.Count > 1)
140-
AddError(VerificationError.Create(VerifierChain,
141-
CommandBarManyShellsGroup,
142-
$"Found more than one Shells CommandBarGroup. Mind that group names are case-sensitive. Correct name is '{CommandBarConstants.ShellGroupName}'",
143-
VerificationSeverity.Warning,
144-
shellGroups, "GameCommandBar"));
145-
}
146-
147-
private void VerifyShellGroup(CommandBarComponentGroup shellGroup)
148-
{
149-
foreach (var component in shellGroup.Components)
150-
{
151-
var shellComponent = component as CommandBarShellComponent;
152-
if (shellComponent?.Type is not CommandBarComponentType.Shell)
153-
{
154-
AddError(VerificationError.Create(VerifierChain,
155-
CommandBarNoShellsComponentInShellGroup,
156-
$"The CommandBar component '{component.Name}' is not a shell component, but part of the '{CommandBarConstants.ShellGroupName}' group.",
157-
VerificationSeverity.Warning, component.Name));
158-
}
159-
}
160-
}
16125
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using AET.ModVerify.Reporting;
2+
using PG.StarWarsGame.Engine.CommandBar;
3+
using PG.StarWarsGame.Engine.CommandBar.Components;
4+
using System;
5+
using System.Linq;
6+
7+
namespace AET.ModVerify.Verifiers;
8+
9+
partial class CommandBarVerifier
10+
{
11+
private void VerifyCommandBarComponents()
12+
{
13+
var occupiedComponentIds = SupportedCommandBarComponentData.GetComponentIdsForEngine(Repository.EngineType).Keys
14+
.ToDictionary(value => value, _ => false);
15+
16+
foreach (var component in GameEngine.CommandBar.Components)
17+
{
18+
if (!occupiedComponentIds.TryGetValue(component.Id, out var alreadyOccupied))
19+
{
20+
AddError(VerificationError.Create(
21+
VerifierChain,
22+
CommandBarUnsupportedComponent,
23+
$"The CommandBar component '{component.Name}' is not supported by the game.",
24+
VerificationSeverity.Information,
25+
component.Name));
26+
}
27+
else
28+
{
29+
occupiedComponentIds[component.Id] = true;
30+
}
31+
32+
if (alreadyOccupied)
33+
{
34+
AddError(VerificationError.Create(VerifierChain,
35+
CommandBarDuplicateComponent,
36+
$"The CommandBar component '{component.Name}' with ID '{component.Id}' already exists.",
37+
VerificationSeverity.Warning,
38+
component.Name));
39+
}
40+
41+
VerifySingleComponent(component);
42+
}
43+
}
44+
45+
private void VerifySingleComponent(CommandBarBaseComponent component)
46+
{
47+
VerifyCommandBarModel(component);
48+
VerifyComponentBone(component);
49+
}
50+
51+
private void VerifyCommandBarModel(CommandBarBaseComponent component)
52+
{
53+
if (component is not CommandBarShellComponent shellComponent)
54+
return;
55+
56+
if (shellComponent.ModelPath is null)
57+
{
58+
AddError(VerificationError.Create(VerifierChain,
59+
CommandBarShellNoModel, $"The CommandBarShellComponent '{component.Name}' has no model specified.",
60+
VerificationSeverity.Error, shellComponent.Name));
61+
return;
62+
}
63+
64+
var model = GameEngine.PGRender.LoadModelAndAnimations(shellComponent.ModelPath.AsSpan(), null);
65+
if (model is null)
66+
{
67+
AddError(VerificationError.Create(VerifierChain,
68+
CommandBarShellNoModel, $"Could not find model '{shellComponent.ModelPath}' for CommandBarShellComponent '{component.Name}'.",
69+
VerificationSeverity.Error, [shellComponent.Name], shellComponent.ModelPath));
70+
return;
71+
}
72+
}
73+
74+
private void VerifyComponentBone(CommandBarBaseComponent component)
75+
{
76+
if (component is CommandBarShellComponent)
77+
return;
78+
79+
if (component.Bone == -1)
80+
{
81+
AddError(VerificationError.Create(VerifierChain,
82+
CommandBarShellNoModel, $"The CommandBar component '{component.Name}' is not connected to a shell component.",
83+
VerificationSeverity.Warning, component.Name));
84+
}
85+
}
86+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System;
2+
using AET.ModVerify.Reporting;
3+
using AnakinRaW.CommonUtilities.Collections;
4+
using PG.StarWarsGame.Engine.CommandBar;
5+
using PG.StarWarsGame.Engine.CommandBar.Components;
6+
7+
namespace AET.ModVerify.Verifiers;
8+
9+
partial class CommandBarVerifier
10+
{
11+
private void VerifyCommandBarShellsGroups()
12+
{
13+
var shellGroups = new FrugalList<string>();
14+
foreach (var groupPair in GameEngine.CommandBar.Groups)
15+
{
16+
if (groupPair.Key == CommandBarConstants.ShellGroupName)
17+
{
18+
shellGroups.Add(groupPair.Key);
19+
VerifyShellGroup(groupPair.Value);
20+
}
21+
else if (groupPair.Key.Equals(CommandBarConstants.ShellGroupName, StringComparison.OrdinalIgnoreCase))
22+
{
23+
shellGroups.Add(groupPair.Key);
24+
}
25+
}
26+
27+
if (shellGroups.Count == 0)
28+
AddError(VerificationError.Create(VerifierChain,
29+
CommandBarNoShellsGroup,
30+
$"No CommandBarGroup '{CommandBarConstants.ShellGroupName}' found.",
31+
VerificationSeverity.Error,
32+
"GameCommandBar"));
33+
34+
if (shellGroups.Count > 1)
35+
AddError(VerificationError.Create(VerifierChain,
36+
CommandBarManyShellsGroup,
37+
$"Found more than one Shells CommandBarGroup. Mind that group names are case-sensitive. Correct name is '{CommandBarConstants.ShellGroupName}'",
38+
VerificationSeverity.Warning,
39+
shellGroups, "GameCommandBar"));
40+
}
41+
42+
private void VerifyShellGroup(CommandBarComponentGroup shellGroup)
43+
{
44+
foreach (var component in shellGroup.Components)
45+
{
46+
var shellComponent = component as CommandBarShellComponent;
47+
if (shellComponent?.Type is not CommandBarComponentType.Shell)
48+
{
49+
AddError(VerificationError.Create(VerifierChain,
50+
CommandBarNoShellsComponentInShellGroup,
51+
$"The CommandBar component '{component.Name}' is not a shell component, but part of the '{CommandBarConstants.ShellGroupName}' group.",
52+
VerificationSeverity.Warning, component.Name));
53+
}
54+
}
55+
}
56+
}

src/ModVerify/Verifiers/AudioFilesVerifier.cs renamed to src/ModVerify/Verifiers/Commons/AudioFilesVerifier.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@
88
using System.Threading;
99
using AET.ModVerify.Reporting;
1010
using AET.ModVerify.Settings;
11+
using AnakinRaW.CommonUtilities.FileSystem;
1112
using AnakinRaW.CommonUtilities.FileSystem.Normalization;
1213
using Microsoft.Extensions.DependencyInjection;
1314
using PG.Commons.Hashing;
1415
using PG.StarWarsGame.Engine;
1516
using PG.StarWarsGame.Engine.Audio.Sfx;
1617
using PG.StarWarsGame.Engine.Localization;
17-
#if NETSTANDARD2_0
18-
using AnakinRaW.CommonUtilities.FileSystem;
19-
#endif
2018

21-
namespace AET.ModVerify.Verifiers;
19+
namespace AET.ModVerify.Verifiers.Commons;
20+
21+
// TODO: Refactor to make this a generic audio file verifier that can be used for
22+
// SFXEvents, MusicEvents and SpeechEvents
2223

2324
public class AudioFilesVerifier : GameVerifier
2425
{

0 commit comments

Comments
 (0)