From c928a092557acb8c2e1abc27800f2e3f74bece85 Mon Sep 17 00:00:00 2001 From: Cameron Reikes Date: Wed, 11 Oct 2023 22:58:12 -0700 Subject: [PATCH] Accept typed speech and perform its action --- assets/main_game_level.bin | Bin 667 -> 2365 bytes main.c | 51 +++++++++++++++---------------------- makeprompt.h | 3 +++ 3 files changed, 23 insertions(+), 31 deletions(-) diff --git a/assets/main_game_level.bin b/assets/main_game_level.bin index 24419e7553000be36daf5971ed9719b9e57a797f..5bfcf696c08b5f5096ab709e0532d4734a350692 100644 GIT binary patch literal 2365 zcmZQ%U|=v^%>*Qo!MSGs1FxRgJHTjUITW_wsmsh7YbQ7`0!3MYIKLz#wFtyv01}Lh zAQCG8i36oc0BKp-IVr_iX~iVy8C5zO0wW~^ILY=XG@FWN#vfq$vS{~&9 zy21B_$bQdy6^GS3+V@XXlXl25JGTE!laRwy5#|G1T*MtJmna?x;ZbuaV6Z!|j%0a^_>wg3PC literal 667 zcmZQ%U|_ha$_ONpK~A8n!=u%{2SD^gAdM`C!nX3A>)yJu#sOpiD-h?GWTX~>O#>2) zj11@o!!+X(hsooip{AZMuHC=()dzc!NkH5H)&Z0w0dN4-K3!0DpyR%z1H<~L1BbkI z9F_}O9$1lO=nxt&b->+E)j`_n>wdR5DF>Ovz5CBqa5+4k*1Esx?iYKQ^)Tz8t}player_input_key); + if(text_to_say.size > 0) { + String8 no_whitespace = S8SkipWhitespace(S8ChopWhitespace(text_to_say)); + if (no_whitespace.size == 0) + { + // this just means cancel the dialog + } + else + { + String8 what_player_said = text_to_say; + what_player_said = S8ListJoin(frame_arena, S8Split(frame_arena, what_player_said, 1, &S8Lit("\n")), &(StringJoin){0}); + + ActionOld to_perform = {0}; + what_player_said = S8Substring(what_player_said, 0, ARRLEN(to_perform.speech.text)); + + chunk_from_s8(&to_perform.speech, what_player_said); + perform_action(&gs, player(&gs), to_perform); + } + } // do dialog Entity *closest_interact_with = 0; { @@ -6932,7 +6921,7 @@ void frame(void) { // begin dialog with closest npc player(&gs)->talking_to = frome(closest_interact_with); - begin_text_input(S8Lit("")); + player(&gs)->player_input_key = begin_text_input(S8Lit("")); } else { diff --git a/makeprompt.h b/makeprompt.h index 003ae6f..ad5ee14 100644 --- a/makeprompt.h +++ b/makeprompt.h @@ -210,6 +210,8 @@ typedef struct RememberedError TextChunk reason_why_its_bad; } RememberedError; +typedef int TextInputResultKey; + typedef struct Entity { bool exists; @@ -233,6 +235,7 @@ typedef struct Entity // npcs bool is_player; + TextInputResultKey player_input_key; void *armature; // copied into the gamestate's arena, created if null. Don't serialize EntityRef joined; EntityRef aiming_shotgun_at;