[513] | 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 | |
---|
[507] | 28 | #include <string> |
---|
| 29 | #include <vector> |
---|
[164] | 30 | #include <iostream> |
---|
[507] | 31 | #include <algorithm> |
---|
| 32 | #include <iterator> |
---|
[164] | 33 | |
---|
| 34 | #include "LevelLoader.h" |
---|
[471] | 35 | #include "tinyxml/tinyxml.h" |
---|
[496] | 36 | #include "orxonox/core/CoreIncludes.h" |
---|
[480] | 37 | #include "orxonox/core/Error.h" |
---|
| 38 | #include "orxonox/objects/BaseObject.h" |
---|
[164] | 39 | |
---|
| 40 | using namespace std; |
---|
| 41 | |
---|
| 42 | namespace loader |
---|
| 43 | { |
---|
| 44 | |
---|
[480] | 45 | LevelLoader::LevelLoader(string file, string path) |
---|
[164] | 46 | { |
---|
[480] | 47 | valid_ = false; |
---|
[513] | 48 | |
---|
[164] | 49 | // Load XML level file |
---|
[480] | 50 | path.append("/"); |
---|
[513] | 51 | path.append(file); |
---|
| 52 | |
---|
[474] | 53 | // Open xml file |
---|
[480] | 54 | doc.LoadFile(path); |
---|
[474] | 55 | |
---|
| 56 | // Check if file was loaded |
---|
| 57 | if (doc.LoadFile()) |
---|
[471] | 58 | { |
---|
[474] | 59 | TiXmlHandle hDoc(&doc); |
---|
[513] | 60 | TiXmlHandle hRoot(0); |
---|
[474] | 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); |
---|
[480] | 69 | rootElement = hRoot.Element(); |
---|
[474] | 70 | |
---|
| 71 | // Set level description |
---|
| 72 | pElem = hRoot.FirstChild("description").Element(); |
---|
| 73 | if (pElem) |
---|
| 74 | { |
---|
[513] | 75 | description_ = pElem->GetText(); |
---|
[474] | 76 | } |
---|
[513] | 77 | |
---|
[474] | 78 | // Set level name |
---|
[480] | 79 | name_ = rootElement->Attribute("name"); |
---|
| 80 | image_ = rootElement->Attribute("image"); |
---|
[513] | 81 | |
---|
[480] | 82 | valid_ = true; |
---|
| 83 | } |
---|
| 84 | else |
---|
| 85 | { |
---|
| 86 | orxonox::Error("Level file has no valid root node"); |
---|
[513] | 87 | } |
---|
[480] | 88 | } |
---|
| 89 | else |
---|
| 90 | { |
---|
| 91 | orxonox::Error("Could not load level file "); |
---|
[513] | 92 | } |
---|
[480] | 93 | } |
---|
| 94 | |
---|
| 95 | void LevelLoader::loadLevel() |
---|
| 96 | { |
---|
| 97 | if (valid_) |
---|
| 98 | { |
---|
| 99 | TiXmlElement* loadElem; |
---|
| 100 | TiXmlElement* worldElem; |
---|
| 101 | TiXmlElement* tElem; |
---|
| 102 | TiXmlNode* tNode; |
---|
[513] | 103 | |
---|
| 104 | |
---|
[474] | 105 | // Set loading screen |
---|
[480] | 106 | loadElem = rootElement->FirstChildElement("loading"); |
---|
| 107 | if (loadElem) |
---|
[474] | 108 | { |
---|
| 109 | // Set background |
---|
[480] | 110 | tElem = loadElem->FirstChildElement("background"); |
---|
| 111 | if (tElem) |
---|
[474] | 112 | { |
---|
[480] | 113 | loadingBackgroundColor_ = tElem->Attribute("color"); |
---|
| 114 | loadingBackgroundImage_ = tElem->Attribute("image"); |
---|
[474] | 115 | } |
---|
| 116 | // Set bar |
---|
[480] | 117 | tElem = loadElem->FirstChildElement("bar"); |
---|
| 118 | if (tElem) |
---|
[474] | 119 | { |
---|
[480] | 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"); |
---|
[474] | 125 | } |
---|
[480] | 126 | showLoadingScreen(); |
---|
[474] | 127 | } |
---|
[513] | 128 | |
---|
[480] | 129 | // Load audio |
---|
| 130 | // TODO |
---|
[513] | 131 | |
---|
[480] | 132 | // Load scripts |
---|
| 133 | // TODO |
---|
[513] | 134 | |
---|
[480] | 135 | // Load world |
---|
| 136 | worldElem = rootElement->FirstChildElement("world"); |
---|
| 137 | if (worldElem) |
---|
[513] | 138 | { |
---|
[480] | 139 | tNode = 0; |
---|
| 140 | while( tNode = worldElem->IterateChildren( tNode ) ) |
---|
| 141 | { |
---|
| 142 | tElem = tNode->ToElement(); |
---|
[496] | 143 | orxonox::BaseObject* obj = ID(tElem->Value())->fabricate(); |
---|
[480] | 144 | obj->loadParams(tElem); |
---|
[513] | 145 | } |
---|
[480] | 146 | } |
---|
[513] | 147 | |
---|
| 148 | std::cout << "Loading finished!\n\n\n\n\n"; |
---|
[474] | 149 | } |
---|
[471] | 150 | } |
---|
[513] | 151 | |
---|
[480] | 152 | void LevelLoader::showLoadingScreen() |
---|
[471] | 153 | { |
---|
[480] | 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 | } |
---|
[513] | 158 | |
---|
[507] | 159 | LevelLoader::~LevelLoader() |
---|
| 160 | { |
---|
| 161 | |
---|
| 162 | } |
---|
[513] | 163 | |
---|
| 164 | |
---|
[507] | 165 | string LevelLoader::name() |
---|
[164] | 166 | { |
---|
[507] | 167 | return this->name_; |
---|
[164] | 168 | } |
---|
[513] | 169 | |
---|
[507] | 170 | string LevelLoader::description() |
---|
[164] | 171 | { |
---|
[507] | 172 | return this->description_; |
---|
[164] | 173 | } |
---|
[513] | 174 | |
---|
[507] | 175 | string LevelLoader::image() |
---|
[164] | 176 | { |
---|
[507] | 177 | return this->image_; |
---|
[164] | 178 | } |
---|
| 179 | |
---|
| 180 | |
---|
| 181 | } |
---|
| 182 | |
---|