Skip to content

Commit 5a83733

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

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-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: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -325,40 +325,39 @@ 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+
bool map_is_easyrpg_file = Player::player_config.prefer_easyrpg_map_files.Get();
332+
std::string map_name = Game_Map::ConstructMapName(map_id, map_is_easyrpg_file);
331333
std::string map_file = FileFinder::Game().FindFile(map_name);
332334
if (map_file.empty()) {
333-
map_name = Game_Map::ConstructMapName(map_id, false);
335+
map_is_easyrpg_file = !map_is_easyrpg_file;
336+
map_name = Game_Map::ConstructMapName(map_id, map_is_easyrpg_file);
334337
map_file = FileFinder::Game().FindFile(map_name);
335338

336339
if (map_file.empty()) {
337340
Output::Error("Loading of Map {} failed.\nThe map was not found.", map_name);
338341
return nullptr;
339342
}
343+
}
340344

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-
}
345+
auto map_stream = FileFinder::Game().OpenInputStream(map_file);
346+
if (!map_stream) {
347+
Output::Error("Loading of Map {} failed.\nMap not readable.", map_name);
348+
return nullptr;
349+
}
346350

351+
if (map_is_easyrpg_file) {
352+
map = lcf::LMU_Reader::LoadXml(map_stream);
353+
} else {
347354
map = lcf::LMU_Reader::Load(map_stream, Player::encoding);
348-
349355
if (Input::IsRecording()) {
350356
map_stream.clear();
351357
map_stream.seekg(0);
352358
Input::AddRecordingData(Input::RecordingData::Hash,
353-
fmt::format("map{:04} {:#08x}", map_id, Utils::CRC32(map_stream)));
359+
fmt::format("map{:04} {:#08x}", map_id, Utils::CRC32(map_stream)));
354360
}
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-
}
361-
map = lcf::LMU_Reader::LoadXml(map_stream);
362361
}
363362

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

0 commit comments

Comments
 (0)