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

Function readGameMapFromFile

source/gamemap/MapHandler.cpp:56–514  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54namespace MapHandler {
55
56bool readGameMapFromFile(const std::string& fileName, GameMap& gameMap)
57{
58 std::stringstream levelFile;
59 if(!Helper::readFileWithoutComments(fileName, levelFile))
60 return false;
61
62 std::string nextParam;
63 // Read in the version number from the level file
64 levelFile >> nextParam;
65 if (nextParam.compare(ODApplication::VERSIONSTRING) != 0)
66 {
67 OD_LOG_WRN("Attempting to load a file produced by a different version of OpenDungeons, filename="
68 + fileName + ", file version=" + nextParam + ", odversion=" + ODApplication::VERSION);
69 return false;
70 }
71
72 levelFile >> nextParam;
73 if (nextParam != "[Info]")
74 {
75 OD_LOG_WRN("Invalid info start format: " + nextParam);
76 return false;
77 }
78
79 // By default, we use the default tileSet
80 gameMap.setTileSetName("");
81
82 // Read in the seats from the level file
83 while (true)
84 {
85 if(!levelFile.good())
86 return false;
87 // Information can contain spaces. We need to use std::getline to get content
88 std::getline(levelFile, nextParam);
89 std::string param;
90 if (nextParam == "[/Info]")
91 {
92 break;
93 }
94
95 param = "Name\t";
96 if (nextParam.compare(0, param.size(), param) == 0)
97 {
98 gameMap.setLevelName(nextParam.substr(param.size()));
99 continue;
100 }
101
102 param = "Description\t";
103 if (nextParam.compare(0, param.size(), param) == 0)
104 {
105 gameMap.setLevelDescription(nextParam.substr(param.size()));
106 continue;
107 }
108
109 param = "Music\t";
110 if (nextParam.compare(0, param.size(), param) == 0)
111 {
112 std::string musicFile = nextParam.substr(param.size());
113 gameMap.setLevelMusicFile(musicFile);

Callers 1

loadLevelMethod · 0.85

Calls 15

readFileWithoutCommentsFunction · 0.85
loadGoalFromStreamFunction · 0.85
readGameEntityFunction · 0.85
setTileSetNameMethod · 0.80
setLevelNameMethod · 0.80
setLevelDescriptionMethod · 0.80
setLevelMusicFileMethod · 0.80
importSeatFromStreamMethod · 0.80
addSeatMethod · 0.80
addGoalForAllSeatsMethod · 0.80
createNewMapMethod · 0.80

Tested by

no test coverage detected