| 191 | } |
| 192 | |
| 193 | std::string Game_Strings::FromFile(std::string_view filename, int encoding, bool& do_yield) { |
| 194 | do_yield = false; |
| 195 | |
| 196 | Filesystem_Stream::InputStream is = FileFinder::OpenText(filename); |
| 197 | if (!is) { |
| 198 | // Emscripten: Try to async fetch the file |
| 199 | auto* request = AsyncHandler::RequestFile("Text", filename); |
| 200 | request->SetImportantFile(true); |
| 201 | request->Start(); |
| 202 | do_yield = !request->IsReady(); |
| 203 | |
| 204 | return {}; |
| 205 | } |
| 206 | |
| 207 | auto vec = Utils::ReadStream(is); |
| 208 | std::string file_content(vec.begin(), vec.end()); |
| 209 | |
| 210 | if (encoding == 0) { |
| 211 | lcf::Encoder enc(Player::encoding); |
| 212 | enc.Encode(file_content); |
| 213 | } else { |
| 214 | // UTF-8: Remove Byte Order Mask |
| 215 | if (file_content.size() >= 3 && file_content[0] == '\xEF' && file_content[1] == '\xBB' && file_content[2] == '\xBF') { |
| 216 | file_content.erase(0, 3); |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | return file_content; |
| 221 | } |
| 222 | |
| 223 | bool Game_Strings::ToFile(Str_Params params, std::string filename, int encoding) { |
| 224 | std::string str = ToString(Get(params.string_id)); |