From 2d144149ffb88b65752e15357d1318bf5a9ef754 Mon Sep 17 00:00:00 2001 From: Cameron Reikes Date: Sun, 26 Feb 2023 10:39:58 -0800 Subject: [PATCH] Saying nothing cancels dialog --- main.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/main.c b/main.c index c31a990..d7b4248 100644 --- a/main.c +++ b/main.c @@ -188,34 +188,41 @@ void begin_text_input(); // called when player engages in dialog, must say somet // a callback, when 'text backend' has finished making text void end_text_input(char *what_player_said) { + player->state = CHARACTER_IDLE; #ifdef WEB // hacky _sapp_emsc_register_eventhandlers(); #endif size_t player_said_len = strlen(what_player_said); - Sentence what_player_said_sentence = {0}; - assert(player_said_len < ARRLEN(what_player_said_sentence.data)); - memcpy(what_player_said_sentence.data, what_player_said, player_said_len); - - // the new elements wouldn't fit! - Dialog *to_append = &player->talking_to->player_dialog; - if(to_append->cur_index + 2 >= ARRLEN(to_append->data)) + if(player_said_len == 0) + { + // this just means cancel the dialog + } + else { - // do it twice - for(int i = 0; i < 2; i++) + Sentence what_player_said_sentence = {0}; + assert(player_said_len < ARRLEN(what_player_said_sentence.data)); + memcpy(what_player_said_sentence.data, what_player_said, player_said_len); + + // the new elements wouldn't fit! + Dialog *to_append = &player->talking_to->player_dialog; + if(to_append->cur_index + 2 >= ARRLEN(to_append->data)) { - // shift array elements backwards, once - assert(ARRLEN(to_append->data) >= 1); - for(int i = 0; i < ARRLEN(to_append->data) - 1; i++) + // do it twice + for(int i = 0; i < 2; i++) { - to_append->data[i] = to_append->data[i + 1]; + // shift array elements backwards, once + assert(ARRLEN(to_append->data) >= 1); + for(int i = 0; i < ARRLEN(to_append->data) - 1; i++) + { + to_append->data[i] = to_append->data[i + 1]; + } + to_append->cur_index--; } - to_append->cur_index--; } + BUFF_APPEND(to_append, what_player_said_sentence); + BUFF_APPEND(to_append, SENTENCE_CONST("NPC response")); } - BUFF_APPEND(to_append, what_player_said_sentence); - BUFF_APPEND(to_append, SENTENCE_CONST("NPC response")); - player->state = CHARACTER_IDLE; } // keydown needs to be referenced when begin text input,