SHA256
Resolve Audio Clips From Level Files
This commit is contained in:
1 parent
35606d6e58
commit
7ea2d8fe3f
5 files changed
+149
-7
No files matched your search
@@ -0,0 +1,46 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace ADOFAIRenderer.Util.Audio.Clip;
|
||||
|
||||
/// <summary>
|
||||
/// File path of every external audio clip the game loads, keyed by the game's audioLib key.
|
||||
///
|
||||
/// The game loads external clips with AudioManager.FindOrLoadAudioClipExternal(path, ...) and stores them in audioLib under
|
||||
/// Path.GetFileName(path) + "*external" (the same string becomes AudioClip.name). Recorded paths:
|
||||
/// - Song: Path.Combine(Path.GetDirectoryName(levelPath), levelData.songFilename) (scnGame song loading).
|
||||
/// - PlaySound event sound: Path.Combine(Path.GetDirectoryName(levelPath), hitsound) (scnGame.LoadSoundCo);
|
||||
/// ffxPlaySound plays it as hitsound + "*external".
|
||||
/// <see cref="Record"/> is called only when the game actually loads the file (the key is not in audioLib yet),
|
||||
/// so the recorded path is the file of the clip audioLib holds under that key.
|
||||
/// Thread-safe.
|
||||
/// </summary>
|
||||
internal static class AudioClipPaths
|
||||
{
|
||||
/// <summary>Suffix of the game's audioLib keys for external clips.</summary>
|
||||
public const string ExternalSuffix = "*external";
|
||||
|
||||
private static readonly Dictionary<string, string> Paths = new();
|
||||
|
||||
/// <summary>audioLib key of an external clip loaded from <paramref name="path"/>.</summary>
|
||||
public static string KeyOf(string path) => Path.GetFileName(path) + ExternalSuffix;
|
||||
|
||||
/// <summary>Records <paramref name="path"/> under <see cref="KeyOf"/>(path), replacing an earlier path of the same key.</summary>
|
||||
public static void Record(string path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path)) return;
|
||||
lock (Paths)
|
||||
{
|
||||
Paths[KeyOf(path)] = path;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Recorded path for an audioLib key (or AudioClip.name) of an external clip.</summary>
|
||||
public static bool TryGetPath(string key, out string path)
|
||||
{
|
||||
lock (Paths)
|
||||
{
|
||||
return Paths.TryGetValue(key, out path!);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user