Added path validity check and catch.

This commit is contained in:
Harrison Deng 2018-12-29 01:10:25 -06:00
parent 5c3e060d14
commit d154f1f749

View File

@ -24,6 +24,7 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
int powLimit;
Node masterNode;
Dictionary<string, ImageHandler> imageHandlersDictionary;
Dictionary<string, NinePatchData> ninePatchDictionary;
int tpl;
int TexturePowerLength { get { return tpl; } set { TextureLength = (int)Math.Pow(2, value); tpl = value; } }
public int TextureLength { get; private set; }
@ -37,7 +38,15 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
internal TexturePacker(string rootDirectoryPath, int powLimit = 12, int startingPower = 8)
{
this.powLimit = powLimit;
string[] paths = Directory.GetFiles(rootDirectoryPath);
string[] paths;
try
{
paths = Directory.GetFiles(rootDirectoryPath);
} catch (DirectoryNotFoundException)
{
throw new ArgumentException("Path " + rootDirectoryPath + " couldn't be found.");
}
TexturePowerLength = startingPower;
List<ImageHandler> imageHandlers = new List<ImageHandler>();
int minAreaRequired = 0;
@ -54,6 +63,15 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
TexturePowerLength++;
}
}
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);
}
}
}
imageHandlers.Sort();
this.imageHandlersDictionary = new Dictionary<string, ImageHandler>();
@ -88,10 +106,14 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
imageHandlerQueue.Clear();
Build(AutoCorrectAtlasSize);
}
if (ninePatchDictionary.ContainsKey(imageHandler.Name))
{
imageHandler.ninePatchData = ninePatchDictionary[imageHandler.Name];
}
}
}
/// <summary>
/// Renders the build into a PNG file and generates the respective <see cref="TextureAtlasData"/> meant for serialization and later to be loaded.
/// </summary>