Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Editors.Audio.Shared.AudioProject.Compiler;
using Editors.Audio.Shared.AudioProject.Models;
using Editors.Audio.Shared.Storage;
using Editors.Audio.Shared.Wwise;
using Shared.Core.Events;

namespace Editors.Audio.AudioEditor.Commands.AudioFilesExplorer
Expand All @@ -18,24 +17,16 @@ public class SetAudioFilesCommand(IAudioEditorStateService audioEditorStateServi

public void Execute(List<AudioFilesTreeNode> selectedAudioFiles, bool addToExistingAudioFiles)
{
var usedSourceIds = new HashSet<uint>();
var audioProject = _audioEditorStateService.AudioProject;

var audioProjectSourceIds = audioProject.GetAudioFileIds();
var languageId = WwiseHash.Compute(audioProject.Language);
var languageSourceIds = _audioRepository.GetUsedVanillaSourceIdsByLanguageId(languageId);

usedSourceIds.UnionWith(audioProjectSourceIds);
usedSourceIds.UnionWith(languageSourceIds);
var usedSourceIds = IdGenerator.GetUsedSourceIds(_audioRepository, _audioEditorStateService.AudioProject);

var audioFiles = new List<AudioFile>();
foreach (var wavFile in selectedAudioFiles)
{
var audioFile = audioProject.GetAudioFile(wavFile.FilePath);
var audioFile = _audioEditorStateService.AudioProject.GetAudioFile(wavFile.FilePath);
if (audioFile == null)
{
var audioFileIds = IdGenerator.GenerateIds(usedSourceIds);
audioFile = AudioFile.Create(audioFileIds.Guid, audioFileIds.Id, wavFile.FileName, wavFile.FilePath);
audioFile = new AudioFile(audioFileIds.Guid, audioFileIds.Id, wavFile.FileName, wavFile.FilePath);
}
audioFiles.Add(audioFile);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Data;
using System.Collections.Generic;
using System.Data;
using Editors.Audio.AudioEditor.Commands.AudioProjectMutation;
using Editors.Audio.AudioEditor.Core;
using Editors.Audio.AudioEditor.Events.AudioProjectEditor.Table;
Expand All @@ -7,7 +8,7 @@

namespace Editors.Audio.AudioEditor.Commands.AudioProjectEditor
{
public class AddEditorRowToViewerCommand(
public class AddRowsToViewerCommand(
IAudioEditorStateService audioEditorStateService,
IAudioProjectMutationUICommandFactory audioProjectMutationUICommandFactory,
IEventHub eventHub) : IUiCommand
Expand All @@ -16,12 +17,14 @@ public class AddEditorRowToViewerCommand(
private readonly IAudioProjectMutationUICommandFactory _audioProjectMutationUICommandFactory = audioProjectMutationUICommandFactory;
private readonly IEventHub _eventHub = eventHub;

public void Execute(DataRow row)
public void Execute(List<DataRow> rows)
{
var selectedAudioProjectExplorerNode = _audioEditorStateService.SelectedAudioProjectExplorerNode;
_audioProjectMutationUICommandFactory.Create(MutationType.Add, selectedAudioProjectExplorerNode.Type).Execute(row);
_eventHub.Publish(new ViewerTableRowAddRequestedEvent(row));
_eventHub.Publish(new EditorTableRowAddedToViewerEvent());
foreach (var row in rows)
{
_audioProjectMutationUICommandFactory.Create(MutationType.Add, _audioEditorStateService.SelectedAudioProjectExplorerNode.Type).Execute(row);
_eventHub.Publish(new ViewerTableRowAddRequestedEvent(row));
_eventHub.Publish(new EditorTableRowAddedToViewerEvent());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ public void Execute(DataRow row)
var audioFiles = _audioEditorStateService.AudioFiles;
var hircSettings = _audioEditorStateService.HircSettings;
var actionEventName = TableHelpers.GetActionEventNameFromRow(row);
_actionEventService.AddActionEvent(actionEventTypeName, actionEventName, audioFiles, hircSettings);

if (actionEventName.StartsWith("Play_"))
_actionEventService.AddPlayActionEvent(actionEventTypeName, actionEventName, audioFiles, hircSettings);
else if (actionEventName.StartsWith("Pause_") || actionEventName.StartsWith("Resume_") || actionEventName.StartsWith("Stop_"))
_actionEventService.AddPauseResumeStopActionEvent(actionEventTypeName, actionEventName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,27 @@ public class AddDialogueEventByPasteCommand(

public void Execute(DataRow row)
{
var audioProject = _audioEditorStateService.AudioProject;
var copiedFromAudioProjectExplorerNode = _audioEditorStateService.CopiedFromAudioProjectExplorerNode;

HircSettings hircSettings = null;
var audioFiles = new List<AudioFile>();

var dialogueEventName = copiedFromAudioProjectExplorerNode.Name;
var dialogueEventName = _audioEditorStateService.CopiedFromAudioProjectExplorerNode.Name;
var dialogueEvent = _audioEditorStateService.AudioProject.GetDialogueEvent(dialogueEventName);
var statePathName = TableHelpers.GetStatePathNameFromRow(row, _audioRepository, dialogueEventName);
var statePath = dialogueEvent.GetStatePath(statePathName);
var soundBank = _audioEditorStateService.AudioProject.GetSoundBank(copiedFromAudioProjectExplorerNode.Parent.Parent.Name);
var soundBankName = _audioEditorStateService.CopiedFromAudioProjectExplorerNode.GetParentSoundBankNode().Name;
var soundBank = _audioEditorStateService.AudioProject.GetSoundBank(soundBankName);

if (statePath.TargetHircTypeIsSound())
{
var sound = soundBank.GetSound(statePath.TargetHircId);
hircSettings = sound.HircSettings;
audioFiles.Add(audioProject.GetAudioFile(sound.SourceId));
audioFiles.Add(_audioEditorStateService.AudioProject.GetAudioFile(sound.SourceId));
}
else if (statePath.TargetHircTypeIsRandomSequenceContainer())
{
var randomSequenceContainer = soundBank.GetRandomSequenceContainer(statePath.TargetHircId);
hircSettings = randomSequenceContainer.HircSettings;
audioFiles = audioProject.GetAudioFiles(soundBank, randomSequenceContainer);
audioFiles = _audioEditorStateService.AudioProject.GetAudioFiles(soundBank, randomSequenceContainer);
}

var statePathList = new List<KeyValuePair<string, string>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Editors.Audio.AudioEditor.Commands.AudioProjectViewer
{
public class EditViewerRowCommand(
public class EditViewerRowsCommand(
IAudioEditorStateService audioEditorStateService,
IUiCommandFactory uiCommandFactory,
IEventHub eventHub) : IUiCommand
Expand All @@ -17,14 +17,14 @@ public class EditViewerRowCommand(
private readonly IUiCommandFactory _uiCommandFactory = uiCommandFactory;
private readonly IEventHub _eventHub = eventHub;

private readonly ILogger _logger = Logging.Create<EditViewerRowCommand>();
private readonly ILogger _logger = Logging.Create<EditViewerRowsCommand>();

public void Execute(List<DataRow> selectedViewerRows)
public void Execute(List<DataRow> rows)
{
// Publish before removing to ensure that an item is still selected
_eventHub.Publish(new ViewerTableRowEditedEvent(selectedViewerRows[0]));
_eventHub.Publish(new ViewerTableRowEditedEvent(rows[0]));

_uiCommandFactory.Create<RemoveViewerRowsCommand>().Execute(selectedViewerRows);
_uiCommandFactory.Create<RemoveViewerRowsCommand>().Execute(rows);

var selectedAudioProjectExplorerNode = _audioEditorStateService.SelectedAudioProjectExplorerNode;
_logger.Here().Information($"Editing {selectedAudioProjectExplorerNode.Type} row in Audio Project Viewer table for {selectedAudioProjectExplorerNode.Name}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public class RemoveViewerRowsCommand(
private readonly IAudioProjectMutationUICommandFactory _audioProjectMutationUICommandFactory = audioProjectMutationUICommandFactory;
private readonly IEventHub _eventHub = eventHub;

public void Execute(List<DataRow> selectedViewerRows)
public void Execute(List<DataRow> rows)
{
var selectedAudioProjectExplorerNode = _audioEditorStateService.SelectedAudioProjectExplorerNode;
foreach (var row in selectedViewerRows)
foreach (var row in rows)
_audioProjectMutationUICommandFactory.Create(MutationType.Remove, selectedAudioProjectExplorerNode.Type).Execute(row);

_eventHub.Publish(new EditorAddRowButtonEnablementUpdateRequestedEvent());
Expand Down
15 changes: 10 additions & 5 deletions Editors/Audio/AudioEditor/Core/AudioEditorFileService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Windows;
Expand Down Expand Up @@ -40,7 +41,7 @@ public class AudioEditorFileService(

public void Save(AudioProjectFile audioProject, string fileName, string filePath)
{
var cleanedAudioProject = AudioProjectFile.Clean(audioProject);
var cleanedAudioProject = audioProject.Clean();

var options = new JsonSerializerOptions
{
Expand Down Expand Up @@ -77,12 +78,16 @@ public void Load(AudioProjectFile audioProject, string fileName, string filePath
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);

// We add the Audio Project name as a suffix to all SoundBank names so if the Audio Project name has changed we need to update them
_audioEditorIntegrityService.UpdateSoundBankNames(audioProject, fileNameWithoutExtension);
_audioEditorIntegrityService.EnsureCorrectSoundBankNames(audioProject, fileNameWithoutExtension);

var currentGame = _applicationSettingsService.CurrentSettings.CurrentGame;
if (currentGame != GameTypeEnum.Warhammer3)
throw new NotImplementedException($"The Audio Editor does not support the selected game.");

// We create a 'dirty' Audio Project to display the whole model in the Audio Project Explorer rather than
// just the clean data from the loaded Audio Project as any unused parts are removed when it's saved
var currentGame = _applicationSettingsService.CurrentSettings.CurrentGame;
var dirtyAudioProject = AudioProjectFile.Create(audioProject, currentGame, fileNameWithoutExtension);
var dirtyAudioProject = AudioProjectFile.CreateNew(audioProject.Language, fileNameWithoutExtension);
AudioProjectFileMerger.Merge(dirtyAudioProject, audioProject, fileNameWithoutExtension, fileNameWithoutExtension);

_audioRepository.Load([audioProject.Language]);

Expand Down
25 changes: 10 additions & 15 deletions Editors/Audio/AudioEditor/Core/AudioEditorIntegrityService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Editors.Audio.AudioEditor.Core
{
public interface IAudioEditorIntegrityService
{
void UpdateSoundBankNames(AudioProjectFile audioProject, string audioProjectNameWithoutExtension);
void EnsureCorrectSoundBankNames(AudioProjectFile audioProject, string audioProjectNameWithoutExtension);
void RefreshSourceIds(AudioProjectFile audioProject);
void CheckDialogueEventInformationIntegrity(List<Wh3DialogueEventDefinition> dialogueEventData);
void CheckAudioProjectDialogueEventIntegrity(AudioProjectFile audioProject);
Expand All @@ -29,7 +29,7 @@ public class AudioEditorIntegrityService(IPackFileService packFileService, IAudi
private readonly IPackFileService _packFileService = packFileService;
private readonly IAudioRepository _audioRepository = audioRepository;

public void UpdateSoundBankNames(AudioProjectFile audioProject, string audioProjectNameWithoutExtension)
public void EnsureCorrectSoundBankNames(AudioProjectFile audioProject, string audioProjectNameWithoutExtension)
{
foreach (var soundBank in audioProject.SoundBanks)
{
Expand All @@ -45,13 +45,7 @@ public void UpdateSoundBankNames(AudioProjectFile audioProject, string audioProj

public void RefreshSourceIds(AudioProjectFile audioProject)
{
var audioProjectSourceIds = audioProject.GetAudioFileIds();
var languageId = WwiseHash.Compute(audioProject.Language);
var languageSourceIds = _audioRepository.GetUsedVanillaSourceIdsByLanguageId(languageId);

var usedSourceIds = new HashSet<uint>();
usedSourceIds.UnionWith(audioProjectSourceIds);
usedSourceIds.UnionWith(languageSourceIds);
var usedSourceIds = IdGenerator.GetUsedSourceIds(_audioRepository, audioProject);

var audioProjectSounds = audioProject.GetSounds();
foreach (var audioFile in audioProject.AudioFiles)
Expand All @@ -66,6 +60,8 @@ public void RefreshSourceIds(AudioProjectFile audioProject)
audioFile.Guid = audioFileIds.Guid;
audioFile.Id = audioFileIds.Id;
}

MessageBox.Show("Delete all your existing WEMs and then recompile the Audio Project as all WEM IDs have now been updated.", "Warning");
}

public void CheckDialogueEventInformationIntegrity(List<Wh3DialogueEventDefinition> information)
Expand Down Expand Up @@ -240,14 +236,16 @@ public void CheckAudioProjectDataIntegrity(AudioProjectFile audioProject, string
usedSourceIds.UnionWith(audioProjectSourceIds);
usedSourceIds.UnionWith(languageSourceIds);

// TODO: Implement a get all references by ID to then replace them all for the clashing IDs

foreach (var soundBank in audioProject.SoundBanks)
{
ResolveSoundBankDataIntegrity(audioProject, audioProjectNameWithoutExtension, soundBank);

if (soundBank.ActionEvents != null)
if (soundBank.ActionEvents.Count != 0)
ResolveActionEventDataIntegrity(usedHircIds, usedSourceIds, soundBank);

if (soundBank.DialogueEvents != null)
if (soundBank.DialogueEvents.Count != 0)
ResolveDialogueEventDataIntegrity(usedHircIds, usedSourceIds, soundBank);
}

Expand Down Expand Up @@ -288,9 +286,6 @@ private static void ResolveSoundBankDataIntegrity(AudioProjectFile audioProject,
if (!string.Equals(soundBank.Language, requiredLanguageAsString, StringComparison.Ordinal))
throw new InvalidOperationException($"SoundBank.Language should be '{requiredLanguageAsString}'.");
}

if (soundBank.LanguageId == 0)
throw new InvalidOperationException("SoundBank.LanguageId should not be 0.");
}

private static void ResolveActionEventDataIntegrity(HashSet<uint> usedHircIds, HashSet<uint> usedSourceIds, SoundBank soundBank)
Expand Down Expand Up @@ -410,7 +405,7 @@ private static void ResolveDialogueEventDataIntegrity(HashSet<uint> usedHircIds,

private static void ResolveStateGroupDataIntegrity(AudioProjectFile audioProject)
{
if (audioProject.StateGroups != null)
if (audioProject.StateGroups.Count != 0)
{
foreach (var stateGroup in audioProject.StateGroups)
{
Expand Down
Loading
Loading