Skip to content

Commit

Permalink
Merge main into '3dSkinRenderer'
Browse files Browse the repository at this point in the history
  • Loading branch information
NessieHax committed Jun 30, 2024
2 parents 4d95586 + b057cb3 commit c1d7ce6
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 127 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
using System.Diagnostics;
using PckStudio.Internal.Skin;

namespace PckStudio.Popups
namespace PckStudio.Forms.Additional_Popups
{
public partial class AddNewSkin : MetroFramework.Forms.MetroForm
public partial class AddSkinPrompt : MetroFramework.Forms.MetroForm
{
public Skin NewSkin => newSkin;

private Skin newSkin;
private Random rng = new Random();

public AddNewSkin()
public AddSkinPrompt()
{
InitializeComponent();
newSkin = new Skin("", Resources.classic_template);
Expand Down
40 changes: 21 additions & 19 deletions PCK-Studio/Forms/Editor/TextureAtlasEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
using OMI.Workers.Color;

using PckStudio.Extensions;
using PckStudio.Internal;
using PckStudio.Internal.Deserializer;
using PckStudio.Internal.Json;
using PckStudio.Internal.Serializer;
Expand All @@ -54,7 +55,7 @@ public Image FinalTexture
private readonly Size _areaSize;
private readonly int _rowCount;
private readonly int _columnCount;
private readonly string _atlasType;
private readonly ResourceLocation _atlasType;
private readonly List<AtlasTile> _tiles;

private AtlasTile _selectedTile;
Expand Down Expand Up @@ -93,31 +94,32 @@ private int SelectedIndex

private const ImageLayoutDirection _imageLayout = ImageLayoutDirection.Horizontal;

public TextureAtlasEditor(PckFile pckFile, string path, Image atlas, Size areaSize)
public TextureAtlasEditor(PckFile pckFile, ResourceLocation resourceLocation, Image atlas)
{
InitializeComponent();

AcquireColorTable(pckFile);

_workingTexture = atlas;

_areaSize = areaSize;
_areaSize = resourceLocation.GetTileArea(atlas.Size);
_pckFile = pckFile;
_rowCount = atlas.Width / areaSize.Width;
_columnCount = atlas.Height / areaSize.Height;
(var tileInfos, _atlasType) = Path.GetFileNameWithoutExtension(path) switch
_rowCount = atlas.Width / _areaSize.Width;
_columnCount = atlas.Height / _areaSize.Height;
_atlasType = resourceLocation;
var tileInfos = resourceLocation.Category switch
{
"terrain" => (Tiles.BlockTileInfos, "blocks"),
"items" => (Tiles.ItemTileInfos, "items"),
"particles" => (Tiles.ParticleTileInfos, "particles"),
"mapicons" => (Tiles.MapIconTileInfos, "map_icons"),
"additionalmapicons" => (Tiles.AdditionalMapIconTileInfos, "additional_map_icons"),
"moon_phases" => (Tiles.MoonPhaseTileInfos, "moon_phases"),
"xporb" => (Tiles.ExperienceOrbTileInfos, "experience_orbs"),
"explosion" => (Tiles.ExplosionTileInfos, "explosions"),
"kz" => (Tiles.PaintingTileInfos, "paintings"),
"Banner_Atlas" => (Tiles.BannerTileInfos, "banners"),
_ => (null, null),
ResourceCategory.BlockAtlas => Tiles.BlockTileInfos,
ResourceCategory.ItemAtlas => Tiles.ItemTileInfos,
ResourceCategory.ParticleAtlas => Tiles.ParticleTileInfos,
ResourceCategory.MapIconAtlas => Tiles.MapIconTileInfos,
ResourceCategory.AdditionalMapIconsAtlas => Tiles.AdditionalMapIconTileInfos,
ResourceCategory.MoonPhaseAtlas => Tiles.MoonPhaseTileInfos,
ResourceCategory.ExperienceOrbAtlas => Tiles.ExperienceOrbTileInfos,
ResourceCategory.ExplosionAtlas => Tiles.ExplosionTileInfos,
ResourceCategory.PaintingAtlas => Tiles.PaintingTileInfos,
ResourceCategory.BannerAtlas => Tiles.BannerTileInfos,
_ => null,
};

originalPictureBox.Image = atlas.GetArea(new Rectangle(0, 0, atlas.Width, atlas.Height));
Expand Down Expand Up @@ -156,7 +158,7 @@ public TextureAtlasEditor(PckFile pckFile, string path, Image atlas, Size areaSi

SelectedIndex = 0;

bool isParticles = _atlasType == "particles";
bool isParticles = _atlasType.Category == ResourceCategory.ParticleAtlas;

// this is directly based on Java's source code for handling enchanted hits
// the particle is assigned a random grayscale color between roughly 154 and 230
Expand Down Expand Up @@ -239,7 +241,7 @@ private void SetImageDisplayed(int index)
selectTilePictureBox.BlendColor = GetBlendColor();
selectTilePictureBox.UseBlendColor = applyColorMaskToolStripMenuItem.Checked;

if (animationButton.Enabled = _atlasType == "blocks" || _atlasType == "items")
if (animationButton.Enabled = _atlasType.Category == ResourceCategory.BlockAtlas || _atlasType.Category == ResourceCategory.ItemAtlas)
{
PckAsset animationAsset;

Expand Down
12 changes: 11 additions & 1 deletion PCK-Studio/Internal/ResourceCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ internal enum ResourceCategory
{
Unknown = -1,
ItemAnimation,
BlockAnimation
BlockAnimation,
ItemAtlas,
BlockAtlas,
ParticleAtlas,
BannerAtlas,
PaintingAtlas,
ExplosionAtlas,
ExperienceOrbAtlas,
MoonPhaseAtlas,
MapIconAtlas,
AdditionalMapIconsAtlas,
}
}
93 changes: 89 additions & 4 deletions PCK-Studio/Internal/ResourceLocation.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,46 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PckStudio.Internal
{
internal class ResourceLocation
internal sealed class ResourceLocation
{
private static readonly Dictionary<string, ResourceLocation> _categoryLookUp = new Dictionary<string, ResourceLocation>()
{
["textures/items"] = new ResourceLocation("textures/items", ResourceCategory.ItemAnimation, 16, isGroup: true),
["textures/blocks"] = new ResourceLocation("textures/blocks", ResourceCategory.BlockAnimation, 16, isGroup: true),
["terrain.png"] = new ResourceLocation("terrain.png", ResourceCategory.BlockAtlas, 16),
["items.png"] = new ResourceLocation("items.png", ResourceCategory.ItemAtlas, 16),
["particles.png"] = new ResourceLocation("particles.png", ResourceCategory.ParticleAtlas, 16),
["item/banner/Banner_Atlas.png"] = new ResourceLocation("item/banner/Banner_Atlas.png", ResourceCategory.BannerAtlas, new Size(6, 7), TillingMode.Custom),
["art/kz.png"] = new ResourceLocation("art/kz.png", ResourceCategory.PaintingAtlas, 16),
["misc/explosion.png"] = new ResourceLocation("misc/explosion.png", ResourceCategory.ExplosionAtlas, 4),
["item/xporb.png"] = new ResourceLocation("item/xporb.png", ResourceCategory.ExperienceOrbAtlas, 4),
["terrain/moon_phases.png"] = new ResourceLocation("terrain/moon_phases.png", ResourceCategory.MoonPhaseAtlas, 4),
["misc/mapicons.png"] = new ResourceLocation("misc/mapicons.png", ResourceCategory.MapIconAtlas, 4),
["misc/additionalmapicons.png"] = new ResourceLocation("misc/additionalmapicons.png", ResourceCategory.AdditionalMapIconsAtlas, 4),
};

public static string GetPathFromCategory(ResourceCategory category)
{
return category switch
{
ResourceCategory.ItemAnimation => "res/textures/items",
ResourceCategory.BlockAnimation => "res/textures/blocks",
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",
_ => string.Empty
};
}
Expand All @@ -29,7 +56,65 @@ public static ResourceCategory GetCategoryFromPath(string path)
if (path.StartsWith("res/textures/blocks"))
return ResourceCategory.BlockAnimation;

return ResourceCategory.Unknown;
string categoryPath = path.Substring("res/".Length);
return _categoryLookUp.ContainsKey(categoryPath) ? _categoryLookUp[categoryPath].Category : ResourceCategory.Unknown;
}

public static ResourceLocation GetFromPath(string path)
{
if (string.IsNullOrWhiteSpace(path) || !path.StartsWith("res/"))
return null;
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;
}

public enum TillingMode
{
Width,
Height,
Custom
}

public readonly string Path;
public readonly ResourceCategory Category;
public readonly Size TillingFactor;
public readonly TillingMode TillingResolution;
public readonly bool IsGroup;

public Size GetTileArea(Size imgSize)
{
int tileFactorWidth = Math.Max(1, TillingFactor.Width);
int tileFactorHeight = Math.Max(1, TillingFactor.Height);
return TillingResolution switch
{
TillingMode.Width => new Size(imgSize.Width / tileFactorWidth, imgSize.Width / tileFactorHeight),
TillingMode.Height => new Size(imgSize.Height / tileFactorWidth, imgSize.Height / tileFactorHeight),
TillingMode.Custom => new Size(imgSize.Width / tileFactorWidth, imgSize.Height / tileFactorHeight),
_ => Size.Empty,
};
}

private ResourceLocation(string path, ResourceCategory category, int tillingFactor, TillingMode tillingResolution = TillingMode.Width, bool isGroup = false)
: this(path, category, new Size(tillingFactor, tillingFactor), tillingResolution, isGroup)
{
}

private ResourceLocation(string path, ResourceCategory category, Size tillingFactor, TillingMode tillingResolution = TillingMode.Width, bool isGroup = false)
{
Path = path;
Category = category;
TillingFactor = tillingFactor;
TillingResolution = tillingResolution;
IsGroup = isGroup;
}

public override string ToString()
{
return "res/" + Path;
}
}
}
Loading

0 comments on commit c1d7ce6

Please sign in to comment.