Core - Add ArmorPieceDescription.cs

This commit is contained in:
miku-666
2025-11-20 05:27:01 +01:00
parent 0289cc94f3
commit b6b6a355a8
2 changed files with 65 additions and 0 deletions

View File

@@ -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<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;
}
}
}

View File

@@ -53,6 +53,7 @@
<Compile Include="AppLanguage.cs" />
<Compile Include="App\SettingsManager.cs" />
<Compile Include="App\Updater.cs" />
<Compile Include="ArmorPieceDescription.cs" />
<Compile Include="Atlas.cs" />
<Compile Include="AtlasGroup.cs" />
<Compile Include="AtlasGroupAnimation.cs" />