Skip to content

Commit 6215395

Browse files
authored
Merge pull request #3419 from florianessl/fix/TranslateTextFiles
Translation fix: Files inside "Text" folder were not translated
2 parents a688712 + f2b826b commit 6215395

4 files changed

Lines changed: 23 additions & 14 deletions

File tree

src/filefinder.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,14 @@ std::string find_generic(const DirectoryTree::Args& args) {
424424
}
425425

426426
std::string find_generic_with_fallback(DirectoryTree::Args& args) {
427+
// Searches first in the Save directory (because the game could have written
428+
// files there, then in the Game directory.
429+
// Disable this behaviour when Game and Save are shared as this breaks the
430+
// translation redirection.
431+
if (Player::shared_game_and_save_directory) {
432+
return find_generic(args);
433+
}
434+
427435
std::string found = FileFinder::Save().FindFile(args);
428436
if (found.empty()) {
429437
return find_generic(args);
@@ -453,11 +461,6 @@ std::string FileFinder::FindFont(std::string_view name) {
453461
return find_generic(args);
454462
}
455463

456-
std::string FileFinder::FindText(std::string_view name) {
457-
DirectoryTree::Args args = { MakePath("Text", name), TEXT_TYPES, 1, true };
458-
return find_generic_with_fallback(args);
459-
}
460-
461464
Filesystem_Stream::InputStream open_generic(std::string_view dir, std::string_view name, DirectoryTree::Args& args) {
462465
if (!Tr::GetCurrentTranslationId().empty()) {
463466
auto tr_fs = Tr::GetCurrentTranslationFilesystem();
@@ -478,6 +481,14 @@ Filesystem_Stream::InputStream open_generic(std::string_view dir, std::string_vi
478481
}
479482

480483
Filesystem_Stream::InputStream open_generic_with_fallback(std::string_view dir, std::string_view name, DirectoryTree::Args& args) {
484+
if (!Tr::GetCurrentTranslationId().empty()) {
485+
auto tr_fs = Tr::GetCurrentTranslationFilesystem();
486+
auto is = tr_fs.OpenFile(args);
487+
if (is) {
488+
return is;
489+
}
490+
}
491+
481492
auto is = FileFinder::Save().OpenFile(args);
482493
if (!is) { is = open_generic(dir, name, args); }
483494
if (!is) {

src/filefinder.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,6 @@ namespace FileFinder {
163163
*/
164164
std::string FindFont(std::string_view name);
165165

166-
/**
167-
* Finds a text file in the current RPG Maker game.
168-
*
169-
* @param name the text path and name.
170-
* @return path to file.
171-
*/
172-
std::string FindText(std::string_view name);
173-
174166
/**
175167
* Finds an image file and opens a file handle to it.
176168
* Searches through the current RPG Maker game and the RTP directories.

src/player.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ namespace Player {
123123
uint32_t escape_char;
124124
std::string game_title;
125125
std::string game_title_original;
126+
bool shared_game_and_save_directory = false;
126127
std::shared_ptr<Meta> meta;
127128
FileExtGuesser::RPG2KFileExtRemap fileext_map;
128129
std::string startup_language;
@@ -716,7 +717,9 @@ void Player::CreateGameObjects() {
716717

717718
std::string game_path = FileFinder::GetFullFilesystemPath(FileFinder::Game());
718719
std::string save_path = FileFinder::GetFullFilesystemPath(FileFinder::Save());
719-
if (game_path == save_path) {
720+
shared_game_and_save_directory = (game_path == save_path);
721+
722+
if (shared_game_and_save_directory) {
720723
Output::DebugStr("Game and Save Directory:");
721724
FileFinder::DumpFilesystem(FileFinder::Game());
722725
} else {

src/player.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,9 @@ namespace Player {
409409
/** Original game title, in case it was overriden by a translation. */
410410
extern std::string game_title_original;
411411

412+
/** Indicates whether FileFinder::Game() and Save() point to the same directory. */
413+
extern bool shared_game_and_save_directory;
414+
412415
/** Meta class containing additional external data for this game. */
413416
extern std::shared_ptr<Meta> meta;
414417

0 commit comments

Comments
 (0)