Updated property access in OMI

This commit is contained in:
miku-666
2023-05-19 18:05:09 +02:00
parent 5257b9d0b5
commit 3e46529d71
8 changed files with 63 additions and 63 deletions
+1 -1
View File
@@ -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;
}
@@ -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");
@@ -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)
{
@@ -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);
+14 -14
View File
@@ -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";
}
+4 -2
View File
@@ -65,12 +65,14 @@ namespace PckStudio.Internal
public ValueTuple<string, string> ToProperty()
{
return new ValueTuple<string, string>("BOX", ToString().Replace(',', '.'));
return new ValueTuple<string, string>("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)
+26 -27
View File
@@ -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<string, string> property)
if (e.Node is TreeNode t && t.Tag is KeyValuePair<string, string> 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<string, string> property &&
if (treeMeta.SelectedNode is TreeNode subnode && subnode.Tag is KeyValuePair<string, string> 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<string, string>("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<string, string>("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<string, string>(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<string, string>)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<string, string> property &&
if (treeMeta.SelectedNode is TreeNode t && t.Tag is KeyValuePair<string, string> 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<string, string>(key, value));
mfNew.Properties.Add(new KeyValuePair<string, string>(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<string, string>(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)
+1 -1