Skip to content

Commit 6ae7af0

Browse files
committed
more code warning cleanup
1 parent 4701a21 commit 6ae7af0

File tree

4 files changed

+42
-29
lines changed

4 files changed

+42
-29
lines changed

Gui/MainForm.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,8 @@ static string constructAnnotationText(Annotation annotation)
595595
void LoadAndPlaySound(byte[] data, string soundName)
596596
{
597597
var (header, pcmData) = SawyerStreamReader.LoadWavFile(data);
598-
var uiSoundObj = new UiSoundObject { Data = pcmData, Header = header, SoundName = soundName };
599-
var uiSoundObjectList = new UiSoundObjectList();
598+
var uiSoundObj = new UiSoundObject(soundName, header, pcmData);
599+
var uiSoundObjectList = new UiSoundObjectList(soundName);
600600
uiSoundObjectList.Audio.Add(uiSoundObj);
601601
CurrentUIObject = uiSoundObjectList;
602602

@@ -608,16 +608,16 @@ void LoadAndPlaySound(byte[] data, string soundName)
608608
}
609609
}
610610

611-
void LoadSoundEffectFile(byte[] data)
611+
void LoadSoundEffectFile(byte[] data, string soundName)
612612
{
613613
var sfxs = SawyerStreamReader.LoadSoundEffectsFromCSS(data);
614614

615615
var i = 0;
616-
var uiSoundObjectList = new UiSoundObjectList();
616+
var uiSoundObjectList = new UiSoundObjectList(soundName);
617617

618618
foreach (var (header, pcmData) in sfxs)
619619
{
620-
var uiSoundObj = new UiSoundObject { Data = pcmData, Header = SawyerStreamWriter.WaveFormatExToRiff(header, pcmData.Length), SoundName = Enum.GetValues<SoundId>().ToList()[i++].ToString() };
620+
var uiSoundObj = new UiSoundObject(Enum.GetValues<SoundId>().ToList()[i++].ToString(), SawyerStreamWriter.WaveFormatExToRiff(header, pcmData.Length), pcmData);
621621
uiSoundObjectList.Audio.Add(uiSoundObj);
622622
}
623623

@@ -654,6 +654,7 @@ public void ImportWave(string soundNameToUpdate)
654654
if (currentUIObject is UiSoundObjectList uiSoundObjList)
655655
{
656656
var soundObj = uiSoundObjList.Audio.Single(s => s.SoundName == soundNameToUpdate);
657+
//soundObj = new UiSoundObject(soundNameToUpdate, header, pcmData);
657658
soundObj.Header = header;
658659
soundObj.Data = pcmData;
659660
RefreshObjectUI();
@@ -664,10 +665,10 @@ public void ImportWave(string soundNameToUpdate)
664665
{
665666
logger.Info($"Replacing music track {soundNameToUpdate} with {openFileDialog.FileName}");
666667
}
667-
else
668-
{
669-
logger.Warning($"Sound name {soundNameToUpdate} was not recognised - no action will be taken.");
670-
}
668+
//else // commenting out because this falsely triggers for cs1.dat for sound effect names
669+
//{
670+
// logger.Warning($"Sound name {soundNameToUpdate} was not recognised - no action will be taken.");
671+
//}
671672
}
672673
}
673674
}
@@ -954,7 +955,7 @@ void LoadNull(string dataKey)
954955

955956
void LoadG1(string filename)
956957
{
957-
CurrentUIObject = new UiG1 { G1 = model.G1 };
958+
CurrentUIObject = new UiG1(model.G1);
958959
LoadDataDump(filename, true);
959960
}
960961

@@ -990,7 +991,7 @@ void tv_AfterSelect(object sender, TreeViewEventArgs e)
990991
{
991992
logger.Debug($"Loading sound effects for {e.Node.Name}");
992993
var sfx = model.SoundEffects[e.Node.Name];
993-
LoadSoundEffectFile(sfx);
994+
LoadSoundEffectFile(sfx, e.Node.Text);
994995
}
995996
else if (Path.GetExtension(e.Node.Name).Equals(".dat", StringComparison.OrdinalIgnoreCase))
996997
{
@@ -1247,7 +1248,7 @@ void RefreshObjectUI()
12471248

12481249
var hdr = soundObject.SoundObjectData.PcmHeader;
12491250
var text = uiLocoObj.LocoObject.StringTable.Table["Name"][LanguageId.English_UK] ?? "<null>";
1250-
var pn = CreateSoundUI(new UiSoundObject { Data = soundObject.PcmData, Header = SawyerStreamWriter.WaveFormatExToRiff(hdr, soundObject.PcmData.Length), SoundName = text });
1251+
var pn = CreateSoundUI(new UiSoundObject(text, SawyerStreamWriter.WaveFormatExToRiff(hdr, soundObject.PcmData.Length), soundObject.PcmData));
12511252
flpImageTable.Controls.Add(pn);
12521253
}
12531254

Gui/MainFormModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ void CreateIndex(string[] allFiles, IProgress<float>? progress)
169169
return;
170170
}
171171

172-
if (!ccObjectCache.TryAdd(file, new UiLocoObject { DatFileInfo = fileInfo, LocoObject = locoObject }))
172+
if (!ccObjectCache.TryAdd(file, new UiLocoObject(fileInfo, locoObject)))
173173
{
174174
logger.Warning($"Didn't add file {file} to cache - already exists (how???)");
175175
}
@@ -364,7 +364,7 @@ static void SerialiseHeaderIndexToFile(string filename, HeaderIndex headerIndex,
364364
else
365365
{
366366
var obj = SawyerStreamReader.LoadFullObjectFromFile(filename, logger: logger);
367-
var uiObj = new UiLocoObject { DatFileInfo = obj.DatFileInfo, LocoObject = obj.LocoObject };
367+
var uiObj = new UiLocoObject(obj.DatFileInfo, obj.LocoObject);
368368
_ = ObjectCache.TryAdd(filename, uiObj);
369369
return uiObj;
370370
}

Gui/UiLocoObject.cs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,46 @@ public interface IUiObjectWithGraphics
1414
}
1515

1616
[TypeConverter(typeof(ExpandableObjectConverter))]
17-
public class UiLocoObject : IUiObject, IUiObjectWithGraphics
17+
public record UiLocoObject(DatFileInfo DatFileInfo, ILocoObject? LocoObject) : IUiObject, IUiObjectWithGraphics
1818
{
19-
public DatFileInfo DatFileInfo { get; set; }
20-
public ILocoObject? LocoObject { get; set; }
2119
public List<G1Element32> G1Elements
2220
{
23-
get => LocoObject?.G1Elements;
24-
set => LocoObject.G1Elements = value;
21+
get => LocoObject?.G1Elements ?? Enumerable.Empty<G1Element32>().ToList();
22+
set
23+
{
24+
if (LocoObject != null)
25+
{
26+
LocoObject.G1Elements = value;
27+
}
28+
}
2529
}
2630
}
2731

2832
[TypeConverter(typeof(ExpandableObjectConverter))]
29-
public class UiSoundObject
33+
public record UiSoundObject(string SoundName)
3034
{
31-
public string SoundName { get; set; }
35+
public UiSoundObject(string soundName, RiffWavHeader header, byte[] data) : this(soundName)
36+
{
37+
Header = header;
38+
Data = data;
39+
}
40+
3241
public RiffWavHeader Header { get; set; }
3342
public byte[] Data { get; set; }
3443
}
3544

3645
[TypeConverter(typeof(ExpandableObjectConverter))]
37-
public class UiSoundObjectList : IUiObject
46+
public record UiSoundObjectList(string FileName) : IUiObject
3847
{
39-
public string FileName { get; set; }
4048
public List<UiSoundObject> Audio { get; set; } = [];
4149
}
4250

4351
[TypeConverter(typeof(ExpandableObjectConverter))]
44-
public class UiG1 : IUiObject, IUiObjectWithGraphics
52+
public record UiG1(G1Dat G1) : IUiObject, IUiObjectWithGraphics
4553
{
46-
public G1Dat G1 { get; set; }
47-
4854
public List<G1Element32> G1Elements
4955
{
50-
get => G1?.G1Elements;
56+
get => G1?.G1Elements ?? Enumerable.Empty<G1Element32>().ToList();
5157
set
5258
{
5359
G1.G1Elements.Clear();

Gui/VersionCheckBody.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
namespace OpenLoco.ObjectEditor.Gui
1+
using System.Text.Json.Serialization;
2+
3+
namespace OpenLoco.ObjectEditor.Gui
24
{
3-
public record VersionCheckBody(string TagName);
5+
public class VersionCheckBody
6+
{
7+
[JsonPropertyName("tag_name")]
8+
public string TagName { get; set; }
9+
}
410
}

0 commit comments

Comments
 (0)