mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-05-24 21:34:31 +00:00
Core - Add ArmorPiece.cs & ArmorSet.cs & rename 'ArmorPieceDescription' to 'ArmorSetDescription'
This commit is contained in:
28
PckStudio.Core/ArmorPiece.cs
Normal file
28
PckStudio.Core/ArmorPiece.cs
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<string, ArmorPieceDescription> _pathLookUp = new Dictionary<string, ArmorPieceDescription>();
|
||||
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>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
20
PckStudio.Core/ArmorSet.cs
Normal file
20
PckStudio.Core/ArmorSet.cs
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
96
PckStudio.Core/ArmorSetDescription.cs
Normal file
96
PckStudio.Core/ArmorSetDescription.cs
Normal file
@@ -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<string, ArmorSetDescription> _pathLookUp = new Dictionary<string, ArmorSetDescription>();
|
||||
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>();
|
||||
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<string, Image> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,9 @@
|
||||
<Compile Include="App\AppLanguage.cs" />
|
||||
<Compile Include="App\SettingsManager.cs" />
|
||||
<Compile Include="App\Updater.cs" />
|
||||
<Compile Include="ArmorPieceDescription.cs" />
|
||||
<Compile Include="ArmorPiece.cs" />
|
||||
<Compile Include="ArmorSet.cs" />
|
||||
<Compile Include="ArmorSetDescription.cs" />
|
||||
<Compile Include="Atlas.cs" />
|
||||
<Compile Include="AtlasGroup.cs" />
|
||||
<Compile Include="AtlasGroupAnimation.cs" />
|
||||
|
||||
Reference in New Issue
Block a user