Minor cleanup and fixes. Now automatically removes "-texture" suffix.
This commit is contained in:
parent
3e5b838abe
commit
d5c898d081
@ -162,6 +162,7 @@ namespace RecrownedAthenaeum.Tools.CommandProcessor
|
|||||||
for (int i = 0; i < commandArguments.Length; i++)
|
for (int i = 0; i < commandArguments.Length; i++)
|
||||||
{
|
{
|
||||||
helpBuilder.Append(commandArguments[i].invokeString);
|
helpBuilder.Append(commandArguments[i].invokeString);
|
||||||
|
if (commandArguments[i].required) helpBuilder.Append('*');
|
||||||
if (i == commandArguments.Length - 2)
|
if (i == commandArguments.Length - 2)
|
||||||
{
|
{
|
||||||
helpBuilder.Append(", and ");
|
helpBuilder.Append(", and ");
|
||||||
@ -172,6 +173,7 @@ namespace RecrownedAthenaeum.Tools.CommandProcessor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
helpBuilder.Append('.');
|
helpBuilder.Append('.');
|
||||||
|
helpBuilder.AppendLine(" [* are required arguments.]");
|
||||||
}
|
}
|
||||||
return helpBuilder.ToString();
|
return helpBuilder.ToString();
|
||||||
}
|
}
|
||||||
|
@ -47,11 +47,12 @@ namespace RecrownedAthenaeum.Tools.NinePatchTools
|
|||||||
|
|
||||||
NinePatchData npData = new NinePatchData(Path.GetFileName(imagePath), leftBound, rightBound, bottomBound, topBound);
|
NinePatchData npData = new NinePatchData(Path.GetFileName(imagePath), leftBound, rightBound, bottomBound, topBound);
|
||||||
string serialized = JsonConvert.SerializeObject(npData, Formatting.Indented);
|
string serialized = JsonConvert.SerializeObject(npData, Formatting.Indented);
|
||||||
|
string modifiedPath = Directory.GetParent(imagePath) + Path.PathSeparator.ToString() + Path.GetFileNameWithoutExtension(imagePath) + "-texture" + Path.GetExtension(imagePath);
|
||||||
File.Move(imagePath, Path.GetFileNameWithoutExtension(imagePath) + "-texture" + Path.GetExtension(imagePath));
|
File.Move(imagePath, modifiedPath);
|
||||||
File.WriteAllText(outPath + ".9p", serialized);
|
File.WriteAllText(outPath + ".9p", serialized);
|
||||||
|
|
||||||
ConsoleUtilities.WriteWrappedLine("Done. Written to \"" + outPath + "\" with values: left = " + leftBound + " right = " + rightBound + " top = " + topBound + " bottom = " + bottomBound);
|
ConsoleUtilities.WriteWrappedLine("Done. Written to \"" + outPath + "\" with values: left = " + leftBound + " right = " + rightBound + " top = " + topBound + " bottom = " + bottomBound);
|
||||||
|
ConsoleUtilities.WriteWrappedLine("Image renamed to: " + Path.GetFileName(modifiedPath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,12 +22,12 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
|
|||||||
|
|
||||||
int powLimit;
|
int powLimit;
|
||||||
Node masterNode;
|
Node masterNode;
|
||||||
Dictionary<string, ImageHandler> imageHandlersDictionary;
|
List<ImageHandler> imageHandlers;
|
||||||
Dictionary<string, NinePatchData> ninePatchDictionary;
|
Dictionary<string, NinePatchData> ninePatchDictionary;
|
||||||
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; private set; }
|
public int TextureLength { get; private set; }
|
||||||
public int TexturesFound { get { return imageHandlersDictionary.Count; } }
|
public int TexturesFound { get { return imageHandlers.Count; } }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Machine to pack multiple textures into one large texture.
|
/// Machine to pack multiple textures into one large texture.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -52,8 +52,9 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
|
|||||||
for (int pathID = 0; pathID < paths.Length; pathID++)
|
for (int pathID = 0; pathID < paths.Length; pathID++)
|
||||||
{
|
{
|
||||||
SupportedExtensions extension;
|
SupportedExtensions extension;
|
||||||
if (Enum.TryParse<SupportedExtensions>(Path.GetExtension(paths[pathID]).ToLower().Substring(1), out extension))
|
if (Enum.TryParse(Path.GetExtension(paths[pathID]).ToLower().Substring(1), out extension))
|
||||||
{
|
{
|
||||||
|
ConsoleUtilities.WriteWrappedLine("Reading texture data for: " + paths[pathID]);
|
||||||
ImageHandler image = new ImageHandler(paths[pathID]);
|
ImageHandler image = new ImageHandler(paths[pathID]);
|
||||||
imageHandlers.Add(image);
|
imageHandlers.Add(image);
|
||||||
minAreaRequired += image.Area;
|
minAreaRequired += image.Area;
|
||||||
@ -72,11 +73,7 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
imageHandlers.Sort();
|
imageHandlers.Sort();
|
||||||
this.imageHandlersDictionary = new Dictionary<string, ImageHandler>();
|
this.imageHandlers = imageHandlers;
|
||||||
foreach (ImageHandler imageHandler in imageHandlers)
|
|
||||||
{
|
|
||||||
this.imageHandlersDictionary.Add(imageHandler.Name, imageHandler);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -88,7 +85,7 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
|
|||||||
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>(imageHandlers);
|
||||||
ImageHandler imageHandler;
|
ImageHandler imageHandler;
|
||||||
while (imageHandlerQueue.TryDequeue(out imageHandler))
|
while (imageHandlerQueue.TryDequeue(out imageHandler))
|
||||||
{
|
{
|
||||||
@ -104,9 +101,14 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
|
|||||||
imageHandlerQueue.Clear();
|
imageHandlerQueue.Clear();
|
||||||
Build(AutoCorrectAtlasSize);
|
Build(AutoCorrectAtlasSize);
|
||||||
}
|
}
|
||||||
if (ninePatchDictionary != null && ninePatchDictionary.ContainsKey(imageHandler.Name))
|
if (ninePatchDictionary != null && ninePatchDictionary.ContainsKey(imageHandler.name))
|
||||||
{
|
{
|
||||||
imageHandler.ninePatchData = ninePatchDictionary[imageHandler.Name];
|
NinePatchData npd = ninePatchDictionary[imageHandler.name];
|
||||||
|
imageHandler.ninePatchData = npd;
|
||||||
|
if (npd.textureName.Contains("-texture"))
|
||||||
|
{
|
||||||
|
imageHandler.name = imageHandler.name.Remove(imageHandler.name.IndexOf("-texture"), 8);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,11 +123,11 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
|
|||||||
{
|
{
|
||||||
GraphicsOptions gOptions = new GraphicsOptions();
|
GraphicsOptions gOptions = new GraphicsOptions();
|
||||||
|
|
||||||
TextureAtlasData.AtlasRegionData[] regions = new TextureAtlasData.AtlasRegionData[imageHandlersDictionary.Count];
|
TextureAtlasData.AtlasRegionData[] regions = new TextureAtlasData.AtlasRegionData[TexturesFound];
|
||||||
|
|
||||||
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.imageHandlers.ToArray();
|
||||||
|
|
||||||
for (int i = 0; i < imageHandlers.Length; i++)
|
for (int i = 0; i < imageHandlers.Length; i++)
|
||||||
{
|
{
|
||||||
@ -133,8 +135,8 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
|
|||||||
ImageHandler ih = imageHandlers[i];
|
ImageHandler ih = imageHandlers[i];
|
||||||
regions[i].SetBounds(ih.x, ih.y, ih.Width, ih.Height);
|
regions[i].SetBounds(ih.x, ih.y, ih.Width, ih.Height);
|
||||||
regions[i].ninePatchData = ih.ninePatchData;
|
regions[i].ninePatchData = ih.ninePatchData;
|
||||||
regions[i].ninePatchData.textureName = null;
|
if (regions[i].ninePatchData != null) regions[i].ninePatchData.textureName = null;
|
||||||
regions[i].name = Path.GetFileNameWithoutExtension(ih.Name);
|
regions[i].name = Path.GetFileNameWithoutExtension(ih.name);
|
||||||
using (Image<Rgba32> image = Image.Load<Rgba32>(ih.path))
|
using (Image<Rgba32> image = Image.Load<Rgba32>(ih.path))
|
||||||
{
|
{
|
||||||
atlasTexture.Mutate(img => img.DrawImage(gOptions, image, new Point(ih.x, ih.y)));
|
atlasTexture.Mutate(img => img.DrawImage(gOptions, image, new Point(ih.x, ih.y)));
|
||||||
@ -152,14 +154,26 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
|
|||||||
|
|
||||||
public void SetNinePatch(string fileName, int a, int b, int c, int d)
|
public void SetNinePatch(string fileName, int a, int b, int c, int d)
|
||||||
{
|
{
|
||||||
ImageHandler imageHandler = imageHandlersDictionary[fileName];
|
|
||||||
NinePatchData ninePatchData = new NinePatchData(fileName, a, b, c, d);
|
NinePatchData ninePatchData = new NinePatchData(fileName, a, b, c, d);
|
||||||
imageHandler.ninePatchData = ninePatchData;
|
RetrieveImageHandler(fileName).ninePatchData = ninePatchData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveNinePatch(string fileName)
|
public void RemoveNinePatch(string name)
|
||||||
{
|
{
|
||||||
imageHandlersDictionary[fileName].ninePatchData = null;
|
|
||||||
|
RetrieveImageHandler(name).ninePatchData = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ImageHandler RetrieveImageHandler(string name)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < TexturesFound; i++)
|
||||||
|
{
|
||||||
|
if (imageHandlers[i].name == name)
|
||||||
|
{
|
||||||
|
return imageHandlers[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new ArgumentException("Couldn't find texture with name: " + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Node
|
private class Node
|
||||||
@ -247,15 +261,16 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
|
|||||||
public readonly string path;
|
public readonly string path;
|
||||||
public readonly IImageInfo image;
|
public readonly IImageInfo image;
|
||||||
public int Area { get { return image.Width * image.Height; } }
|
public int Area { get { return image.Width * image.Height; } }
|
||||||
public string Name { get { return Path.GetFileName(path); } }
|
public string name;
|
||||||
public int Width { get { return image.Width; } }
|
public int Width { get { return image.Width; } }
|
||||||
public int Height { get { return image.Height; } }
|
public int Height { get { return image.Height; } }
|
||||||
public int x, y;
|
public int x, y;
|
||||||
public NinePatchData ninePatchData;
|
public NinePatchData ninePatchData;
|
||||||
|
|
||||||
internal ImageHandler(String path)
|
internal ImageHandler(string path)
|
||||||
{
|
{
|
||||||
this.path = path;
|
this.path = path;
|
||||||
|
name = Path.GetFileName(path);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (FileStream stream = new FileStream(path, FileMode.Open))
|
using (FileStream stream = new FileStream(path, FileMode.Open))
|
||||||
|
@ -7,7 +7,8 @@ namespace RecrownedAthenaeum.Tools.TextureAtlasTools
|
|||||||
{
|
{
|
||||||
class TexturePackerCommand : EngineCommand
|
class TexturePackerCommand : EngineCommand
|
||||||
{
|
{
|
||||||
|
private const int DMP = 9;
|
||||||
|
private const int DSP = 6;
|
||||||
public TexturePackerCommand() : base("texturepacker")
|
public TexturePackerCommand() : base("texturepacker")
|
||||||
{
|
{
|
||||||
help = "Packs a given directory composed of png and jpg files into an atlas. Can also add 9patch properties. Images with the associated \".9p\" files will automatically be defined in the resulting .tatlas file, but can be overwritten by use of the \"-9p\" argument.";
|
help = "Packs a given directory composed of png and jpg files into an atlas. Can also add 9patch properties. Images with the associated \".9p\" files will automatically be defined in the resulting .tatlas file, but can be overwritten by use of the \"-9p\" argument.";
|
||||||
@ -16,8 +17,8 @@ namespace RecrownedAthenaeum.Tools.TextureAtlasTools
|
|||||||
new EngineCommandArgument("-i", "for input directory containing the textures.", true),
|
new EngineCommandArgument("-i", "for input directory containing the textures.", true),
|
||||||
new EngineCommandArgument("-o", "Path for output files. Points to non-existent file. Will create texture and definitions file with name.", true),
|
new EngineCommandArgument("-o", "Path for output files. Points to non-existent file. Will create texture and definitions file with name.", true),
|
||||||
new EngineCommandArgument("-9p", "Can be used multiple times for defining a 9patch. This parameter requires a name, left patch, right patch, top patch, and bottom patch in the format \"name,a,b,c,d\"."),
|
new EngineCommandArgument("-9p", "Can be used multiple times for defining a 9patch. This parameter requires a name, left patch, right patch, top patch, and bottom patch in the format \"name,a,b,c,d\"."),
|
||||||
new EngineCommandArgument("-sp", "Starting power for one side of the texture. Default is 8."),
|
new EngineCommandArgument("-sp", "Starting power for one side of the texture. Default is " + DSP + "."),
|
||||||
new EngineCommandArgument("-mp", "Maximum power for one side of the texture. Default is 8."),
|
new EngineCommandArgument("-mp", "Maximum power for one side of the texture. Default is " + DMP + "."),
|
||||||
new EngineCommandArgument("-dau", "Disables automatically upscaling the texture."),
|
new EngineCommandArgument("-dau", "Disables automatically upscaling the texture."),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -27,8 +28,8 @@ namespace RecrownedAthenaeum.Tools.TextureAtlasTools
|
|||||||
|
|
||||||
TexturePacker texturePacker = null;
|
TexturePacker texturePacker = null;
|
||||||
string path = null;
|
string path = null;
|
||||||
int mp = 9;
|
int mp = DMP;
|
||||||
int sp = 6;
|
int sp = DSP;
|
||||||
bool dau = false;
|
bool dau = false;
|
||||||
string output = null;
|
string output = null;
|
||||||
|
|
||||||
@ -48,7 +49,7 @@ namespace RecrownedAthenaeum.Tools.TextureAtlasTools
|
|||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
ConsoleUtilities.WriteWrappedLine("Please enter a valid starting power of two of the lengths of the resulting texture atlas. Leave blank for default of " + sp + ".");
|
ConsoleUtilities.WriteWrappedLine("Please enter a valid starting power of two for the lengths of the resulting texture atlas. Leave blank for default of " + sp + ".");
|
||||||
input = Console.ReadLine();
|
input = Console.ReadLine();
|
||||||
if (input == "q") return;
|
if (input == "q") return;
|
||||||
if (input.Length == 0) break;
|
if (input.Length == 0) break;
|
||||||
|
Loading…
Reference in New Issue
Block a user