[164] | 1 | #include <string.h> |
---|
| 2 | #include <iostream> |
---|
| 3 | |
---|
| 4 | #include "LevelLoader.h" |
---|
[471] | 5 | //#include "xml/xmlParser.h" |
---|
| 6 | #include "tinyxml/tinyxml.h" |
---|
[164] | 7 | |
---|
| 8 | using namespace std; |
---|
| 9 | |
---|
| 10 | namespace loader |
---|
| 11 | { |
---|
| 12 | |
---|
| 13 | LevelLoader::LevelLoader(string file, string dir) |
---|
| 14 | { |
---|
| 15 | // Load XML level file |
---|
| 16 | dir.append("/"); |
---|
| 17 | dir.append(file); |
---|
[471] | 18 | |
---|
| 19 | TiXmlDocument doc(file); |
---|
| 20 | bool loadOkay = doc.LoadFile(); |
---|
| 21 | if (loadOkay) |
---|
| 22 | { |
---|
| 23 | |
---|
| 24 | } |
---|
| 25 | else |
---|
| 26 | { |
---|
| 27 | std::string err = "Could not load level file "; |
---|
| 28 | err.append(file); |
---|
| 29 | std::cout << err << std::endl; |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | /* |
---|
[469] | 33 | rootNode = XMLNode::openFileHelper(dir.c_str(),"orxonoxworld"); |
---|
[164] | 34 | // TODO: Error handling |
---|
| 35 | |
---|
| 36 | // Assing general level infos to class variables |
---|
[470] | 37 | |
---|
| 38 | this->name_ = rootNode.getAttribute("name"); |
---|
| 39 | this->image_ = rootNode.getAttribute("image"); |
---|
| 40 | this->description_ = rootNode.getChildNode("description").getText(); |
---|
[164] | 41 | |
---|
[470] | 42 | loadingScreenNode = rootNode.getChildNode("loading"); |
---|
| 43 | if (!loadingScreenNode.isEmpty()) |
---|
| 44 | { |
---|
| 45 | this->showLoadingScreen(); |
---|
| 46 | } |
---|
[471] | 47 | |
---|
| 48 | worldNode = rootNode.getChildNode("world"); |
---|
| 49 | if (!worldNode.isEmpty()) |
---|
| 50 | { |
---|
| 51 | |
---|
| 52 | } |
---|
| 53 | */ |
---|
| 54 | |
---|
[470] | 55 | |
---|
| 56 | /* |
---|
[164] | 57 | // Assign sub-nodes |
---|
[347] | 58 | if (rootNode.nChildNode("LightManager")==1) |
---|
[164] | 59 | { |
---|
| 60 | // Init Luightmanager... |
---|
[470] | 61 | }*/ |
---|
[164] | 62 | |
---|
| 63 | /* |
---|
| 64 | |
---|
| 65 | worldNode = rootNode.getChildNode("WorldEntities"); |
---|
| 66 | scriptNode = rootNode.getChildNode("ScriptManager"); |
---|
| 67 | cameraNode = rootNode.getChildNode("CameraMan"); |
---|
| 68 | lightNode = rootNode.getChildNode("LightManager"); |
---|
| 69 | */ |
---|
| 70 | |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | LevelLoader::~LevelLoader() |
---|
| 74 | { |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | string LevelLoader::name() |
---|
| 81 | { |
---|
| 82 | return this->name_; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | string LevelLoader::description() |
---|
| 86 | { |
---|
| 87 | return this->description_; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | string LevelLoader::image() |
---|
| 91 | { |
---|
| 92 | return this->image_; |
---|
| 93 | } |
---|
| 94 | |
---|
[470] | 95 | void LevelLoader::showLoadingScreen() |
---|
[164] | 96 | { |
---|
| 97 | cout << "\n\n\nThis is Orxonox\nthe hottest 3D action shooter ever to exist\n\n\n"; |
---|
| 98 | cout << "Level: " << name() << "\nDescription:" << description() << "\nImage:"<<image()<<"\n\n\n"; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | /* |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | void LevelLoader::loadWorld(WorldManager* wm) |
---|
| 105 | { |
---|
| 106 | if (!worldNode.getChildNode("lights").isEmpty()) |
---|
| 107 | { |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | } |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | void LevelLoader::loadLights(LightManager* lm) |
---|
| 115 | { |
---|
| 116 | if (!lightNode.getChildNode("lights").isEmpty()) |
---|
| 117 | { |
---|
| 118 | int nLights = lightNode.getChildNode("lights").nChildNode("light"); |
---|
| 119 | for (int i=0; i<nLights;i++) |
---|
| 120 | { |
---|
| 121 | XMLNode t = lightNode.getChildNode("lights").getChildNode("light",i); |
---|
| 122 | const char* diffuse = t.getAttribute("diffuse-color"); |
---|
| 123 | const char* coor = t.getAttribute("abs-coor"); |
---|
| 124 | lm->addLight(diffuse,coor); |
---|
| 125 | } |
---|
| 126 | } |
---|
| 127 | lm->setAmbient(lightNode.getChildNode("ambient").getAttribute("color")); |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | void LevelLoader::loadCameras(CameraManager* cm) |
---|
| 131 | { |
---|
| 132 | if (!cameraNode.getChildNode("cameras").isEmpty()) |
---|
| 133 | { |
---|
| 134 | int nCameras = cameraNode.getChildNode("cameras").nChildNode("camera"); |
---|
| 135 | for (int i=0; i<nCameras;i++) |
---|
| 136 | { |
---|
| 137 | XMLNode t = cameraNode.getChildNode("cameras").getChildNode("camera",i); |
---|
| 138 | |
---|
| 139 | |
---|
| 140 | cm->addCamera(); |
---|
| 141 | } |
---|
| 142 | } |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | |
---|
| 146 | void LevelLoader::loadScripts(ScriptManager* sm) |
---|
| 147 | { |
---|
| 148 | if (!scriptNode.getChildNode("scripts").isEmpty()) |
---|
| 149 | { |
---|
| 150 | int nScripts = scriptNode.getChildNode("scripts").nChildNode("script"); |
---|
| 151 | for (int i=0; i<nScripts;i++) |
---|
| 152 | { |
---|
| 153 | XMLNode t = scriptNode.getChildNode("scripts").getChildNode("script",i); |
---|
| 154 | sm->addScript(t.getAttribute("file")); |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | } |
---|
| 158 | } |
---|
| 159 | */ |
---|
| 160 | |
---|
| 161 | |
---|
| 162 | } |
---|
| 163 | |
---|