Merge branch 'main' into 3dSkinRenderer

This commit is contained in:
miku-666
2024-11-30 10:21:31 +01:00
5 changed files with 84 additions and 87 deletions

View File

@@ -21,6 +21,22 @@ namespace PckStudio.Extensions
{
private const string MipMap = "MipMapLevel";
internal static PckAsset CreateNewAssetIf(this PckFile pck, bool condition, string filename, PckAssetType filetype, IDataFormatWriter writer)
{
if (condition)
{
return pck.CreateNewAsset(filename, filetype, writer);
}
return default;
}
internal static PckAsset CreateNewAsset(this PckFile pck, string filename, PckAssetType filetype, IDataFormatWriter writer)
{
PckAsset asset = pck.CreateNewAsset(filename, filetype);
asset.SetData(writer);
return asset;
}
internal static Image GetTexture(this PckAsset asset)
{
if (asset.Type != PckAssetType.SkinFile &&

View File

@@ -1,24 +0,0 @@
using OMI.Formats.Pck;
using OMI.Workers;
namespace PckStudio.Extensions
{
internal static class PckFileExtensions
{
internal static PckAsset CreateNewAssetIf(this PckFile pck, bool condition, string filename, PckAssetType filetype, IDataFormatWriter writer)
{
if (condition)
{
return pck.CreateNewAsset(filename, filetype, writer);
}
return null;
}
internal static PckAsset CreateNewAsset(this PckFile pck, string filename, PckAssetType filetype, IDataFormatWriter writer)
{
PckAsset asset = pck.CreateNewAsset(filename, filetype);
asset.SetData(writer);
return asset;
}
}
}

View File

@@ -18,11 +18,15 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
namespace PckStudio.Internal
{
internal sealed class ResourceLocation
{
private static List<ResourceLocation> ResourceGroups = new List<ResourceLocation>();
private static readonly ResourceLocation Unknown = new ResourceLocation(string.Empty, ResourceCategory.Unknown, 1);
private static readonly Dictionary<string, ResourceLocation> _categoryLookUp = new Dictionary<string, ResourceLocation>()
{
["textures/items"] = new ResourceLocation("textures/items", ResourceCategory.ItemAnimation, 16, isGroup: true),
@@ -43,37 +47,33 @@ namespace PckStudio.Internal
{
return category switch
{
ResourceCategory.ItemAnimation => "res/textures/items",
ResourceCategory.BlockAnimation => "res/textures/blocks",
ResourceCategory.ItemAnimation => _categoryLookUp["textures/items"].ToString(),
ResourceCategory.BlockAnimation => _categoryLookUp["textures/blocks"].ToString(),
ResourceCategory.BlockAtlas => "res/terrain.png",
ResourceCategory.ItemAtlas => "res/items.png",
ResourceCategory.ParticleAtlas => "res/particles.png",
ResourceCategory.BannerAtlas => "res/item/banner/Banner_Atlas.png",
ResourceCategory.PaintingAtlas => "res/art/kz.png",
ResourceCategory.ExplosionAtlas => "res/misc/explosion.png",
ResourceCategory.ExperienceOrbAtlas => "res/item/xporb.png",
ResourceCategory.MoonPhaseAtlas => "res/terrain/moon_phases.png",
ResourceCategory.MapIconAtlas => "res/misc/mapicons.png",
ResourceCategory.AdditionalMapIconsAtlas => "res/misc/additionalmapicons.png",
ResourceCategory.BlockAtlas => _categoryLookUp["terrain.png"].ToString(),
ResourceCategory.ItemAtlas => _categoryLookUp["items.png"].ToString(),
ResourceCategory.ParticleAtlas => _categoryLookUp["particles.png"].ToString(),
ResourceCategory.BannerAtlas => _categoryLookUp["item/banner/Banner_Atlas.png"].ToString(),
ResourceCategory.PaintingAtlas => _categoryLookUp["art/kz.png"].ToString(),
ResourceCategory.ExplosionAtlas => _categoryLookUp["misc/explosion.png"].ToString(),
ResourceCategory.ExperienceOrbAtlas => _categoryLookUp["item/xporb.png"].ToString(),
ResourceCategory.MoonPhaseAtlas => _categoryLookUp["terrain/moon_phases.png"].ToString(),
ResourceCategory.MapIconAtlas => _categoryLookUp["misc/mapicons.png"].ToString(),
ResourceCategory.AdditionalMapIconsAtlas => _categoryLookUp["misc/additionalmapicons.png"].ToString(),
_ => string.Empty
};
}
public static ResourceCategory GetCategoryFromPath(string path)
{
return GetFromPath(path)?.Category ?? ResourceCategory.Unknown;
}
public static ResourceCategory GetCategoryFromPath(string path) => GetFromPath(path).Category;
public static ResourceLocation GetFromPath(string path)
{
if (string.IsNullOrWhiteSpace(path) || !path.StartsWith("res/"))
return null;
return Unknown;
string categoryPath = path.Substring("res/".Length);
if (categoryPath.StartsWith("textures/items"))
categoryPath = "textures/items";
if (categoryPath.StartsWith("textures/blocks"))
categoryPath = "textures/blocks";
return _categoryLookUp.ContainsKey(categoryPath) ? _categoryLookUp[categoryPath] : null;
if (_categoryLookUp.ContainsKey(categoryPath))
return _categoryLookUp[categoryPath];
return ResourceGroups.Where(group => categoryPath.StartsWith(group.Path)).FirstOrDefault() ?? Unknown;
}
public enum TillingMode
@@ -114,6 +114,8 @@ namespace PckStudio.Internal
TillingFactor = tillingFactor;
Tilling = tilling;
IsGroup = isGroup;
if (isGroup)
ResourceGroups.Add(this);
}
public override string ToString()

View File

@@ -460,50 +460,54 @@ namespace PckStudio
}
ResourceLocation resourceLocation = ResourceLocation.GetFromPath(asset.Filename);
Debug.WriteLine("Handling Resource file: " + resourceLocation?.ToString());
if (resourceLocation is null || resourceLocation.Category == ResourceCategory.Unknown)
return;
Debug.WriteLine("Handling Resource file: " + resourceLocation?.ToString());
if (resourceLocation.Category != ResourceCategory.BlockAnimation &&
resourceLocation.Category != ResourceCategory.ItemAnimation)
switch (resourceLocation.Category)
{
Image img = asset.GetTexture();
var viewer = new TextureAtlasEditor(currentPCK, resourceLocation, img);
if (viewer.ShowDialog(this) == DialogResult.OK)
{
Image texture = viewer.FinalTexture;
asset.SetTexture(texture);
wasModified = true;
BuildMainTreeView();
}
return;
}
case ResourceCategory.Unknown:
Debug.WriteLine($"Unknown Resource Category.");
break;
case ResourceCategory.ItemAnimation:
case ResourceCategory.BlockAnimation:
Animation animation = asset.GetDeserializedData(AnimationDeserializer.DefaultDeserializer);
string internalName = Path.GetFileNameWithoutExtension(asset.Filename);
IList<JsonTileInfo> textureInfos = resourceLocation.Category == ResourceCategory.ItemAnimation ? Tiles.ItemTileInfos : Tiles.BlockTileInfos;
string displayname = textureInfos.FirstOrDefault(p => p.InternalName == internalName)?.DisplayName ?? internalName;
if (resourceLocation.Category != ResourceCategory.ItemAnimation &&
resourceLocation.Category != ResourceCategory.BlockAnimation)
return;
Animation animation = asset.GetDeserializedData(AnimationDeserializer.DefaultDeserializer);
string internalName = Path.GetFileNameWithoutExtension(asset.Filename);
IList<JsonTileInfo> textureInfos = resourceLocation.Category switch
{
ResourceCategory.BlockAnimation => Tiles.BlockTileInfos,
ResourceCategory.ItemAnimation => Tiles.ItemTileInfos,
_ => Array.Empty<JsonTileInfo>().ToList()
};
string displayname = textureInfos.FirstOrDefault(p => p.InternalName == internalName)?.DisplayName ?? internalName;
string[] specialTileNames = { "clock", "compass" };
using (AnimationEditor animationEditor = new AnimationEditor(animation, displayname, internalName.ToLower().EqualsAny(specialTileNames)))
{
if (animationEditor.ShowDialog(this) == DialogResult.OK)
{
wasModified = true;
asset.SetSerializedData(animationEditor.Result, AnimationSerializer.DefaultSerializer);
BuildMainTreeView();
}
string[] specialTileNames = { "clock", "compass" };
using (AnimationEditor animationEditor = new AnimationEditor(animation, displayname, internalName.ToLower().EqualsAny(specialTileNames)))
{
if (animationEditor.ShowDialog(this) == DialogResult.OK)
{
wasModified = true;
asset.SetSerializedData(animationEditor.Result, AnimationSerializer.DefaultSerializer);
BuildMainTreeView();
}
}
break;
case ResourceCategory.ItemAtlas:
case ResourceCategory.BlockAtlas:
case ResourceCategory.ParticleAtlas:
case ResourceCategory.BannerAtlas:
case ResourceCategory.PaintingAtlas:
case ResourceCategory.ExplosionAtlas:
case ResourceCategory.ExperienceOrbAtlas:
case ResourceCategory.MoonPhaseAtlas:
case ResourceCategory.MapIconAtlas:
case ResourceCategory.AdditionalMapIconsAtlas:
Image img = asset.GetTexture();
var viewer = new TextureAtlasEditor(currentPCK, resourceLocation, img);
if (viewer.ShowDialog(this) == DialogResult.OK)
{
Image texture = viewer.FinalTexture;
asset.SetTexture(texture);
wasModified = true;
BuildMainTreeView();
}
break;
default:
Debug.WriteLine($"Unhandled Resource Category: {resourceLocation.Category}");
break;
}
}

View File

@@ -270,7 +270,6 @@
<Compile Include="Extensions\ImageSection.cs" />
<Compile Include="Extensions\ListExtensions.cs" />
<Compile Include="Extensions\MathExtensions.cs" />
<Compile Include="Extensions\PckFileExtensions.cs" />
<Compile Include="Forms\Additional-Popups\NumericPrompt.cs">
<SubType>Form</SubType>
</Compile>