1 #include "AnimationGraphFactory.h"
2 
3 namespace animation
4 {
5 
AnimationGraphFactory()6 	AnimationGraphFactory::AnimationGraphFactory()
7 	{
8 	}
9 
createGraph(const std::string & _filename)10 	AnimationGraph* AnimationGraphFactory::createGraph(const std::string& _filename)
11 	{
12 		AnimationGraph* result = nullptr;
13 
14 		MyGUI::xml::Document doc;
15 		if (doc.open(_filename))
16 		{
17 			MyGUI::xml::Element* root = doc.getRoot();
18 			if (root)
19 			{
20 				result = new AnimationGraph(root->findAttribute("name"));
21 
22 				MyGUI::xml::ElementEnumerator data = root->getElementEnumerator();
23 				while (data.next())
24 				{
25 					if (data->getName() == "Node")
26 					{
27 						IAnimationNode* node = mNodeFactory.createNode(data->findAttribute("type"), data->findAttribute("name"), result);
28 						result->addNode(node);
29 
30 						MyGUI::xml::ElementEnumerator prop = data->getElementEnumerator();
31 						while (prop.next("Property"))
32 						{
33 							std::string key = prop->findAttribute("key");
34 							std::string value = prop->findAttribute("value");
35 
36 							node->setProperty(key, value);
37 						}
38 					}
39 					else if (data->getName() == "Connection")
40 					{
41 						IAnimationNode* from_node = result->getNodeByName(data->findAttribute("from"));
42 						IAnimationNode* to_node = result->getNodeByName(data->findAttribute("to"));
43 
44 						MyGUI::xml::ElementEnumerator point = data->getElementEnumerator();
45 						while (point.next("Point"))
46 						{
47 							from_node->addConnection(
48 								point->findAttribute("from"),
49 								to_node,
50 								point->findAttribute("to"));
51 						}
52 					}
53 				}
54 			}
55 		}
56 
57 		return result;
58 	}
59 
60 } // namespace animation
61