Saying nothing cancels dialog

main
Cameron Murphy Reikes 2 years ago
parent a6d8a66bb8
commit 2d144149ff

@ -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 // a callback, when 'text backend' has finished making text
void end_text_input(char *what_player_said) void end_text_input(char *what_player_said)
{ {
player->state = CHARACTER_IDLE;
#ifdef WEB // hacky #ifdef WEB // hacky
_sapp_emsc_register_eventhandlers(); _sapp_emsc_register_eventhandlers();
#endif #endif
size_t player_said_len = strlen(what_player_said); size_t player_said_len = strlen(what_player_said);
Sentence what_player_said_sentence = {0}; if(player_said_len == 0)
assert(player_said_len < ARRLEN(what_player_said_sentence.data)); {
memcpy(what_player_said_sentence.data, what_player_said, player_said_len); // this just means cancel the dialog
}
// the new elements wouldn't fit! else
Dialog *to_append = &player->talking_to->player_dialog;
if(to_append->cur_index + 2 >= ARRLEN(to_append->data))
{ {
// do it twice Sentence what_player_said_sentence = {0};
for(int i = 0; i < 2; i++) 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 // do it twice
assert(ARRLEN(to_append->data) >= 1); for(int i = 0; i < 2; i++)
for(int i = 0; i < ARRLEN(to_append->data) - 1; 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, // keydown needs to be referenced when begin text input,

Loading…
Cancel
Save