From 2f78b0323a10ed5c8e799c4c4233abc57359094e Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Mon, 10 Nov 2025 07:29:36 +0100 Subject: [PATCH] Core - Update PckAudioFile for readability --- PCK-Studio/Forms/Editor/AudioEditor.cs | 2 +- PckStudio.Core/FileFormats/PckAudioFile.cs | 42 ++++++++----------- .../IO/PckAudio/PckAudioFileReader.cs | 9 +--- .../IO/PckAudio/PckAudioFileWriter.cs | 4 +- 4 files changed, 22 insertions(+), 35 deletions(-) diff --git a/PCK-Studio/Forms/Editor/AudioEditor.cs b/PCK-Studio/Forms/Editor/AudioEditor.cs index 05acd345..7ac98946 100644 --- a/PCK-Studio/Forms/Editor/AudioEditor.cs +++ b/PCK-Studio/Forms/Editor/AudioEditor.cs @@ -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)); diff --git a/PckStudio.Core/FileFormats/PckAudioFile.cs b/PckStudio.Core/FileFormats/PckAudioFile.cs index 848d69b6..0cf4b526 100644 --- a/PckStudio.Core/FileFormats/PckAudioFile.cs +++ b/PckStudio.Core/FileFormats/PckAudioFile.cs @@ -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 Credits { get; } = new Dictionary(); - 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 SongNames { get; } = new List(); - 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 /// 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]; } - /// 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 /// True when category was created, otherwise false /// - 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 /// True when category was created, otherwise false /// - public bool AddCategory(AudioCategory.EAudioType category) - => AddCategory(AudioCategory.EAudioParameterType.unk0, category); + public bool AddCategory(AudioCategory.EAudioType category) => AddCategory("", category, AudioCategory.EAudioParameterType.Unk0); /// True when category was removed, otherwise false /// diff --git a/PckStudio.Core/IO/PckAudio/PckAudioFileReader.cs b/PckStudio.Core/IO/PckAudio/PckAudioFileReader.cs index d1b8165a..a4489fe5 100644 --- a/PckStudio.Core/IO/PckAudio/PckAudioFileReader.cs +++ b/PckStudio.Core/IO/PckAudio/PckAudioFileReader.cs @@ -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, 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); } } diff --git a/PckStudio.Core/IO/PckAudio/PckAudioFileWriter.cs b/PckStudio.Core/IO/PckAudio/PckAudioFileWriter.cs index 73c343bb..61ddae27 100644 --- a/PckStudio.Core/IO/PckAudio/PckAudioFileWriter.cs +++ b/PckStudio.Core/IO/PckAudio/PckAudioFileWriter.cs @@ -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); }