diff --git a/PckStudio.Core/ArmorPiece.cs b/PckStudio.Core/ArmorPiece.cs new file mode 100644 index 00000000..05321a59 --- /dev/null +++ b/PckStudio.Core/ArmorPiece.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; +using System.Text; +using System.Threading.Tasks; + +namespace PckStudio.Core +{ + public sealed class ArmorPiece(Vector3 position, Vector3 size, Vector2 uv, bool mirrorTexture = default, float infalte = default) + { + public static ArmorPiece Helmet { get; } = new ArmorPiece(new(-4, -8, -4), new(8), new(0)); + public static ArmorPiece Chest { get; } = new ArmorPiece(new(-4, 0, -2), new(8, 12, 4), new(16)); + public static ArmorPiece Waist { get; } = new ArmorPiece(new(-4, 0, -2), new(8, 12, 4), new(16, 48)); + public static ArmorPiece RightShoulder { get; } = new ArmorPiece(new(-3, -2, -2), new(4, 12, 4), new(40, 16)); + public static ArmorPiece LeftShoulder { get; } = new ArmorPiece(new(-1, -2, -2), new(4, 12, 4), new(40, 16), mirrorTexture: true); + public static ArmorPiece RightPants { get; } = new ArmorPiece(new(-2, 0, -2), new(4, 12, 4), new(0, 48)); + public static ArmorPiece LeftPants { get; } = new ArmorPiece(new(-2, 0, -2), new(4, 12, 4), new(0, 48), mirrorTexture: true); + public static ArmorPiece RightBoot { get; } = new ArmorPiece(new(-2, 0, -2), new(4, 12, 4), new(0, 16)); + public static ArmorPiece LeftBoot { get; } = new ArmorPiece(new(-2, 0, -2), new(4, 12, 4), new(0, 16), mirrorTexture: true); + + public Vector3 Position { get; } = position; + public Vector3 Size { get; } = size; + public Vector2 Uv { get; } = uv; + public bool MirrorTexture { get; } = mirrorTexture; + public float Infalte { get; } = infalte; + } +} diff --git a/PckStudio.Core/ArmorPieceDescription.cs b/PckStudio.Core/ArmorPieceDescription.cs deleted file mode 100644 index b993cb07..00000000 --- a/PckStudio.Core/ArmorPieceDescription.cs +++ /dev/null @@ -1,64 +0,0 @@ -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/ArmorSet.cs b/PckStudio.Core/ArmorSet.cs new file mode 100644 index 00000000..7ea1f148 --- /dev/null +++ b/PckStudio.Core/ArmorSet.cs @@ -0,0 +1,20 @@ +using System.Drawing; +using PckStudio.Core.Skin; + +namespace PckStudio.Core +{ + public sealed class ArmorSet + { + public string Name { get; } + public Image BaseTexture => _layers[0]; + public Image Layer => _layers[1]; + private Image[] _layers = new Image[2]; + + public ArmorSet(string name, Image baseTexture, Image overlay) + { + Name = name; + _layers[0] = baseTexture; + _layers[1] = overlay; + } + } +} \ No newline at end of file diff --git a/PckStudio.Core/ArmorSetDescription.cs b/PckStudio.Core/ArmorSetDescription.cs new file mode 100644 index 00000000..fe73727e --- /dev/null +++ b/PckStudio.Core/ArmorSetDescription.cs @@ -0,0 +1,96 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PckStudio.Core.Extensions; +using PckStudio.Interfaces; + +namespace PckStudio.Core +{ + public sealed class ArmorSetDescription + { + private static readonly Dictionary _pathLookUp = new Dictionary(); + private static readonly string _resourcePath = ResourceLocations.GetFromCategory(ResourceCategory.ArmorTextures).FullPath; + public static ArmorSetDescription Empty = new ArmorSetDescription(string.Empty, 0, 0); + public static ArmorSetDescription Leather = new ArmorSetDescription("cloth", layerCount: 1); + public static ArmorSetDescription Chain = new ArmorSetDescription("chain"); + public static ArmorSetDescription Iron = new ArmorSetDescription("iron"); + public static ArmorSetDescription Gold = new ArmorSetDescription("gold"); + public static ArmorSetDescription Diamond = new ArmorSetDescription("diamond"); + public static ArmorSetDescription Turtle = new ArmorSetDescription("turtle", textureCount: 1); + + + public string Name { get; } + public int LayerCount { get; } + public int TextureCount { get; } + public int AssetCount { get; } + public bool IsEmpty => this == Empty; + + private ArmorSetDescription(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 GetArmorNames()) + { + _pathLookUp.Add(path, this); + } + } + + public static ArmorSetDescription GetFromAssetName(string name) + { + return _pathLookUp.ContainsKey(name ?? string.Empty) ? _pathLookUp[name] : Empty; + } + + public string[] GetAssetPaths() => GetArmorNames().Select(name => Path.Combine($"{_resourcePath}/", name)).ToArray(); + + public string[] GetArmorNames() + { + if (AssetCount <= 0) + return Array.Empty(); + string[] result = new string[AssetCount]; + for (int i = 0; i < TextureCount; i++) + { + string assetPath = $"{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; + } + + public ArmorSet GetArmorSet(ITryGet tryGetTexture) + { + Image baseTexture = default; + Image overlayTexture = default; + string[] assetPaths = GetAssetPaths(); + if (TextureCount < 2 && tryGetTexture.TryGet(assetPaths[0], out Image t0)) + { + return new ArmorSet(Name, t0.Combine(t0, ImageLayoutDirection.Vertical), overlayTexture); + } + for (int i = 0; i < TextureCount / 2; i++) + { + if (tryGetTexture.TryGet(assetPaths[i + 0], out Image t1) && + tryGetTexture.TryGet(assetPaths[i + 1], out Image t2)) + { + baseTexture = t1.Combine(t2, ImageLayoutDirection.Vertical); + } + } + if (LayerCount > 0 && + tryGetTexture.TryGet(assetPaths[2], out Image t3) && + tryGetTexture.TryGet(assetPaths[3], out Image t4)) + { + overlayTexture = t3.Combine(t4, ImageLayoutDirection.Vertical); + } + return new ArmorSet(Name, baseTexture, overlayTexture); + } + } +} diff --git a/PckStudio.Core/PckStudio.Core.csproj b/PckStudio.Core/PckStudio.Core.csproj index c883555b..fd6c7cf3 100644 --- a/PckStudio.Core/PckStudio.Core.csproj +++ b/PckStudio.Core/PckStudio.Core.csproj @@ -53,7 +53,9 @@ - + + +