diff --git a/MinecraftUSkinEditor/Classes/FileTypes/AudioPCKFile.cs b/MinecraftUSkinEditor/Classes/FileTypes/PCKAudioFile.cs similarity index 91% rename from MinecraftUSkinEditor/Classes/FileTypes/AudioPCKFile.cs rename to MinecraftUSkinEditor/Classes/FileTypes/PCKAudioFile.cs index 53c9ec52..d81db2cf 100644 --- a/MinecraftUSkinEditor/Classes/FileTypes/AudioPCKFile.cs +++ b/MinecraftUSkinEditor/Classes/FileTypes/PCKAudioFile.cs @@ -16,7 +16,8 @@ namespace PckStudio.Classes.FileTypes public readonly int type = 1; - public AudioCategory[] Categories { get; } = new AudioCategory[8]; + public AudioCategory[] Categories => Array.FindAll(_categories, c => c is not null); + private AudioCategory[] _categories { get; } = new AudioCategory[8]; public Dictionary Credits { get; } = new Dictionary(); @@ -117,7 +118,7 @@ namespace PckStudio.Classes.FileTypes if (category < AudioCategory.EAudioType.Overworld || category > AudioCategory.EAudioType.Unused) throw new InvalidCategoryException(nameof(category)); - return Categories[(int)category]; + return _categories[(int)category]; } /// @@ -131,13 +132,6 @@ namespace PckStudio.Classes.FileTypes audioCategory = null; return false; } - - public int GetCategoryCount() - { - int count = 0; - Array.ForEach(Categories, c => { if (c is not null) count++; }); - return count; - } /// True when category was created, otherwise false /// @@ -147,7 +141,7 @@ namespace PckStudio.Classes.FileTypes category > AudioCategory.EAudioType.Unused) throw new InvalidCategoryException(nameof(category)); bool exists = HasCategory(category); - if (!exists) Categories[(int)category] = new AudioCategory(parameterType, category); + if (!exists) _categories[(int)category] = new AudioCategory(parameterType, category); return !exists; } @@ -161,7 +155,7 @@ namespace PckStudio.Classes.FileTypes public bool RemoveCategory(AudioCategory.EAudioType category) { bool exists = HasCategory(category); - if (exists) Categories[(int)category] = null; + if (exists) _categories[(int)category] = null; return exists; } diff --git a/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileReader.cs b/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileReader.cs index ab7fee3e..bfa23923 100644 --- a/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileReader.cs +++ b/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileReader.cs @@ -75,7 +75,6 @@ namespace PckStudio.Classes.IO.PCK List creditIds = new List(); foreach (var c in _file.Categories) { - if (c is null) continue; int audioCount = ReadInt(stream); for (; 0 < audioCount; audioCount--) { diff --git a/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileWriter.cs b/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileWriter.cs index 5e727a72..18628ec4 100644 --- a/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileWriter.cs +++ b/MinecraftUSkinEditor/Classes/IO/PCK/PCKAudioFileWriter.cs @@ -57,10 +57,9 @@ namespace PckStudio.Classes.IO.PCK private void WriteCategories(Stream stream) { - WriteInt(stream, _file.GetCategoryCount()); + WriteInt(stream, _file.Categories.Length); foreach (var category in _file.Categories) { - if (category is null) continue; WriteInt(stream, (int)category.parameterType); WriteInt(stream, (int)category.audioType); WriteString(stream, category.Name); @@ -72,7 +71,6 @@ namespace PckStudio.Classes.IO.PCK bool addCredit = true; foreach (var category in _file.Categories) { - if (category is null) continue; WriteInt(stream, category.SongNames.Count + (addCredit ? _file.Credits.Count * 2 : 0)); foreach (var name in category.SongNames) { diff --git a/MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs b/MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs index 4cf09777..95df3e26 100644 --- a/MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs +++ b/MinecraftUSkinEditor/Forms/Editor/AudioEditor.cs @@ -27,18 +27,6 @@ namespace PckStudio.Forms.Editor LOCFile loc; bool _isLittleEndian = false; - public class CategorySorter : IComparer - { - public int Compare(object x, object y) - { - if (x is TreeNode xt && y is TreeNode yt && - xt.Tag is PCKAudioFile.AudioCategory xcategory && - yt.Tag is PCKAudioFile.AudioCategory ycategory) - return xcategory.audioType.CompareTo(ycategory.audioType); - return -1; - } - } - public static readonly List Categories = new List { "Overworld", @@ -112,10 +100,9 @@ namespace PckStudio.Forms.Editor foreach (var category in audioFile.Categories) { - if (category is null) continue; if (category.Name == "include_overworld" && category.audioType == PCKAudioFile.AudioCategory.EAudioType.Creative && - audioFile.Categories[0] is PCKAudioFile.AudioCategory overworldCategory) + audioFile.TryGetCategory(PCKAudioFile.AudioCategory.EAudioType.Overworld, out PCKAudioFile.AudioCategory overworldCategory)) { foreach(var name in category.SongNames.ToList()) { @@ -125,17 +112,12 @@ namespace PckStudio.Forms.Editor playOverworldInCreative.Checked = true; } - TreeNode treeNode = new TreeNode(GetCategoryFromId(category.audioType)); + TreeNode treeNode = new TreeNode(GetCategoryFromId(category.audioType), (int)category.audioType, (int)category.audioType); treeNode.Tag = category; - treeNode.ImageIndex = (int)category.audioType; - treeNode.SelectedImageIndex = (int)category.audioType; treeView1.Nodes.Add(treeNode); } playOverworldInCreative.Enabled = audioFile.HasCategory(PCKAudioFile.AudioCategory.EAudioType.Creative); - - treeView1.TreeViewNodeSorter = new CategorySorter(); - treeView1.Sort(); } // https://stackoverflow.com/a/25064568 by Alik Khilazhev -MattNL @@ -213,7 +195,7 @@ namespace PckStudio.Forms.Editor string[] avalible = Categories.FindAll(str => !audioFile.HasCategory(GetCategoryId(str)) ).ToArray(); if (avalible.Length > 0) { - using addCategory add = new addCategory(avalible); //sets category adding dialog + using addCategory add = new addCategory(avalible); if (add.ShowDialog() == DialogResult.OK) audioFile.AddCategory(GetCategoryId(add.Category)); } @@ -369,7 +351,6 @@ namespace PckStudio.Forms.Editor PCKAudioFile.AudioCategory overworldCategory = audioFile.GetCategory(PCKAudioFile.AudioCategory.EAudioType.Overworld); foreach (var category in audioFile.Categories) { - if (category is null) continue; category.Name = ""; if (playOverworldInCreative.Checked && category.audioType == PCKAudioFile.AudioCategory.EAudioType.Creative) { diff --git a/MinecraftUSkinEditor/PckStudio.csproj b/MinecraftUSkinEditor/PckStudio.csproj index 589b6ce3..6dd425cd 100644 --- a/MinecraftUSkinEditor/PckStudio.csproj +++ b/MinecraftUSkinEditor/PckStudio.csproj @@ -140,7 +140,7 @@ - +