From b07462b439be1c0e3c4bd55814ee93e65deb2d05 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Fri, 15 Mar 2024 23:08:26 +0100 Subject: [PATCH] Update OMI submodule - Changed pck file property api - Move LocFile InitializeDefault to extension class --- PCK-Studio/Extensions/LocFileExtensions.cs | 22 +++++ PCK-Studio/Features/WiiUPanel.cs | 2 +- .../Forms/Skins-And-Textures/AddNewSkin.cs | 16 ++-- .../Skins-And-Textures/AdvancedOptions.cs | 2 +- .../Forms/Skins-And-Textures/generateModel.cs | 12 +-- PCK-Studio/Forms/Utilities/pckCenterOpen.cs | 4 +- PCK-Studio/Helper/AnimationHelper.cs | 4 +- PCK-Studio/MainForm.cs | 83 ++++++++++--------- PCK-Studio/PckStudio.csproj | 1 + Vendor/OMI-Lib | 2 +- 10 files changed, 89 insertions(+), 59 deletions(-) create mode 100644 PCK-Studio/Extensions/LocFileExtensions.cs diff --git a/PCK-Studio/Extensions/LocFileExtensions.cs b/PCK-Studio/Extensions/LocFileExtensions.cs new file mode 100644 index 00000000..787ac540 --- /dev/null +++ b/PCK-Studio/Extensions/LocFileExtensions.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using OMI.Formats.Languages; + +namespace PckStudio.Extensions +{ + internal static class LocFileExtensions + { + + public static void InitializeDefault(this LOCFile locFile, string packName) => locFile.Initialize("en-EN", ("IDS_DISPLAY_NAME", packName)); + + public static void Initialize(this LOCFile locFile, string language, params (string, string)[] locKeyValuePairs) + { + locFile.AddLanguage(language); + foreach (var locKeyValue in locKeyValuePairs) + locFile.AddLocKey(locKeyValue.Item1, locKeyValue.Item2); + } + } +} diff --git a/PCK-Studio/Features/WiiUPanel.cs b/PCK-Studio/Features/WiiUPanel.cs index ab6aa5f4..adc3baac 100644 --- a/PCK-Studio/Features/WiiUPanel.cs +++ b/PCK-Studio/Features/WiiUPanel.cs @@ -237,7 +237,7 @@ namespace PckStudio.Features currentPCK = reader.FromFile(filepath); if (currentPCK is null) return string.Empty; return currentPCK.TryGetFile("0", PckFileType.InfoFile, out var file) - ? file.Properties.GetPropertyValue("PACKID") + ? file.GetProperty("PACKID") : string.Empty; } diff --git a/PCK-Studio/Forms/Skins-And-Textures/AddNewSkin.cs b/PCK-Studio/Forms/Skins-And-Textures/AddNewSkin.cs index 7c80ab59..bae14ad6 100644 --- a/PCK-Studio/Forms/Skins-And-Textures/AddNewSkin.cs +++ b/PCK-Studio/Forms/Skins-And-Textures/AddNewSkin.cs @@ -242,32 +242,32 @@ namespace PckStudio.Popups } string skinId = _skinId.ToString("d08"); skin.Filename = $"dlcskin{skinId}.png"; - skin.Properties.Add("DISPLAYNAME", textSkinName.Text); + skin.AddProperty("DISPLAYNAME", textSkinName.Text); if (currentLoc is not null) { string skinDisplayNameLocKey = $"IDS_dlcskin{skinId}_DISPLAYNAME"; - skin.Properties.Add("DISPLAYNAMEID", skinDisplayNameLocKey); + skin.AddProperty("DISPLAYNAMEID", skinDisplayNameLocKey); currentLoc.AddLocKey(skinDisplayNameLocKey, textSkinName.Text); } if (!string.IsNullOrEmpty(textThemeName.Text)) { - skin.Properties.Add("THEMENAME", textThemeName.Text); + skin.AddProperty("THEMENAME", textThemeName.Text); if (currentLoc is not null) { - skin.Properties.Add("THEMENAMEID", $"IDS_dlcskin{skinId}_THEMENAME"); + skin.AddProperty("THEMENAMEID", $"IDS_dlcskin{skinId}_THEMENAME"); currentLoc.AddLocKey($"IDS_dlcskin{skinId}_THEMENAME", textThemeName.Text); } } - skin.Properties.Add("ANIM", anim); - skin.Properties.Add("GAME_FLAGS", "0x18"); - skin.Properties.Add("FREE", "1"); + skin.AddProperty("ANIM", anim); + skin.AddProperty("GAME_FLAGS", "0x18"); + skin.AddProperty("FREE", "1"); if (HasCape) { cape.Filename = $"dlccape{skinId}.png"; - skin.Properties.Add("CAPEPATH", cape.Filename); + skin.AddProperty("CAPEPATH", cape.Filename); } skin.SetData(skinPictureBox.Image, ImageFormat.Png); DialogResult = DialogResult.OK; diff --git a/PCK-Studio/Forms/Skins-And-Textures/AdvancedOptions.cs b/PCK-Studio/Forms/Skins-And-Textures/AdvancedOptions.cs index 65f15c65..e536a96f 100644 --- a/PCK-Studio/Forms/Skins-And-Textures/AdvancedOptions.cs +++ b/PCK-Studio/Forms/Skins-And-Textures/AdvancedOptions.cs @@ -67,7 +67,7 @@ namespace PckStudio.Popups if (index == -1 || (Enum.IsDefined(typeof(PckFileType), index) && (int)file.Filetype == index)) { - file.Properties.Add(propertyKeyTextBox.Text, propertyValueTextBox.Text); + file.AddProperty(propertyKeyTextBox.Text, propertyValueTextBox.Text); } } diff --git a/PCK-Studio/Forms/Skins-And-Textures/generateModel.cs b/PCK-Studio/Forms/Skins-And-Textures/generateModel.cs index 64e7dadb..9171edf1 100644 --- a/PCK-Studio/Forms/Skins-And-Textures/generateModel.cs +++ b/PCK-Studio/Forms/Skins-And-Textures/generateModel.cs @@ -141,7 +141,7 @@ namespace PckStudio.Forms } comboParent.Items.Clear(); comboParent.Items.AddRange(ValidModelBoxTypes); - LoadData(file.Properties); + LoadData(file); } private static readonly Regex sWhitespace = new Regex(@"\s+"); public static string ReplaceWhitespace(string input, string replacement) @@ -149,9 +149,9 @@ namespace PckStudio.Forms return sWhitespace.Replace(input, replacement); } - private void LoadData(PckFileProperties properties) + private void LoadData(PckFileData file) { - comboParent.Enabled = properties.GetProperties("BOX").All(kv => { + comboParent.Enabled = file.GetMultipleProperties("BOX").All(kv => { var box = SkinBOX.FromString(kv.Value); if (ValidModelBoxTypes.Contains(box.Type)) { @@ -160,7 +160,7 @@ namespace PckStudio.Forms } return false; }); - properties.GetProperties("OFFSET").All(kv => { + file.GetMultipleProperties("OFFSET").All(kv => { string[] offset = ReplaceWhitespace(kv.Value, ",").TrimEnd('\n', '\r', ' ').Split(','); if (offset.Length < 3) return false; @@ -176,7 +176,7 @@ namespace PckStudio.Forms return false; }); - _ANIM = properties.GetPropertyValue("ANIM", SkinANIM.FromString); + _ANIM = file.GetProperty("ANIM", SkinANIM.FromString); UpdateListView(); Rerender(); } @@ -1094,7 +1094,7 @@ namespace PckStudio.Forms { foreach (var part in modelBoxes) { - _file.Properties.Add("BOX", part); + _file.AddProperty("BOX", part); } //Bitmap bitmap2 = new Bitmap(64, 64); diff --git a/PCK-Studio/Forms/Utilities/pckCenterOpen.cs b/PCK-Studio/Forms/Utilities/pckCenterOpen.cs index 3bdc4fd7..4676107e 100644 --- a/PCK-Studio/Forms/Utilities/pckCenterOpen.cs +++ b/PCK-Studio/Forms/Utilities/pckCenterOpen.cs @@ -182,7 +182,7 @@ namespace PckStudio.Forms string capePath = ""; bool hasCape = false; - foreach (var entry in newSkin.Properties) + foreach (var entry in newSkin.GetProperties()) { if (entry.Key == "DISPLAYNAME") { @@ -264,7 +264,7 @@ namespace PckStudio.Forms if (skinPicture.Height == skinPicture.Width) { //determines skin type based on image dimensions, existence of BOX tags, and the ANIM value - foreach (var entry in newSkin.Properties) + foreach (var entry in newSkin.GetProperties()) { if (entry.Key == "BOX") { diff --git a/PCK-Studio/Helper/AnimationHelper.cs b/PCK-Studio/Helper/AnimationHelper.cs index a9714d15..0312624a 100644 --- a/PCK-Studio/Helper/AnimationHelper.cs +++ b/PCK-Studio/Helper/AnimationHelper.cs @@ -18,7 +18,7 @@ namespace PckStudio.Helper internal static void SaveAnimationToFile(PckFileData file, Animation animation) { string anim = animation.BuildAnim(); - file.Properties.SetProperty("ANIM", anim); + file.SetProperty("ANIM", anim); var texture = animation.BuildTexture(); file.SetData(texture, ImageFormat.Png); } @@ -30,7 +30,7 @@ namespace PckStudio.Helper { var texture = file.GetTexture(); var frameTextures = texture.Split(ImageLayoutDirection.Vertical); - var _animation = new Animation(frameTextures, file.Properties.GetPropertyValue("ANIM")); + var _animation = new Animation(frameTextures, file.GetProperty("ANIM")); _animation.Category = file.Filename.Split('/').Contains("items") ? AnimationCategory.Items : AnimationCategory.Blocks; diff --git a/PCK-Studio/MainForm.cs b/PCK-Studio/MainForm.cs index e3398be6..0912e5d5 100644 --- a/PCK-Studio/MainForm.cs +++ b/PCK-Studio/MainForm.cs @@ -203,7 +203,7 @@ namespace PckStudio { if (currentPCK.TryGetFile("0", PckFileType.InfoFile, out PckFileData file)) { - file.Properties.RemoveAll(t => t.Key.Equals("LOCK")); + file.RemoveProperties("LOCK"); } } @@ -428,7 +428,7 @@ namespace PckStudio public void HandleSkinFile(PckFileData file) { - if (file.Properties.HasProperty("BOX")) + if (file.HasProperty("BOX")) { using generateModel generate = new generateModel(file); if (generate.ShowDialog() == DialogResult.OK) @@ -441,7 +441,7 @@ namespace PckStudio } var img = file.GetTexture(); - using var skinViewer = new SkinPreview(img, file.Properties.GetPropertyValue("ANIM", SkinANIM.FromString)); + using var skinViewer = new SkinPreview(img, file.GetProperty("ANIM", SkinANIM.FromString)); skinViewer.ShowDialog(this); } @@ -472,13 +472,13 @@ namespace PckStudio if (e.Node.TryGetTagData(out PckFileData file)) { viewFileInfoToolStripMenuItem.Visible = true; - if (file.Properties.HasProperty("BOX")) + if (file.HasProperty("BOX")) { buttonEdit.Text = "EDIT BOXES"; buttonEdit.Visible = true; } - else if (file.Properties.HasProperty("ANIM") && - file.Properties.GetPropertyValue("ANIM", s => SkinANIM.FromString(s) == (SkinAnimMask.RESOLUTION_64x64 | SkinAnimMask.SLIM_MODEL))) + else if (file.HasProperty("ANIM") && + file.GetProperty("ANIM", s => SkinANIM.FromString(s) == (SkinAnimMask.RESOLUTION_64x64 | SkinAnimMask.SLIM_MODEL))) { buttonEdit.Text = "View Skin"; buttonEdit.Visible = true; @@ -554,10 +554,13 @@ namespace PckStudio private void extractFile(string outFilePath, PckFileData file) { File.WriteAllBytes(outFilePath, file.Data); - if (file.Properties.Count > 0) + if (file.PropertyCount > 0) { using var fs = File.CreateText($"{outFilePath}.txt"); - file.Properties.ForEach(property => fs.WriteLine($"{property.Key}: {property.Value}")); + foreach (var property in file.GetProperties()) + { + fs.WriteLine($"{property.Key}: {property.Value}"); + } } } @@ -723,10 +726,10 @@ namespace PckStudio { if (TryGetLocFile(out LOCFile locFile)) { - if (file.Properties.HasProperty("THEMENAMEID")) - locFile.RemoveLocKey(file.Properties.GetPropertyValue("THEMENAMEID")); - if (file.Properties.HasProperty("DISPLAYNAMEID")) - locFile.RemoveLocKey(file.Properties.GetPropertyValue("DISPLAYNAMEID")); + if (file.TryGetProperty("THEMENAMEID", out string value)) + locFile.RemoveLocKey(value); + if (file.TryGetProperty("DISPLAYNAMEID", out value)) + locFile.RemoveLocKey(value); TrySetLocFile(locFile); } } @@ -978,7 +981,8 @@ namespace PckStudio if (node.Tag is PckFileData node_file) { PckFileData new_file = newPCKFile.CreateNewFile(node_file.Filename.Replace(parent_file.Filename + "/", String.Empty), node_file.Filetype); - foreach (var prop in node_file.Properties) new_file.Properties.Add(prop); + foreach (var prop in node_file.GetProperties()) + new_file.AddProperty(prop); new_file.SetData(node_file.Data); } } @@ -1017,8 +1021,7 @@ namespace PckStudio if (treeMeta.SelectedNode is TreeNode subnode && subnode.Tag is KeyValuePair property && treeViewMain.SelectedNode is TreeNode node && node.Tag is PckFileData file) { - int i = file.Properties.IndexOf(property); - if (i != -1) + if (file.HasProperty(property.Key)) { switch (property.Key) { @@ -1028,7 +1031,7 @@ namespace PckStudio using ANIMEditor diag = new ANIMEditor(property.Value); if (diag.ShowDialog(this) == DialogResult.OK) { - file.Properties[i] = new KeyValuePair("ANIM", diag.ResultAnim.ToString()); + file.SetProperty(file.GetPropertyIndex(property), new KeyValuePair("ANIM", diag.ResultAnim.ToString())); RebuildSubPCK(treeViewMain.SelectedNode.FullPath); ReloadMetaTreeView(); wasModified = true; @@ -1049,7 +1052,7 @@ namespace PckStudio using BoxEditor diag = new BoxEditor(property.Value, IsSubPCKNode(treeViewMain.SelectedNode.FullPath)); if (diag.ShowDialog(this) == DialogResult.OK) { - file.Properties[i] = new KeyValuePair("BOX", diag.Result.ToString()); + file.SetProperty(file.GetPropertyIndex(property), new KeyValuePair("BOX", diag.Result.ToString())); RebuildSubPCK(treeViewMain.SelectedNode.FullPath); ReloadMetaTreeView(); wasModified = true; @@ -1073,7 +1076,7 @@ namespace PckStudio { if (addProperty.ShowDialog() == DialogResult.OK) { - file.Properties[i] = addProperty.Property; + file.SetProperty(file.GetPropertyIndex(property), addProperty.Property); RebuildSubPCK(treeViewMain.SelectedNode.FullPath); ReloadMetaTreeView(); wasModified = true; @@ -1100,7 +1103,10 @@ namespace PckStudio TreeNode newNode = new TreeNode(); newNode.Text = Path.GetFileName(diag.NewText); var newFile = new PckFileData(diag.NewText, file.Filetype); - file.Properties.ForEach(newFile.Properties.Add); + foreach (var property in file.GetProperties()) + { + newFile.AddProperty(property); + } newFile.SetData(file.Data); newFile.Filename = diag.NewText; newNode.Tag = newFile; @@ -1132,7 +1138,7 @@ namespace PckStudio { if (treeMeta.SelectedNode is TreeNode t && t.Tag is KeyValuePair property && treeViewMain.SelectedNode is TreeNode main && main.Tag is PckFileData file && - file.Properties.Remove(property)) + file.RemoveProperty(property)) { treeMeta.SelectedNode.Remove(); RebuildSubPCK(treeViewMain.SelectedNode.FullPath); @@ -1146,7 +1152,7 @@ namespace PckStudio if (treeViewMain.SelectedNode is TreeNode node && node.Tag is PckFileData file) { - foreach (var property in file.Properties) + foreach (var property in file.GetProperties()) { treeMeta.Nodes.Add(CreateNode(property.Key, property)); } @@ -1161,7 +1167,7 @@ namespace PckStudio using AddPropertyPrompt addProperty = new AddPropertyPrompt(); if (addProperty.ShowDialog() == DialogResult.OK) { - file.Properties.Add(addProperty.Property); + file.AddProperty(addProperty.Property); RebuildSubPCK(treeViewMain.SelectedNode.FullPath); ReloadMetaTreeView(); wasModified = true; @@ -1205,8 +1211,8 @@ namespace PckStudio var pack = new PckFile(3); var zeroFile = pack.CreateNewFile("0", PckFileType.InfoFile); - zeroFile.Properties.Add("PACKID", packId.ToString()); - zeroFile.Properties.Add("PACKVERSION", packVersion.ToString()); + zeroFile.AddProperty("PACKID", packId); + zeroFile.AddProperty("PACKVERSION", packVersion); var locFile = new LOCFile(); locFile.InitializeDefault(packName); @@ -1234,8 +1240,8 @@ namespace PckStudio var texturepackInfo = pack.CreateNewFile($"{res}/{res}Info.pck", PckFileType.TexturePackInfoFile); - texturepackInfo.Properties.Add("PACKID", "0"); - texturepackInfo.Properties.Add("DATAPATH", $"{res}Data.pck"); + texturepackInfo.AddProperty("PACKID", "0"); + texturepackInfo.AddProperty("DATAPATH", $"{res}Data.pck"); texturepackInfo.SetData(new PckFileWriter(infoPCK, LittleEndianCheckBox.Checked ? OMI.Endianness.LittleEndian : OMI.Endianness.BigEndian)); @@ -1390,7 +1396,7 @@ namespace PckStudio //attempts to generate reimportable metadata file out of minefiles metadata string metaData = ""; - foreach (var entry in file.Properties) + foreach (var entry in file.GetProperties()) { metaData += $"{entry.Key}: {entry.Value}{Environment.NewLine}"; } @@ -1468,7 +1474,7 @@ namespace PckStudio { string[] param = property.Split(':'); if (param.Length < 2) continue; - newFile.Properties.Add((param[0], param[1])); + newFile.AddProperty(param[0], param[1]); //switch (param[0]) //{ // case "DISPLAYNAMEID": @@ -1602,7 +1608,7 @@ namespace PckStudio { } - mfNew.Properties.Add(new KeyValuePair(key, value)); + mfNew.AddProperty(key, value); } wasModified = true; } @@ -1884,7 +1890,7 @@ namespace PckStudio "File path: " + file.Filename + "\nAssigned File type: " + (int)file.Filetype + " (" + file.Filetype + ")" + "\nFile size: " + file.Size + - "\nProperties count: " + file.Properties.Count + "\nProperties count: " + file.PropertyCount , Path.GetFileName(file.Filename) + " file info"); } } @@ -1995,7 +2001,7 @@ namespace PckStudio int idx = line.IndexOf(' '); if (idx == -1 || line.Length - 1 == idx) continue; - file.Properties.Add((line.Substring(0, idx), line.Substring(idx + 1))); + file.AddProperty(line.Substring(0, idx), line.Substring(idx + 1)); } ReloadMetaTreeView(); RebuildSubPCK(treeViewMain.SelectedNode.FullPath); @@ -2010,9 +2016,10 @@ namespace PckStudio if (treeViewMain.SelectedNode.TryGetTagData(out PckFileData file) && file.Filetype == PckFileType.SkinFile) { - foreach (var p in file.Properties.FindAll(s => s.Key == "BOX" || s.Key == "OFFSET")) + foreach (var p in file.GetProperties()) { - file.Properties[file.Properties.IndexOf(p)] = new KeyValuePair(p.Key, p.Value.Replace(',', '.')); + if (p.Key == "BOX" || p.Key == "OFFSET") + file.SetProperty(file.GetPropertyIndex(p), new KeyValuePair(p.Key, p.Value.Replace(',', '.'))); } ReloadMetaTreeView(); RebuildSubPCK(treeViewMain.SelectedNode.FullPath); @@ -2044,18 +2051,18 @@ namespace PckStudio { if (treeViewMain.SelectedNode.TryGetTagData(out PckFileData file)) { - var props = file.Properties.Select(p => p.Key + " " + p.Value); + var props = file.GetProperties().Select(p => p.Key + " " + p.Value); using (var input = new MultiTextPrompt(props.ToArray())) { if (input.ShowDialog(this) == DialogResult.OK) { - file.Properties.Clear(); + file.ClearProperties(); foreach (var line in input.TextOutput) { int idx = line.IndexOf(' '); if (idx == -1 || line.Length - 1 == idx) continue; - file.Properties.Add((line.Substring(0, idx).Replace(":", string.Empty), line.Substring(idx + 1))); + file.AddProperty(line.Substring(0, idx).Replace(":", string.Empty), line.Substring(idx + 1)); } ReloadMetaTreeView(); RebuildSubPCK(treeViewMain.SelectedNode.FullPath); @@ -2183,7 +2190,7 @@ namespace PckStudio using BoxEditor diag = new BoxEditor(SkinBOX.Empty, IsSubPCKNode(treeViewMain.SelectedNode.FullPath)); if (diag.ShowDialog(this) == DialogResult.OK) { - file.Properties.Add("BOX", diag.Result); + file.AddProperty("BOX", diag.Result); RebuildSubPCK(treeViewMain.SelectedNode.FullPath); ReloadMetaTreeView(); wasModified = true; @@ -2199,7 +2206,7 @@ namespace PckStudio using ANIMEditor diag = new ANIMEditor(SkinANIM.Empty); if (diag.ShowDialog(this) == DialogResult.OK) { - file.Properties.Add("ANIM", diag.ResultAnim); + file.AddProperty("ANIM", diag.ResultAnim); RebuildSubPCK(treeViewMain.SelectedNode.FullPath); ReloadMetaTreeView(); wasModified = true; diff --git a/PCK-Studio/PckStudio.csproj b/PCK-Studio/PckStudio.csproj index 3013435f..2d1966d1 100644 --- a/PCK-Studio/PckStudio.csproj +++ b/PCK-Studio/PckStudio.csproj @@ -133,6 +133,7 @@ + diff --git a/Vendor/OMI-Lib b/Vendor/OMI-Lib index 036d680f..bf46386e 160000 --- a/Vendor/OMI-Lib +++ b/Vendor/OMI-Lib @@ -1 +1 @@ -Subproject commit 036d680f977f1db2e2ec7ab8fc5813b990278aed +Subproject commit bf46386e771fd573a625dfb124695ee4d8deeba5