Cleaned up code.

This commit is contained in:
Harrison Deng 2018-12-29 00:29:53 -06:00
parent eedc083e03
commit fd4f2f7124
2 changed files with 10 additions and 19 deletions

View File

@ -52,10 +52,7 @@ namespace RecrownedAthenaeum.Tools.CommandProcessor
/// Runs the command. /// Runs the command.
/// </summary> /// </summary>
/// <param name="arguments">arguments to be used. May be null.</param> /// <param name="arguments">arguments to be used. May be null.</param>
public virtual void Run(string[] arguments = null) public abstract void Run(string[] arguments = null);
{
}
/// <summary> /// <summary>
/// Check if given argument is viable for command. /// Check if given argument is viable for command.

View File

@ -9,11 +9,12 @@ using SixLabors.ImageSharp.Processing;
using SixLabors.Primitives; using SixLabors.Primitives;
using System.Linq; using System.Linq;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Runtime.InteropServices;
namespace RecrownedAthenaeum.Tools.TextureAtlas namespace RecrownedAthenaeum.Tools.TextureAtlas
{ {
public class TexturePacker : IDisposable public class TexturePacker
{ {
private enum SupportedExtensions private enum SupportedExtensions
{ {
@ -23,10 +24,9 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
int powLimit; int powLimit;
Node masterNode; Node masterNode;
Dictionary<string, ImageHandler> imageHandlersDictionary; Dictionary<string, ImageHandler> imageHandlersDictionary;
int textureLength;
int tpl; int tpl;
int TexturePowerLength { get { return tpl; } set { textureLength = (int)Math.Pow(2, value); tpl = value; } } int TexturePowerLength { get { return tpl; } set { TextureLength = (int)Math.Pow(2, value); tpl = value; } }
public int TextureLength { get { return textureLength; } } public int TextureLength { get; private set; }
public int TexturesFound { get { return imageHandlersDictionary.Count; } } public int TexturesFound { get { return imageHandlersDictionary.Count; } }
/// <summary> /// <summary>
/// Machine to pack multiple textures into one large texture. /// Machine to pack multiple textures into one large texture.
@ -49,7 +49,7 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
ImageHandler image = new ImageHandler(paths[pathID]); ImageHandler image = new ImageHandler(paths[pathID]);
imageHandlers.Add(image); imageHandlers.Add(image);
minAreaRequired += image.Area; minAreaRequired += image.Area;
while (minAreaRequired > textureLength*textureLength) while (minAreaRequired > TextureLength*TextureLength)
{ {
TexturePowerLength++; TexturePowerLength++;
} }
@ -70,8 +70,8 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
public void Build(bool AutoCorrectAtlasSize = true) public void Build(bool AutoCorrectAtlasSize = true)
{ {
masterNode = new Node(); masterNode = new Node();
masterNode.region.Width = textureLength; masterNode.region.Width = TextureLength;
masterNode.region.Height = textureLength; masterNode.region.Height = TextureLength;
Queue<ImageHandler> imageHandlerQueue = new Queue<ImageHandler>(imageHandlersDictionary.Values); Queue<ImageHandler> imageHandlerQueue = new Queue<ImageHandler>(imageHandlersDictionary.Values);
ImageHandler imageHandler; ImageHandler imageHandler;
while (imageHandlerQueue.TryDequeue(out imageHandler)) while (imageHandlerQueue.TryDequeue(out imageHandler))
@ -82,7 +82,7 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
{ {
if (!AutoCorrectAtlasSize || TexturePowerLength + 1 > powLimit) if (!AutoCorrectAtlasSize || TexturePowerLength + 1 > powLimit)
{ {
throw new InvalidOperationException("Texture not large enough. Current size: " + textureLength + "x" + textureLength + "."); throw new InvalidOperationException("Texture not large enough. Current size: " + TextureLength + "x" + TextureLength + ".");
} }
TexturePowerLength += 1; TexturePowerLength += 1;
imageHandlerQueue.Clear(); imageHandlerQueue.Clear();
@ -103,7 +103,7 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
TextureAtlasData.TextureAtlasRegion[] regions = new TextureAtlasData.TextureAtlasRegion[imageHandlersDictionary.Count]; TextureAtlasData.TextureAtlasRegion[] regions = new TextureAtlasData.TextureAtlasRegion[imageHandlersDictionary.Count];
using (Image<Rgba32> atlasTexture = new Image<Rgba32>(textureLength, textureLength)) using (Image<Rgba32> atlasTexture = new Image<Rgba32>(TextureLength, TextureLength))
{ {
ImageHandler[] imageHandlers = this.imageHandlersDictionary.Values.ToArray(); ImageHandler[] imageHandlers = this.imageHandlersDictionary.Values.ToArray();
@ -145,12 +145,6 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
imageHandlersDictionary[fileName].ninePatchData = null; imageHandlersDictionary[fileName].ninePatchData = null;
} }
public void Dispose()
{
ImageHandler[] imageHandlers = this.imageHandlersDictionary.Values.ToArray();
this.imageHandlersDictionary.Clear();
}
private class Node private class Node
{ {
public Node parent; public Node parent;