-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start parsing sfxevents and duplicate checker
- Loading branch information
Showing
36 changed files
with
647 additions
and
184 deletions.
There are no files selected for viewing
Submodule PetroglyphTools
updated
2 files
+46 −0 | PG.Commons/PG.Commons/Hashing/Crc32HashingService.cs | |
+18 −0 | PG.Commons/PG.Commons/Hashing/ICrc32HashingService.cs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading; | ||
using AnakinRaW.CommonUtilities.Collections; | ||
using PG.StarWarsGame.Engine.Database; | ||
using PG.StarWarsGame.Engine.DataTypes; | ||
|
||
namespace AET.ModVerify.Steps; | ||
|
||
public sealed class DuplicateFinderStep( | ||
IGameDatabase gameDatabase, | ||
VerificationSettings settings, | ||
IServiceProvider serviceProvider) | ||
: GameVerificationStep(gameDatabase, settings, serviceProvider) | ||
{ | ||
public const string DuplicateFound = "DUP00"; | ||
|
||
protected override string LogFileName => "Duplicates"; | ||
|
||
public override string Name => "Duplicate Definitions"; | ||
|
||
protected override void RunVerification(CancellationToken token) | ||
{ | ||
CheckDatabaseForDuplicates(Database.GameObjects, "GameObject"); | ||
CheckDatabaseForDuplicates(Database.SfxEvents, "SFXEvent"); | ||
} | ||
|
||
private void CheckDatabaseForDuplicates<T>(IXmlDatabase<T> database, string context) where T : XmlObject | ||
{ | ||
foreach (var key in database.EntryKeys) | ||
{ | ||
var entries = database.GetEntries(key); | ||
if (entries.Count > 1) | ||
AddError(VerificationError.Create(DuplicateFound, CreateDuplicateErrorMessage(context, entries))); | ||
} | ||
} | ||
|
||
private string CreateDuplicateErrorMessage<T>(string context, ReadOnlyFrugalList<T> entries) where T : XmlObject | ||
{ | ||
var firstEntry = entries.First(); | ||
|
||
var message = $"{context} '{firstEntry.Name}' ({firstEntry.Crc32}) has duplicate definitions: "; | ||
|
||
foreach (var entry in entries) | ||
message += $"['{entry.Name}' in {entry.Location.XmlFile}] "; | ||
|
||
return message.TrimEnd(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/PetroglyphTools/PG.StarWarsGame.Engine/DataTypes/SfxEvent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using PG.Commons.Hashing; | ||
using PG.StarWarsGame.Files.XML; | ||
|
||
namespace PG.StarWarsGame.Engine.DataTypes; | ||
|
||
public sealed class SfxEvent : XmlObject | ||
{ | ||
private int _volumeValue; | ||
|
||
public bool IsPreset { get; } | ||
|
||
public SfxEvent? Preset { get; } | ||
|
||
public int Volume => Preset?.Volume ?? _volumeValue; | ||
|
||
internal SfxEvent(string name, Crc32 nameCrc, XmlLocationInfo location) | ||
: base(name, nameCrc, location) | ||
{ | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/PetroglyphTools/PG.StarWarsGame.Engine/DataTypes/XmlObject.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using PG.Commons.DataTypes; | ||
using PG.Commons.Hashing; | ||
using PG.StarWarsGame.Files.XML; | ||
|
||
namespace PG.StarWarsGame.Engine.DataTypes; | ||
|
||
public abstract class XmlObject( | ||
string name, | ||
Crc32 nameCrc, | ||
XmlLocationInfo location) | ||
: IHasCrc32 | ||
{ | ||
public XmlLocationInfo Location { get; } = location; | ||
|
||
public Crc32 Crc32 { get; } = nameCrc; | ||
|
||
public string Name { get; } = name ?? throw new ArgumentNullException(nameof(name)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
...e.Engine/Pipeline/IGameDatabaseService.cs → ...e.Engine/Database/IGameDatabaseService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/PetroglyphTools/PG.StarWarsGame.Engine/Database/IXmlDatabase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Collections.Generic; | ||
using AnakinRaW.CommonUtilities.Collections; | ||
using PG.Commons.Hashing; | ||
using PG.StarWarsGame.Engine.DataTypes; | ||
|
||
namespace PG.StarWarsGame.Engine.Database; | ||
|
||
public interface IXmlDatabase<T> where T : XmlObject | ||
{ | ||
ICollection<T> Entries { get; } | ||
|
||
ICollection<Crc32> EntryKeys { get; } | ||
|
||
ReadOnlyFrugalList<T> GetEntries(Crc32 key); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.