private void LoadValuesFromSource()
{
if (!string.IsNullOrEmpty(this._sourceField))
{
_sourceField = _sourceField.Replace("/", "\\");
tileset xts = null;
try
{
xts = FileManager.XmlDeserialize<tileset>(_sourceField);
}
catch (FileNotFoundException)
{
string fileAttemptedToLoad = _sourceField;
if (FileManager.IsRelative(_sourceField))
{
fileAttemptedToLoad = FileManager.RelativeDirectory + _sourceField;
}
string message = "Could not find the shared tsx file \n" + fileAttemptedToLoad +
"\nIf this is a relative file name, then the loader will use " +
"the FileManager's RelativeDirectory to make the file absolute. Therefore, be sure to set the FileManger's RelativeDirectory to the file represented by " +
"this fileset before setting this property if setting this property manually.";
throw new FileNotFoundException(message);
}
if (xts.image != null)
{
Images = new TilesetImage[xts.image.Length];
Parallel.For(0, xts.image.Length, count =>
{
this.Images[count] = new TilesetImage
{
Source = xts.image[count].source,
height = xts.image[count].height != 0 ? xts.image[count].height : xts.tileheight,
width = xts.image[count].width != 0 ? xts.image[count].width : xts.tilewidth
};
});
}
this.Name = xts.name;
this.Margin = xts.margin;
this.Spacing = xts.spacing;
this.Tileheight = xts.tileheight;
this.Tilewidth = xts.tilewidth;
this.Tiles = xts.tile;
}
}