From 3e46529d71eea4b247713972bcd670d0f5fee0ef Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Fri, 19 May 2023 18:05:09 +0200 Subject: [PATCH] Updated property access in OMI --- PCK-Studio/Features/WiiUPanel.cs | 2 +- .../Skins-And-Textures/AdvancedOptions.cs | 8 +-- .../Forms/Skins-And-Textures/addnewskin.cs | 19 ++++--- .../Forms/Skins-And-Textures/generateModel.cs | 8 +-- PCK-Studio/Forms/Utilities/pckCenterOpen.cs | 28 +++++----- PCK-Studio/Internals/SkinBOX.cs | 6 ++- PCK-Studio/MainForm.cs | 53 +++++++++---------- Vendor/OMI-Lib | 2 +- 8 files changed, 63 insertions(+), 63 deletions(-) diff --git a/PCK-Studio/Features/WiiUPanel.cs b/PCK-Studio/Features/WiiUPanel.cs index e1f3aab4..d81bae23 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", PckFile.FileData.FileType.InfoFile, out var file) - ? file.Properties.GetProperty("PACKID").Item2 + ? file.Properties.GetPropertyValue("PACKID") : string.Empty; } diff --git a/PCK-Studio/Forms/Skins-And-Textures/AdvancedOptions.cs b/PCK-Studio/Forms/Skins-And-Textures/AdvancedOptions.cs index 6af62511..c34dfba0 100644 --- a/PCK-Studio/Forms/Skins-And-Textures/AdvancedOptions.cs +++ b/PCK-Studio/Forms/Skins-And-Textures/AdvancedOptions.cs @@ -28,7 +28,7 @@ namespace PckStudio { foreach (PckFile.FileData file in currentPCK.Files) { - file.Properties.Add((entryTypeTextBox.Text, entryDataTextBox.Text)); + file.Properties.Add(entryTypeTextBox.Text, entryDataTextBox.Text); } MessageBox.Show("Data Added to All Entries"); } @@ -41,7 +41,7 @@ namespace PckStudio if (Path.GetExtension(file.Filename) == ".png" && Image.FromStream(png).Size.Height == Image.FromStream(png).Size.Width) { - file.Properties.Add((entryTypeTextBox.Text, entryDataTextBox.Text)); + file.Properties.Add(entryTypeTextBox.Text, entryDataTextBox.Text); } } MessageBox.Show("Data Added to 64x64 Image Entries"); @@ -55,7 +55,7 @@ namespace PckStudio if (Path.GetExtension(file.Filename) == ".png" && Image.FromStream(png).Size.Height == Image.FromStream(png).Size.Width / 2) { - file.Properties.Add((entryTypeTextBox.Text, entryDataTextBox.Text)); + file.Properties.Add(entryTypeTextBox.Text, entryDataTextBox.Text); } } MessageBox.Show("Data Added to 64x32 Image Entries"); @@ -68,7 +68,7 @@ namespace PckStudio MemoryStream png = new MemoryStream(file.Data); if (Path.GetExtension(file.Filename) == ".png") { - file.Properties.Add((entryTypeTextBox.Text, entryDataTextBox.Text)); + file.Properties.Add(entryTypeTextBox.Text, entryDataTextBox.Text); } } MessageBox.Show("Data Added to All PNG Image Entries"); diff --git a/PCK-Studio/Forms/Skins-And-Textures/addnewskin.cs b/PCK-Studio/Forms/Skins-And-Textures/addnewskin.cs index f4a8a77d..b579ed21 100644 --- a/PCK-Studio/Forms/Skins-And-Textures/addnewskin.cs +++ b/PCK-Studio/Forms/Skins-And-Textures/addnewskin.cs @@ -216,8 +216,7 @@ namespace PckStudio private void CreateButton_Click(object sender, EventArgs e) { - int _skinId = -1; - if (!int.TryParse(textSkinID.Text, out _skinId)) + if (!int.TryParse(textSkinID.Text, out int _skinId)) { MessageBox.Show("The Skin ID Must be a Unique 8 Digit Number Thats Not Already in Use", "Invalid Skin ID", MessageBoxButtons.OK, MessageBoxIcon.Error); return; @@ -226,24 +225,24 @@ namespace PckStudio skin.Filename = $"dlcskin{skinId}.png"; string skinDisplayNameLocKey = $"IDS_dlcskin{skinId}_DISPLAYNAME"; currentLoc.AddLocKey(skinDisplayNameLocKey, textSkinName.Text); - skin.Properties.Add(("DISPLAYNAME", textSkinName.Text)); - skin.Properties.Add(("DISPLAYNAMEID", skinDisplayNameLocKey)); + skin.Properties.Add("DISPLAYNAME", textSkinName.Text); + skin.Properties.Add("DISPLAYNAMEID", skinDisplayNameLocKey); if (!string.IsNullOrEmpty(textThemeName.Text)) { - skin.Properties.Add(("THEMENAME", textThemeName.Text)); - skin.Properties.Add(("THEMENAMEID", $"IDS_dlcskin{skinId}_THEMENAME")); + skin.Properties.Add("THEMENAME", textThemeName.Text); + skin.Properties.Add("THEMENAMEID", $"IDS_dlcskin{skinId}_THEMENAME"); currentLoc.AddLocKey($"IDS_dlcskin{skinId}_THEMENAME", textThemeName.Text); } - skin.Properties.Add(("ANIM", anim.ToString())); - skin.Properties.Add(("GAME_FLAGS", "0x18")); - skin.Properties.Add(("FREE", "1")); + skin.Properties.Add("ANIM", anim); + skin.Properties.Add("GAME_FLAGS", "0x18"); + skin.Properties.Add("FREE", "1"); if (HasCape) { try { cape.Filename = $"dlccape{skinId}.png"; - skin.Properties.Add(("CAPEPATH", cape.Filename)); + skin.Properties.Add("CAPEPATH", cape.Filename); } catch (Exception) { diff --git a/PCK-Studio/Forms/Skins-And-Textures/generateModel.cs b/PCK-Studio/Forms/Skins-And-Textures/generateModel.cs index f22558d2..60b0154f 100644 --- a/PCK-Studio/Forms/Skins-And-Textures/generateModel.cs +++ b/PCK-Studio/Forms/Skins-And-Textures/generateModel.cs @@ -133,11 +133,11 @@ namespace PckStudio { foreach (var property in boxes) { - switch (property.Item1) + switch (property.Key) { case "BOX": { - var box = SkinBOX.FromString(property.Item2); + var box = SkinBOX.FromString(property.Value); string name = box.Type; if (ValidModelBoxTypes.Contains(name)) @@ -151,7 +151,7 @@ namespace PckStudio case "OFFSET": { - string[] offset = ReplaceWhitespace(property.Item2, ",").TrimEnd('\n', '\r', ' ').Split(','); + string[] offset = ReplaceWhitespace(property.Value, ",").TrimEnd('\n', '\r', ' ').Split(','); if (offset.Length < 3) continue; string name = offset[0]; string dimension = offset[1]; // "Y" @@ -1099,7 +1099,7 @@ namespace PckStudio Bitmap bitmap1 = new Bitmap(displayBox.Width, displayBox.Height); foreach (var part in modelBoxes) { - boxes.Add(part.ToProperty()); + boxes.Add("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 66967f39..16202fe5 100644 --- a/PCK-Studio/Forms/Utilities/pckCenterOpen.cs +++ b/PCK-Studio/Forms/Utilities/pckCenterOpen.cs @@ -187,15 +187,15 @@ namespace PckStudio.Forms foreach (var entry in newSkin.Properties) { - if (entry.Item1 == "DISPLAYNAME") + if (entry.Key == "DISPLAYNAME") { - skinName = entry.Item2; - skinDisplayNames.Add(new Item() { Id = newSkin.Filename.Remove(15, 4), Name = entry.Item2 }); + skinName = entry.Key; + skinDisplayNames.Add(new Item() { Id = newSkin.Filename.Remove(15, 4), Name = entry.Value }); } - if (entry.Item1 == "CAPEPATH") + if (entry.Key == "CAPEPATH") { hasCape = true; - capePath = entry.Item2; + capePath = entry.Value; } } @@ -269,11 +269,11 @@ namespace PckStudio.Forms //determines skin type based on image dimensions, existence of BOX tags, and the ANIM value foreach (var entry in newSkin.Properties) { - if (entry.Item1.ToString() == "BOX") + if (entry.Key == "BOX") { string mClass = ""; string mData = ""; - foreach (char dCheck in entry.Item2) + foreach (char dCheck in entry.Key) { if (dCheck.ToString() != " ") { @@ -281,7 +281,7 @@ namespace PckStudio.Forms } else { - mData = entry.Item2.Remove(0, mClass.Count() + 1); + mData = entry.Value.Remove(0, mClass.Count() + 1); break; } } @@ -318,13 +318,13 @@ namespace PckStudio.Forms } } - if (entry.Item1 == "OFFSET") + if (entry.Key == "OFFSET") { string oClass = ""; string oData = ""; - foreach (char oCheck in entry.Item2) + foreach (char oCheck in entry.Value) { - oData = entry.Item2; + oData = entry.Value; if (oCheck.ToString() != " ") { oClass += oCheck.ToString(); @@ -353,13 +353,13 @@ namespace PckStudio.Forms } } - if (entry.Item1 == "ANIM") + if (entry.Key == "ANIM") { - if (entry.Item2 == "0x40000") + if (entry.Value == "0x40000") { } - else if (entry.Item2 == "0x80000") + else if (entry.Value == "0x80000") { skinType = "alex"; } diff --git a/PCK-Studio/Internals/SkinBOX.cs b/PCK-Studio/Internals/SkinBOX.cs index 764444e7..a934f823 100644 --- a/PCK-Studio/Internals/SkinBOX.cs +++ b/PCK-Studio/Internals/SkinBOX.cs @@ -65,12 +65,14 @@ namespace PckStudio.Internal public ValueTuple ToProperty() { - return new ValueTuple("BOX", ToString().Replace(',', '.')); + return new ValueTuple("BOX", ToString()); } public override string ToString() { - return $"{Type} {Pos.X} {Pos.Y} {Pos.Z} {Size.X} {Size.Y} {Size.Z} {UV.X} {UV.Y} {Convert.ToInt32(HideWithArmor)} {Convert.ToInt32(Mirror)} {Scale}"; + return + $"{Type} {Pos.X} {Pos.Y} {Pos.Z} {Size.X} {Size.Y} {Size.Z} {UV.X} {UV.Y} {Convert.ToInt32(HideWithArmor)} {Convert.ToInt32(Mirror)} {Scale}" + .Replace(',', '.'); } private static Vector2 TryGetVector2(string[] arguments, int startIndex) diff --git a/PCK-Studio/MainForm.cs b/PCK-Studio/MainForm.cs index 1795db73..7a2cc9d3 100644 --- a/PCK-Studio/MainForm.cs +++ b/PCK-Studio/MainForm.cs @@ -193,7 +193,7 @@ namespace PckStudio { if (currentPCK.TryGetFile("0", PckFile.FileData.FileType.InfoFile, out PckFile.FileData file)) { - file.Properties.RemoveAll(t => t.property.Equals("LOCK")); + file.Properties.RemoveAll(t => t.Key.Equals("LOCK")); } } @@ -574,7 +574,7 @@ namespace PckStudio if (file.Properties.Count > 0) { using var fs = File.CreateText($"{extractFilePath}.txt"); - file.Properties.ForEach(property => fs.WriteLine($"{property.Item1}: {property.Item2}")); + file.Properties.ForEach(property => fs.WriteLine($"{property.Key}: {property.Value}")); } // Verification that file extraction path was successful MessageBox.Show("File Extracted"); @@ -598,7 +598,7 @@ namespace PckStudio if (file.Properties.Count > 0) { using var fs = File.CreateText($"{dialog.SelectedPath}/{file.Filename}.txt"); - file.Properties.ForEach(property => fs.WriteLine($"{property.Item1}: {property.Item2}")); + file.Properties.ForEach(property => fs.WriteLine($"{property.Key}: {property.Value}")); } } } @@ -615,7 +615,7 @@ namespace PckStudio if (file.Properties.Count > 0) { using var fs = File.CreateText($"{dialog.SelectedPath}/{file.Filename}.txt"); - file.Properties.ForEach(property => fs.WriteLine($"{property.Item1}: {property.Item2}")); + file.Properties.ForEach(property => fs.WriteLine($"{property.Key} : {property.Value}")); } } }); @@ -709,8 +709,8 @@ namespace PckStudio { foreach (var property in file.Properties) { - if (property.Item1 == "THEMENAMEID" || property.Item1 == "DISPLAYNAMEID") - locFile.RemoveLocKey(property.Item2); + if (property.Key == "THEMENAMEID" || property.Key == "DISPLAYNAMEID") + locFile.RemoveLocKey(property.Value); } TrySetLocFile(locFile); } @@ -972,30 +972,30 @@ namespace PckStudio private void treeMeta_AfterSelect(object sender, TreeViewEventArgs e) { - if (e.Node is TreeNode t && t.Tag is ValueTuple property) + if (e.Node is TreeNode t && t.Tag is KeyValuePair property) { - entryTypeTextBox.Text = property.Item1; - entryDataTextBox.Text = property.Item2; + entryTypeTextBox.Text = property.Key; + entryDataTextBox.Text = property.Value; } } private void treeMeta_DoubleClick(object sender, EventArgs e) { - if (treeMeta.SelectedNode is TreeNode subnode && subnode.Tag is ValueTuple property && + if (treeMeta.SelectedNode is TreeNode subnode && subnode.Tag is KeyValuePair property && treeViewMain.SelectedNode is TreeNode node && node.Tag is PckFile.FileData file) { int i = file.Properties.IndexOf(property); if (i != -1) { - switch (property.Item1) + switch (property.Key) { case "ANIM" when file.Filetype == PckFile.FileData.FileType.SkinFile: try { - using ANIMEditor diag = new ANIMEditor(property.Item2); + using ANIMEditor diag = new ANIMEditor(property.Value); if (diag.ShowDialog(this) == DialogResult.OK) { - file.Properties[i] = ("ANIM", diag.ResultAnim.ToString()); + file.Properties[i] = new KeyValuePair("ANIM", diag.ResultAnim.ToString()); if (IsSubPCKNode(treeViewMain.SelectedNode.FullPath)) RebuildSubPCK(treeViewMain.SelectedNode); ReloadMetaTreeView(); @@ -1013,10 +1013,10 @@ namespace PckStudio case "BOX" when file.Filetype == PckFile.FileData.FileType.SkinFile: try { - using BoxEditor diag = new BoxEditor(property.Item2, IsSubPCKNode(treeViewMain.SelectedNode.FullPath)); + using BoxEditor diag = new BoxEditor(property.Value, IsSubPCKNode(treeViewMain.SelectedNode.FullPath)); if (diag.ShowDialog(this) == DialogResult.OK) { - file.Properties[i] = ("BOX", diag.Result); + file.Properties[i] = new KeyValuePair("BOX", diag.Result.ToString()); if (IsSubPCKNode(treeViewMain.SelectedNode.FullPath)) RebuildSubPCK(treeViewMain.SelectedNode); ReloadMetaTreeView(); @@ -1036,11 +1036,11 @@ namespace PckStudio } - using (addMeta addDialog = new addMeta(property.Item1, property.Item2)) + using (AddPropertyPrompt addDialog = new AddPropertyPrompt(property.Key, property.Value)) { if (addDialog.ShowDialog() == DialogResult.OK) { - file.Properties[i] = (addDialog.PropertyName, addDialog.PropertyValue); + file.Properties[i] = new KeyValuePair(addDialog.PropertyName, addDialog.PropertyValue); if (IsSubPCKNode(treeViewMain.SelectedNode.FullPath)) RebuildSubPCK(treeViewMain.SelectedNode); ReloadMetaTreeView(); @@ -1077,8 +1077,7 @@ namespace PckStudio mf.Filename = dirName + (string.IsNullOrEmpty(dirName) ? "" : "/") + newFileName; //sets minfile name to file name foreach (var entry in mfO.Properties) { - var property = (ValueTuple)entry; - mf.Properties.Add(property); + mf.Properties.Add(entry); } TreeNode newNode = new TreeNode(); @@ -1096,7 +1095,7 @@ namespace PckStudio private void deleteEntryToolStripMenuItem_Click(object sender, EventArgs e) { - if (treeMeta.SelectedNode is TreeNode t && t.Tag is ValueTuple property && + if (treeMeta.SelectedNode is TreeNode t && t.Tag is KeyValuePair property && treeViewMain.SelectedNode is TreeNode main && main.Tag is PckFile.FileData file && file.Properties.Remove(property)) { @@ -1114,7 +1113,7 @@ namespace PckStudio { foreach (var property in file.Properties) { - treeMeta.Nodes.Add(CreateNode(property.Item1, property)); + treeMeta.Nodes.Add(CreateNode(property.Key, property)); } } } @@ -1124,7 +1123,7 @@ namespace PckStudio if (treeViewMain.SelectedNode is TreeNode t && t.Tag is PckFile.FileData file) { - using addMeta add = new addMeta(); + using AddPropertyPrompt add = new AddPropertyPrompt(); if (add.ShowDialog() == DialogResult.OK) { file.Properties.Add((add.PropertyName, add.PropertyValue)); @@ -1407,7 +1406,7 @@ namespace PckStudio foreach (var entry in file.Properties) { - metaData += $"{entry.Item1}: {entry.Item2}{Environment.NewLine}"; + metaData += $"{entry.Key}: {entry.Value}{Environment.NewLine}"; } File.WriteAllText(sfd.SelectedPath + @"\" + file.Filename + ".txt", metaData); @@ -1621,7 +1620,7 @@ namespace PckStudio { } - mfNew.Properties.Add(new ValueTuple(key, value)); + mfNew.Properties.Add(new KeyValuePair(key, value)); } wasModified = true; } @@ -2052,9 +2051,9 @@ namespace PckStudio { if (treeViewMain.SelectedNode is TreeNode node && node.Tag is PckFile.FileData file && file.Filetype == PckFile.FileData.FileType.SkinFile) { - foreach(var p in file.Properties.FindAll(s => s.property == "BOX" || s.property == "OFFSET")) + foreach(var p in file.Properties.FindAll(s => s.Key == "BOX" || s.Key == "OFFSET")) { - file.Properties[file.Properties.IndexOf(p)] = (p.property, p.value.Replace(',','.')); + file.Properties[file.Properties.IndexOf(p)] = new KeyValuePair(p.Key, p.Value.Replace(',','.')); } ReloadMetaTreeView(); if (IsSubPCKNode(node.FullPath)) RebuildSubPCK(node); @@ -2123,7 +2122,7 @@ namespace PckStudio if (treeViewMain.SelectedNode is TreeNode node && node.Tag is PckFile.FileData file) { - var props = file.Properties.Select(l => l.property + " " + l.value); + var props = file.Properties.Select(p => p.Key + " " + p.Value); using (var input = new TextPrompt(props.ToArray())) { if (input.ShowDialog(this) == DialogResult.OK) diff --git a/Vendor/OMI-Lib b/Vendor/OMI-Lib index a168e876..7b1ac2d6 160000 --- a/Vendor/OMI-Lib +++ b/Vendor/OMI-Lib @@ -1 +1 @@ -Subproject commit a168e876825ae2cbb8bbf55b76aa2852af233576 +Subproject commit 7b1ac2d6c69964afc51034c940bc0d2dbbebad6d