Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 507 was 507, checked in by nicolape, 16 years ago
  • Skybox and ambient light load now from level file sample.oxw. Added objects to and methods to parse this tags. Added a tokenizer function to split strings into smaller strings (for reading out the light colours for examle). Moved Tokenizer and String2number into misc directory. deleted old unised xml class
File size: 3.1 KB
Line 
1#include <string>
2#include <vector>
3#include <iostream>
4#include <algorithm>
5#include <iterator>
6
7#include "LevelLoader.h"
8#include "tinyxml/tinyxml.h"
9#include "orxonox/core/CoreIncludes.h"
10#include "orxonox/core/Error.h"
11#include "orxonox/objects/BaseObject.h"
12
13using namespace std;
14
15namespace loader
16{
17
18LevelLoader::LevelLoader(string file, string path)
19{
20        valid_ = false;
21       
22        // Load XML level file
23        path.append("/");
24        path.append(file);     
25       
26        // Open xml file
27        doc.LoadFile(path);
28
29        // Check if file was loaded
30        if (doc.LoadFile())
31        {
32                TiXmlHandle hDoc(&doc);
33                TiXmlHandle hRoot(0);           
34                TiXmlElement* pElem;
35
36                // Check for root element
37                pElem = hDoc.FirstChildElement("orxonoxworld").Element();
38                if (pElem)
39                {
40                        // Set root element
41                        hRoot = TiXmlHandle(pElem);
42                        rootElement = hRoot.Element();
43
44                        // Set level description
45                        pElem = hRoot.FirstChild("description").Element();
46                        if (pElem)
47                        {
48                                description_ = pElem->GetText();       
49                        }
50                       
51                        // Set level name
52                        name_ = rootElement->Attribute("name");
53                        image_ = rootElement->Attribute("image");
54                       
55                        valid_ = true;
56                }
57                else
58                {
59                        orxonox::Error("Level file has no valid root node");
60                }       
61        }
62        else
63        {
64                orxonox::Error("Could not load level file ");
65        }       
66}
67
68        void LevelLoader::loadLevel()
69        {
70                if (valid_)
71                {
72                        TiXmlElement* loadElem;
73                        TiXmlElement* worldElem;
74                        TiXmlElement* tElem;
75                        TiXmlNode* tNode;
76                       
77                       
78                        // Set loading screen
79                        loadElem = rootElement->FirstChildElement("loading");
80                        if (loadElem)
81                        {
82                                // Set background
83                                tElem = loadElem->FirstChildElement("background");
84                                if (tElem)
85                                {
86                                        loadingBackgroundColor_ = tElem->Attribute("color");
87                                        loadingBackgroundImage_ = tElem->Attribute("image");
88                                }
89                                // Set bar
90                                tElem = loadElem->FirstChildElement("bar");
91                                if (tElem)
92                                {
93                                        loadingBarImage_ = tElem->Attribute("image");;
94                                        loadingBarTop_ = tElem->Attribute("top");
95                                        loadingBarLeft_ = tElem->Attribute("left");
96                                        loadingBarWidth_ = tElem->Attribute("width");
97                                        loadingBarHeight_ = tElem->Attribute("height");
98                                }
99                                showLoadingScreen();
100                        }
101                       
102                        // Load audio
103                        // TODO
104                       
105                        // Load scripts
106                        // TODO
107                       
108                        // Load world
109                        worldElem = rootElement->FirstChildElement("world");
110                        if (worldElem)
111                        {       
112                                tNode = 0;
113                                while( tNode = worldElem->IterateChildren( tNode ) )
114                                {
115                                        tElem = tNode->ToElement();
116                                        orxonox::BaseObject* obj = ID(tElem->Value())->fabricate();
117                                        obj->loadParams(tElem);
118                                }                       
119                        }
120                       
121                        std::cout << "Loading finished!\n\n\n\n\n";                                             
122                }
123        }
124       
125        void LevelLoader::showLoadingScreen()
126        {
127                std::cout << "\n\n\nThis is Orxonox\nthe hottest 3D action shooter ever to exist\n\n\n";
128                std::cout << "Level: " << name() << "\nDescription:" << description() << "\nImage:"<<image()<<"\n\n\n";
129                std::cout << "Backgroundcolor: " << loadingBackgroundColor_ << "\nBackgroundimage:" << loadingBackgroundImage_ << "\n\n\n";
130        }
131       
132        LevelLoader::~LevelLoader()
133        {
134
135        }
136       
137       
138        string LevelLoader::name()
139        {
140                return this->name_;
141        }
142       
143        string LevelLoader::description()
144        {
145                return this->description_;
146        }
147       
148        string LevelLoader::image()
149        {
150                return this->image_;
151        }
152
153
154}
155
Note: See TracBrowser for help on using the repository browser.