MCPcopy Create free account
hub / github.com/EasyRPG/Player / LoadMapFile

Method LoadMapFile

src/game_map.cpp:324–370  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

322}
323
324std::unique_ptr<lcf::rpg::Map> Game_Map::LoadMapFile(int map_id) {
325 std::unique_ptr<lcf::rpg::Map> map;
326
327 // Try loading EasyRPG map files first, then fallback to normal RPG Maker
328 // FIXME: Assert map was cached for async platforms
329 std::string map_name = Game_Map::ConstructMapName(map_id, true);
330 std::string map_file = FileFinder::Game().FindFile(map_name);
331 if (map_file.empty()) {
332 map_name = Game_Map::ConstructMapName(map_id, false);
333 map_file = FileFinder::Game().FindFile(map_name);
334
335 if (map_file.empty()) {
336 Output::Error("Loading of Map {} failed.\nThe map was not found.", map_name);
337 return nullptr;
338 }
339
340 auto map_stream = FileFinder::Game().OpenInputStream(map_file);
341 if (!map_stream) {
342 Output::Error("Loading of Map {} failed.\nMap not readable.", map_name);
343 return nullptr;
344 }
345
346 map = lcf::LMU_Reader::Load(map_stream, Player::encoding);
347
348 if (Input::IsRecording()) {
349 map_stream.clear();
350 map_stream.seekg(0);
351 Input::AddRecordingData(Input::RecordingData::Hash,
352 fmt::format("map{:04} {:#08x}", map_id, Utils::CRC32(map_stream)));
353 }
354 } else {
355 auto map_stream = FileFinder::Game().OpenInputStream(map_file);
356 if (!map_stream) {
357 Output::Error("Loading of Map {} failed.\nMap not readable.", map_name);
358 return nullptr;
359 }
360 map = lcf::LMU_Reader::LoadXml(map_stream);
361 }
362
363 Output::Debug("Loaded Map {}", map_name);
364
365 if (map.get() == NULL) {
366 Output::ErrorStr(lcf::LcfReader::GetError());
367 }
368
369 return map;
370}
371
372void Game_Map::SetupCommon() {
373 screen_width = (Player::screen_width / 16.0) * SCREEN_TILE_SIZE;

Callers

nothing calls this directly

Calls 6

GameClass · 0.85
OpenInputStreamMethod · 0.80
FindFileMethod · 0.45
emptyMethod · 0.45
clearMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected