Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/game_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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";
}
1 change: 1 addition & 0 deletions src/game_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> 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();
};
Expand Down
33 changes: 16 additions & 17 deletions src/game_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,40 +325,39 @@ void Game_Map::SetupFromSave(
std::unique_ptr<lcf::rpg::Map> Game_Map::LoadMapFile(int map_id) {
std::unique_ptr<lcf::rpg::Map> 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 mapIsEasyRpgFile = Player::player_config.prefer_easyrpg_map_files.Get();
std::string map_name = Game_Map::ConstructMapName(map_id, mapIsEasyRpgFile);
std::string map_file = FileFinder::Game().FindFile(map_name);
if (map_file.empty()) {
map_name = Game_Map::ConstructMapName(map_id, false);
mapIsEasyRpgFile = !mapIsEasyRpgFile;
map_name = Game_Map::ConstructMapName(map_id, mapIsEasyRpgFile);
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 (mapIsEasyRpgFile) {
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);
Expand Down