Skip to content

Commit

Permalink
StringVar: add find generic fallback function for FindText
Browse files Browse the repository at this point in the history
  • Loading branch information
enewey committed Jul 5, 2023
1 parent 10b3cd9 commit 694c5bb
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/filefinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,15 @@ std::string find_generic(const DirectoryTree::Args& args) {
return FileFinder::Game().FindFile(args);
}

std::string find_generic_with_fallback(DirectoryTree::Args& args) {
std::string found = find_generic(args);
if (found.empty()) {
return FileFinder::Save().FindFile(args);
}

return found;
}

std::string FileFinder::FindImage(StringView dir, StringView name) {
DirectoryTree::Args args = { MakePath(dir, name), IMG_TYPES, 1, false };
return find_generic(args);
Expand All @@ -361,7 +370,7 @@ std::string FileFinder::FindFont(StringView name) {

std::string FileFinder::FindText(StringView name) {
DirectoryTree::Args args = { MakePath("Text", name), TEXT_TYPES, 1, true };
return find_generic(args);
return find_generic_with_fallback(args);
}

Filesystem_Stream::InputStream open_generic(StringView dir, StringView name, DirectoryTree::Args& args) {
Expand All @@ -387,7 +396,7 @@ Filesystem_Stream::InputStream open_generic_with_fallback(StringView dir, String
auto is = open_generic(dir, name, args);
if (!is) { is = FileFinder::Save().OpenFile(args); }
if (!is) {
Output::Debug("Unable to find in either Game or Save: {}/{}", dir, name);
Output::Debug("Unable to open in either Game or Save: {}/{}", dir, name);
}

return is;
Expand Down

0 comments on commit 694c5bb

Please sign in to comment.