From 82db7a22bca7158601e28631f51a8c74f2733635 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Sat, 30 Nov 2024 10:18:02 +0100 Subject: [PATCH 1/4] ResourceLocation - Add 'Unknown' ResourceLocation instance & improved 'ResourceLocation.GetFromPath' --- PCK-Studio/Internal/ResourceLocation.cs | 45 ++++++------- PCK-Studio/MainForm.cs | 86 +++++++++++++------------ 2 files changed, 68 insertions(+), 63 deletions(-) diff --git a/PCK-Studio/Internal/ResourceLocation.cs b/PCK-Studio/Internal/ResourceLocation.cs index e83992d8..89b9601b 100644 --- a/PCK-Studio/Internal/ResourceLocation.cs +++ b/PCK-Studio/Internal/ResourceLocation.cs @@ -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 ResourceGroups = new List(); + private static readonly ResourceLocation Unknown = new ResourceLocation(string.Empty, ResourceCategory.Unknown, 1); + private static readonly Dictionary _categoryLookUp = new Dictionary() { ["textures/items"] = new ResourceLocation("textures/items", ResourceCategory.ItemAnimation, 16, isGroup: true), @@ -43,37 +47,32 @@ namespace PckStudio.Internal { return category switch { - ResourceCategory.ItemAnimation => "res/textures/items", - ResourceCategory.BlockAnimation => "res/textures/blocks", - 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.ItemAnimation => _categoryLookUp["textures/items"].ToString(), + ResourceCategory.BlockAnimation => _categoryLookUp["textures/blocks"].ToString(), + 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 +113,8 @@ namespace PckStudio.Internal TillingFactor = tillingFactor; Tilling = tilling; IsGroup = isGroup; + if (isGroup) + ResourceGroups.Add(this); } public override string ToString() diff --git a/PCK-Studio/MainForm.cs b/PCK-Studio/MainForm.cs index 315629a7..3c9d651a 100644 --- a/PCK-Studio/MainForm.cs +++ b/PCK-Studio/MainForm.cs @@ -457,50 +457,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 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 textureInfos = resourceLocation.Category switch - { - ResourceCategory.BlockAnimation => Tiles.BlockTileInfos, - ResourceCategory.ItemAnimation => Tiles.ItemTileInfos, - _ => Array.Empty().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; } } From ababe8c5f678d848714156270b4c0e347bf385dc Mon Sep 17 00:00:00 2001 From: PhoenixARC <46140834+PhoenixARC@users.noreply.github.com> Date: Sun, 15 Dec 2024 09:24:33 -0500 Subject: [PATCH 2/4] Add update counter to README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a4ea5003..fdd65e4f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# PCK Studio +# PCK Studio ![GitHub All Releases](https://img.shields.io/github/downloads/PhoenixARC/-PCK-Studio/total?label=Total%20Downloads&logo=github) Modify .PCK archives as you please.
> **If you have any issues or would like to suggested a feature, we encourage you to [open a new issue on Github](https://github.com/PhoenixARC/-PCK-Studio/issues).** @@ -59,4 +59,4 @@ $ cd PCK-Studio ## Contributors > [yaboiFoxx](https://github.com/yaboiFoxx) for Improved UI concept
-> [XxModZxXWiiPlaza](https://github.com/XxModZxXWiiPlaza)
\ No newline at end of file +> [XxModZxXWiiPlaza](https://github.com/XxModZxXWiiPlaza)
From da633f52b01ed7132e07190a89a950f9e6ffa040 Mon Sep 17 00:00:00 2001 From: EternalModz <86510009+EternalModz@users.noreply.github.com> Date: Sat, 21 Dec 2024 11:29:36 -0800 Subject: [PATCH 3/4] Added some more stats Updated the header with a few more stats for GitHub. (Stars, forks, etc.) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fdd65e4f..256c49e1 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -# PCK Studio ![GitHub All Releases](https://img.shields.io/github/downloads/PhoenixARC/-PCK-Studio/total?label=Total%20Downloads&logo=github) -Modify .PCK archives as you please.
+# PCK Studio ![GitHub All Releases](https://img.shields.io/github/downloads/PhoenixARC/-PCK-Studio/total?label=Total%20Downloads&logo=github) ![GitHub Stars](https://img.shields.io/github/stars/PhoenixARC/-PCK-Studio?label=Stars&logo=github) ![GitHub Forks](https://img.shields.io/github/forks/PhoenixARC/-PCK-Studio?label=Forks&logo=github) ![GitHub Issues](https://img.shields.io/github/issues/PhoenixARC/-PCK-Studio?label=Open%20Issues&logo=github) ![GitHub Pull Requests](https://img.shields.io/github/issues-pr/PhoenixARC/-PCK-Studio?label=Pull%20Requests&logo=github) +Modify .PCK archives as you please.
> **If you have any issues or would like to suggested a feature, we encourage you to [open a new issue on Github](https://github.com/PhoenixARC/-PCK-Studio/issues).** From 66a641fd56c899af44f8cf1261ed71b6ed2a915c Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Tue, 24 Dec 2024 13:14:22 +0100 Subject: [PATCH 4/4] MainForm - Disable 'Skins.pck' creation upon creating a new skin pack --- PCK-Studio/MainForm.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PCK-Studio/MainForm.cs b/PCK-Studio/MainForm.cs index 3c9d651a..0e4cba47 100644 --- a/PCK-Studio/MainForm.cs +++ b/PCK-Studio/MainForm.cs @@ -1524,7 +1524,7 @@ namespace PckStudio namePrompt.OKButtonText = "Ok"; if (namePrompt.ShowDialog(this) == DialogResult.OK) { - currentPCK = InitializePack(new Random().Next(8000, int.MaxValue), 0, namePrompt.NewText, true); + currentPCK = InitializePack(new Random().Next(8000, int.MaxValue), 0, namePrompt.NewText, false); MarkTemplateFile(); LoadEditorTab(); }