Changeset 7648 for code/trunk/src/orxonox/LevelManager.cc
- Timestamp:
- Nov 13, 2010, 11:55:23 PM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/releasetodo (added) merged: 7614,7625-7629,7638-7639,7645-7647
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/LevelManager.cc
r7284 r7648 32 32 33 33 #include "util/ScopedSingletonManager.h" 34 #include "core/ClassTreeMask.h" 34 35 #include "core/CommandLineParser.h" 35 36 #include "core/ConfigValueIncludes.h" … … 37 38 #include "core/Loader.h" 38 39 #include "core/Resource.h" 40 #include "core/XMLFile.h" 39 41 #include "PlayerManager.h" 40 42 #include "Level.h" 43 #include "LevelInfo.h" 41 44 42 45 namespace orxonox … … 56 59 ModifyConfigValue(defaultLevelName_, tset, CommandLineParser::getValue("level").getString()); 57 60 } 61 62 this->compileAvailableLevelList(); 58 63 } 59 64 … … 125 130 } 126 131 127 const std::string& LevelManager::getAvailableLevelListItem(unsigned int index) const132 unsigned int LevelManager::getNumberOfLevels() 128 133 { 129 if (index >= availableLevels_.size()) 130 return BLANKSTRING; 134 this->updateAvailableLevelList(); 135 136 return this->availableLevels_.size(); 137 } 138 139 LevelInfoItem* LevelManager::getAvailableLevelListItem(unsigned int index) const 140 { 141 if (index >= this->availableLevels_.size()) 142 return NULL; 131 143 else 132 return availableLevels_[index]; 144 { 145 std::map<std::string, LevelInfoItem*>::const_iterator it = this->infos_.find(this->availableLevels_[index]); 146 return it->second; 147 } 133 148 } 134 149 135 150 void LevelManager::compileAvailableLevelList() 136 151 { 137 this->availableLevels_.clear();138 152 Ogre::StringVectorPtr levels = Resource::findResourceNames("*.oxw"); 153 // Iterate over all *.oxw level files. 139 154 for (Ogre::StringVector::const_iterator it = levels->begin(); it != levels->end(); ++it) 140 155 { 156 //TODO: Replace with tag, 141 157 if (it->find("old/") != 0) 142 158 { 143 159 size_t pos = it->find(".oxw"); 160 161 bool infoExists = false; 162 // Load the LevelInfo object from the level file. 163 XMLFile file = XMLFile(*it); 164 ClassTreeMask mask = ClassTreeMask(); 165 mask.exclude(ClassIdentifier<BaseObject>::getIdentifier()); 166 mask.include(ClassIdentifier<LevelInfo>::getIdentifier()); 167 Loader::load(&file, mask, false); 168 for(ObjectList<LevelInfo>::iterator item = ObjectList<LevelInfo>::begin(); item != ObjectList<LevelInfo>::end(); ++item) 169 { 170 LevelInfoItem* info = item->copy(); 171 if(info->getXMLFilename() == *it) 172 { 173 this->infos_.insert(std::pair<std::string, LevelInfoItem*>(it->substr(0, pos),info)); 174 infoExists = true; 175 } 176 } 177 Loader::unload(&file, mask); 178 if(!infoExists) 179 { 180 this->infos_.insert(std::pair<std::string, LevelInfoItem*>(it->substr(0, pos), new LevelInfoItem(it->substr(0, pos), *it))); 181 } 182 144 183 this->availableLevels_.push_back(it->substr(0, pos)); 145 184 } 146 185 } 147 186 } 187 188 void LevelManager::updateAvailableLevelList(void) 189 { 190 //TODO: Implement some kind of update? 191 } 148 192 }
Note: See TracChangeset
for help on using the changeset viewer.