Skip to content

Commit

Permalink
Editor: removed some remnants of old audio system
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-mogilko committed Oct 26, 2023
1 parent 154d3c6 commit 7c52f9f
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 158 deletions.
13 changes: 0 additions & 13 deletions Editor/AGS.Editor/AGSEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1334,19 +1334,6 @@ private string[] ConstructFileListForEXE()
return files.ToArray();
}

public void SetMODMusicFlag()
{
foreach (AudioClip clip in _game.RootAudioClipFolder.GetAllAudioClipsFromAllSubFolders())
{
if (clip.FileType == AudioClipFileType.MOD)
{
_game.Settings.HasMODMusic = true;
return;
}
}
_game.Settings.HasMODMusic = false;
}

public bool AboutToDeleteSprite(int spriteNumber)
{
PreDeleteSpriteEventArgs evArgs = new PreDeleteSpriteEventArgs(spriteNumber);
Expand Down
4 changes: 2 additions & 2 deletions Editor/AGS.Editor/BuildTargets/BuildTargetDataFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ private void CreateAudioVOXFile(bool forceRebuild)

public override bool Build(CompileMessages errors, bool forceRebuild)
{
if (!base.Build(errors, forceRebuild)) return false;
Factory.AGSEditor.SetMODMusicFlag();
if (!base.Build(errors, forceRebuild))
return false;
if (!DataFileWriter.SaveThisGameToFile(AGSEditor.COMPILED_DTA_FILE_NAME, Factory.AGSEditor.CurrentGame, errors))
{
return false;
Expand Down
1 change: 0 additions & 1 deletion Editor/AGS.Editor/BuildTargets/BuildTargetDebug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public override void DeleteMainGameData(string name)

private object CreateDebugFiles(IWorkProgress progress, object parameter)
{
Factory.AGSEditor.SetMODMusicFlag();
CompileMessages errors = (parameter as CompileMessages);
if (!DataFileWriter.SaveThisGameToFile(AGSEditor.COMPILED_DTA_FILE_NAME, Factory.AGSEditor.CurrentGame, errors))
{
Expand Down
69 changes: 1 addition & 68 deletions Editor/AGS.Editor/Components/AudioComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -479,87 +479,20 @@ public override void RefreshDataFromGame()
CreateDefaultAudioClipTypes();
}

IList<AudioClip> allAudio = null;

if ((!_agsEditor.CurrentGame.SavedXmlVersionIndex.HasValue) ||
(_agsEditor.CurrentGame.SavedXmlVersionIndex < 5))
{
ImportSoundAndMusicFromOldVersion();
allAudio = _agsEditor.CurrentGame.RootAudioClipFolder.GetAllAudioClipsFromAllSubFolders();

UpdateScoreSound(allAudio);
UpdateViewFrameSounds(allAudio, _agsEditor.CurrentGame.RootViewFolder);
}

if (allAudio == null)
{
allAudio = _agsEditor.CurrentGame.RootAudioClipFolder.GetAllAudioClipsFromAllSubFolders();
}
IList<AudioClip> allAudio = _agsEditor.CurrentGame.RootAudioClipFolder.GetAllAudioClipsFromAllSubFolders();
AudioClipTypeTypeConverter.SetAudioClipTypeList(_agsEditor.CurrentGame.AudioClipTypes);
AudioClipTypeConverter.SetAudioClipList(allAudio);

RePopulateTreeView();
}

private void UpdateScoreSound(IList<AudioClip> allAudio)
{
if (_agsEditor.CurrentGame.Settings.PlaySoundOnScore > 0)
{
AudioClip clip = _agsEditor.CurrentGame.FindAudioClipForOldSoundNumber(allAudio, _agsEditor.CurrentGame.Settings.PlaySoundOnScore);
if (clip != null)
{
_agsEditor.CurrentGame.Settings.PlaySoundOnScore = clip.Index;
}
else
{
_agsEditor.CurrentGame.Settings.PlaySoundOnScore = AudioClip.FixedIndexNoValue;
}
}
}

private void UpdateViewFrameSounds(IList<AudioClip> allAudio, ViewFolder views)
{
foreach (View view in views.Views)
{
foreach (ViewLoop loop in view.Loops)
{
foreach (ViewFrame frame in loop.Frames)
{
if (frame.Sound > 0)
{
AudioClip clip = _agsEditor.CurrentGame.FindAudioClipForOldSoundNumber(allAudio, frame.Sound);
if (clip != null)
{
frame.Sound = clip.Index;
}
else
{
frame.Sound = AudioClip.FixedIndexNoValue;
}
}
}
}
}

foreach (ViewFolder folder in views.SubFolders)
{
UpdateViewFrameSounds(allAudio, folder);
}
}

private void CreateDefaultAudioClipTypes()
{
_agsEditor.CurrentGame.AudioClipTypes.Add(new AudioClipType(1, "Ambient Sound", 1, 0, true, CrossfadeSpeed.No));
_agsEditor.CurrentGame.AudioClipTypes.Add(new AudioClipType(DEFAULT_AUDIO_TYPE_MUSIC, "Music", 1, 30, true, _agsEditor.CurrentGame.Settings.CrossfadeMusic));
_agsEditor.CurrentGame.AudioClipTypes.Add(new AudioClipType(DEFAULT_AUDIO_TYPE_SOUND, "Sound", 0, 0, false, CrossfadeSpeed.No));
}

private void ImportSoundAndMusicFromOldVersion()
{
ImportAllFilesFromDirectoryIntoNewFolder("Music", "Music", "music*.*", AudioFileBundlingType.InSeparateVOX, true, DEFAULT_AUDIO_TYPE_MUSIC);
ImportAllFilesFromDirectoryIntoNewFolder("Sounds", "Sound", "sound*.*", AudioFileBundlingType.InGameEXE, false, DEFAULT_AUDIO_TYPE_SOUND);
}

private void ImportAllFilesFromDirectoryIntoNewFolder(string newFolderName, string sourceDir, string fileMask, AudioFileBundlingType bundlingType, bool repeat, int type)
{
AudioClipFolder soundFolder = new AudioClipFolder(newFolderName);
Expand Down
30 changes: 0 additions & 30 deletions Editor/AGS.Editor/Components/RoomsComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,6 @@ private Room LoadNewRoomIntoMemory(UnloadedRoom newRoom, CompileMessages errors)
_loadedRoom.Modified |= ImportExport.CreateInteractionScripts(_loadedRoom, errors);
_loadedRoom.Modified |= HookUpInteractionVariables(_loadedRoom);
_loadedRoom.Modified |= HandleObsoleteSettings(_loadedRoom, errors);
_loadedRoom.Modified |= AddPlayMusicCommandToPlayerEntersRoomScript(_loadedRoom, errors);
if (_loadedRoom.Script.Modified)
{
if (_roomScriptEditors.ContainsKey(_loadedRoom.Number))
Expand All @@ -933,35 +932,6 @@ private bool HandleObsoleteSettings(Room room, CompileMessages errors)
#pragma warning restore 0612
}

private bool AddPlayMusicCommandToPlayerEntersRoomScript(Room room, CompileMessages errors)
{
#pragma warning disable 0612
bool scriptModified = false;
if (room.PlayMusicOnRoomLoad > 0)
{
AudioClip clip = _agsEditor.CurrentGame.FindAudioClipForOldMusicNumber(null, room.PlayMusicOnRoomLoad);
if (clip == null)
{
errors.Add(new CompileWarning("Room " + room.Number + ": Unable to find aMusic" + room.PlayMusicOnRoomLoad + " which was set as this room's start music"));
return scriptModified;
}

string functionName = room.Interactions.GetScriptFunctionNameForInteractionSuffix(Room.EVENT_SUFFIX_ROOM_LOAD);
if (string.IsNullOrEmpty(functionName))
{
functionName = "Room_" + Room.EVENT_SUFFIX_ROOM_LOAD;
room.Interactions.SetScriptFunctionNameForInteractionSuffix(Room.EVENT_SUFFIX_ROOM_LOAD, functionName);
}

room.Script.Text = ScriptGeneration.InsertFunction(room.Script.Text, functionName, "",
" " + clip.ScriptName + ".Play();", amendExisting: true, insertBeforeExistingCode: true);
scriptModified = true;
}

return scriptModified;
#pragma warning restore 0612
}

private bool ApplyDefaultMaskResolution(Room room)
{
int mask = _agsEditor.CurrentGame.Settings.DefaultRoomMaskResolution;
Expand Down
34 changes: 0 additions & 34 deletions Editor/AGS.Types/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -551,40 +551,6 @@ public int FindFirstAvailableRoomNumber(int startingFromNumber)
return startingFromNumber;
}

public AudioClip FindAudioClipForOldSoundNumber(IList<AudioClip> allAudio, int soundNumber)
{
if (allAudio == null)
{
allAudio = _audioClips.RootFolder.GetAllAudioClipsFromAllSubFolders();
}
string searchForName = string.Format("aSound{0}", soundNumber);
foreach (AudioClip clip in allAudio)
{
if (clip.ScriptName == searchForName)
{
return clip;
}
}
return null;
}

public AudioClip FindAudioClipForOldMusicNumber(IList<AudioClip> allAudio, int musicNumber)
{
if (allAudio == null)
{
allAudio = _audioClips.RootFolder.GetAllAudioClipsFromAllSubFolders();
}
string searchForName = string.Format("aMusic{0}", musicNumber);
foreach (AudioClip clip in allAudio)
{
if (clip.ScriptName == searchForName)
{
return clip;
}
}
return null;
}

// CLNUP
// TODO: remove this after we have proper zoom controls in all editors;
// default zoom-in should be relied on the actual image size if on anything
Expand Down
10 changes: 0 additions & 10 deletions Editor/AGS.Types/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public Settings()
private ScriptAPIVersion _scriptCompatLevel = ScriptAPIVersion.Highest;
private ScriptAPIVersion _scriptAPIVersionReal = Utilities.GetActualAPI(ScriptAPIVersion.Highest);
private ScriptAPIVersion _scriptCompatLevelReal = Utilities.GetActualAPI(ScriptAPIVersion.Highest);
private bool _enforceNewAudio = true;
private bool _oldKeyHandling = false;
private bool _scaleCharacterSpriteOffsets = true;
private int _playSoundOnScore = -1;
Expand All @@ -98,7 +97,6 @@ public Settings()
private bool _backwardsText = false;
private int _uniqueID;
private Guid _guid;
private bool _hasMODMusic = false;
private int _totalScore = 0;
private bool _runGameLoopsWhileDialogOptionsDisplayed = false;
private InventoryHotspotMarker _inventoryHotspotMarker = new InventoryHotspotMarker();
Expand Down Expand Up @@ -893,13 +891,6 @@ public int MaximumScore
set { _totalScore = value; }
}

[Browsable(false)]
public bool HasMODMusic
{
get { return _hasMODMusic; }
set { _hasMODMusic = value; }
}

[DisplayName("Default mask resolution")]
[Description("What resolution do room region masks have relative to the room size")]
[Category("Rooms")]
Expand Down Expand Up @@ -1087,7 +1078,6 @@ public void FromXml(XmlNode node)
_runGameLoopsWhileDialogOptionsDisplayed = false;
_inventoryHotspotMarker = new InventoryHotspotMarker();
_audioIndexer = AudioClip.FixedIndexBase;
_enforceNewAudio = false;
_gameFileName = string.Empty;

SerializeUtils.DeserializeFromXML(this, node);
Expand Down

0 comments on commit 7c52f9f

Please sign in to comment.