Performed basic tests and fixed 9patch and texturepacker.
This commit is contained in:
@@ -10,6 +10,7 @@ using SixLabors.Primitives;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace RecrownedAthenaeum.Tools.TextureAtlas
|
||||
{
|
||||
@@ -41,11 +42,11 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
|
||||
string[] paths;
|
||||
try
|
||||
{
|
||||
paths = Directory.GetFiles(rootDirectoryPath);
|
||||
|
||||
} catch (DirectoryNotFoundException)
|
||||
paths = Directory.GetFiles(rootDirectoryPath);
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
throw new ArgumentException("Path " + rootDirectoryPath + " couldn't be found.");
|
||||
throw new ArgumentException("Path " + rootDirectoryPath + " couldn't be resolved.");
|
||||
}
|
||||
TexturePowerLength = startingPower;
|
||||
List<ImageHandler> imageHandlers = new List<ImageHandler>();
|
||||
@@ -66,11 +67,10 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
|
||||
else if (Path.GetExtension(paths[pathID]).ToLower() == ".9p")
|
||||
{
|
||||
if (ninePatchDictionary == null) ninePatchDictionary = new Dictionary<string, NinePatchData>();
|
||||
using (StreamReader streamReader = new StreamReader(paths[pathID]))
|
||||
{
|
||||
NinePatchData npData = JsonConvert.DeserializeObject<NinePatchData>(streamReader.ReadLine());
|
||||
ninePatchDictionary.Add(npData.textureName, npData);
|
||||
}
|
||||
ConsoleUtilities.WriteWrappedLine("Reading ninepatch data for: " + paths[pathID]);
|
||||
string serialized = File.ReadAllText(paths[pathID]);
|
||||
NinePatchData npData = JsonConvert.DeserializeObject<NinePatchData>(serialized);
|
||||
ninePatchDictionary.Add(npData.textureName, npData);
|
||||
}
|
||||
}
|
||||
imageHandlers.Sort();
|
||||
@@ -148,11 +148,7 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
|
||||
}
|
||||
}
|
||||
string serialized = JsonConvert.SerializeObject(new TextureAtlasData(atlasName + ".png", regions), Formatting.Indented);
|
||||
|
||||
using (StreamWriter stream = new StreamWriter(output + "/" + atlasName + ".tatlas"))
|
||||
{
|
||||
stream.WriteLine(serialized);
|
||||
}
|
||||
File.WriteAllText(output + "/" + atlasName + ".tatlas", serialized);
|
||||
}
|
||||
|
||||
public void SetNinePatch(string fileName, int a, int b, int c, int d)
|
||||
@@ -261,9 +257,15 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
|
||||
internal ImageHandler(String path)
|
||||
{
|
||||
this.path = path;
|
||||
using (FileStream stream = new FileStream(path, FileMode.Open))
|
||||
try
|
||||
{
|
||||
image = Image.Identify(stream);
|
||||
using (FileStream stream = new FileStream(path, FileMode.Open))
|
||||
{
|
||||
image = Image.Identify(stream);
|
||||
}
|
||||
} catch (SecurityException)
|
||||
{
|
||||
throw new ArgumentException("Security exception occurred for image: " + path);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -13,7 +13,7 @@ namespace RecrownedAthenaeum.Tools.TextureAtlasTools
|
||||
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.";
|
||||
arguments = new[] {
|
||||
commandArguments = new[] {
|
||||
new EngineCommandArgument("-interactive", "runs in interactive mode. Ninepatches must still be defined with arguments or previously defined with associated \".9p\" files. Other arguments will be ignored."),
|
||||
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),
|
||||
@@ -41,12 +41,12 @@ namespace RecrownedAthenaeum.Tools.TextureAtlasTools
|
||||
ConsoleUtilities.WriteWrappedLine("Please enter path of folder containing the textures to be packed.");
|
||||
input = Console.ReadLine();
|
||||
if (input == "q") return;
|
||||
path = input;
|
||||
path = input.Replace("\"", "");
|
||||
|
||||
ConsoleUtilities.WriteWrappedLine("Please enter output path of file name.");
|
||||
input = Console.ReadLine();
|
||||
if (input == "q") return;
|
||||
output = input;
|
||||
output = input.Replace("\"", "");
|
||||
|
||||
do
|
||||
{
|
||||
@@ -70,8 +70,14 @@ namespace RecrownedAthenaeum.Tools.TextureAtlasTools
|
||||
int indexOfInputArg = IndexOfArgumentIn("-i", arguments);
|
||||
if (indexOfInputArg + 1 >= arguments.Length) throw new ArgumentException("-i is not followed by input path.");
|
||||
path = arguments[1 + IndexOfArgumentIn("-i", arguments)];
|
||||
int.TryParse(arguments[IndexOfArgumentIn("-mp", arguments) + 1], out mp);
|
||||
int.TryParse(arguments[IndexOfArgumentIn("-sp", arguments) + 1], out sp);
|
||||
if (HasArgument("-mp", arguments))
|
||||
{
|
||||
int.TryParse(arguments[IndexOfArgumentIn("-mp", arguments) + 1], out mp);
|
||||
}
|
||||
if (HasArgument("-sp", arguments))
|
||||
{
|
||||
int.TryParse(arguments[IndexOfArgumentIn("-sp", arguments) + 1], out sp);
|
||||
}
|
||||
int indexOfOutputArg = IndexOfArgumentIn("-o", arguments);
|
||||
if (indexOfOutputArg + 1 >= arguments.Length) throw new ArgumentException("-o is not followed by input path.");
|
||||
output = arguments[IndexOfArgumentIn("-o", arguments) + 1];
|
||||
|
Reference in New Issue
Block a user