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