Skip to content

Commit

Permalink
scenes/pokemon_*name: Refuse numbers.
Browse files Browse the repository at this point in the history
Neither Trainer nor Pokemon names are allowed to have a number in
them in-game.
  • Loading branch information
kbembedded committed Nov 8, 2023
1 parent c617ce3 commit e9b34ac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
15 changes: 10 additions & 5 deletions scenes/pokemon_nickname.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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;
}

Expand Down
13 changes: 4 additions & 9 deletions scenes/pokemon_ot_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit e9b34ac

Please sign in to comment.