From dbfcdda5a9f03623ee82485b1c3fc627341078d7 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Mon, 27 Oct 2025 18:32:13 +0100 Subject: [PATCH] PckStudio.Core - Add NamedData.cs --- PCK-Studio/Controls/PckEditor.cs | 8 +++--- PCK-Studio/Forms/Editor/ModelEditor.cs | 25 ++++++++++--------- PckStudio.Core/NamedData.cs | 14 +++++++++++ PckStudio.Core/PckStudio.Core.csproj | 1 + .../Format/External/BlockBenchModel.cs | 3 ++- PckStuido.ModelSupport/GameModelImporter.cs | 1 + PckStuido.ModelSupport/GameModelInfo.cs | 1 + PckStuido.ModelSupport/NamedTexture.cs | 17 ------------- .../PckStuido.ModelSupport.csproj | 4 +-- 9 files changed, 38 insertions(+), 36 deletions(-) create mode 100644 PckStudio.Core/NamedData.cs delete mode 100644 PckStuido.ModelSupport/NamedTexture.cs diff --git a/PCK-Studio/Controls/PckEditor.cs b/PCK-Studio/Controls/PckEditor.cs index 86711022..d7be02fa 100644 --- a/PCK-Studio/Controls/PckEditor.cs +++ b/PCK-Studio/Controls/PckEditor.cs @@ -253,7 +253,7 @@ namespace PckStudio.Controls Image texture = asset.GetTexture(); string textureName = Path.GetFileName(texturePath); - NamedTexture modelTexture = new NamedTexture(textureName, texture); + NamedData modelTexture = new NamedData(textureName, texture); bool hasCustomModel = false; bool hasDefaultModel = TryGetDefaultEntityModel(modelName, out Model model); @@ -2033,7 +2033,7 @@ namespace PckStudio.Controls return true; } - private void ShowSimpleModelRender(Model model, NamedTexture modelTexture) + private void ShowSimpleModelRender(Model model, NamedData modelTexture) { MetroForm form = new MetroForm(); form.Icon = Resources.ProjectLogo; @@ -2057,7 +2057,7 @@ namespace PckStudio.Controls if (openFileDialog.ShowDialog(this) == DialogResult.OK) { - var modelInfo = new GameModelInfo(model, new NamedTexture[1] { modelTexture }); + var modelInfo = new GameModelInfo(model, new NamedData[1] { modelTexture }); GameModelImporter.Default.Export(openFileDialog.FileName, modelInfo); } } @@ -2078,7 +2078,7 @@ namespace PckStudio.Controls renderer.VSync = true; renderer.BackColor = Color.FromArgb(30, 30, 30); renderer.Dock = DockStyle.Fill; - renderer.Texture = modelTexture.Texture; + renderer.Texture = modelTexture.Value; renderer.LoadModel(model); renderer.ResetCamera(); diff --git a/PCK-Studio/Forms/Editor/ModelEditor.cs b/PCK-Studio/Forms/Editor/ModelEditor.cs index 83e0c20d..124fa073 100644 --- a/PCK-Studio/Forms/Editor/ModelEditor.cs +++ b/PCK-Studio/Forms/Editor/ModelEditor.cs @@ -17,6 +17,7 @@ using PckStudio.ModelSupport; using PckStudio.Core.Json; using PckStudio.Core.Extensions; using PckStudio.Internal.App; +using PckStudio.Core; namespace PckStudio.Forms.Editor { @@ -178,16 +179,16 @@ namespace PckStudio.Forms.Editor private class NamedTextureTreeNode : TreeNode { - private readonly NamedTexture _namedTexture; + private readonly NamedData _namedTexture; - public NamedTextureTreeNode(NamedTexture namedTexture) + public NamedTextureTreeNode(NamedData namedTexture) : base(namedTexture.Name) { Tag = namedTexture; _namedTexture = namedTexture; } - public Image GetTexture() => _namedTexture.Texture; + public Image GetTexture() => _namedTexture.Value; } private void LoadModels() @@ -221,7 +222,7 @@ namespace PckStudio.Forms.Editor if (openFileDialog.ShowDialog(this) == DialogResult.OK) { - IEnumerable textures = GetModelTextures(model.Name); + IEnumerable> textures = GetModelTextures(model.Name); var modelInfo = new GameModelInfo(model, textures); GameModelImporter.Default.Export(openFileDialog.FileName, modelInfo); } @@ -236,18 +237,18 @@ namespace PckStudio.Forms.Editor //removeToolStripMenuItem.Visible = e.Node is ModelPartNode || e.Node is ModelBoxNode; if (e.Node is ModelNode modelNode && modelNode.Model.Name != modelViewport.CurrentModelName) { - NamedTexture[] textures = GetModelTextures(modelNode.Model.Name).ToArray(); + NamedData[] textures = GetModelTextures(modelNode.Model.Name).ToArray(); textureImageList.Images.Clear(); namedTexturesTreeView.Nodes.Clear(); - foreach ((int i, NamedTexture item) in textures.enumerate()) + foreach ((int i, NamedData item) in textures.enumerate()) { - textureImageList.Images.Add(item.Texture); + textureImageList.Images.Add(item.Value); namedTexturesTreeView.Nodes.Add(new NamedTextureTreeNode(item) { ImageIndex = i, SelectedImageIndex = i }); } if (textures.Length != 0) - modelViewport.Texture = textures[0].Texture; + modelViewport.Texture = textures[0].Value; modelViewport.LoadModel(modelNode.Model); if (GameModelImporter.ModelMetaData.TryGetValue(modelNode.Model.Name, out JsonModelMetaData modelMetaData) && !string.IsNullOrEmpty(modelMetaData.MaterialName) && @@ -270,14 +271,14 @@ namespace PckStudio.Forms.Editor } } - private IEnumerable GetModelTextures(string modelName) + private IEnumerable> GetModelTextures(string modelName) { if (!GameModelImporter.ModelMetaData.ContainsKey(modelName) || GameModelImporter.ModelMetaData[modelName]?.TextureLocations?.Length <= 0) yield break; foreach (var textureLocation in GameModelImporter.ModelMetaData[modelName].TextureLocations) { if (_textures.TryGet(textureLocation, out Image img)) - yield return new NamedTexture(Path.GetFileName(textureLocation), img); + yield return new NamedData(Path.GetFileName(textureLocation), img); } yield break; } @@ -304,9 +305,9 @@ namespace PckStudio.Forms.Editor EditorValue.SetModel(modelInfo.Model); - foreach (NamedTexture texture in modelInfo.Textures) + foreach (NamedData texture in modelInfo.Textures) { - _textures.TrySet(texture.Name, texture.Texture); + _textures.TrySet(texture.Name, texture.Value); } LoadModels(); diff --git a/PckStudio.Core/NamedData.cs b/PckStudio.Core/NamedData.cs new file mode 100644 index 00000000..717db6f6 --- /dev/null +++ b/PckStudio.Core/NamedData.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PckStudio.Core +{ + public readonly struct NamedData(string name, T value) + { + public readonly string Name = name; + public readonly T Value = value; + } +} diff --git a/PckStudio.Core/PckStudio.Core.csproj b/PckStudio.Core/PckStudio.Core.csproj index 7adf9aa9..6b4dd442 100644 --- a/PckStudio.Core/PckStudio.Core.csproj +++ b/PckStudio.Core/PckStudio.Core.csproj @@ -113,6 +113,7 @@ + diff --git a/PckStuido.ModelSupport/Format/External/BlockBenchModel.cs b/PckStuido.ModelSupport/Format/External/BlockBenchModel.cs index 8d53d32d..1c3f5e3e 100644 --- a/PckStuido.ModelSupport/Format/External/BlockBenchModel.cs +++ b/PckStuido.ModelSupport/Format/External/BlockBenchModel.cs @@ -11,6 +11,7 @@ using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using NamedTexture = PckStudio.Core.NamedData; namespace PckStudio.ModelSupport.Format.External { @@ -200,7 +201,7 @@ namespace PckStudio.ModelSupport.Format.External { public static implicit operator Image(Texture texture) => texture.GetImage(); public static implicit operator Texture(Image image) => new Texture(image); - public static implicit operator Texture(NamedTexture namedTexture) => new Texture(namedTexture.Name, namedTexture.Texture); + public static implicit operator Texture(NamedTexture namedTexture) => new Texture(namedTexture.Name, namedTexture.Value); private const string _TEXTUREDATAHEAD = "data:image/png;base64,"; diff --git a/PckStuido.ModelSupport/GameModelImporter.cs b/PckStuido.ModelSupport/GameModelImporter.cs index 39ee90c8..5730d551 100644 --- a/PckStuido.ModelSupport/GameModelImporter.cs +++ b/PckStuido.ModelSupport/GameModelImporter.cs @@ -34,6 +34,7 @@ using PckStudio.Core.Extensions; using PckStudio.Core; using PckStudio.ModelSupport.Format.External; using PckStuido.ModelSupport.Properties; +using NamedTexture = PckStudio.Core.NamedData; namespace PckStudio.ModelSupport { diff --git a/PckStuido.ModelSupport/GameModelInfo.cs b/PckStuido.ModelSupport/GameModelInfo.cs index 4c7fd3fe..dd53eb5a 100644 --- a/PckStuido.ModelSupport/GameModelInfo.cs +++ b/PckStuido.ModelSupport/GameModelInfo.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using OMI.Formats.Model; +using NamedTexture = PckStudio.Core.NamedData; namespace PckStudio.ModelSupport { diff --git a/PckStuido.ModelSupport/NamedTexture.cs b/PckStuido.ModelSupport/NamedTexture.cs deleted file mode 100644 index b5ad9e0a..00000000 --- a/PckStuido.ModelSupport/NamedTexture.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -namespace PckStudio.ModelSupport -{ - public readonly struct NamedTexture - { - public readonly string Name; - public readonly Image Texture; - - public NamedTexture(string name, Image texture) - { - Name = name; - Texture = texture; - } - } -} diff --git a/PckStuido.ModelSupport/PckStuido.ModelSupport.csproj b/PckStuido.ModelSupport/PckStuido.ModelSupport.csproj index 72b6fa34..d7697c87 100644 --- a/PckStuido.ModelSupport/PckStuido.ModelSupport.csproj +++ b/PckStuido.ModelSupport/PckStuido.ModelSupport.csproj @@ -6,7 +6,7 @@ AnyCPU {43BCACD7-5405-4499-9B45-E1435AC03C26} Library - NDEBUG + NDEBUG Properties PckStuido.ModelSupport PckStuido.ModelSupport @@ -57,7 +57,6 @@ - True @@ -86,6 +85,7 @@ ResXFileCodeGenerator Resources.Designer.cs + Designer