Core - Update PckAudioFile for readability

This commit is contained in:
miku-666
2025-11-10 07:29:36 +01:00
parent e5489daa2f
commit 2f78b0323a
4 changed files with 22 additions and 35 deletions

View File

@@ -5,22 +5,18 @@ using OMI.Formats.Languages;
namespace PckStudio.Core.FileFormats
{
public class PckAudioFile
public sealed class PckAudioFile
{
public class InvalidCategoryException : Exception
{
public InvalidCategoryException(string message) : base(message)
{ }
}
public sealed class InvalidCategoryException(string message) : Exception(message) { }
public readonly int type = 1;
public readonly int Type = 1;
public AudioCategory[] Categories => Array.FindAll(_categories, c => c is not null);
private AudioCategory[] _categories { get; } = new AudioCategory[9];
public Dictionary<string, string> Credits { get; } = new Dictionary<string, string>();
public class AudioCategory
public sealed class AudioCategory
{
public enum EAudioType : int
{
@@ -37,20 +33,20 @@ namespace PckStudio.Core.FileFormats
public enum EAudioParameterType : int
{
unk0, // dimension music
unk1, // unused music ?
Unk0, // dimension music
Unk1, // unused music ?
}
public string Name { get; set; } = string.Empty;
public EAudioType AudioType { get; }
public List<string> SongNames { get; } = new List<string>();
public EAudioParameterType parameterType { get; }
public EAudioParameterType ParameterType { get; }
public AudioCategory(string name, EAudioParameterType parameterType, EAudioType audioType)
{
this.Name = name;
this.parameterType = parameterType;
this.AudioType = audioType;
Name = name;
ParameterType = parameterType;
AudioType = audioType;
}
}
@@ -107,18 +103,16 @@ namespace PckStudio.Core.FileFormats
/// <exception cref="InvalidCategoryException"></exception>
public AudioCategory GetCategory(AudioCategory.EAudioType category)
{
if (category < AudioCategory.EAudioType.Overworld ||
category > AudioCategory.EAudioType.BuildOff)
if (!Enum.IsDefined(typeof(AudioCategory.EAudioType), category))
throw new InvalidCategoryException(nameof(category));
return _categories[(int)category];
}
/// <exception cref="InvalidCategoryException"></exception>
public bool TryGetCategory(AudioCategory.EAudioType category, out AudioCategory audioCategory)
{
if (GetCategory(category) is AudioCategory a)
if (GetCategory(category) is AudioCategory audioCat)
{
audioCategory = a;
audioCategory = audioCat;
return true;
}
audioCategory = null;
@@ -127,10 +121,9 @@ namespace PckStudio.Core.FileFormats
/// <returns>True when category was created, otherwise false</returns>
/// <exception cref="InvalidCategoryException"></exception>
public bool AddCategory(AudioCategory.EAudioParameterType parameterType, AudioCategory.EAudioType category, string name = "")
{
if (category < AudioCategory.EAudioType.Overworld ||
category > AudioCategory.EAudioType.BuildOff)
public bool AddCategory(string name, AudioCategory.EAudioType category, AudioCategory.EAudioParameterType parameterType)
{
if (!Enum.IsDefined(typeof(AudioCategory.EAudioType), category))
throw new InvalidCategoryException(nameof(category));
bool exists = HasCategory(category);
if (!exists)
@@ -140,8 +133,7 @@ namespace PckStudio.Core.FileFormats
/// <returns>True when category was created, otherwise false</returns>
/// <exception cref="InvalidCategoryException"></exception>
public bool AddCategory(AudioCategory.EAudioType category)
=> AddCategory(AudioCategory.EAudioParameterType.unk0, category);
public bool AddCategory(AudioCategory.EAudioType category) => AddCategory("", category, AudioCategory.EAudioParameterType.Unk0);
/// <returns>True when category was removed, otherwise false</returns>
/// <exception cref="InvalidCategoryException"></exception>