Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/script_engine/src/lib/script_engine/script_manager.cc @ 8157

Last change on this file since 8157 was 8157, checked in by snellen, 18 years ago

this won't compile

File size: 2.6 KB
Line 
1#include <string>
2#include <list>
3
4#include "script.h"
5#include "script_manager.h"
6#include "lunar.h"
7
8
9ScriptManager::ScriptManager()
10{
11  this->init();
12}
13
14ScriptManager::~ScriptManager()
15{
16
17
18}
19
20ScriptManager* ScriptManager::getInstance()
21{
22
23  if (!ScriptManager::singletonRef)
24    ScriptManager::singletonRef = new ScriptManager();
25  return ScriptManager::singletonRef;
26
27}
28
29void ScriptManager::loadParams(const TiXmlElement* root)
30{
31  //BaseObject::loadParams(root);
32
33  const TiXmlElement* scripts = root->FirstChildElement("Scripts");
34
35  if( scripts == NULL)
36  {
37    PRINTF(1)("ScriptManager is missing 'Scripts'\n");
38  }
39  else
40  {
41    createScriptList(scripts);
42  }
43
44
45}
46
47void ScriptManager::tick(float timestep)
48{
49}
50
51
52void ScriptManager::initScripts()
53{
54  for(std::list<LuaScript>::iterator it = scriptList.begin(); it != scriptList.end(); it++ )
55  {
56    (*it).script.loadFile((*it).name);
57  }
58}
59
60void ScriptManager::init()
61{
62  currentWorld.assign("");
63
64}
65
66
67void  ScriptManager::createScriptList(const 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
100void  ScriptManager::setCurrentScriptFile(std::string& file)
101 {
102   if( !fileIsInScriptList(file) )
103     currentScript.name = file;
104   else
105     currentScript.name.assign("");
106 }
107
108void  ScriptManager::addObjectToScript(std::string& object, LuaScript& script)
109{
110  if(!objectIsInObjectList(object,script))
111    script.objectList.push_back(object);
112}
113
114
115bool ScriptManager::fileIsInScriptList(std::string& file)
116{
117  for(std::list<LuaScript>::const_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
128bool ScriptManager::objectIsInObjectList(std::string& object, const LuaScript& script)
129{
130  for(std::list<std::string>::const_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 TracBrowser for help on using the repository browser.