From b6b6a355a8d9e34eb259786093805b749c9c5f2f Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Thu, 20 Nov 2025 05:27:01 +0100 Subject: [PATCH] Core - Add ArmorPieceDescription.cs --- PckStudio.Core/ArmorPieceDescription.cs | 64 +++++++++++++++++++++++++ PckStudio.Core/PckStudio.Core.csproj | 1 + 2 files changed, 65 insertions(+) create mode 100644 PckStudio.Core/ArmorPieceDescription.cs diff --git a/PckStudio.Core/ArmorPieceDescription.cs b/PckStudio.Core/ArmorPieceDescription.cs new file mode 100644 index 00000000..b993cb07 --- /dev/null +++ b/PckStudio.Core/ArmorPieceDescription.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PckStudio.Core +{ + public sealed class ArmorPieceDescription + { + private static readonly Dictionary _pathLookUp = new Dictionary(); + private static readonly string _resourcePath = ResourceLocations.GetFromCategory(ResourceCategory.ArmorTextures).FullPath; + public static ArmorPieceDescription Empty = new ArmorPieceDescription(string.Empty, 0, 0); + public static ArmorPieceDescription Leather = new ArmorPieceDescription("cloth", layerCount: 1); + public static ArmorPieceDescription Chain = new ArmorPieceDescription("chain"); + public static ArmorPieceDescription Iron = new ArmorPieceDescription("iron"); + public static ArmorPieceDescription Gold = new ArmorPieceDescription("gold"); + public static ArmorPieceDescription Diamond = new ArmorPieceDescription("diamond"); + public static ArmorPieceDescription Turtle = new ArmorPieceDescription("turtle", textureCount: 1); + + + public string Name { get; } + public int LayerCount { get; } + public int TextureCount { get; } + public int AssetCount { get; } + + private ArmorPieceDescription(string name, int layerCount = 0, int textureCount = 2) + { + Name = name; + if (string.IsNullOrEmpty(name) && layerCount == 0 && textureCount == 0) + return; + LayerCount = Math.Min(Math.Max(layerCount, 0), ('z' - 'b')); + TextureCount = Math.Max(textureCount, 1); + AssetCount = (LayerCount + 1) * TextureCount; + foreach (var path in GetAssetPaths()) + { + _pathLookUp.Add(path, this); + } + } + + public static ArmorPieceDescription GetFromAssetName(string name) + { + return _pathLookUp.ContainsKey(name ?? string.Empty) ? _pathLookUp[name] : Empty; + } + + public string[] GetAssetPaths() + { + if (AssetCount <= 0) + return Array.Empty(); + string[] result = new string[AssetCount]; + for (int i = 0; i < TextureCount; i++) + { + string assetPath = Path.Combine($"{_resourcePath}/", $"{Name}_{i + 1}"); + result[i*(LayerCount+1)] = assetPath; + for (int j = 0; j < LayerCount; j++) + { + result[i * TextureCount + 1 + j] = $"{assetPath}_{Convert.ToChar('b' + j)}"; + } + } + return result; + } + } +} diff --git a/PckStudio.Core/PckStudio.Core.csproj b/PckStudio.Core/PckStudio.Core.csproj index 8b43570f..0b8a5ba2 100644 --- a/PckStudio.Core/PckStudio.Core.csproj +++ b/PckStudio.Core/PckStudio.Core.csproj @@ -53,6 +53,7 @@ +