Update shell

This commit is contained in:
Thomas
2026-03-05 17:38:46 +00:00
parent b54a53b9c8
commit 635869f226
5 changed files with 267 additions and 9 deletions

View File

@@ -50,6 +50,23 @@ static int s_mars_depth = 0;
#define PAUSE_ITEM_COUNT 3
static int s_pause_selection = 0; /* 0=Resume, 1=Restart, 2=Quit */
#ifdef __EMSCRIPTEN__
/* JS-initiated level load request (level-select dropdown in shell). */
static int s_js_load_request = 0;
static char s_js_load_path[ASSET_PATH_MAX] = {0};
#endif
#ifdef __EMSCRIPTEN__
/* Called from the JS shell level-select dropdown to load a level into
* gameplay mode. Sets a deferred request that game_update() picks up on
* the next frame so we don't mutate game state from an arbitrary call site. */
EMSCRIPTEN_KEEPALIVE
void game_load_level(const char *path) {
snprintf(s_js_load_path, sizeof(s_js_load_path), "%s", path);
s_js_load_request = 1;
}
#endif
static const char *theme_name(LevelTheme t) {
switch (t) {
case THEME_PLANET_SURFACE: return "Planet Surface";
@@ -343,6 +360,39 @@ static void pause_update(void) {
}
static void game_update(float dt) {
#ifdef __EMSCRIPTEN__
/* Handle deferred level load from JS shell dropdown. */
if (s_js_load_request && s_js_load_path[0]) {
s_js_load_request = 0;
/* Tear down whatever mode we are in. */
if (s_mode == MODE_PLAY || s_mode == MODE_PAUSED) {
level_free(&s_level);
} else if (s_mode == MODE_EDITOR) {
editor_free(&s_editor);
}
s_mode = MODE_PLAY;
s_testing_from_editor = false;
if (!load_level_file(s_js_load_path)) {
fprintf(stderr, "Failed to load level from shell: %s\n",
s_js_load_path);
/* Fall back to the first campaign level. */
if (!load_level_file("assets/levels/moon01.lvl")) {
g_engine.running = false;
}
}
/* Also seed the editor path so pressing E opens this level. */
snprintf(s_edit_path, sizeof(s_edit_path), "%s", s_js_load_path);
s_js_load_path[0] = '\0';
SDL_SetWindowTitle(g_engine.window, "Jump 'n Run");
return;
}
#endif
if (s_mode == MODE_EDITOR) {
editor_update(&s_editor, dt);