Skip to content

Commit

Permalink
Allow requesting and listening to requests fron JS
Browse files Browse the repository at this point in the history
  • Loading branch information
Desdaemon committed Nov 3, 2024
1 parent 6592270 commit d25ea2a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/async_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* along with EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
*/

#include "web_api.h"
#include <cstdlib>
#include <fstream>
#include <map>
Expand Down Expand Up @@ -247,6 +248,7 @@ FileRequestAsync* AsyncHandler::RequestFile(StringView folder_name, StringView f
}

//Output::Debug("Waiting for {}", path);
Web_API::OnRequestFile(path);

return RegisterRequest(std::move(path), std::string(folder_name), std::string(file_name));
}
Expand Down
1 change: 1 addition & 0 deletions src/platform/emscripten/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ EMSCRIPTEN_BINDINGS(player_interface) {
.class_function("setNametagMode", &Emscripten_Interface::SetNametagMode)
.class_function("setSessionToken", &Emscripten_Interface::SetSessionToken, emscripten::allow_raw_pointers())
.class_function("resetCanvas", &Emscripten_Interface::ResetCanvas)
.class_function("preloadFile", &Emscripten_Interface::PreloadFile, emscripten::allow_raw_pointers())
;

emscripten::class_<Emscripten_Interface_Private>("api_private")
Expand Down
2 changes: 2 additions & 0 deletions src/platform/emscripten/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class Emscripten_Interface {
static void SetNametagMode(int mode);
static void SetSessionToken(std::string t);
static bool ResetCanvas();

static void PreloadFile(std::string dir, std::string path, bool graphic);
};

class Emscripten_Interface_Private {
Expand Down
6 changes: 6 additions & 0 deletions src/web_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,9 @@ bool Web_API::ShouldConnectPlayer(std::string_view uuid) {
}, uuid.data(), uuid.size());
return result == 1;
}

void Web_API::OnRequestFile(std::string_view path) {
EM_ASM({
onRequestFile(UTF8ToString($0, $1));
}, path.data(), path.size());
}
2 changes: 2 additions & 0 deletions src/web_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ namespace Web_API {
void ShowToastMessage(std::string_view msg, std::string_view icon);

bool ShouldConnectPlayer(std::string_view uuid);

void OnRequestFile(std::string_view path);
}

#endif
Expand Down

0 comments on commit d25ea2a

Please sign in to comment.