Added path validity check and catch.
This commit is contained in:
parent
5c3e060d14
commit
d154f1f749
@ -24,6 +24,7 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
|
|||||||
int powLimit;
|
int powLimit;
|
||||||
Node masterNode;
|
Node masterNode;
|
||||||
Dictionary<string, ImageHandler> imageHandlersDictionary;
|
Dictionary<string, ImageHandler> imageHandlersDictionary;
|
||||||
|
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; }
|
||||||
@ -37,7 +38,15 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
|
|||||||
internal TexturePacker(string rootDirectoryPath, int powLimit = 12, int startingPower = 8)
|
internal TexturePacker(string rootDirectoryPath, int powLimit = 12, int startingPower = 8)
|
||||||
{
|
{
|
||||||
this.powLimit = powLimit;
|
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;
|
TexturePowerLength = startingPower;
|
||||||
List<ImageHandler> imageHandlers = new List<ImageHandler>();
|
List<ImageHandler> imageHandlers = new List<ImageHandler>();
|
||||||
int minAreaRequired = 0;
|
int minAreaRequired = 0;
|
||||||
@ -49,11 +58,20 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
|
|||||||
ImageHandler image = new ImageHandler(paths[pathID]);
|
ImageHandler image = new ImageHandler(paths[pathID]);
|
||||||
imageHandlers.Add(image);
|
imageHandlers.Add(image);
|
||||||
minAreaRequired += image.Area;
|
minAreaRequired += image.Area;
|
||||||
while (minAreaRequired > TextureLength*TextureLength)
|
while (minAreaRequired > TextureLength * TextureLength)
|
||||||
{
|
{
|
||||||
TexturePowerLength++;
|
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();
|
imageHandlers.Sort();
|
||||||
this.imageHandlersDictionary = new Dictionary<string, ImageHandler>();
|
this.imageHandlersDictionary = new Dictionary<string, ImageHandler>();
|
||||||
@ -88,8 +106,12 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
|
|||||||
imageHandlerQueue.Clear();
|
imageHandlerQueue.Clear();
|
||||||
Build(AutoCorrectAtlasSize);
|
Build(AutoCorrectAtlasSize);
|
||||||
}
|
}
|
||||||
|
if (ninePatchDictionary.ContainsKey(imageHandler.Name))
|
||||||
|
{
|
||||||
|
imageHandler.ninePatchData = ninePatchDictionary[imageHandler.Name];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user