Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 5, 2006, 3:47:10 PM (18 years ago)
Author:
snellen
Message:

this won't compile

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/script_engine/src/lib/script_engine/script_manager.cc

    r8138 r8155  
    44#include "script.h"
    55#include "script_manager.h"
     6#include "lunar.h"
    67
    78
    8 ScriptManager::ScriptManager(std::string& world)
     9ScriptManager::ScriptManager()
    910{
    10   this->init(world);
    11 
     11  this->init();
    1212}
    1313
     
    2727}
    2828
     29void ScriptManager::loadParams(const TiXmlElement* root)
     30{
     31  //BaseObject::loadParams(root);
    2932
    30 //!< Fills the worldObject list
     33  const TiXmlElement* scripts = root->FirstChildElement("Scripts");
    3134
    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  }
    3443
    3544
    3645}
    3746
    38 
    39 
    40 void ScriptManager::loadParams(const TiXmlElement* root)
    41 {
    42   //BaseObject::loadParams(root);
    43 
    44 
    45 }
    46 
    47 
    4847void ScriptManager::tick(float timestep)
    49 {
    50 }
    51 
    52 void ScriptManager::changeWorld(std::string& newWorld)
    5348{
    5449}
     
    5752void ScriptManager::initScripts()
    5853{
     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
    5964}
    6065
    6166
     67void  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
     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>::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>::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.