Skip to content

Commit 4df3b3c

Browse files
committed
Verify GameObject icons
1 parent 84cd691 commit 4df3b3c

5 files changed

Lines changed: 59 additions & 8 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using AET.ModVerify.Reporting;
2+
using PG.StarWarsGame.Engine.GameObjects;
3+
4+
namespace AET.ModVerify.Verifiers.GameObjects;
5+
6+
public sealed partial class GameObjectTypeVerifier
7+
{
8+
private void VerifyIcons(GameObject gameObject, string[] context)
9+
{
10+
VerifyObjectIcon(gameObject, context);
11+
}
12+
13+
private void VerifyObjectIcon(GameObject gameObject, string[] context)
14+
{
15+
if (string.IsNullOrEmpty(gameObject.IconName))
16+
return;
17+
18+
/*
19+
* The engine loads game object icons with different strategies, depending on where the icon is displayed:
20+
* 1. the game loads the texture from MTD and supports the faction prefixes e.g, r_ or e_
21+
* Faction prefixes have higher priority than the non-prefix versions. The player's faction (not the object owner) is used.
22+
* This applies to all command bar components (such as build buttons)
23+
* 2. the game loads the texture form MTD and does NOT support faction prefix.
24+
* If the texture is not found, the game searches the texture with forced .dds name in the Textures folder.
25+
* This applies to the GUI dialogs (such as battle summary)
26+
* 3. the game only loads the texture from MTD NOT supporting faction prefix nor textures folder fallback.
27+
* This applies (only) to the neutralize hero dialog
28+
*
29+
* We only verify whether the icon exists in the MTD data, as this is the primary case to all strategies
30+
* (and it's what really should only be used for mods)
31+
* Faction-specific icons are not verified as they are statically not decidable.
32+
*/
33+
34+
if (!GameEngine.CommandBar.IconExists(gameObject))
35+
{
36+
AddError(VerificationError.Create(this, VerifierErrorCodes.FileNotFound,
37+
$"Could not find icon '{gameObject.IconName}' for game object type '{gameObject.Name}'.",
38+
VerificationSeverity.Warning, context, gameObject.IconName!));
39+
}
40+
}
41+
}

src/ModVerify/Verifiers/GameObjects/GameObjectTypeVerifier.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ protected override void VerifyEntity(GameObject entity, string[] context, double
3131
{
3232
VerifyXRefs(entity, context);
3333
VerifyModels(entity, context, token);
34+
VerifyIcons(entity, context);
3435
}
3536

3637
protected override void PostEntityVerify(CancellationToken token)

src/PetroglyphTools/PG.StarWarsGame.Engine/CommandBar/CommandBarGameManager.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,11 @@ public bool IconExists(GameObject gameObject)
9090
if (MtdFile is null)
9191
return false;
9292

93-
//if (string.IsNullOrEmpty(gameObject.IconName))
94-
// return false;
95-
96-
//var crc = _hashingService.GetCrc32Upper(gameObject.IconName);
93+
if (string.IsNullOrEmpty(gameObject.IconName))
94+
return false;
9795

98-
//return MtdFile.Content.Contains(crc);
96+
var crc = _hashingService.GetCrc32Upper(gameObject.IconName, PGConstants.DefaultPGEncoding);
9997

100-
return false;
98+
return MtdFile.Content.Contains(crc);
10199
}
102100
}

src/PetroglyphTools/PG.StarWarsGame.Engine/GameObjects/GameObject.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public sealed class GameObject : NamedXmlObject
4747
public string? DamagedSmokeAssetModel { get; internal set; }
4848

4949
public IReadOnlyList<(string terrain, string model)> LandTerrainModelMappingValues { get; }
50-
50+
public string? IconName { get; internal set; }
51+
5152
internal GameObject(
5253
string name,
5354
string classification,
@@ -69,6 +70,7 @@ internal void ApplyBaseType(GameObject baseType)
6970
// The following properties must not be inherited from the base type:
7071
// ID, CRC, Name, Location, IsLoadingComplete, ClassificationName and VariantOfExistingType[Name], LuaScript
7172

73+
// TODO
7274
GalacticModel = baseType.GalacticModel;
7375
DestroyedGalacticModel = baseType.DestroyedGalacticModel;
7476
LandModel = baseType.LandModel;
@@ -80,6 +82,8 @@ internal void ApplyBaseType(GameObject baseType)
8082
SpaceAnimOverrideModel = baseType.SpaceAnimOverrideModel;
8183
DamagedSmokeAssetModel = baseType.DamagedSmokeAssetModel;
8284
InternalLandTerrainModelMapping.ClearAddRange(baseType.InternalLandTerrainModelMapping);
85+
86+
IconName = baseType.IconName;
8387
}
8488

8589
internal void PostLoadFixup()

src/PetroglyphTools/PG.StarWarsGame.Engine/Xml/Parsers/NamedObjects/GameObjectParser.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,17 @@ protected override void BuildMappings()
185185
PetroglyphXmlStringParser.Instance.Parse,
186186
(obj, val) => obj.DamagedSmokeAssetModel = val);
187187

188-
188+
189189
AddMapping(
190190
GameObjectXmlTags.GuiModelName,
191191
PetroglyphXmlStringParser.Instance.Parse,
192192
(obj, val) => obj.GuiModel = val);
193193

194+
AddMapping(
195+
GameObjectXmlTags.IconName,
196+
PetroglyphXmlStringParser.Instance.Parse,
197+
(obj, val) => obj.IconName = val);
198+
194199
AddMapping(
195200
GameObjectXmlTags.VariantOfExistingType,
196201
PetroglyphXmlStringParser.Instance.Parse,
@@ -215,5 +220,7 @@ internal static class GameObjectXmlTags
215220
public const string DamagedSmokeAssetName = "Damaged_Smoke_Asset_Name";
216221

217222
public const string VariantOfExistingType = "Variant_Of_Existing_Type";
223+
224+
public const string IconName = "Icon_Name";
218225
}
219226
}

0 commit comments

Comments
 (0)