Skip to content

Commit e1dbcd8

Browse files
committed
copy back data from sound viewmodel to sound object
1 parent f3fc48a commit e1dbcd8

File tree

6 files changed

+27
-12
lines changed

6 files changed

+27
-12
lines changed

Gui/ViewModels/DatTypes/BaseLocoFileViewModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ public virtual void Delete() { }
4141

4242
async Task SaveWrapper()
4343
{
44+
// note - this is the DAT file source, not the true source...
4445
if (CurrentFile is FileSystemItemObject fsio && fsio.ObjectSource is ObjectSource.LocomotionSteam or ObjectSource.LocomotionGoG)
4546
{
46-
var box = MessageBoxManager.GetMessageBoxStandard("Confirm Save", "This is a vanilla loco file - are you sure you want to overwrite it?", ButtonEnum.YesNo);
47+
var box = MessageBoxManager.GetMessageBoxStandard("Confirm Save", $"{CurrentFile.Filename} is a vanilla Locomotion file - are you sure you want to overwrite it?", ButtonEnum.YesNo);
4748
var result = await box.ShowAsync();
4849

4950
if (result != ButtonResult.Yes)
@@ -57,7 +58,7 @@ async Task SaveWrapper()
5758

5859
async Task DeleteWrapper()
5960
{
60-
var box = MessageBoxManager.GetMessageBoxStandard("Confirm Delete", "Are you sure you would like to delete?", ButtonEnum.YesNo);
61+
var box = MessageBoxManager.GetMessageBoxStandard("Confirm Delete", $"Are you sure you would like to delete {CurrentFile.Filename}?", ButtonEnum.YesNo);
6162
var result = await box.ShowAsync();
6263

6364
if (result == ButtonResult.Yes)

Gui/ViewModels/DatTypes/DatObjectEditorViewModel.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public static IObjectViewModel<ILocoStruct> GetViewModelFromStruct(ILocoStruct l
111111
public override void Load()
112112
{
113113
// this stops any currently-playing sounds
114-
if (ExtraContentViewModel is SoundViewModel svm)
114+
if (ExtraContentViewModel is AudioViewModel svm)
115115
{
116116
svm.Dispose();
117117
}
@@ -132,7 +132,7 @@ public override void Load()
132132
: new DefaultImageTableNameProvider();
133133

134134
ExtraContentViewModel = CurrentObject.LocoObject.Object is SoundObject soundObject
135-
? new SoundViewModel(CurrentObject.DatFileInfo.S5Header.Name, soundObject.SoundObjectData.PcmHeader, soundObject.PcmData)
135+
? new AudioViewModel(CurrentObject.DatFileInfo.S5Header.Name, soundObject.SoundObjectData.PcmHeader, soundObject.PcmData)
136136
: new ImageTableViewModel(CurrentObject.LocoObject, imageNameProvider, Model.PaletteMap, CurrentObject.Images, Model.Logger);
137137
}
138138
else
@@ -226,6 +226,20 @@ void SaveCore(string filename)
226226
CurrentObject.LocoObject.Object = CurrentObjectViewModel.GetAsUnderlyingType(CurrentObject.LocoObject.Object);
227227
}
228228

229+
// this is hacky but it should work
230+
if (ExtraContentViewModel is AudioViewModel avm && CurrentObject.LocoObject.Object is SoundObject so)
231+
{
232+
CurrentObject.LocoObject.Object = so with
233+
{
234+
PcmData = avm.Data,
235+
SoundObjectData = so.SoundObjectData with
236+
{
237+
PcmHeader = SawyerStreamWriter.RiffToWaveFormatEx(avm.Header),
238+
Length = (uint)avm.Data.Length
239+
}
240+
};
241+
}
242+
229243
SawyerStreamWriter.Save(filename,
230244
S5HeaderViewModel?.Name ?? CurrentObject.DatFileInfo.S5Header.Name,
231245
S5HeaderViewModel?.SourceGame ?? CurrentObject.DatFileInfo.S5Header.SourceGame,

Gui/ViewModels/DatTypes/MusicViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public MusicViewModel(FileSystemItem currentFile, ObjectEditorModel model)
1616
public override void Load()
1717
{
1818
var (header, data) = SawyerStreamReader.LoadWavFile(CurrentFile.Filename);
19-
SoundViewModel = new SoundViewModel(
19+
SoundViewModel = new AudioViewModel(
2020
GetDisplayName(CurrentFile.DisplayName),
2121
header,
2222
data);
@@ -38,7 +38,7 @@ static string GetDisplayName(string filename)
3838
}
3939

4040
[Reactive]
41-
public SoundViewModel SoundViewModel { get; set; }
41+
public AudioViewModel SoundViewModel { get; set; }
4242

4343
public override void Save()
4444
{

Gui/ViewModels/DatTypes/SoundEffectsViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ public override void Load()
2020
{
2121
var soundIdNames = Enum.GetValues<SoundId>();
2222
SoundViewModels = SawyerStreamReader.LoadSoundEffectsFromCSS(CurrentFile.Filename)
23-
.Select((x, i) => new SoundViewModel(soundIdNames[i].ToString(), x.header, x.data))
23+
.Select((x, i) => new AudioViewModel(soundIdNames[i].ToString(), x.header, x.data))
2424
.ToBindingList();
2525
}
2626

2727
[Reactive]
28-
public BindingList<SoundViewModel> SoundViewModels { get; set; } = [];
28+
public BindingList<AudioViewModel> SoundViewModels { get; set; } = [];
2929

3030
public override void Save()
3131
{

Gui/ViewModels/SubObjectTypes/SoundViewModel.cs renamed to Gui/ViewModels/SubObjectTypes/AudioViewModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414

1515
namespace OpenLoco.Gui.ViewModels
1616
{
17-
public class SoundViewModel : ReactiveObject, IExtraContentViewModel, IDisposable
17+
public class AudioViewModel : ReactiveObject, IExtraContentViewModel, IDisposable
1818
{
1919
WaveOutEvent? CurrentWOEvent { get; set; }
2020

21-
public SoundViewModel(string soundName, WaveFormatEx pcmHeader, byte[] pcmData)
21+
public AudioViewModel(string soundName, WaveFormatEx pcmHeader, byte[] pcmData)
2222
: this(soundName, SawyerStreamWriter.WaveFormatExToRiff(pcmHeader, pcmData.Length), pcmData) { }
2323

24-
public SoundViewModel(string soundName, RiffWavHeader riffHeader, byte[] pcmData)
24+
public AudioViewModel(string soundName, RiffWavHeader riffHeader, byte[] pcmData)
2525
{
2626
Name = soundName;
2727
Header = riffHeader;

Gui/Views/MainWindow.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
</ScrollViewer>
196196
</DataTemplate>
197197

198-
<DataTemplate DataType="vm:SoundViewModel">
198+
<DataTemplate DataType="vm:AudioViewModel">
199199
<Border BorderThickness="1">
200200
<StackPanel Orientation="Vertical" Background="{DynamicResource ScrollBarTrackFill}">
201201
<StackPanel Margin="4" Orientation="Horizontal">

0 commit comments

Comments
 (0)