Skip to content

Commit

Permalink
Implemented new LDB field "System.easyrpg_apply_lang_from_save" to ch…
Browse files Browse the repository at this point in the history
…eck if the Player should automatically apply the startup language from the latest save file

Also, formatting & compiler warning
  • Loading branch information
florianessl committed Feb 3, 2025
1 parent 9bee8ab commit eaacf36
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,11 @@ void Scene::PushTitleScene(bool pop_stack_top) {
if (!Player::startup_language.empty()) {
Player::translation.SelectLanguage(Player::startup_language);
} else if (Player::translation.HasTranslations()) {
std::string lang = Player::translation.GetLatestSavegameLanguage();
if (lang != "default") {
Player::translation.SelectLanguage(lang);
if (Player::translation.IsApplyLanguageFromSavefiles()) {
std::string lang = Player::translation.GetLatestSavegameLanguage();
if (lang != "default") {
Player::translation.SelectLanguage(lang);
}
}
if (Player::player_config.lang_select_on_start.Get() == ConfigEnum::StartupLangSelect::Always
|| (!FileFinder::HasSavegame() && Player::player_config.lang_select_on_start.Get() == ConfigEnum::StartupLangSelect::FirstStartup)) {
Expand Down
3 changes: 1 addition & 2 deletions src/scene_save.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ bool Scene_Save::Save(std::ostream& os, int slot_id, bool prepare_save) {
#ifdef LIBLCF_HAS_LANG_FIELD
if (!Tr::HasActiveTranslation()) {
save.easyrpg_data.language = lcf::DBString(lcf::rpg::SaveEasyRpgData::kDefaultLanguage);
}
else {
} else {
save.easyrpg_data.language = lcf::DBString(Player::translation.GetCurrentLanguage().lang_dir);
}
#endif
Expand Down
1 change: 1 addition & 0 deletions src/scene_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ void Scene_Settings::vUpdate() {
case Window_Settings::eAudio:
case Window_Settings::eAudioMidi:
case Window_Settings::eAudioSoundfont:
case Window_Settings::eLanguage:
case Window_Settings::eLicense:
case Window_Settings::eEngine:
case Window_Settings::eInputButtonCategory:
Expand Down
8 changes: 8 additions & 0 deletions src/translation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ const std::vector<Language>& Translation::GetLanguages() const
return languages;
}

bool Translation::IsApplyLanguageFromSavefiles() {
#ifdef LIBLCF_HAS_LANG_FIELD
return lcf::Data::system.easyrpg_apply_lang_from_save;
#else
return false;
#endif
}

std::string Translation::GetLatestSavegameLanguage() {
// TODO: Disable for platforms with slow I/O

Expand Down
5 changes: 5 additions & 0 deletions src/translation.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ class Translation {
*/
void SelectLanguage(StringView lang_id);

/*
Determines if the game language should be automatically detected and set from save files.
*/
bool IsApplyLanguageFromSavefiles();

/**
* Looks up the latest savegame from the Save folder and returns the defined language.
*
Expand Down

0 comments on commit eaacf36

Please # to comment.