Skip to content

Commit

Permalink
pokerus: Separate out accessor functions from scene
Browse files Browse the repository at this point in the history
Signed-off-by: Kris Bahnsen <Kris@KBEmbedded.com>
  • Loading branch information
kbembedded committed Aug 6, 2024
1 parent 2f9f536 commit eafd365
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 43 deletions.
14 changes: 14 additions & 0 deletions src/include/pokemon_pokerus.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef POKEMON_POKERUS_H
#define POKEMON_POKERUS_H

#include <src/include/pokemon_data.h>

#pragma once

const char* pokerus_get_status_str(PokemonData* pdata);

void pokerus_set_strain(PokemonData* pdata, uint8_t strain);

void pokerus_set_days(PokemonData *pdata, uint8_t days);

#endif // POKEMON_POKERUS_H
51 changes: 51 additions & 0 deletions src/pokemon_pokerus.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <gui/modules/variable_item_list.h>
#include <furi.h>

#include <src/include/pokemon_data.h>

static const char* pokerus_states[] = {
"Clean",
"Infected",
"Cured",
"",
};

const char* pokerus_get_status_str(PokemonData* pdata) {
uint8_t pokerus;

pokerus = pokemon_stat_get(pdata, STAT_POKERUS, NONE);

if(pokerus == 0x00)
return pokerus_states[0];

if((pokerus & 0x0f) != 0x00)
return pokerus_states[1];

return pokerus_states[2];
}

void pokerus_set_strain(PokemonData* pdata, uint8_t strain) {
uint8_t pokerus;

/* Need to read/modify/write the existing stat */
pokerus = pokemon_stat_get(pdata, STAT_POKERUS, NONE);
pokerus &= 0x0f;
pokerus |= (strain << 4);

if((pokerus & 0xf0) == 0x00)
pokerus = 0;

pokemon_stat_set(pdata, STAT_POKERUS, NONE, pokerus);
}

void pokerus_set_days(PokemonData *pdata, uint8_t days) {
uint8_t pokerus;

days &= 0x0f;

/* Need to read/modify/write the existing stat */
pokerus = pokemon_stat_get(pdata, STAT_POKERUS, NONE);
pokerus &= 0xf0;
pokerus |= days;
pokemon_stat_set(pdata, STAT_POKERUS, NONE, pokerus);
}
10 changes: 0 additions & 10 deletions src/scenes/include/pokemon_pokerus.h

This file was deleted.

4 changes: 2 additions & 2 deletions src/scenes/pokemon_gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <src/scenes/include/pokemon_menu.h>
#include <src/include/pokemon_shiny.h>
#include <src/include/pokemon_gender.h>
#include <src/scenes/include/pokemon_pokerus.h>
#include <src/include/pokemon_pokerus.h>
#include <src/include/unown_form.h>

static void scene_change_from_main_cb(void* context, uint32_t index) {
Expand Down Expand Up @@ -188,7 +188,7 @@ void pokemon_scene_gen_on_enter(void* context) {
submenu_add_item(
pokemon_fap->submenu, buf, PokemonSceneGender, scene_change_from_main_cb, pokemon_fap);

snprintf(buf, sizeof(buf), "Pokerus: %s", select_pokerus_status(pokemon_fap));
snprintf(buf, sizeof(buf), "Pokerus: %s", pokerus_get_status_str(pokemon_fap->pdata));
submenu_add_item(
pokemon_fap->submenu, buf, PokemonScenePokerus, scene_change_from_main_cb, pokemon_fap);

Expand Down
35 changes: 4 additions & 31 deletions src/scenes/pokemon_pokerus.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@
#include <src/include/pokemon_app.h>

#include <src/scenes/include/pokemon_scene.h>

static const char* pokerus_states[] = {
"Clean",
"Infected",
"Cured",
"",
};
#include <src/include/pokemon_pokerus.h>

static const char* strains[] = {
"None",
Expand All @@ -21,16 +15,6 @@ static const char* strains[] = {
"",
};

const char* select_pokerus_status(PokemonFap* pokemon_fap) {
uint8_t pokerus;

pokerus = pokemon_stat_get(pokemon_fap->pdata, STAT_POKERUS, NONE);

if(pokerus == 0x00) return pokerus_states[0];
if((pokerus & 0x0f) != 0x00) return pokerus_states[1];
return pokerus_states[2];
}

struct pokerus_itemlist {
VariableItem* strain;
VariableItem* days;
Expand All @@ -41,13 +25,8 @@ static void select_pokerus_rebuild_list(PokemonFap* pokemon_fap);

static void select_strain_callback(VariableItem* item) {
uint8_t index = variable_item_get_current_value_index(item);
uint8_t pokerus;
PokemonFap* pokemon_fap = variable_item_get_context(item);

/* Need to read/modify/write the existing stat */
pokerus = pokemon_stat_get(pokemon_fap->pdata, STAT_POKERUS, NONE);
pokerus &= 0x0f;

/* Need to set the new text from the mangled index */
variable_item_set_current_value_text(item, strains[index]);

Expand All @@ -58,24 +37,18 @@ static void select_strain_callback(VariableItem* item) {
index = 0x04; // Map this back to the A strain
else
index--;
pokerus |= (index << 4);
if((pokerus & 0xf0) == 0x00) pokerus = 0;
pokemon_stat_set(pokemon_fap->pdata, STAT_POKERUS, NONE, pokerus);

pokerus_set_strain(pokemon_fap->pdata, index);

select_pokerus_rebuild_list(pokemon_fap);
variable_item_list_set_selected_item(pokemon_fap->variable_item_list, 0);
}

static void select_days_callback(VariableItem* item) {
uint8_t index = variable_item_get_current_value_index(item);
uint8_t pokerus;
PokemonFap* pokemon_fap = variable_item_get_context(item);

/* Need to read/modify/write the existing stat */
pokerus = pokemon_stat_get(pokemon_fap->pdata, STAT_POKERUS, NONE);
pokerus &= 0xf0;
pokerus |= index;
pokemon_stat_set(pokemon_fap->pdata, STAT_POKERUS, NONE, pokerus);
pokerus_set_days(pokemon_fap->pdata, index);

select_pokerus_rebuild_list(pokemon_fap);
variable_item_list_set_selected_item(pokemon_fap->variable_item_list, 1);
Expand Down

0 comments on commit eafd365

Please sign in to comment.