diff --git a/binding-mruby/binding-mruby.cpp b/binding-mruby/binding-mruby.cpp index 815ce00..7cb0b64 100644 --- a/binding-mruby/binding-mruby.cpp +++ b/binding-mruby/binding-mruby.cpp @@ -261,6 +261,22 @@ runRMXPScripts(mrb_state *mrb, mrbc_context *ctx) return; } + /* Load Ruby Game Scripting System from rgss.rb */ + try + { + SDL_rw_file_helper fileHelper; + fileHelper.filename = "rgss.rb"; + char * contents = fileHelper.read(); + int ai = mrb_gc_arena_save(mrb); + mrb_load_nstring_cxt(mrb, contents, fileHelper.length, ctx); + mrb_gc_arena_restore(mrb, ai); + } + catch (const Exception &e) + { + printf("Failed to read rgss.rb\n"); + return; + } + /* We use a secondary util state to unmarshal the scripts */ mrb_state *scriptMrb = mrb_open(); diff --git a/binding-mruby/mrb-ext/file-helper.cpp b/binding-mruby/mrb-ext/file-helper.cpp index 8caf829..eff63a7 100644 --- a/binding-mruby/mrb-ext/file-helper.cpp +++ b/binding-mruby/mrb-ext/file-helper.cpp @@ -2,7 +2,16 @@ #include "file-helper.h" #include +#ifdef __EMSCRIPTEN__ +#include "emscripten.hpp" +#endif + char* SDL_rw_file_helper::read() { + +#ifdef __EMSCRIPTEN__ + load_file_async_js(filename); +#endif + SDL_RWops *rw = SDL_RWFromFile(filename, "rb"); if (rw == NULL) return NULL; diff --git a/src/emscripten.cpp b/src/emscripten.cpp index da253bf..7f31f84 100644 --- a/src/emscripten.cpp +++ b/src/emscripten.cpp @@ -28,8 +28,10 @@ EM_JS(void, load_file_async_js, (const char* fullPathC), { // Get target URL const iurl = "gameasync/" + fullPath; - // Delete original file - FS.unlink(path + "/" + filename); + // Delete original file if existent + try { + FS.unlink(path + "/" + filename); + } catch (err) {} // Get the new file FS.createPreloadedFile(path, filename, iurl, true, true, function() {