From b1589811080c8916f8a4d0c5dc4bb1a91c0590b9 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Wed, 3 May 2023 16:07:19 +0200 Subject: [PATCH] Added 'Internals' folder to project and moved SkinANIM, SkinBox, CommitInfo and ProgramInfo(ApplicationBuildInfo now) into 'Internals' --- .../Models/DefaultModels/Steve64x64Model.cs | 6 +- PCK-Studio/Classes/Models/SkinBox.cs | 64 --------- PCK-Studio/Forms/Editor/ANIMEditor.cs | 2 +- PCK-Studio/Forms/Editor/BoxEditor.cs | 8 +- .../Forms/Skins-And-Textures/SkinPreview.cs | 2 +- .../Forms/Skins-And-Textures/addnewskin.cs | 2 +- .../Forms/Skins-And-Textures/generateModel.cs | 130 ++++++++---------- PCK-Studio/Internals/ApplicationBuildInfo.cs | 47 +++++++ PCK-Studio/Internals/CommitInfo.cs | 50 +++++++ .../{Classes/Utils => Internals}/SkinANIM.cs | 2 +- PCK-Studio/Internals/SkinBOX.cs | 90 ++++++++++++ PCK-Studio/MainForm.cs | 3 +- PCK-Studio/PckStudio.csproj | 6 +- PCK-Studio/Program.cs | 55 -------- 14 files changed, 263 insertions(+), 204 deletions(-) delete mode 100644 PCK-Studio/Classes/Models/SkinBox.cs create mode 100644 PCK-Studio/Internals/ApplicationBuildInfo.cs create mode 100644 PCK-Studio/Internals/CommitInfo.cs rename PCK-Studio/{Classes/Utils => Internals}/SkinANIM.cs (99%) create mode 100644 PCK-Studio/Internals/SkinBOX.cs diff --git a/PCK-Studio/Classes/Models/DefaultModels/Steve64x64Model.cs b/PCK-Studio/Classes/Models/DefaultModels/Steve64x64Model.cs index 481f5877..34bd557e 100644 --- a/PCK-Studio/Classes/Models/DefaultModels/Steve64x64Model.cs +++ b/PCK-Studio/Classes/Models/DefaultModels/Steve64x64Model.cs @@ -1,12 +1,12 @@ -using PckStudio.Classes.Utils; -using PckStudio.Models; -using System; +using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Security.Policy; using System.Text; using System.Threading.Tasks; +using PckStudio.Internal; +using PckStudio.Models; namespace PckStudio.Classes.Models.DefaultModels { diff --git a/PCK-Studio/Classes/Models/SkinBox.cs b/PCK-Studio/Classes/Models/SkinBox.cs deleted file mode 100644 index e27587cd..00000000 --- a/PCK-Studio/Classes/Models/SkinBox.cs +++ /dev/null @@ -1,64 +0,0 @@ -using System; -using System.Numerics; -using System.Text.RegularExpressions; -using System.Windows.Forms; - -namespace PckStudio.Classes.Models -{ - public class SkinBox - { - public string Type; - public Vector3 Pos; - public Vector3 Size; - public float U, V; - public bool HideWithArmor; - public bool Mirror; - public float Scale; - public SkinBox(string input) - { - try - { - string[] arguments = Regex.Split(input, @"\s+"); // split by whitespace - - int old_length = arguments.Length - 1; - - Array.Resize(ref arguments, 12); - - for (int x = 11; x > old_length; x--) - { - arguments[x] = "0"; // set any missing arguments to '0' - } - - Type = arguments[0].ToUpper(); // just in case a box has all lower, the editor still parses correctly - - Pos = new Vector3(float.Parse(arguments[1]), float.Parse(arguments[2]), float.Parse(arguments[3])); - Size = new Vector3(float.Parse(arguments[4]), float.Parse(arguments[5]), float.Parse(arguments[6])); - U = float.Parse(arguments[7]); - V = float.Parse(arguments[8]); - HideWithArmor = Convert.ToBoolean(int.Parse(arguments[9])); - Mirror = Convert.ToBoolean(int.Parse(arguments[10])); - Scale = float.Parse(arguments[11]); - } - catch (FormatException fex) - { - MessageBox.Show($"A Format Exception was thrown\nFailed to parse BOX value\n{fex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - catch (IndexOutOfRangeException iex) // this should be MUCH more rare now - { - MessageBox.Show($"A box paramater was out of range\nFailed to parse BOX value\n{iex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - catch (Exception ex) - { - Type = string.Empty; - } - } - - public ValueTuple ToProperty() - { - string value = $"{Type} {Pos.X} {Pos.Y} {Pos.Z} {Size.X} {Size.Y} {Size.Z} {U} {V} {Convert.ToInt32(HideWithArmor)} {Convert.ToInt32(Mirror)} {Scale}"; - return new ValueTuple("BOX", value.Replace(',', '.')); - } - } -} diff --git a/PCK-Studio/Forms/Editor/ANIMEditor.cs b/PCK-Studio/Forms/Editor/ANIMEditor.cs index d13f2863..643cbf9b 100644 --- a/PCK-Studio/Forms/Editor/ANIMEditor.cs +++ b/PCK-Studio/Forms/Editor/ANIMEditor.cs @@ -5,7 +5,7 @@ using System.Diagnostics; using System.Windows.Forms; using System.Collections.Generic; -using PckStudio.Classes.Utils; +using PckStudio.Internal; using PckStudio.Forms.Additional_Popups; namespace PckStudio.Forms.Editor diff --git a/PCK-Studio/Forms/Editor/BoxEditor.cs b/PCK-Studio/Forms/Editor/BoxEditor.cs index 771f3bc6..ac1bbfef 100644 --- a/PCK-Studio/Forms/Editor/BoxEditor.cs +++ b/PCK-Studio/Forms/Editor/BoxEditor.cs @@ -1,6 +1,6 @@ using System; using System.Windows.Forms; -using PckStudio.Classes.Models; +using PckStudio.Internal; namespace PckStudio.Forms.Editor { @@ -14,7 +14,7 @@ namespace PckStudio.Forms.Editor inflationUpDown.Enabled = hasInflation; - SkinBox box = new SkinBox(inBOX); + var box = SkinBOX.FromString(inBOX); if (string.IsNullOrEmpty(box.Type) || !parentComboBox.Items.Contains(box.Type)) { @@ -28,8 +28,8 @@ namespace PckStudio.Forms.Editor SizeXUpDown.Value = (decimal)box.Size.X; SizeYUpDown.Value = (decimal)box.Size.Y; SizeZUpDown.Value = (decimal)box.Size.Z; - uvXUpDown.Value = (decimal)box.U; - uvYUpDown.Value = (decimal)box.V; + uvXUpDown.Value = (decimal)box.UV.X; + uvYUpDown.Value = (decimal)box.UV.Y; armorCheckBox.Checked = box.HideWithArmor; mirrorCheckBox.Checked = box.Mirror; inflationUpDown.Value = (decimal)box.Scale; diff --git a/PCK-Studio/Forms/Skins-And-Textures/SkinPreview.cs b/PCK-Studio/Forms/Skins-And-Textures/SkinPreview.cs index d24c9df4..e3ce8ed0 100644 --- a/PCK-Studio/Forms/Skins-And-Textures/SkinPreview.cs +++ b/PCK-Studio/Forms/Skins-And-Textures/SkinPreview.cs @@ -2,7 +2,7 @@ using System.Drawing; using System.Windows.Forms; using PckStudio.Classes.Models.DefaultModels; -using PckStudio.Classes.Utils; +using PckStudio.Internal; using PckStudio.Models; namespace PckStudio.Forms diff --git a/PCK-Studio/Forms/Skins-And-Textures/addnewskin.cs b/PCK-Studio/Forms/Skins-And-Textures/addnewskin.cs index b45db1c7..f4a8a77d 100644 --- a/PCK-Studio/Forms/Skins-And-Textures/addnewskin.cs +++ b/PCK-Studio/Forms/Skins-And-Textures/addnewskin.cs @@ -4,9 +4,9 @@ using System.IO; using System.Windows.Forms; using System.Drawing.Drawing2D; using System.Drawing.Imaging; -using PckStudio.Classes.Utils; using OMI.Formats.Languages; using OMI.Formats.Pck; +using PckStudio.Internal; using PckStudio.Forms.Editor; using PckStudio.Classes.IO._3DST; diff --git a/PCK-Studio/Forms/Skins-And-Textures/generateModel.cs b/PCK-Studio/Forms/Skins-And-Textures/generateModel.cs index f5ea6374..b49a4938 100644 --- a/PCK-Studio/Forms/Skins-And-Textures/generateModel.cs +++ b/PCK-Studio/Forms/Skins-And-Textures/generateModel.cs @@ -4,15 +4,15 @@ using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Linq; -using System.Numerics; using System.Windows.Forms; using System.Collections; using System.IO; +using System.Text.RegularExpressions; + using Newtonsoft.Json; using MetroFramework.Forms; -using PckStudio.Classes.Models; -using System.Text.RegularExpressions; using OMI.Formats.Pck; +using PckStudio.Internal; namespace PckStudio { @@ -93,7 +93,7 @@ namespace PckStudio "TOOL1", }; - List modelBoxes = new List(); + List modelBoxes = new List(); List modelOffsets = new List(); class ModelOffset @@ -137,7 +137,7 @@ namespace PckStudio { case "BOX": { - SkinBox box = new SkinBox(property.Item2); + var box = SkinBOX.FromString(property.Item2); string name = box.Type; if (ValidModelBoxTypes.Contains(name)) @@ -208,8 +208,8 @@ namespace PckStudio // Chooses Render settings based on current direction foreach (ListViewItem listViewItem in listViewBoxes.Items) { - if (!(listViewItem.Tag is SkinBox)) continue; - SkinBox part = listViewItem.Tag as SkinBox; + if (!(listViewItem.Tag is SkinBOX part)) + continue; float x = displayBox.Width / 2; float y = 0; @@ -287,8 +287,8 @@ namespace PckStudio part.Size.X * 5, part.Size.Y * 5); RectangleF srcRect = new RectangleF( - (part.U + part.Size.Z) * gfx_scale, - (part.V + part.Size.Z) * gfx_scale, + (part.UV.X + part.Size.Z) * gfx_scale, + (part.UV.Y + part.Size.Z) * gfx_scale, part.Size.X * gfx_scale, part.Size.Y * gfx_scale); graphics.DrawImage(texturePreview.Image, destRect, srcRect, GraphicsUnit.Pixel); @@ -360,8 +360,8 @@ namespace PckStudio part.Size.Z * 5, part.Size.Y * 5); RectangleF srcRect = new RectangleF( - (part.U + part.Size.Z + part.Size.X) * gfx_scale, - (part.V + part.Size.Z) * gfx_scale, + (part.UV.X + part.Size.Z + part.Size.X) * gfx_scale, + (part.UV.Y + part.Size.Z) * gfx_scale, part.Size.Z * gfx_scale, part.Size.Y * gfx_scale); graphics.DrawImage(texturePreview.Image, destRect, srcRect, GraphicsUnit.Pixel); @@ -438,8 +438,8 @@ namespace PckStudio part.Size.X * 5, part.Size.Y * 5); RectangleF srcRect = new RectangleF( - (part.U + part.Size.Z * 2 + part.Size.X) * gfx_scale, - (part.V + part.Size.Z) * gfx_scale, + (part.UV.X + part.Size.Z * 2 + part.Size.X) * gfx_scale, + (part.UV.Y + part.Size.Z) * gfx_scale, part.Size.X * gfx_scale, part.Size.Y * gfx_scale); graphics.DrawImage(texturePreview.Image, destRect, srcRect, GraphicsUnit.Pixel); @@ -510,8 +510,8 @@ namespace PckStudio part.Size.Z * 5, part.Size.Y * 5); RectangleF srcRect = new RectangleF( - (part.U + part.Size.Z + part.Size.X) * gfx_scale, - (part.V + part.Size.Z) * gfx_scale, + (part.UV.X + part.Size.Z + part.Size.X) * gfx_scale, + (part.UV.Y + part.Size.Z) * gfx_scale, part.Size.Z * gfx_scale, part.Size.Y * gfx_scale); graphics.DrawImage(texturePreview.Image, destRect, srcRect, GraphicsUnit.Pixel); @@ -546,8 +546,8 @@ namespace PckStudio float width = part.Size.X * 2; float height = part.Size.Y * 2; float length = part.Size.Z * 2; - float u = part.U * 2; - float v = part.V * 2; + float u = part.UV.X * 2; + float v = part.UV.Y * 2; Random r = new Random(); Brush brush = new SolidBrush(Color.FromArgb(r.Next(int.MinValue, int.MaxValue))); graphics.FillRectangle(brush, u + length, v, width, length); @@ -873,7 +873,7 @@ namespace PckStudio //Creates Item private void createToolStripMenuItem_Click(object sender, EventArgs e) { - modelBoxes.Add(new SkinBox("NEW_BOX 0 0 0 1 1 1 0 0 0 0 0")); + modelBoxes.Add(SkinBOX.FromString("NEW_BOX 0 0 0 1 1 1 0 0 0 0 0")); updateListView(); render(); } @@ -883,10 +883,10 @@ namespace PckStudio private void listView1_SelectedIndexChanged(object sender, EventArgs e) { changeColorToolStripMenuItem.Visible = false; - if (listViewBoxes.SelectedItems.Count != 0 && listViewBoxes.SelectedItems[0].Tag is SkinBox) + if (listViewBoxes.SelectedItems.Count != 0 && listViewBoxes.SelectedItems[0].Tag is SkinBOX) { changeColorToolStripMenuItem.Visible = true; - var part = listViewBoxes.SelectedItems[0].Tag as SkinBox; + var part = listViewBoxes.SelectedItems[0].Tag as SkinBOX; //graphics.DrawRectangle(Pens.Yellow, x + (float)double.Parse(this.selected.SubItems[3].Text) * 5 - 1, y + (float)double.Parse(this.selected.SubItems[2].Text) * 5 - 1, (float)double.Parse(this.selected.SubItems[6].Text) * 5 + 2, (float)double.Parse(this.selected.SubItems[5].Text) * 5 + 2); //graphics.DrawRectangle(Pens.Black, x + (float)double.Parse(this.selected.SubItems[3].Text) * 5, y + (float)double.Parse(this.selected.SubItems[2].Text) * 5, (float)double.Parse(this.selected.SubItems[6].Text) * 5, (float)double.Parse(this.selected.SubItems[5].Text) * 5); comboParent.Text = part.Type; @@ -896,8 +896,8 @@ namespace PckStudio SizeXUpDown.Value = (decimal)part.Size.X; SizeYUpDown.Value = (decimal)part.Size.Y; SizeZUpDown.Value = (decimal)part.Size.Z; - TextureXUpDown.Value = (decimal)part.U; - TextureYUpDown.Value = (decimal)part.V; + TextureXUpDown.Value = (decimal)part.UV.X; + TextureYUpDown.Value = (decimal)part.UV.Y; render(); } } @@ -907,9 +907,8 @@ namespace PckStudio private void comboParent_SelectedIndexChanged(object sender, EventArgs e) { if (listViewBoxes.SelectedItems.Count != 0 && - listViewBoxes.SelectedItems[0].Tag is SkinBox) + listViewBoxes.SelectedItems[0].Tag is SkinBOX part) { - var part = listViewBoxes.SelectedItems[0].Tag as SkinBox; part.Type = comboParent.Text; buttonIMPORT.Enabled = true; buttonEXPORT.Enabled = true; @@ -928,9 +927,8 @@ namespace PckStudio private void SizeXUpDown_ValueChanged(object sender, EventArgs e) { if (listViewBoxes.SelectedItems.Count != 0 && - listViewBoxes.SelectedItems[0].Tag is SkinBox) + listViewBoxes.SelectedItems[0].Tag is SkinBOX part) { - var part = listViewBoxes.SelectedItems[0].Tag as SkinBox; part.Size.X = (float)SizeXUpDown.Value; } updateListView(); @@ -940,9 +938,8 @@ namespace PckStudio private void SizeYUpDown_ValueChanged(object sender, EventArgs e) { if (listViewBoxes.SelectedItems.Count != 0 && - listViewBoxes.SelectedItems[0].Tag is SkinBox) + listViewBoxes.SelectedItems[0].Tag is SkinBOX part) { - var part = listViewBoxes.SelectedItems[0].Tag as SkinBox; part.Size.Y = (float)SizeYUpDown.Value; } updateListView(); @@ -952,9 +949,8 @@ namespace PckStudio private void SizeZUpDown_ValueChanged(object sender, EventArgs e) { if (listViewBoxes.SelectedItems.Count != 0 && - listViewBoxes.SelectedItems[0].Tag is SkinBox) + listViewBoxes.SelectedItems[0].Tag is SkinBOX part) { - var part = listViewBoxes.SelectedItems[0].Tag as SkinBox; part.Size.Z = (float)SizeZUpDown.Value; } updateListView(); @@ -964,9 +960,8 @@ namespace PckStudio private void PosXUpDown_ValueChanged(object sender, EventArgs e) { if (listViewBoxes.SelectedItems.Count != 0 && - listViewBoxes.SelectedItems[0].Tag is SkinBox) + listViewBoxes.SelectedItems[0].Tag is SkinBOX part) { - var part = listViewBoxes.SelectedItems[0].Tag as SkinBox; part.Pos.X = (float)PosXUpDown.Value; } updateListView(); @@ -977,9 +972,8 @@ namespace PckStudio private void PosYUpDown_ValueChanged(object sender, EventArgs e) { if (listViewBoxes.SelectedItems.Count != 0 && - listViewBoxes.SelectedItems[0].Tag is SkinBox) + listViewBoxes.SelectedItems[0].Tag is SkinBOX part) { - var part = listViewBoxes.SelectedItems[0].Tag as SkinBox; part.Pos.Y = (float)PosYUpDown.Value; } updateListView(); @@ -990,9 +984,8 @@ namespace PckStudio private void PosZUpDown_ValueChanged(object sender, EventArgs e) { if (listViewBoxes.SelectedItems.Count != 0 && - listViewBoxes.SelectedItems[0].Tag is SkinBox) + listViewBoxes.SelectedItems[0].Tag is SkinBOX part) { - var part = listViewBoxes.SelectedItems[0].Tag as SkinBox; part.Pos.Z = (float)PosZUpDown.Value; } updateListView(); @@ -1032,10 +1025,9 @@ namespace PckStudio private void TextureXUpDown_ValueChanged(object sender, EventArgs e) { if (listViewBoxes.SelectedItems.Count != 0 && - listViewBoxes.SelectedItems[0].Tag is SkinBox) + listViewBoxes.SelectedItems[0].Tag is SkinBOX part) { - var part = listViewBoxes.SelectedItems[0].Tag as SkinBox; - part.U = (int)TextureXUpDown.Value; + part.UV.X = (int)TextureXUpDown.Value; } updateListView(); render(); @@ -1046,10 +1038,9 @@ namespace PckStudio private void TextureYUpDown_ValueChanged(object sender, EventArgs e) { if (listViewBoxes.SelectedItems.Count != 0 && - listViewBoxes.SelectedItems[0].Tag is SkinBox) + listViewBoxes.SelectedItems[0].Tag is SkinBOX part) { - var part = listViewBoxes.SelectedItems[0].Tag as SkinBox; - part.V = (int)TextureXUpDown.Value; + part.UV.Y = (int)TextureYUpDown.Value; } updateListView(); render(); @@ -1155,12 +1146,12 @@ namespace PckStudio //Loads in model template(Steve) private void buttonTemplate_Click(object sender, EventArgs e) { - modelBoxes.Add(new SkinBox("HEAD -4 -8 -4 8 8 8 0 0 0 0 0")); - modelBoxes.Add(new SkinBox("BODY -4 0 -2 8 12 4 16 16 0 0 0")); - modelBoxes.Add(new SkinBox("ARM0 -3 -2 -2 4 12 4 40 16 0 0 0")); - modelBoxes.Add(new SkinBox("ARM1 -1 -2 -2 4 12 4 40 16 0 1 0")); - modelBoxes.Add(new SkinBox("LEG0 -2 0 -2 4 12 4 0 16 0 0 0")); - modelBoxes.Add(new SkinBox("LEG1 -2 0 -2 4 12 4 0 16 0 1 0")); + modelBoxes.Add(SkinBOX.FromString("HEAD -4 -8 -4 8 8 8 0 0 0 0 0")); + modelBoxes.Add(SkinBOX.FromString("BODY -4 0 -2 8 12 4 16 16 0 0 0")); + modelBoxes.Add(SkinBOX.FromString("ARM0 -3 -2 -2 4 12 4 40 16 0 0 0")); + modelBoxes.Add(SkinBOX.FromString("ARM1 -1 -2 -2 4 12 4 40 16 0 1 0")); + modelBoxes.Add(SkinBOX.FromString("LEG0 -2 0 -2 4 12 4 0 16 0 0 0")); + modelBoxes.Add(SkinBOX.FromString("LEG1 -2 0 -2 4 12 4 0 16 0 1 0")); comboParent.Enabled = true; updateListView(); render(); @@ -1179,8 +1170,8 @@ namespace PckStudio listViewItem.SubItems.Add(new ListViewItem.ListViewSubItem(listViewItem, part.Size.X.ToString())); listViewItem.SubItems.Add(new ListViewItem.ListViewSubItem(listViewItem, part.Size.Y.ToString())); listViewItem.SubItems.Add(new ListViewItem.ListViewSubItem(listViewItem, part.Size.Z.ToString())); - listViewItem.SubItems.Add(new ListViewItem.ListViewSubItem(listViewItem, part.U.ToString())); - listViewItem.SubItems.Add(new ListViewItem.ListViewSubItem(listViewItem, part.V.ToString())); + listViewItem.SubItems.Add(new ListViewItem.ListViewSubItem(listViewItem, part.UV.X.ToString())); + listViewItem.SubItems.Add(new ListViewItem.ListViewSubItem(listViewItem, part.UV.Y.ToString())); listViewBoxes.Items.Add(listViewItem); } } @@ -1223,23 +1214,21 @@ namespace PckStudio List lines = str1.Split(new[] { "\n\r", "\n" }, StringSplitOptions.None).ToList(); if (string.IsNullOrEmpty(lines[lines.Count - 1])) lines.RemoveAt(lines.Count - 1); - int passedlines = 0; - for (int i = 0; i < lines.Count;) + for (int i = 0; i < lines.Count; i += 11) { - string name = lines[0 + passedlines]; - string parent = lines[1 + passedlines]; - float PosX = float.Parse(lines[3 + passedlines]); - float PosY = float.Parse(lines[4 + passedlines]); - float PosZ = float.Parse(lines[5 + passedlines]); - float SizeX = float.Parse(lines[6 + passedlines]); - float SizeY = float.Parse(lines[7 + passedlines]); - float SizeZ = float.Parse(lines[8 + passedlines]); - float UvX = float.Parse(lines[9 + passedlines]); - float UvY = float.Parse(lines[10 + passedlines]); - passedlines += 11; - i += 11; + string name = lines[0 + i]; + string parent = lines[1 + i]; + float PosX = float.Parse(lines[3 + i]); + float PosY = float.Parse(lines[4 + i]); + float PosZ = float.Parse(lines[5 + i]); + float SizeX = float.Parse(lines[6 + i]); + float SizeY = float.Parse(lines[7 + i]); + float SizeZ = float.Parse(lines[8 + i]); + float UvX = float.Parse(lines[9 + i]); + float UvY = float.Parse(lines[10 + i]); + // CSM doesn't support armor, mirror, or scale values as far as I know of - May - modelBoxes.Add(new SkinBox($"{parent} {PosX} {PosY} {PosZ} {SizeX} {SizeY} {SizeZ} {UvX} {UvY} {false} {false} {0}")); + modelBoxes.Add(SkinBOX.FromString($"{parent} {PosX} {PosY} {PosZ} {SizeX} {SizeY} {SizeZ} {UvX} {UvY} {false} {false} {0}")); } } comboParent.Enabled = true; @@ -1326,9 +1315,8 @@ namespace PckStudio private void listView1_Click(object sender, EventArgs e) { if (listViewBoxes.SelectedItems.Count != 0 && listViewBoxes.SelectedItems[0] != null && - listViewBoxes.SelectedItems[0].Tag is SkinBox) + listViewBoxes.SelectedItems[0].Tag is SkinBOX part) { - var part = listViewBoxes.SelectedItems[0].Tag as SkinBox; comboParent.Text = part.Type; PosXUpDown.Value = (decimal)part.Pos.X; PosYUpDown.Value = (decimal)part.Pos.Y; @@ -1336,8 +1324,8 @@ namespace PckStudio SizeXUpDown.Value = (decimal)part.Size.X; SizeYUpDown.Value = (decimal)part.Size.Y; SizeZUpDown.Value = (decimal)part.Size.Z; - TextureXUpDown.Value = (decimal)part.U; - TextureYUpDown.Value = (decimal)part.V; + TextureXUpDown.Value = (decimal)part.UV.X; + TextureYUpDown.Value = (decimal)part.UV.Y; SizeXUpDown.Enabled = true; SizeYUpDown.Enabled = true; SizeZUpDown.Enabled = true; @@ -1376,9 +1364,9 @@ namespace PckStudio private void delStuffUsingDelKey(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Delete && listViewBoxes.SelectedItems.Count != 0 && - listViewBoxes.SelectedItems[0].Tag is SkinBox) + listViewBoxes.SelectedItems[0].Tag is SkinBOX part) { - if (modelBoxes.Remove(listViewBoxes.SelectedItems[0].Tag as SkinBox)) + if (modelBoxes.Remove(part)) listViewBoxes.SelectedItems[0].Remove(); render(); } diff --git a/PCK-Studio/Internals/ApplicationBuildInfo.cs b/PCK-Studio/Internals/ApplicationBuildInfo.cs new file mode 100644 index 00000000..54c29118 --- /dev/null +++ b/PCK-Studio/Internals/ApplicationBuildInfo.cs @@ -0,0 +1,47 @@ +/* Copyright (c) 2023-present miku-666, MattNL + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. +**/ +using System; +using System.IO; +using System.Reflection; + +namespace PckStudio.Internal +{ + static class ApplicationBuildInfo + { + // this is to specify which build release this is. This is manually updated for now + // TODO: add different chars for different configurations + private const string BuildType = "b"; + private static System.Globalization.Calendar _buildCalendar; + private static DateTime date = new FileInfo(Assembly.GetExecutingAssembly().Location).LastWriteTime; + private static string _betaBuildVersion; + + public static string BetaBuildVersion + { + get + { + // adopted Minecraft Java Edition Snapshot format (YYwWWn) + // to keep better track of work in progress features and builds + _buildCalendar ??= new System.Globalization.CultureInfo("en-US").Calendar; + return _betaBuildVersion ??= string.Format("#{0}w{1}{2}", + date.ToString("yy"), + _buildCalendar.GetWeekOfYear(date, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Monday), + BuildType); + } + } + } +} diff --git a/PCK-Studio/Internals/CommitInfo.cs b/PCK-Studio/Internals/CommitInfo.cs new file mode 100644 index 00000000..47ca025e --- /dev/null +++ b/PCK-Studio/Internals/CommitInfo.cs @@ -0,0 +1,50 @@ +/* Copyright (c) 2023-present miku-666 + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. +**/ +using System.Linq; +using System.Reflection; + +namespace PckStudio.Internal +{ + static class CommitInfo + { + private static string _branchName = null; + private static string _commitHash = null; + + public static string BranchName + { + get + { + return _branchName ??= Assembly + .GetEntryAssembly() + .GetCustomAttributes() + .FirstOrDefault(attr => attr.Key == "GitBranch")?.Value; + } + } + + public static string CommitHash + { + get + { + return _commitHash ??= Assembly + .GetEntryAssembly() + .GetCustomAttributes() + .FirstOrDefault(attr => attr.Key == "GitHash")?.Value; + } + } + } +} diff --git a/PCK-Studio/Classes/Utils/SkinANIM.cs b/PCK-Studio/Internals/SkinANIM.cs similarity index 99% rename from PCK-Studio/Classes/Utils/SkinANIM.cs rename to PCK-Studio/Internals/SkinANIM.cs index 58f56a2e..13fd332e 100644 --- a/PCK-Studio/Classes/Utils/SkinANIM.cs +++ b/PCK-Studio/Internals/SkinANIM.cs @@ -18,7 +18,7 @@ using System; using System.Text.RegularExpressions; -namespace PckStudio.Classes.Utils +namespace PckStudio.Internal { /// /// For usage see diff --git a/PCK-Studio/Internals/SkinBOX.cs b/PCK-Studio/Internals/SkinBOX.cs new file mode 100644 index 00000000..d32948e8 --- /dev/null +++ b/PCK-Studio/Internals/SkinBOX.cs @@ -0,0 +1,90 @@ +/* Copyright (c) 2023-present miku-666, MattNL + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1.The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. +**/ +using System; +using System.Numerics; + +namespace PckStudio.Internal +{ + public class SkinBOX + { + public string Type; + public Vector3 Pos; + public Vector3 Size; + public Vector2 UV; + public bool HideWithArmor; + public bool Mirror; + public float Scale; + + public SkinBOX(string type, Vector3 pos, Vector3 size, Vector2 uv, + bool hideWithArmor = false, bool mirror = false, float scale = 0.0f) + { + Type = type; + Pos = pos; + Size = size; + UV = uv; + HideWithArmor = hideWithArmor; + Mirror = mirror; + Scale = scale; + } + + public static SkinBOX FromString(string value) + { + var arguments = value.Split(' '); + if (arguments.Length < 9) + { + throw new ArgumentException("Arguments must have at least a length of 9"); + } + var type = arguments[0]; + var pos = TryGetVector3(arguments, 1); + var size = TryGetVector3(arguments, 4); + var uv = TryGetVector2(arguments, 7); + var skinBox = new SkinBOX(type, pos, size, uv); + if (arguments.Length >= 10) + skinBox.HideWithArmor = arguments[9] == "1"; + if (arguments.Length >= 11) + skinBox.Mirror = arguments[10] == "1"; + if (arguments.Length >= 12) + float.TryParse(arguments[11], out skinBox.Scale); + return skinBox; + } + + public ValueTuple ToProperty() + { + return new ValueTuple("BOX", ToString().Replace(',', '.')); + } + + 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}"; + } + + private static Vector2 TryGetVector2(string[] arguments, int startIndex) + { + float.TryParse(arguments[startIndex], out float x); + float.TryParse(arguments[startIndex + 1], out float y); + return new Vector2(x, y); + } + + private static Vector3 TryGetVector3(string[] arguments, int startIndex) + { + var vec2 = TryGetVector2(arguments, startIndex); + float.TryParse(arguments[startIndex + 2], out float z); + return new Vector3(vec2, z); + } + } +} diff --git a/PCK-Studio/MainForm.cs b/PCK-Studio/MainForm.cs index 63938557..e0ee7a34 100644 --- a/PCK-Studio/MainForm.cs +++ b/PCK-Studio/MainForm.cs @@ -27,6 +27,7 @@ using PckStudio.Forms.Additional_Popups; using PckStudio.Classes.Misc; using PckStudio.Classes.IO.PCK; using PckStudio.Classes.IO._3DST; +using PckStudio.Internal; namespace PckStudio { @@ -75,7 +76,7 @@ namespace PckStudio ChangelogRichTextBox.Text = Resources.CHANGELOG; #if BETA - labelVersion.Text += $"{Program.Info.BetaBuildVersion}"; + labelVersion.Text += $"{ApplicationBuildInfo.BetaBuildVersion}"; #endif #if DEBUG labelVersion.Text += $" (Debug build: {CommitInfo.BranchName}@{CommitInfo.CommitHash})"; diff --git a/PCK-Studio/PckStudio.csproj b/PCK-Studio/PckStudio.csproj index c5fbddfb..7c3c8638 100644 --- a/PCK-Studio/PckStudio.csproj +++ b/PCK-Studio/PckStudio.csproj @@ -167,6 +167,7 @@ + @@ -189,10 +190,10 @@ - + - + @@ -222,6 +223,7 @@ + Form diff --git a/PCK-Studio/Program.cs b/PCK-Studio/Program.cs index f35c6e09..bcac4a6f 100644 --- a/PCK-Studio/Program.cs +++ b/PCK-Studio/Program.cs @@ -1,63 +1,10 @@ using System; using System.Diagnostics; using System.IO; -using System.Linq; -using System.Reflection; using System.Windows.Forms; namespace PckStudio { - sealed class ProgramInfo - { - // this is to specify which build release this is. This is manually updated for now - // TODO: add different chars for different configurations - private const string BuildType = "b"; - private static System.Globalization.Calendar _buildCalendar; - private DateTime date = new FileInfo(Assembly.GetExecutingAssembly().Location).LastWriteTime; - - public string BetaBuildVersion - { - get - { - // adopted Minecraft Java Edition Snapshot format (YYwWWn) - // to keep better track of work in progress features and builds - _buildCalendar ??= new System.Globalization.CultureInfo("en-US").Calendar; - return string.Format("#{0}w{1}{2}", - date.ToString("yy"), - _buildCalendar.GetWeekOfYear(date, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Monday), - BuildType); - } - } - } - - static class CommitInfo - { - private static string _branchName = null; - private static string _commitHash = null; - - public static string BranchName - { - get - { - return _branchName ??= Assembly - .GetEntryAssembly() - .GetCustomAttributes() - .FirstOrDefault(attr => attr.Key == "GitBranch")?.Value; - } - } - - public static string CommitHash - { - get - { - return _commitHash ??= Assembly - .GetEntryAssembly() - .GetCustomAttributes() - .FirstOrDefault(attr => attr.Key == "GitHash")?.Value; - } - } - } - static class Program { public static readonly string ProjectUrl = "https://github.com/PhoenixARC/-PCK-Studio"; @@ -66,8 +13,6 @@ namespace PckStudio public static readonly string AppData = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "PCK-Studio"); public static readonly string AppDataCache = Path.Combine(AppData, "cache"); - public static readonly ProgramInfo Info = new ProgramInfo(); - /// /// The main entry point for the application. ///