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.
/// </summary>
/// <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>
/// Check if given argument is viable for command.

View File

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