Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/script_engine/script_manager.cc @ 8537

Last change on this file since 8537 was 8408, checked in by bensch, 19 years ago

trunk: merged the script_engine branche back here
merged with command
svn merge https://svn.orxonox.net/orxonox/branches/script_engine . -r8284:HEAD
no conflicts

File size: 2.1 KB
Line 
1#include <string>
2#include <list>
3
4#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD
5
6
7#include "script_manager.h"
8#include "lunar.h"
9
10#include "class_list.h"
11
12#include "script.h"
13#include "script_trigger.h"
14#include "luaincl.h"
15#include "loading/load_param.h"
16#include "parser/tinyxml/tinyxml.h"
17
18
19
20ScriptManager::ScriptManager(const TiXmlElement* root)
21{
22  this->setName("ScriptManager");
23  this->scripts = NULL;
24  this->triggers = NULL;
25
26  if (root != NULL)
27    this->loadParams(root);
28}
29
30
31
32ScriptManager::~ScriptManager()
33{
34  this->flush();
35}
36
37
38void ScriptManager::loadParams(const TiXmlElement* root)
39{
40  BaseObject::loadParams(root);
41  {
42    LoadParamXML(root, "Scripts", this, ScriptManager, createScripts);
43
44    LoadParamXML(root, "ScriptTriggers", this, ScriptManager, createTriggers);
45  } // make shure that the loading process is finished
46
47  // fill the scripts and triggers (doing that on runtime is very slow!)
48  getTriggers();
49  getScripts();
50}
51
52
53
54void  ScriptManager::flush()
55{
56  //Delete all scripts as they aren't deleted automatically
57  if(this->getScripts())
58    while(!scripts->empty())
59      delete scripts->front();
60}
61
62void  ScriptManager::createScripts(const TiXmlElement* scripts)
63{
64
65  LOAD_PARAM_START_CYCLE(scripts, object);
66  {
67    new Script(object);
68  }
69  LOAD_PARAM_END_CYCLE(object);
70
71}
72
73void ScriptManager::createTriggers(const TiXmlElement* triggers)
74{
75  LOAD_PARAM_START_CYCLE(triggers, object);
76  {
77    new ScriptTrigger(object);
78  }
79  LOAD_PARAM_END_CYCLE(object);
80
81}
82
83
84Script* ScriptManager::getScriptByFile(const std::string& file)
85{
86  if(getScripts())
87    for(std::list<BaseObject*>::const_iterator it = scripts->begin(); it != scripts->end(); it++ )
88    {
89      if( (dynamic_cast<Script*>(*it))->getFileName().compare(file) == 0)
90      {
91        return dynamic_cast<Script*>(*it);
92      }
93    }
94
95  return NULL;
96
97}
98
99
100bool ScriptManager::getScripts()
101{
102  return (this->scripts != NULL || (this->scripts = ClassList::getList(CL_SCRIPT)) != NULL);
103}
104
105bool ScriptManager::getTriggers()
106{
107  return (this->triggers != NULL || (this->triggers = ClassList::getList(CL_SCRIPT_TRIGGER)) != NULL);
108}
109
110
111
Note: See TracBrowser for help on using the repository browser.