Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 513 was 513, checked in by nicolasc, 16 years ago

added copyright notice
network still need to be done

File size: 3.9 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *
4 *
5 *   License notice:
6 *
7 *   This program is free software; you can redistribute it and/or
8 *   modify it under the terms of the GNU General Public License
9 *   as published by the Free Software Foundation; either version 2
10 *   of the License, or (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program; if not, write to the Free Software
19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 *
21 *   Author:
22 *      ...
23 *   Co-authors:
24 *      ...
25 *
26 */
27
28#include <string>
29#include <vector>
30#include <iostream>
31#include <algorithm>
32#include <iterator>
33
34#include "LevelLoader.h"
35#include "tinyxml/tinyxml.h"
36#include "orxonox/core/CoreIncludes.h"
37#include "orxonox/core/Error.h"
38#include "orxonox/objects/BaseObject.h"
39
40using namespace std;
41
42namespace loader
43{
44
45LevelLoader::LevelLoader(string file, string path)
46{
47        valid_ = false;
48
49        // Load XML level file
50        path.append("/");
51        path.append(file);
52
53        // Open xml file
54        doc.LoadFile(path);
55
56        // Check if file was loaded
57        if (doc.LoadFile())
58        {
59                TiXmlHandle hDoc(&doc);
60                TiXmlHandle hRoot(0);
61                TiXmlElement* pElem;
62
63                // Check for root element
64                pElem = hDoc.FirstChildElement("orxonoxworld").Element();
65                if (pElem)
66                {
67                        // Set root element
68                        hRoot = TiXmlHandle(pElem);
69                        rootElement = hRoot.Element();
70
71                        // Set level description
72                        pElem = hRoot.FirstChild("description").Element();
73                        if (pElem)
74                        {
75                                description_ = pElem->GetText();
76                        }
77
78                        // Set level name
79                        name_ = rootElement->Attribute("name");
80                        image_ = rootElement->Attribute("image");
81
82                        valid_ = true;
83                }
84                else
85                {
86                        orxonox::Error("Level file has no valid root node");
87                }
88        }
89        else
90        {
91                orxonox::Error("Could not load level file ");
92        }
93}
94
95        void LevelLoader::loadLevel()
96        {
97                if (valid_)
98                {
99                        TiXmlElement* loadElem;
100                        TiXmlElement* worldElem;
101                        TiXmlElement* tElem;
102                        TiXmlNode* tNode;
103
104
105                        // Set loading screen
106                        loadElem = rootElement->FirstChildElement("loading");
107                        if (loadElem)
108                        {
109                                // Set background
110                                tElem = loadElem->FirstChildElement("background");
111                                if (tElem)
112                                {
113                                        loadingBackgroundColor_ = tElem->Attribute("color");
114                                        loadingBackgroundImage_ = tElem->Attribute("image");
115                                }
116                                // Set bar
117                                tElem = loadElem->FirstChildElement("bar");
118                                if (tElem)
119                                {
120                                        loadingBarImage_ = tElem->Attribute("image");;
121                                        loadingBarTop_ = tElem->Attribute("top");
122                                        loadingBarLeft_ = tElem->Attribute("left");
123                                        loadingBarWidth_ = tElem->Attribute("width");
124                                        loadingBarHeight_ = tElem->Attribute("height");
125                                }
126                                showLoadingScreen();
127                        }
128
129                        // Load audio
130                        // TODO
131
132                        // Load scripts
133                        // TODO
134
135                        // Load world
136                        worldElem = rootElement->FirstChildElement("world");
137                        if (worldElem)
138                        {
139                                tNode = 0;
140                                while( tNode = worldElem->IterateChildren( tNode ) )
141                                {
142                                        tElem = tNode->ToElement();
143                                        orxonox::BaseObject* obj = ID(tElem->Value())->fabricate();
144                                        obj->loadParams(tElem);
145                                }
146                        }
147
148                        std::cout << "Loading finished!\n\n\n\n\n";
149                }
150        }
151
152        void LevelLoader::showLoadingScreen()
153        {
154                std::cout << "\n\n\nThis is Orxonox\nthe hottest 3D action shooter ever to exist\n\n\n";
155                std::cout << "Level: " << name() << "\nDescription:" << description() << "\nImage:"<<image()<<"\n\n\n";
156                std::cout << "Backgroundcolor: " << loadingBackgroundColor_ << "\nBackgroundimage:" << loadingBackgroundImage_ << "\n\n\n";
157        }
158
159        LevelLoader::~LevelLoader()
160        {
161
162        }
163
164
165        string LevelLoader::name()
166        {
167                return this->name_;
168        }
169
170        string LevelLoader::description()
171        {
172                return this->description_;
173        }
174
175        string LevelLoader::image()
176        {
177                return this->image_;
178        }
179
180
181}
182
Note: See TracBrowser for help on using the repository browser.