From fd4f2f7124c059d35c8f896fc6f484a1ccfce14a Mon Sep 17 00:00:00 2001 From: Harrison Deng Date: Sat, 29 Dec 2018 00:29:53 -0600 Subject: [PATCH] Cleaned up code. --- .../CommandProcessor/EngineCommand.cs | 5 +--- .../TextureAtlasTools/TexturePacker.cs | 24 +++++++------------ 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/RecrownedAthenaeum.ConsoleTools/CommandProcessor/EngineCommand.cs b/RecrownedAthenaeum.ConsoleTools/CommandProcessor/EngineCommand.cs index 2fd9d27..4a272cd 100644 --- a/RecrownedAthenaeum.ConsoleTools/CommandProcessor/EngineCommand.cs +++ b/RecrownedAthenaeum.ConsoleTools/CommandProcessor/EngineCommand.cs @@ -52,10 +52,7 @@ namespace RecrownedAthenaeum.Tools.CommandProcessor /// Runs the command. /// /// arguments to be used. May be null. - public virtual void Run(string[] arguments = null) - { - - } + public abstract void Run(string[] arguments = null); /// /// Check if given argument is viable for command. diff --git a/RecrownedAthenaeum.ConsoleTools/TextureAtlasTools/TexturePacker.cs b/RecrownedAthenaeum.ConsoleTools/TextureAtlasTools/TexturePacker.cs index d3b2410..9136c7c 100644 --- a/RecrownedAthenaeum.ConsoleTools/TextureAtlasTools/TexturePacker.cs +++ b/RecrownedAthenaeum.ConsoleTools/TextureAtlasTools/TexturePacker.cs @@ -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 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; } } /// /// 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 imageHandlerQueue = new Queue(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 atlasTexture = new Image(textureLength, textureLength)) + using (Image atlasTexture = new Image(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;