From 5a83733329cb1a7192392fc46528b96dd9278db6 Mon Sep 17 00:00:00 2001 From: Ian Ling Date: Sat, 15 Nov 2025 21:46:11 -0800 Subject: [PATCH] Add config option allowing map loader to prefer RPG Maker files --- src/game_config.cpp | 2 ++ src/game_config.h | 1 + src/game_map.cpp | 33 ++++++++++++++++----------------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/game_config.cpp b/src/game_config.cpp index da57f786ed..4f94cb7098 100644 --- a/src/game_config.cpp +++ b/src/game_config.cpp @@ -683,6 +683,7 @@ void Game_Config::LoadFromStream(Filesystem_Stream::InputStream& is) { player.screenshot_timestamp.FromIni(ini); player.automatic_screenshots.FromIni(ini); player.automatic_screenshots_interval.FromIni(ini); + player.prefer_easyrpg_map_files.FromIni(ini); } void Game_Config::WriteToStream(Filesystem_Stream::OutputStream& os) const { @@ -776,6 +777,7 @@ void Game_Config::WriteToStream(Filesystem_Stream::OutputStream& os) const { player.screenshot_timestamp.ToIni(os); player.automatic_screenshots.ToIni(os); player.automatic_screenshots_interval.ToIni(os); + player.prefer_easyrpg_map_files.ToIni(os); os << "\n"; } diff --git a/src/game_config.h b/src/game_config.h index 271e573972..bfcddde403 100644 --- a/src/game_config.h +++ b/src/game_config.h @@ -108,6 +108,7 @@ struct Game_ConfigPlayer { BoolConfigParam screenshot_timestamp{ "Screenshot timestamp", "Add the current date and time to the file name", "Player", "ScreenshotTimestamp", true }; BoolConfigParam automatic_screenshots{ "Automatic screenshots", "Periodically take screenshots", "Player", "AutomaticScreenshots", false }; RangeConfigParam automatic_screenshots_interval{ "Screenshot interval", "The interval between automatic screenshots (seconds)", "Player", "AutomaticScreenshotsInterval", 30, 1, 999999 }; + 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 }; void Hide(); }; diff --git a/src/game_map.cpp b/src/game_map.cpp index d2363e6a98..ca49966eb8 100644 --- a/src/game_map.cpp +++ b/src/game_map.cpp @@ -325,40 +325,39 @@ void Game_Map::SetupFromSave( std::unique_ptr Game_Map::LoadMapFile(int map_id) { std::unique_ptr map; - // Try loading EasyRPG map files first, then fallback to normal RPG Maker + // Attempt to load either the EasyRPG map file or the RPG Maker map file first, depending on config. + // If it fails, try the other one. // FIXME: Assert map was cached for async platforms - std::string map_name = Game_Map::ConstructMapName(map_id, true); + bool map_is_easyrpg_file = Player::player_config.prefer_easyrpg_map_files.Get(); + std::string map_name = Game_Map::ConstructMapName(map_id, map_is_easyrpg_file); std::string map_file = FileFinder::Game().FindFile(map_name); if (map_file.empty()) { - map_name = Game_Map::ConstructMapName(map_id, false); + map_is_easyrpg_file = !map_is_easyrpg_file; + map_name = Game_Map::ConstructMapName(map_id, map_is_easyrpg_file); map_file = FileFinder::Game().FindFile(map_name); if (map_file.empty()) { Output::Error("Loading of Map {} failed.\nThe map was not found.", map_name); return nullptr; } + } - auto map_stream = FileFinder::Game().OpenInputStream(map_file); - if (!map_stream) { - Output::Error("Loading of Map {} failed.\nMap not readable.", map_name); - return nullptr; - } + auto map_stream = FileFinder::Game().OpenInputStream(map_file); + if (!map_stream) { + Output::Error("Loading of Map {} failed.\nMap not readable.", map_name); + return nullptr; + } + if (map_is_easyrpg_file) { + map = lcf::LMU_Reader::LoadXml(map_stream); + } else { map = lcf::LMU_Reader::Load(map_stream, Player::encoding); - if (Input::IsRecording()) { map_stream.clear(); map_stream.seekg(0); Input::AddRecordingData(Input::RecordingData::Hash, - fmt::format("map{:04} {:#08x}", map_id, Utils::CRC32(map_stream))); + fmt::format("map{:04} {:#08x}", map_id, Utils::CRC32(map_stream))); } - } else { - auto map_stream = FileFinder::Game().OpenInputStream(map_file); - if (!map_stream) { - Output::Error("Loading of Map {} failed.\nMap not readable.", map_name); - return nullptr; - } - map = lcf::LMU_Reader::LoadXml(map_stream); } Output::Debug("Loaded Map {}", map_name);