Skip to content

Commit 7255c43

Browse files
committed
Add config option allowing map loader to prefer RPG Maker files
1 parent 31de2a7 commit 7255c43

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

src/game_config.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,7 @@ void Game_Config::LoadFromStream(Filesystem_Stream::InputStream& is) {
683683
player.screenshot_timestamp.FromIni(ini);
684684
player.automatic_screenshots.FromIni(ini);
685685
player.automatic_screenshots_interval.FromIni(ini);
686+
player.prefer_easyrpg_map_files.FromIni(ini);
686687
}
687688

688689
void Game_Config::WriteToStream(Filesystem_Stream::OutputStream& os) const {
@@ -776,6 +777,7 @@ void Game_Config::WriteToStream(Filesystem_Stream::OutputStream& os) const {
776777
player.screenshot_timestamp.ToIni(os);
777778
player.automatic_screenshots.ToIni(os);
778779
player.automatic_screenshots_interval.ToIni(os);
780+
player.prefer_easyrpg_map_files.ToIni(os);
779781

780782
os << "\n";
781783
}

src/game_config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ struct Game_ConfigPlayer {
108108
BoolConfigParam screenshot_timestamp{ "Screenshot timestamp", "Add the current date and time to the file name", "Player", "ScreenshotTimestamp", true };
109109
BoolConfigParam automatic_screenshots{ "Automatic screenshots", "Periodically take screenshots", "Player", "AutomaticScreenshots", false };
110110
RangeConfigParam<int> automatic_screenshots_interval{ "Screenshot interval", "The interval between automatic screenshots (seconds)", "Player", "AutomaticScreenshotsInterval", 30, 1, 999999 };
111+
BoolConfigParam prefer_easyrpg_map_files{ "Prefer EasyRPG map files", "Attempt to load EasyRPG map files (.emu) first and fall back to RPG Maker map files (.lmu)", "Player", "PreferEasyRpgMapFiles", true };
111112

112113
void Hide();
113114
};

src/game_map.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -325,40 +325,40 @@ void Game_Map::SetupFromSave(
325325
std::unique_ptr<lcf::rpg::Map> Game_Map::LoadMapFile(int map_id) {
326326
std::unique_ptr<lcf::rpg::Map> map;
327327

328-
// Try loading EasyRPG map files first, then fallback to normal RPG Maker
328+
// Attempt to load either the EasyRPG map file or the RPG Maker map file first, depending on config.
329+
// If it fails, try the other one.
329330
// FIXME: Assert map was cached for async platforms
330-
std::string map_name = Game_Map::ConstructMapName(map_id, true);
331+
std::string map_name = Game_Map::ConstructMapName(map_id, Player::player_config.prefer_easyrpg_map_files);
331332
std::string map_file = FileFinder::Game().FindFile(map_name);
333+
bool mapIsEasyRpgFile = Player::player_config.prefer_easyrpg_map_files;
332334
if (map_file.empty()) {
333-
map_name = Game_Map::ConstructMapName(map_id, false);
335+
map_name = Game_Map::ConstructMapName(map_id, !Player::player_config.prefer_easyrpg_map_files);
334336
map_file = FileFinder::Game().FindFile(map_name);
335337

336338
if (map_file.empty()) {
337339
Output::Error("Loading of Map {} failed.\nThe map was not found.", map_name);
338340
return nullptr;
339341
}
340342

341-
auto map_stream = FileFinder::Game().OpenInputStream(map_file);
342-
if (!map_stream) {
343-
Output::Error("Loading of Map {} failed.\nMap not readable.", map_name);
344-
return nullptr;
345-
}
343+
mapIsEasyRpgFile = !mapIsEasyRpgFile;
344+
}
346345

347-
map = lcf::LMU_Reader::Load(map_stream, Player::encoding);
346+
auto map_stream = FileFinder::Game().OpenInputStream(map_file);
347+
if (!map_stream) {
348+
Output::Error("Loading of Map {} failed.\nMap not readable.", map_name);
349+
return nullptr;
350+
}
348351

352+
if (mapIsEasyRpgFile) {
353+
map = lcf::LMU_Reader::LoadXml(map_stream);
354+
} else {
355+
map = lcf::LMU_Reader::Load(map_stream, Player::encoding);
349356
if (Input::IsRecording()) {
350357
map_stream.clear();
351358
map_stream.seekg(0);
352359
Input::AddRecordingData(Input::RecordingData::Hash,
353-
fmt::format("map{:04} {:#08x}", map_id, Utils::CRC32(map_stream)));
354-
}
355-
} else {
356-
auto map_stream = FileFinder::Game().OpenInputStream(map_file);
357-
if (!map_stream) {
358-
Output::Error("Loading of Map {} failed.\nMap not readable.", map_name);
359-
return nullptr;
360+
fmt::format("map{:04} {:#08x}", map_id, Utils::CRC32(map_stream)));
360361
}
361-
map = lcf::LMU_Reader::LoadXml(map_stream);
362362
}
363363

364364
Output::Debug("Loaded Map {}", map_name);

0 commit comments

Comments
 (0)