SHA256
47 lines
1.9 KiB
C#
47 lines
1.9 KiB
C#
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!);
|
|
}
|
|
}
|
|
}
|