From e9b34acc2e8165839f1943a7a906c6ce391bd8d2 Mon Sep 17 00:00:00 2001 From: Kris Bahnsen Date: Mon, 6 Nov 2023 00:12:17 -0800 Subject: [PATCH] scenes/pokemon_*name: Refuse numbers. Neither Trainer nor Pokemon names are allowed to have a number in them in-game. --- scenes/pokemon_nickname.c | 15 ++++++++++----- scenes/pokemon_ot_name.c | 13 ++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/scenes/pokemon_nickname.c b/scenes/pokemon_nickname.c index df34d4c7e9d..eb4d5eecd15 100644 --- a/scenes/pokemon_nickname.c +++ b/scenes/pokemon_nickname.c @@ -22,6 +22,7 @@ static char name_buf[11]; static bool select_nickname_input_validator(const char* text, FuriString* error, void* context) { PokemonFap* pokemon_fap = (PokemonFap*)context; bool rc = true; + unsigned int i; if(text[0] == '\0') { /* Get the pokemon's name and populate our buffer with it */ @@ -30,19 +31,23 @@ static bool select_nickname_input_validator(const char* text, FuriString* error, return true; } - if(rc == false) { - furi_string_printf(error, "Some error?"); - } else { + for(i = 0; i < strlen(text); i++) { + if(isdigit((unsigned int)text[i])) { + furi_string_printf(error, "Name cannot\ncontain\nnumbers!"); + rc = false; + } + } + + if(rc == true) { /* Clear existing nickname in trade block*/ memset(pokemon_fap->trade_block->nickname, TERM_, sizeof(struct name)); /* Encode string to nickname */ pokemon_str_to_encoded_array( (uint8_t*)pokemon_fap->trade_block->nickname, (char*)text, strlen(text)); + FURI_LOG_D(TAG, "[nickname] Set nickname to %s", text); } - FURI_LOG_D(TAG, "[nickname] Set nickname to %s", text); - return rc; } diff --git a/scenes/pokemon_ot_name.c b/scenes/pokemon_ot_name.c index f26ddd8d76c..74e41cacd12 100644 --- a/scenes/pokemon_ot_name.c +++ b/scenes/pokemon_ot_name.c @@ -15,30 +15,25 @@ static bool select_ot_name_input_validator(const char* text, FuriString* error, bool rc = true; unsigned int i; - // XXX If no pokemon name, use default. How TF to have text input handle that? // OT name is 7 chars max on gen 1, so only take that and then fill the rest of the 11 bytes with term for(i = 0; i < sizeof(ot_name_buf); i++) { - if(!isalnum((unsigned int)text[i])) { - if(text[i] == '\0') break; + if(isdigit((unsigned int)text[i])) { + furi_string_printf(error, "Name cannot\ncontain\nnumbers!"); rc = false; - break; } } - if(rc == false) { - furi_string_printf(error, "Some error?"); - } else { + if(rc == true) { /* Clear existing OT Name in trade block*/ memset(pokemon_fap->trade_block->ot_name, TERM_, sizeof(struct name)); /* Encode string to OT Name */ pokemon_str_to_encoded_array( (uint8_t*)pokemon_fap->trade_block->ot_name, (char*)text, strlen(text)); + FURI_LOG_D(TAG, "[ot_name] Set OT name to %s", text); } - FURI_LOG_D(TAG, "[ot_name] Set OT name to %s", text); - return rc; }