From bd54e83d6e21f9eaab830095663a7ddad4c70c5c Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Fri, 22 Apr 2022 14:15:24 -0700 Subject: more web ui refactoring --- web/dartboat_wasm.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'web/dartboat_wasm.c') diff --git a/web/dartboat_wasm.c b/web/dartboat_wasm.c index 7dbfc59..e00c330 100644 --- a/web/dartboat_wasm.c +++ b/web/dartboat_wasm.c @@ -21,12 +21,12 @@ struct match_state *state; void set_user_active() { EM_ASM(setUserActive()); - EM_ASM(setPromptHandlerVisit()); + EM_ASM({setPromptHandler($0)}, "visit"); } void set_boat_active() { EM_ASM(setBoatActive()); - EM_ASM(setPromptHandlerNull()); + EM_ASM({setPromptHandler()}, ""); } void suggested(int rem, char *buf) { @@ -68,9 +68,9 @@ EMSCRIPTEN_KEEPALIVE int is_match_over() { } void match_over() { - EM_ASM(setPromptHandlerInit()); + EM_ASM({setPromptHandler($0)}, "init"); EM_ASM({promptSugg($0)}, "Press OK to play again."); - EM_ASM(setNoOneActive()); + EM_ASM(setNoneActive()); } EMSCRIPTEN_KEEPALIVE void draw_match() { @@ -116,7 +116,7 @@ EMSCRIPTEN_KEEPALIVE void draw_match() { if (l1->rem <= 0) { EM_ASM({promptMsg($0)}, "Darts needed?"); - EM_ASM(setPromptHandlerNumDarts()); + EM_ASM({setPromptHandler($0)}, "num_darts"); } else if (l2->rem <= 0) { EM_ASM({promptMsg($0)}, "Bot wins. :("); match_over(); @@ -247,7 +247,7 @@ EMSCRIPTEN_KEEPALIVE void resp_numdarts(int n_darts) { ((double)l->start / (((l->n_visits - 1) * 3) + n_darts)) * 3); EM_ASM({promptMsg($0)}, "You win! :)"); match_over(); - EM_ASM(setPromptHandlerInit()); + EM_ASM({setPromptHandler($0)}, "init"); } void init_boat() { @@ -278,6 +278,8 @@ EMSCRIPTEN_KEEPALIVE void start_match() { state->l1 = leg_init(501, "User"); state->l2 = leg_init(501, "Bot"); + EM_ASM({updateUserName($0)}, state->l1->name); + EM_ASM({updateBoatName($0)}, state->l2->name); EM_ASM({updateUserRem($0)}, state->l1->rem); EM_ASM({updateBoatStateRem($0)}, state->l2->rem); @@ -297,5 +299,5 @@ EMSCRIPTEN_KEEPALIVE void change_delay(int delay) { } int main() { - EM_ASM(initMatch()); + start_match(); } -- cgit v1.2.3-70-g09d2