Skip to content

Commit 99d81be

Browse files
committed
fix bugs in parser and start engine compliant gameobject parsing
1 parent b096bf5 commit 99d81be

27 files changed

Lines changed: 458 additions & 324 deletions

src/PetroglyphTools/PG.StarWarsGame.Engine/Audio/Sfx/SfxEvent.cs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
using System.Collections.Generic;
2+
using System.Collections.ObjectModel;
3+
using System.Diagnostics;
24
using System.Linq;
35
using PG.Commons.Hashing;
46
using PG.StarWarsGame.Files.XML;
57
using PG.StarWarsGame.Files.XML.Data;
68

79
namespace PG.StarWarsGame.Engine.Audio.Sfx;
810

11+
[DebuggerDisplay("{Name}")]
912
public sealed class SfxEvent : NamedXmlObject
1013
{
1114
private byte _minVolume = DefaultMinVolume;
@@ -45,6 +48,11 @@ public sealed class SfxEvent : NamedXmlObject
4548
public const byte DefaultMaxPan2d = 50;
4649
public const float DefaultVolumeSaturationDistance = 300.0f;
4750

51+
internal readonly List<string> PreSamplesInternal = new();
52+
internal readonly List<string> SamplesInternal = new();
53+
internal readonly List<string> PostSamplesInternal = new();
54+
internal readonly List<string> LocalizedTextIDsInternal = new();
55+
4856
public bool IsPreset { get; internal set; }
4957

5058
public bool Is3D { get; internal set; } = DefaultIs3d;
@@ -69,14 +77,14 @@ public sealed class SfxEvent : NamedXmlObject
6977

7078
public IEnumerable<string> AllSamples => PreSamples.Concat(Samples).Concat(PostSamples);
7179

72-
public IReadOnlyList<string> PreSamples { get; internal set; } = [];
73-
74-
public IReadOnlyList<string> Samples { get; internal set; } = [];
80+
public IReadOnlyList<string> PreSamples { get; }
7581

76-
public IReadOnlyList<string> PostSamples { get; internal set; } = [];
82+
public IReadOnlyList<string> Samples { get; }
7783

78-
public IReadOnlyList<string> LocalizedTextIDs { get; internal set; } = [];
84+
public IReadOnlyList<string> PostSamples { get; }
7985

86+
public IReadOnlyList<string> LocalizedTextIDs { get; }
87+
8088
public byte Priority { get; internal set; } = DefaultPriority;
8189

8290
public byte Probability { get; internal set; } = DefaultProbability;
@@ -161,6 +169,7 @@ public uint MaxPostdelay
161169
internal SfxEvent(string name, Crc32 nameCrc, XmlLocationInfo location)
162170
: base(name, nameCrc, location)
163171
{
172+
PreSamples = new ReadOnlyCollection<string>(PreSamplesInternal);
164173
}
165174

166175
internal void FixupValues()
@@ -197,10 +206,10 @@ public void ApplyPreset(SfxEvent preset)
197206
IsAmbientVo = preset.IsAmbientVo;
198207
IsLocalized = preset.IsLocalized;
199208
PlaySequentially = preset.PlaySequentially;
200-
PreSamples = preset.PreSamples;
201-
Samples = preset.Samples;
202-
PostSamples = preset.PostSamples;
203-
LocalizedTextIDs = preset.LocalizedTextIDs;
209+
SetList(PreSamplesInternal, preset.PreSamplesInternal);
210+
SetList(SamplesInternal, preset.SamplesInternal);
211+
SetList(PostSamplesInternal, preset.PostSamplesInternal);
212+
SetList(LocalizedTextIDsInternal, preset.LocalizedTextIDsInternal);
204213
Priority = preset.Priority;
205214
Probability = preset.Probability;
206215
PlayCount = preset.PlayCount;
@@ -219,6 +228,13 @@ public void ApplyPreset(SfxEvent preset)
219228
MaxPitch = preset.MaxPitch;
220229
MinPan2D = preset.MinPan2D;
221230
MaxPan2D = preset.MaxPan2D;
231+
return;
232+
233+
static void SetList(List<string> target, List<string> source)
234+
{
235+
target.Clear();
236+
target.AddRange(source);
237+
}
222238
}
223239

224240
private static void AdjustMinMaxValues(ref byte minValue, ref byte maxValue)

src/PetroglyphTools/PG.StarWarsGame.Engine/Audio/Sfx/SfxEventGameManager.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@
1111

1212
namespace PG.StarWarsGame.Engine.Audio.Sfx;
1313

14-
internal class SfxEventGameManager(GameRepository repository, GameEngineErrorReporterWrapper errorReporter, IServiceProvider serviceProvider)
15-
: GameManagerBase<SfxEvent>(repository, errorReporter, serviceProvider), ISfxEventGameManager
14+
internal class SfxEventGameManager(
15+
GameEngineType engineType,
16+
GameRepository repository,
17+
GameEngineErrorReporterWrapper errorReporter,
18+
IServiceProvider serviceProvider)
19+
: GameManagerBase<SfxEvent>(engineType, repository, errorReporter, serviceProvider), ISfxEventGameManager
1620
{
1721
public IEnumerable<LanguageType> InstalledLanguages { get; private set; } = [];
1822

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
namespace PG.StarWarsGame.Engine.CommandBar;
1616

1717
internal partial class CommandBarGameManager(
18+
GameEngineType engineType,
1819
GameRepository repository,
1920
PGRender pgRender,
2021
IGameConstants gameConstants,
2122
IFontManager fontManager,
2223
GameEngineErrorReporterWrapper errorReporter,
2324
IServiceProvider serviceProvider)
24-
: GameManagerBase<CommandBarBaseComponent>(repository, errorReporter, serviceProvider), ICommandBarGameManager
25+
: GameManagerBase<CommandBarBaseComponent>(engineType, repository, errorReporter, serviceProvider), ICommandBarGameManager
2526
{
2627
private readonly ICrc32HashingService _hashingService = serviceProvider.GetRequiredService<ICrc32HashingService>();
2728
private readonly IMtdFileService _mtdFileService = serviceProvider.GetRequiredService<IMtdFileService>();

src/PetroglyphTools/PG.StarWarsGame.Engine/CommandBar/Xml/CommandBarComponentData.cs

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using System.Collections.ObjectModel;
43
using System.Numerics;
54
using PG.Commons.Hashing;
@@ -9,26 +8,39 @@
98

109
namespace PG.StarWarsGame.Engine.CommandBar.Xml;
1110

12-
public sealed class CommandBarComponentData(string name, Crc32 crc, XmlLocationInfo location) : NamedXmlObject(name, crc, location)
11+
public sealed class CommandBarComponentData : NamedXmlObject
1312
{
1413
public const float DefaultScale = 1.0f;
1514
public const float DefaultBlinkRate = 0.2f;
1615
public const int DefaultBaseLayer = 2;
1716
public static readonly Vector2 DefaultOffsetWidescreenValue = new(9.9999998e17f, 9.9999998e17f);
1817
public static readonly Vector4Int WhiteColor = new(255, 255, 255, 255);
1918

20-
public IReadOnlyList<string> SelectedTextureNames { get; internal set; } = [];
21-
public IReadOnlyList<string> BlankTextureNames { get; internal set; } = [];
22-
public IReadOnlyList<string> IconAlternateTextureNames { get; internal set; } = [];
23-
public IReadOnlyList<string> MouseOverTextureNames { get; internal set; } = [];
24-
public IReadOnlyList<string> BarTextureNames { get; internal set; } = [];
25-
public IReadOnlyList<string> BarOverlayNames { get; internal set; } = [];
26-
public IReadOnlyList<string> AlternateFontNames { get; internal set; } = [];
27-
public IReadOnlyList<string> TooltipTexts { get; internal set; } = [];
28-
public IReadOnlyList<string> LowerEffectTextureNames { get; internal set; } = [];
29-
public IReadOnlyList<string> UpperEffectTextureNames { get; internal set; } = [];
30-
public IReadOnlyList<string> OverlayTextureNames { get; internal set; } = [];
31-
public IReadOnlyList<string> Overlay2TextureNames { get; internal set; } = [];
19+
internal readonly List<string> SelectedTextureNamesInternal = [];
20+
internal readonly List<string> BlankTextureNamesInternal = [];
21+
internal readonly List<string> IconAlternateTextureNamesInternal = [];
22+
internal readonly List<string> MouseOverTextureNamesInternal = [];
23+
internal readonly List<string> BarTextureNamesInternal = [];
24+
internal readonly List<string> BarOverlayNamesInternal = [];
25+
internal readonly List<string> AlternateFontNamesInternal = [];
26+
internal readonly List<string> TooltipTextsInternal = [];
27+
internal readonly List<string> LowerEffectTextureNamesInternal = [];
28+
internal readonly List<string> UpperEffectTextureNamesInternal = [];
29+
internal readonly List<string> OverlayTextureNamesInternal = [];
30+
internal readonly List<string> Overlay2TextureNamesInternal = [];
31+
32+
public IReadOnlyList<string> SelectedTextureNames { get; }
33+
public IReadOnlyList<string> BlankTextureNames { get; }
34+
public IReadOnlyList<string> IconAlternateTextureNames { get; }
35+
public IReadOnlyList<string> MouseOverTextureNames { get; }
36+
public IReadOnlyList<string> BarTextureNames { get; }
37+
public IReadOnlyList<string> BarOverlayNames { get; }
38+
public IReadOnlyList<string> AlternateFontNames { get; }
39+
public IReadOnlyList<string> TooltipTexts { get; }
40+
public IReadOnlyList<string> LowerEffectTextureNames { get; }
41+
public IReadOnlyList<string> UpperEffectTextureNames { get; }
42+
public IReadOnlyList<string> OverlayTextureNames { get; }
43+
public IReadOnlyList<string> Overlay2TextureNames { get; }
3244

3345
public string? IconTextureName { get; internal set; }
3446
public string? DisabledTextureName { get; internal set; }
@@ -128,21 +140,26 @@ public sealed class CommandBarComponentData(string name, Crc32 crc, XmlLocationI
128140
public Vector4Int? TextColor2 { get; internal set; }
129141
public Vector4Int? MaxBarColor { get; internal set; } = WhiteColor;
130142

131-
internal void FixupValues()
143+
public CommandBarComponentData(string name, Crc32 crc, XmlLocationInfo location) : base(name, crc, location)
132144
{
133-
if (AlternateFontNames.Count == 0)
134-
return;
135-
var newFontNames = new string[AlternateFontNames.Count];
136-
for (var i = 0; i < AlternateFontNames.Count; i++)
137-
{
138-
var current = AlternateFontNames[i];
145+
SelectedTextureNames = new ReadOnlyCollection<string>(SelectedTextureNamesInternal);
146+
BlankTextureNames = new ReadOnlyCollection<string>(BlankTextureNamesInternal);
147+
IconAlternateTextureNames = new ReadOnlyCollection<string>(IconAlternateTextureNamesInternal);
148+
MouseOverTextureNames = new ReadOnlyCollection<string>(MouseOverTextureNamesInternal);
149+
BarTextureNames = new ReadOnlyCollection<string>(BarTextureNamesInternal);
150+
BarOverlayNames = new ReadOnlyCollection<string>(BarOverlayNamesInternal);
151+
AlternateFontNames = new ReadOnlyCollection<string>(AlternateFontNamesInternal);
152+
TooltipTexts = new ReadOnlyCollection<string>(TooltipTextsInternal);
153+
LowerEffectTextureNames = new ReadOnlyCollection<string>(LowerEffectTextureNamesInternal);
154+
UpperEffectTextureNames = new ReadOnlyCollection<string>(UpperEffectTextureNamesInternal);
155+
OverlayTextureNames = new ReadOnlyCollection<string>(OverlayTextureNamesInternal);
156+
Overlay2TextureNames = new ReadOnlyCollection<string>(Overlay2TextureNamesInternal);
157+
}
139158

140-
if (current.AsSpan().IndexOf('_') != -1)
141-
newFontNames[i] = current.Replace('_', ' ');
142-
else
143-
newFontNames[i] = current;
144-
}
145-
AlternateFontNames = new ReadOnlyCollection<string>(newFontNames);
159+
internal void FixupValues()
160+
{
161+
for (var i = 0; i < AlternateFontNamesInternal.Count; i++)
162+
AlternateFontNamesInternal[i] = AlternateFontNamesInternal[i].Replace('_', ' ');
146163
}
147164
}
148165

src/PetroglyphTools/PG.StarWarsGame.Engine/GameConstants/GameConstants.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66

77
namespace PG.StarWarsGame.Engine.GameConstants;
88

9-
internal class GameConstants(GameRepository repository, GameEngineErrorReporterWrapper errorReporter, IServiceProvider serviceProvider)
10-
: GameManagerBase(repository, errorReporter, serviceProvider), IGameConstants
9+
internal class GameConstants(
10+
GameEngineType engineType,
11+
GameRepository repository,
12+
GameEngineErrorReporterWrapper errorReporter,
13+
IServiceProvider serviceProvider)
14+
: GameManagerBase(engineType, repository, errorReporter, serviceProvider), IGameConstants
1115
{
1216
protected override Task InitializeCoreAsync(CancellationToken token)
1317
{

src/PetroglyphTools/PG.StarWarsGame.Engine/GameManagerBase.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@
1212

1313
namespace PG.StarWarsGame.Engine;
1414

15-
internal abstract class GameManagerBase<T>(GameRepository repository, GameEngineErrorReporterWrapper errorReporter, IServiceProvider serviceProvider)
16-
: GameManagerBase(repository, errorReporter, serviceProvider), IGameManager<T>
15+
internal abstract class GameManagerBase<T>(
16+
GameEngineType engineType,
17+
GameRepository repository,
18+
GameEngineErrorReporterWrapper errorReporter,
19+
IServiceProvider serviceProvider)
20+
: GameManagerBase(engineType, repository, errorReporter, serviceProvider), IGameManager<T>
1721
{
1822
protected readonly FrugalValueListDictionary<Crc32, T> NamedEntries = new();
1923

@@ -40,11 +44,18 @@ internal abstract class GameManagerBase
4044
protected readonly GameEngineErrorReporterWrapper ErrorReporter;
4145

4246
public bool IsInitialized => _initialized;
43-
44-
protected GameManagerBase(GameRepository repository, GameEngineErrorReporterWrapper errorReporter, IServiceProvider serviceProvider)
47+
48+
public GameEngineType EngineType { get; }
49+
50+
protected GameManagerBase(
51+
GameEngineType engineType,
52+
GameRepository repository,
53+
GameEngineErrorReporterWrapper errorReporter,
54+
IServiceProvider serviceProvider)
4555
{
4656
GameRepository = repository ?? throw new ArgumentNullException(nameof(repository));
4757
ServiceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
58+
EngineType = engineType;
4859
Logger = serviceProvider.GetService<ILoggerFactory>()?.CreateLogger(GetType());
4960
FileSystem = serviceProvider.GetRequiredService<IFileSystem>();
5061
ErrorReporter = errorReporter ?? throw new ArgumentNullException(nameof(errorReporter));

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
4+
using System.Diagnostics;
45
using PG.Commons.Hashing;
56
using PG.StarWarsGame.Files.XML;
67
using PG.StarWarsGame.Files.XML.Data;
78

89
namespace PG.StarWarsGame.Engine.GameObjects;
910

11+
[DebuggerDisplay("{Name} ({ClassificationName})")]
1012
public sealed class GameObject : NamedXmlObject
1113
{
1214
internal GameObject(
13-
string type,
14-
string name,
15-
Crc32 nameCrc,
15+
string name,
16+
string classification,
17+
Crc32 nameCrc,
1618
int index,
17-
GameObjectType estimatedType,
1819
XmlLocationInfo location)
1920
: base(name, nameCrc, location)
2021
{
2122
if (index < 0)
2223
throw new ArgumentOutOfRangeException(nameof(index), "Index must be greater than 0.");
2324
Index = index;
2425
Id = (int)nameCrc;
25-
Type = type ?? throw new ArgumentNullException(nameof(type));
26-
EstimatedType = estimatedType;
26+
ClassificationName = classification ?? throw new ArgumentNullException(nameof(classification));
2727
LandTerrainModelMapping = new ReadOnlyDictionary<string, string>(InternalLandTerrainModelMapping);
2828
}
2929

3030
internal int Id { get; }
3131

3232
public int Index { get; }
3333

34-
public string Type { get; }
34+
public string ClassificationName { get; }
3535

36-
public string VariantOfExistingTypeName { get; internal set; }
36+
public string? VariantOfExistingTypeName { get; internal set; }
3737

38-
public bool IsLoadingComplete { get; internal set; }
39-
40-
public GameObjectType EstimatedType { get; }
38+
public GameObject? VariantOfExistingType { get; internal set; }
4139

40+
public bool IsLoadingComplete { get; internal set; }
41+
4242
public string? GalacticModel { get; internal set; }
4343

4444
public string? DestroyedGalacticModel { get; internal set; }
@@ -57,7 +57,7 @@ internal GameObject(
5757

5858
public string? LandAnimOverrideModel { get; internal set; }
5959

60-
public string? XxxSpaceModeModel { get; internal set; }
60+
public string SpaceAnimOverrideModel { get; internal set; }
6161

6262
public string? DamagedSmokeAssetModel { get; internal set; }
6363

@@ -81,8 +81,11 @@ public IEnumerable<string> Models
8181
AddNotEmpty(models, GalacticFleetOverrideModel);
8282
AddNotEmpty(models, GuiModel);
8383
AddNotEmpty(models, ModelName);
84+
85+
// TODO: Is this really correct?
8486
AddNotEmpty(models, LandAnimOverrideModel, s => s.EndsWith(".alo", StringComparison.OrdinalIgnoreCase));
85-
AddNotEmpty(models, XxxSpaceModeModel);
87+
AddNotEmpty(models, SpaceAnimOverrideModel, s => s.EndsWith(".alo", StringComparison.OrdinalIgnoreCase));
88+
8689
AddNotEmpty(models, DamagedSmokeAssetModel);
8790
foreach (var model in InternalLandTerrainModelMapping.Values)
8891
models.Add(model);
@@ -109,4 +112,9 @@ public void PostLoadFixup()
109112
// The engine loads references for scripts, images, hardpoints, etc.,
110113
// but we don't do that here.
111114
}
115+
116+
internal void ApplyBaseType(GameObject baseType)
117+
{
118+
throw new NotImplementedException();
119+
}
112120
}

0 commit comments

Comments
 (0)