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

@@ -593,7 +593,7 @@ namespace PckStudio.Forms.Editor
EditorValue.RemoveCategory(category.AudioType);
EditorValue.AddCategory(category.parameterType, GetCategoryId(add.SelectedItem), category.AudioType == PckAudioFile.AudioCategory.EAudioType.Overworld && playOverworldInCreative.Checked ? "include_overworld" : "");
EditorValue.AddCategory(category.AudioType == PckAudioFile.AudioCategory.EAudioType.Overworld && playOverworldInCreative.Checked ? "include_overworld" : "", GetCategoryId(add.SelectedItem), category.ParameterType);
PckAudioFile.AudioCategory newCategory = EditorValue.GetCategory(GetCategoryId(add.SelectedItem));

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>

View File

@@ -9,12 +9,7 @@ using System.Text;
namespace PckStudio.Core.IO.PckAudio
{
public class InvalidAudioPckException : Exception
{
public InvalidAudioPckException(string message) : base(message)
{ }
}
public class InvalidAudioPckException(string message) : Exception(message) { }
public class PckAudioFileReader : IDataFormatReader<PckAudioFile>, IDataFormatReader
{
@@ -86,7 +81,7 @@ namespace PckStudio.Core.IO.PckAudio
// AddCategory puts the file's categories out of order and causes some songs to be put in the wrong categories
// This is my simple fix for the issue.
_OriginalAudioTypeOrder.Add(audioType);
_file.AddCategory(parameterType, audioType, name);
_file.AddCategory(name, audioType, parameterType);
}
}

View File

@@ -41,7 +41,7 @@ namespace PckStudio.Core.IO.PckAudio
: Encoding.Unicode,
leaveOpen: true, _endianness))
{
writer.Write(_file.type);
writer.Write(_file.Type);
WriteLookUpTable(writer);
WriteCategories(writer);
WriteCategorySongs(writer);
@@ -70,7 +70,7 @@ namespace PckStudio.Core.IO.PckAudio
writer.Write(_file.Categories.Length);
foreach (PckAudioFile.AudioCategory category in _file.Categories)
{
writer.Write((int)category.parameterType);
writer.Write((int)category.ParameterType);
writer.Write((int)category.AudioType);
WriteString(writer, category.Name);
}