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