Changeset 8155 in orxonox.OLD for branches/script_engine/src/lib/script_engine/script_manager.cc
- Timestamp:
- Jun 5, 2006, 3:47:10 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/script_engine/src/lib/script_engine/script_manager.cc
r8138 r8155 4 4 #include "script.h" 5 5 #include "script_manager.h" 6 #include "lunar.h" 6 7 7 8 8 ScriptManager::ScriptManager( std::string& world)9 ScriptManager::ScriptManager() 9 10 { 10 this->init(world); 11 11 this->init(); 12 12 } 13 13 … … 27 27 } 28 28 29 void ScriptManager::loadParams(const TiXmlElement* root) 30 { 31 //BaseObject::loadParams(root); 29 32 30 //!< Fills the worldObject list 33 const TiXmlElement* scripts = root->FirstChildElement("Scripts"); 31 34 32 void ScriptManager::init(std::string& world) 33 { 35 if( element == NULL) 36 { 37 PRINTF(1)("ScriptManager is missing 'Scripts'\n"); 38 } 39 else 40 { 41 createScriptList(scripts); 42 } 34 43 35 44 36 45 } 37 46 38 39 40 void ScriptManager::loadParams(const TiXmlElement* root)41 {42 //BaseObject::loadParams(root);43 44 45 }46 47 48 47 void ScriptManager::tick(float timestep) 49 {50 }51 52 void ScriptManager::changeWorld(std::string& newWorld)53 48 { 54 49 } … … 57 52 void ScriptManager::initScripts() 58 53 { 54 for(std::list<LuaScript>::iterator it = scriptList.begin(); it != scriptList.end(); it++ ) 55 { 56 (*it).script.loadFile((*it).name); 57 } 58 } 59 60 void ScriptManager::init() 61 { 62 currentWorld.assign(""); 63 59 64 } 60 65 61 66 67 void ScriptManager::createScriptList(TiXmlElement* scripts) 68 { 69 const TiXmlElement* script = scripts->FirstChildElement(); 70 const TiXmlElement* object; 71 72 PRINTF(4)("Creating scriptlist\n"); 73 74 while( script != NULL) 75 { 76 LoadParam(script, "file", this, ScriptManager, setCurrentScriptFile) 77 .describe("the fileName of the script, that should be loaded into this world") 78 .defaultValues(""); 79 80 if(!currentScript.name.empty()) // if LoadParam didn't fail... fill the object list with the needed objects 81 { 82 object = script->FirstChildElement("object"); 83 84 while(object != NULL) 85 { 86 addObjectToScript(object->Value(), currentScript); 87 object = object->NextSiblingElement("object"); 88 } 89 90 scriptList.push_back(currentScript); 91 } 92 93 script = script->NextSiblingElement("Script"); 94 95 } 96 97 98 } 99 100 void ScriptManager::setCurrentScriptFile(std::string& file) 101 { 102 if( !fileIsInScriptList(file) ) 103 currentScript.name = file; 104 else 105 currentScript.name.assign(""); 106 } 107 108 void ScriptManager::addObjectToScript(std::string& object, LuaScript& script) 109 { 110 if(!objectIsInObjectList(object,script)) 111 script.objectList.push_back(object); 112 } 113 114 115 bool ScriptManager::fileIsInScriptList(std::string& file) 116 { 117 for(std::list<LuaScript>::iterator it = scriptList.begin(); it != scriptList.end(); it++ ) 118 { 119 if( (*it).name.compare(file) == 0) 120 { 121 return true; 122 } 123 } 124 return false; 125 } 126 127 128 bool ScriptManager::objectIsInObjectList(std::string& object, const LuaScript& script) 129 { 130 for(std::list<std::string>::iterator it = script.objectList.begin(); it != script.objectList.end(); it++ ) 131 { 132 if( (*it).compare(object) == 0) 133 { 134 return true; 135 } 136 } 137 return false; 138 } 139 140
Note: See TracChangeset
for help on using the changeset viewer.