Skip to content

Commit

Permalink
select_pokemon: Use intermediate variable for curr_pokemon
Browse files Browse the repository at this point in the history
Make it easier to change this later as curr_pokemon might be
redundant.
  • Loading branch information
kbembedded committed Sep 15, 2023
1 parent 5d8823a commit 783e376
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions views/select_pokemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ static void select_pokemon_render_callback(Canvas* canvas, void* model) {

static bool select_pokemon_input_callback(InputEvent* event, void* context) {
PokemonFap* pokemon_fap = (PokemonFap*)context;
int pokemon_num = pokemon_fap->curr_pokemon;
bool consumed = false;

furi_assert(context);
Expand All @@ -45,41 +46,41 @@ static bool select_pokemon_input_callback(InputEvent* event, void* context) {

/* Move back one through the pokedex listing */
case InputKeyLeft:
if(pokemon_fap->curr_pokemon == 0)
pokemon_fap->curr_pokemon = 150;
if(pokemon_num == 0)
pokemon_num = 150;
else
pokemon_fap->curr_pokemon--;
pokemon_num--;
consumed = true;
break;

/* Move back ten through the pokemon listing, wrap to max pokemon on
/* Move back ten through the pokemon listing, wrap to max pokemon on
* underflow.
*/
case InputKeyDown:
if(pokemon_fap->curr_pokemon >= 10)
pokemon_fap->curr_pokemon -= 10;
if(pokemon_num >= 10)
pokemon_num -= 10;
else
pokemon_fap->curr_pokemon = 150;
pokemon_num = 150;
consumed = true;
break;

/* Move forward one through the pokedex listing */
case InputKeyRight:
if(pokemon_fap->curr_pokemon == 150)
pokemon_fap->curr_pokemon = 0;
if(pokemon_num == 150)
pokemon_num = 0;
else
pokemon_fap->curr_pokemon++;
pokemon_num++;
consumed = true;
break;

/* Move forward ten through the pokemon listing, wrap to min pokemon on
/* Move forward ten through the pokemon listing, wrap to min pokemon on
* overflow.
*/
case InputKeyUp:
if(pokemon_fap->curr_pokemon <= 140)
pokemon_fap->curr_pokemon += 10;
if(pokemon_num <= 140)
pokemon_num += 10;
else
pokemon_fap->curr_pokemon = 0;
pokemon_num = 0;
consumed = true;
break;

Expand All @@ -88,6 +89,8 @@ static bool select_pokemon_input_callback(InputEvent* event, void* context) {
break;
}

pokemon_fap->curr_pokemon = pokemon_num;

return consumed;
}

Expand Down

0 comments on commit 783e376

Please sign in to comment.