Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

corrected mistakes

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