Просмотр исходного кода

scenes/pokemon_*name: Refuse numbers.

Neither Trainer nor Pokemon names are allowed to have a number in
them in-game.
Kris Bahnsen 2 лет назад
Родитель
Сommit
e9b34acc2e
2 измененных файлов с 14 добавлено и 14 удалено
  1. 10 5
      scenes/pokemon_nickname.c
  2. 4 9
      scenes/pokemon_ot_name.c

+ 10 - 5
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;
 }
 

+ 4 - 9
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;
 }