Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/loader/LevelLoader.cc @ 474

Last change on this file since 474 was 474, checked in by nicolape, 16 years ago
File size: 4.5 KB
Line 
1#include <string.h>
2#include <iostream>
3
4#include "LevelLoader.h"
5#include "tinyxml/tinyxml.h"
6#include "orxonox/core/IdentifierIncludes.h"
7
8using namespace std;
9
10namespace loader
11{
12
13LevelLoader::LevelLoader(string file, string dir)
14{
15        // Load XML level file
16        dir.append("/");
17        dir.append(file);       
18       
19        // Open xml file
20        TiXmlDocument doc(file);
21
22        // Check if file was loaded
23        if (doc.LoadFile())
24        {
25                TiXmlHandle hDoc(&doc);
26                TiXmlHandle hRoot(0);   
27
28                TiXmlElement* pElem;
29               
30
31                // Check for root element
32                pElem = hDoc.FirstChildElement("orxonoxworld").Element();
33                if (pElem)
34                {
35                        // Set root element
36                        hRoot = TiXmlHandle(pElem);
37
38                        // Set level description
39                        pElem = hRoot.FirstChild("description").Element();
40                        if (pElem)
41                        {
42                                description_ = pElem->GetText();       
43                        }
44                       
45                        // Set level name
46                        pElem = hRoot.Element();
47                        name_ = pElem->Attribute("name");
48                        image_ = pElem->Attribute("image");
49                       
50                        // Set loading screen
51                        pElem = hRoot.FirstChild("loading").Element();
52                        if (pElem)
53                        {
54                                // Set background
55                                pElem = hRoot.FirstChild("loading").FirstChild("background").Element();
56                                if (pElem)
57                                {
58                                        loadingBackgroundColor_ = pElem->Attribute("color");
59                                        loadingBackgroundImage_ = pElem->Attribute("image");
60                                }
61                                // Set bar
62                                pElem = hRoot.FirstChild("loading").FirstChild("bar").Element();
63                                if (pElem)
64                                {
65                                        loadingBarImage_ = pElem->Attribute("image");;
66                                        loadingBarTop_ = pElem->Attribute("top");
67                                        loadingBarLeft_ = pElem->Attribute("left");
68                                        loadingBarWidth_ = pElem->Attribute("width");
69                                        loadingBarHeight_ = pElem->Attribute("height");
70                                }
71                        }
72                                               
73                       
74                }
75                else
76                {
77                        std::string err = "Level file has no valid root node";
78                        std::cout << err << std::endl;
79                }       
80        }
81        else
82        {
83                std::string err = "Could not load level file ";
84                err.append(file); 
85                std::cout << err << std::endl;
86        }       
87       
88       
89        //orxonox::BaseObject* bla = orxonox::ID("classname")->fabricate();
90        //bla->loadParams();
91       
92       
93        /*
94        rootNode = XMLNode::openFileHelper(dir.c_str(),"orxonoxworld");
95        // TODO: Error handling
96
97        // Assing general level infos to class variables
98       
99        this->name_ = rootNode.getAttribute("name");
100        this->image_ = rootNode.getAttribute("image");
101        this->description_ = rootNode.getChildNode("description").getText();
102 
103        loadingScreenNode = rootNode.getChildNode("loading");
104        if (!loadingScreenNode.isEmpty())
105        {
106                this->showLoadingScreen();
107        }
108
109        worldNode = rootNode.getChildNode("world");
110        if (!worldNode.isEmpty())
111        {
112               
113        }
114        */
115
116 
117  /*
118  // Assign sub-nodes
119  if (rootNode.nChildNode("LightManager")==1)
120  {
121        // Init Luightmanager...
122  }*/
123 
124  /*
125 
126        worldNode = rootNode.getChildNode("WorldEntities");
127        scriptNode = rootNode.getChildNode("ScriptManager");
128        cameraNode = rootNode.getChildNode("CameraMan");
129        lightNode = rootNode.getChildNode("LightManager");
130*/
131
132}
133
134LevelLoader::~LevelLoader()
135{
136
137
138}
139
140
141string LevelLoader::name()
142{
143        return this->name_;
144}
145
146string LevelLoader::description()
147{
148        return this->description_;
149}
150
151string LevelLoader::image()
152{
153        return this->image_;
154}
155
156void LevelLoader::showLoadingScreen()
157{
158        cout << "\n\n\nThis is Orxonox\nthe hottest 3D action shooter ever to exist\n\n\n";
159        cout << "Level: " << name() << "\nDescription:" << description() << "\nImage:"<<image()<<"\n\n\n";
160}
161
162/*
163
164
165void LevelLoader::loadWorld(WorldManager* wm)
166{
167        if (!worldNode.getChildNode("lights").isEmpty())
168        {
169               
170               
171        }
172}
173
174
175void LevelLoader::loadLights(LightManager* lm)
176{
177        if (!lightNode.getChildNode("lights").isEmpty())
178        {
179                int nLights = lightNode.getChildNode("lights").nChildNode("light");
180                for (int i=0; i<nLights;i++)
181                {
182                        XMLNode t = lightNode.getChildNode("lights").getChildNode("light",i);
183                        const char* diffuse = t.getAttribute("diffuse-color");
184                        const char* coor = t.getAttribute("abs-coor");
185                        lm->addLight(diffuse,coor);     
186                }
187        }
188        lm->setAmbient(lightNode.getChildNode("ambient").getAttribute("color"));       
189}
190
191void LevelLoader::loadCameras(CameraManager* cm)
192{
193        if (!cameraNode.getChildNode("cameras").isEmpty())
194        {
195                int nCameras = cameraNode.getChildNode("cameras").nChildNode("camera");
196                for (int i=0; i<nCameras;i++)
197                {
198                        XMLNode t = cameraNode.getChildNode("cameras").getChildNode("camera",i);
199                       
200                       
201                        cm->addCamera();
202                }
203        }
204}
205
206
207void LevelLoader::loadScripts(ScriptManager* sm)
208{
209        if (!scriptNode.getChildNode("scripts").isEmpty())
210        {
211                int nScripts = scriptNode.getChildNode("scripts").nChildNode("script");
212                for (int i=0; i<nScripts;i++)
213                {
214                        XMLNode t = scriptNode.getChildNode("scripts").getChildNode("script",i);
215                        sm->addScript(t.getAttribute("file"));
216                }
217       
218        }
219}
220*/
221
222
223}
224
Note: See TracBrowser for help on using the repository browser.