mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-06-29 09:16:02 +00:00
PckStudio.Core - Add NamedData.cs
This commit is contained in:
@@ -253,7 +253,7 @@ namespace PckStudio.Controls
|
||||
Image texture = asset.GetTexture();
|
||||
string textureName = Path.GetFileName(texturePath);
|
||||
|
||||
NamedTexture modelTexture = new NamedTexture(textureName, texture);
|
||||
NamedData<Image> modelTexture = new NamedData<Image>(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<Image> 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<Image>[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();
|
||||
|
||||
|
||||
@@ -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<Image> _namedTexture;
|
||||
|
||||
public NamedTextureTreeNode(NamedTexture namedTexture)
|
||||
public NamedTextureTreeNode(NamedData<Image> 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<NamedTexture> textures = GetModelTextures(model.Name);
|
||||
IEnumerable<NamedData<Image>> 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<Image>[] textures = GetModelTextures(modelNode.Model.Name).ToArray();
|
||||
|
||||
textureImageList.Images.Clear();
|
||||
namedTexturesTreeView.Nodes.Clear();
|
||||
|
||||
foreach ((int i, NamedTexture item) in textures.enumerate())
|
||||
foreach ((int i, NamedData<Image> 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<NamedTexture> GetModelTextures(string modelName)
|
||||
private IEnumerable<NamedData<Image>> 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<Image>(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<Image> texture in modelInfo.Textures)
|
||||
{
|
||||
_textures.TrySet(texture.Name, texture.Texture);
|
||||
_textures.TrySet(texture.Name, texture.Value);
|
||||
}
|
||||
|
||||
LoadModels();
|
||||
|
||||
14
PckStudio.Core/NamedData.cs
Normal file
14
PckStudio.Core/NamedData.cs
Normal file
@@ -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<T>(string name, T value)
|
||||
{
|
||||
public readonly string Name = name;
|
||||
public readonly T Value = value;
|
||||
}
|
||||
}
|
||||
@@ -113,6 +113,7 @@
|
||||
<Compile Include="Json\UpdateInformation.cs" />
|
||||
<Compile Include="Misc\FileCacher.cs" />
|
||||
<Compile Include="Misc\OpenFolderDialog.cs" />
|
||||
<Compile Include="NamedData.cs" />
|
||||
<Compile Include="PackInfo.cs" />
|
||||
<Compile Include="ResourceCategory.cs" />
|
||||
<Compile Include="ResourceLocation.cs" />
|
||||
|
||||
@@ -11,6 +11,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NamedTexture = PckStudio.Core.NamedData<System.Drawing.Image>;
|
||||
|
||||
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,";
|
||||
|
||||
|
||||
@@ -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<System.Drawing.Image>;
|
||||
|
||||
namespace PckStudio.ModelSupport
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using OMI.Formats.Model;
|
||||
using NamedTexture = PckStudio.Core.NamedData<System.Drawing.Image>;
|
||||
|
||||
namespace PckStudio.ModelSupport
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{43BCACD7-5405-4499-9B45-E1435AC03C26}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<DefineConstants Condition="'$(Configuration)' != 'Debug'">NDEBUG</DefineConstants>
|
||||
<DefineConstants Condition="'$(Configuration)' != 'Debug'">NDEBUG</DefineConstants>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>PckStuido.ModelSupport</RootNamespace>
|
||||
<AssemblyName>PckStuido.ModelSupport</AssemblyName>
|
||||
@@ -57,7 +57,6 @@
|
||||
<Compile Include="Json\JsonDefaultModel.cs" />
|
||||
<Compile Include="Json\JsonModelMetaData.cs" />
|
||||
<Compile Include="ModelImporter.cs" />
|
||||
<Compile Include="NamedTexture.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
@@ -86,6 +85,7 @@
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user