/// <summary>
/// Read the AAML file
/// </summary>
public void Read()
{
var AAMLFile = new XmlDocument();
try
{
AAMLFile.Load(AAMLFileName);
}
catch (IOException)
{
throw new IOException(
String.Format(
"The animation file with name '{0}' could not be loaded. The most common causes for this error are " +
"either the path was misspelled, or the 'Copy to Output Directory' property of your setup file " +
"is not set to 'Copy if newer'. To change this in VS, right click on your setup file in the solution " +
"explorer, select properties, and change the 'Copy to Output Directory' property to 'Copy if newer'.",
AAMLFileName
)
);
}
XmlElement root;
if (AAMLFile.ChildNodes.Count < 2)
{
throw new AAMLSyntaxException(
String.Format("No root node in AAML file '{0}'.", AAMLFileName));
}
root = AAMLFile.ChildNodes[1] as XmlElement;
if (root == null)
{
throw new AAMLSyntaxException(
String.Format("No root node in AAML file '{0}'.", AAMLFileName));
}
var rootChildrenElementsOnly = new List <XmlElement>(
from child in root.ChildNodes.Cast <XmlNode>()
where child is XmlElement
select(XmlElement) child);
if (rootChildrenElementsOnly.Count < 2)
{
throw new AAMLSyntaxException(
String.Format("Invalid root node in AAML file '{0}'. Requires at least " +
"two nodes for 'SpriteSheet' and 'AnimationMap'.", AAMLFileName));
}
var first = rootChildrenElementsOnly[0];
var second = rootChildrenElementsOnly[1];
XmlElement spriteSheet, animationMap;
if (first.Name == SPRITE_SHEET && second.Name == ANIMATION_MAP)
{
spriteSheet = first;
animationMap = second;
}
else if (second.Name == SPRITE_SHEET && first.Name == ANIMATION_MAP)
{
spriteSheet = second;
animationMap = first;
}
else
{
throw new AAMLSyntaxException(
String.Format("Invalid AAML file '{0}'. Expected a SpriteSheet " +
"element and an AnimationMap element.", AAMLFileName));
}
var sheetReader = new SpriteSheetReader(spriteSheet);
var mapReader = new AnimationMapReader(animationMap);
sheetReader.Load();
mapReader.Load();
Map = new AnimationMap(mapReader.States, sheetReader.Sheet, mapReader.InitState);
}