Changeset 7963 for code/branches/usability/src/libraries/core/Loader.cc
- Timestamp:
- Feb 26, 2011, 6:44:25 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/usability/src/libraries/core/Loader.cc
r7648 r7963 147 147 Returns true if successful. 148 148 */ 149 bool Loader::load(const XMLFile* file, const ClassTreeMask& mask, bool verbose )149 bool Loader::load(const XMLFile* file, const ClassTreeMask& mask, bool verbose, bool bRemoveLuaTags) 150 150 { 151 151 if (!file) … … 155 155 156 156 std::string xmlInput; 157 if (file->getLuaSupport() )157 if (file->getLuaSupport() && !bRemoveLuaTags) 158 158 { 159 159 // Use the LuaState to replace the XML tags (calls our function) … … 172 172 } 173 173 xmlInput = Resource::open(file->getFilename())->getAsString(); 174 175 if (bRemoveLuaTags) 176 { 177 // Remove all Lua code. 178 // Note: we only need this to speed up parsing of level files at the 179 // start of the program. 180 // Assumption: the LevelInfo tag does not use Lua scripting 181 xmlInput = removeLuaTags(xmlInput); 182 } 174 183 } 175 184 … … 271 280 } 272 281 273 std::string Loader::replaceLuaTags(const std::string& text) 274 { 275 // create map with all Lua tags 276 std::map<size_t, bool> luaTags; 282 bool Loader::getLuaTags(const std::string& text, std::map<size_t, bool>& luaTags) 283 { 284 // fill map with all Lua tags 277 285 { 278 286 size_t pos = 0; … … 328 336 { 329 337 COUT(2) << "Warning: Error in level file" << std::endl; 330 // todo: errorhandling 331 return ""; 332 } 333 } 338 // TODO: error handling 339 return false; 340 } 341 } 342 343 return true; 344 } 345 346 std::string Loader::replaceLuaTags(const std::string& text) 347 { 348 // create a map with all lua tags 349 std::map<size_t, bool> luaTags; 350 if (!getLuaTags(text, luaTags)) 351 return ""; 334 352 335 353 // Use a stringstream object to speed up the parsing … … 421 439 return output.str(); 422 440 } 441 442 std::string Loader::removeLuaTags(const std::string& text) 443 { 444 // create a map with all lua tags 445 std::map<size_t, bool> luaTags; 446 if (!getLuaTags(text, luaTags)) 447 return ""; 448 449 // Use a stringstream object to speed up the concatenation 450 std::ostringstream output; 451 452 // cut the original string into pieces and only write the non Lua parts 453 std::map<size_t, bool>::iterator it = luaTags.begin(); 454 bool bLuaCode = false; 455 size_t start = 0; 456 size_t end = 0; 457 458 do 459 { 460 if (it != luaTags.end()) 461 end = (it++)->first; 462 else 463 end = std::string::npos; 464 465 if (!bLuaCode) 466 { 467 output << text.substr(start, end - start); 468 start = end + 5; 469 } 470 else 471 start = end + 2; 472 473 bLuaCode = !bLuaCode; 474 } 475 while (end != std::string::npos); 476 477 return output.str(); 478 } 423 479 }
Note: See TracChangeset
for help on using the changeset viewer.