XmlScriptsFile.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "core/Logger.h"
  2. #include "core/ScriptManager.h"
  3. #include "core/XmlScriptsFile.h"
  4. XmlScriptsFile::XmlScriptsFile( const Ogre::String& file ):
  5. XmlFile( file )
  6. {
  7. }
  8. XmlScriptsFile::~XmlScriptsFile()
  9. {
  10. }
  11. void
  12. XmlScriptsFile::LoadScripts()
  13. {
  14. TiXmlNode* node = m_File.RootElement();
  15. if( node == NULL || node->ValueStr() != "scripts" )
  16. {
  17. LOG_ERROR( m_File.ValueStr() + " is not a valid scripts file! No <scripts> in root." );
  18. return;
  19. }
  20. node = node->FirstChild();
  21. ScriptManager &script_manager(ScriptManager::getSingleton());
  22. while( node != NULL )
  23. {
  24. if( node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "script" )
  25. {
  26. script_manager.RunFile( GetString( node, "file" ) );
  27. }
  28. else if( node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "system_script" )
  29. {
  30. Ogre::String name = GetString( node, "name" );
  31. if( name == "" )
  32. {
  33. LOG_ERROR( "There is no name specified for <system_script> tag." );
  34. continue;
  35. }
  36. script_manager.AddEntity( ScriptManager::SYSTEM, name, NULL );
  37. }
  38. node = node->NextSibling();
  39. }
  40. }