MCPcopy Create free account
hub / github.com/OpenDungeons/OpenDungeons / readGameEntity

Function readGameEntity

source/gamemap/MapHandler.cpp:516–551  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

514}
515
516bool readGameEntity(GameMap& gameMap, const std::string& item, GameEntityType type, std::stringstream& levelFile)
517{
518 std::string nextParam;
519 levelFile >> nextParam;
520 if (nextParam != "[" + item + "]")
521 return false;
522
523 uint32_t nbEntity = 0;
524 while(true)
525 {
526 if(!levelFile.good())
527 return false;
528
529 levelFile >> nextParam;
530 if (nextParam == "[/" + item + "]")
531 break;
532
533 std::string entire_line = nextParam;
534 std::getline(levelFile, nextParam);
535 entire_line += nextParam;
536
537 std::stringstream ss(entire_line);
538 GameEntity* entity = Entities::getGameEntityFromStream(&gameMap, type, ss);
539 if(entity == nullptr)
540 {
541 OD_LOG_ERR("unexpected null entity type=" + Helper::toString(static_cast<uint32_t>(type)));
542 return false;
543 }
544
545 entity->addToGameMap();
546 ++nbEntity;
547 }
548 OD_LOG_INF("Loaded " + Helper::toString(nbEntity) + " " + item + " in level");
549
550 return true;
551}
552
553bool writeGameMapToFile(const std::string& fileName, GameMap& gameMap)
554{

Callers 1

readGameMapFromFileFunction · 0.85

Calls 3

getGameEntityFromStreamFunction · 0.85
toStringFunction · 0.50
addToGameMapMethod · 0.45

Tested by

no test coverage detected