Skip to content

Commit eafd365

Browse files
committed
pokerus: Separate out accessor functions from scene
Signed-off-by: Kris Bahnsen <Kris@KBEmbedded.com>
1 parent 2f9f536 commit eafd365

File tree

5 files changed

+71
-43
lines changed

5 files changed

+71
-43
lines changed

src/include/pokemon_pokerus.h

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef POKEMON_POKERUS_H
2+
#define POKEMON_POKERUS_H
3+
4+
#include <src/include/pokemon_data.h>
5+
6+
#pragma once
7+
8+
const char* pokerus_get_status_str(PokemonData* pdata);
9+
10+
void pokerus_set_strain(PokemonData* pdata, uint8_t strain);
11+
12+
void pokerus_set_days(PokemonData *pdata, uint8_t days);
13+
14+
#endif // POKEMON_POKERUS_H

src/pokemon_pokerus.c

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include <gui/modules/variable_item_list.h>
2+
#include <furi.h>
3+
4+
#include <src/include/pokemon_data.h>
5+
6+
static const char* pokerus_states[] = {
7+
"Clean",
8+
"Infected",
9+
"Cured",
10+
"",
11+
};
12+
13+
const char* pokerus_get_status_str(PokemonData* pdata) {
14+
uint8_t pokerus;
15+
16+
pokerus = pokemon_stat_get(pdata, STAT_POKERUS, NONE);
17+
18+
if(pokerus == 0x00)
19+
return pokerus_states[0];
20+
21+
if((pokerus & 0x0f) != 0x00)
22+
return pokerus_states[1];
23+
24+
return pokerus_states[2];
25+
}
26+
27+
void pokerus_set_strain(PokemonData* pdata, uint8_t strain) {
28+
uint8_t pokerus;
29+
30+
/* Need to read/modify/write the existing stat */
31+
pokerus = pokemon_stat_get(pdata, STAT_POKERUS, NONE);
32+
pokerus &= 0x0f;
33+
pokerus |= (strain << 4);
34+
35+
if((pokerus & 0xf0) == 0x00)
36+
pokerus = 0;
37+
38+
pokemon_stat_set(pdata, STAT_POKERUS, NONE, pokerus);
39+
}
40+
41+
void pokerus_set_days(PokemonData *pdata, uint8_t days) {
42+
uint8_t pokerus;
43+
44+
days &= 0x0f;
45+
46+
/* Need to read/modify/write the existing stat */
47+
pokerus = pokemon_stat_get(pdata, STAT_POKERUS, NONE);
48+
pokerus &= 0xf0;
49+
pokerus |= days;
50+
pokemon_stat_set(pdata, STAT_POKERUS, NONE, pokerus);
51+
}

src/scenes/include/pokemon_pokerus.h

-10
This file was deleted.

src/scenes/pokemon_gen.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <src/scenes/include/pokemon_menu.h>
1313
#include <src/include/pokemon_shiny.h>
1414
#include <src/include/pokemon_gender.h>
15-
#include <src/scenes/include/pokemon_pokerus.h>
15+
#include <src/include/pokemon_pokerus.h>
1616
#include <src/include/unown_form.h>
1717

1818
static void scene_change_from_main_cb(void* context, uint32_t index) {
@@ -188,7 +188,7 @@ void pokemon_scene_gen_on_enter(void* context) {
188188
submenu_add_item(
189189
pokemon_fap->submenu, buf, PokemonSceneGender, scene_change_from_main_cb, pokemon_fap);
190190

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

src/scenes/pokemon_pokerus.c

+4-31
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@
44
#include <src/include/pokemon_app.h>
55

66
#include <src/scenes/include/pokemon_scene.h>
7-
8-
static const char* pokerus_states[] = {
9-
"Clean",
10-
"Infected",
11-
"Cured",
12-
"",
13-
};
7+
#include <src/include/pokemon_pokerus.h>
148

159
static const char* strains[] = {
1610
"None",
@@ -21,16 +15,6 @@ static const char* strains[] = {
2115
"",
2216
};
2317

24-
const char* select_pokerus_status(PokemonFap* pokemon_fap) {
25-
uint8_t pokerus;
26-
27-
pokerus = pokemon_stat_get(pokemon_fap->pdata, STAT_POKERUS, NONE);
28-
29-
if(pokerus == 0x00) return pokerus_states[0];
30-
if((pokerus & 0x0f) != 0x00) return pokerus_states[1];
31-
return pokerus_states[2];
32-
}
33-
3418
struct pokerus_itemlist {
3519
VariableItem* strain;
3620
VariableItem* days;
@@ -41,13 +25,8 @@ static void select_pokerus_rebuild_list(PokemonFap* pokemon_fap);
4125

4226
static void select_strain_callback(VariableItem* item) {
4327
uint8_t index = variable_item_get_current_value_index(item);
44-
uint8_t pokerus;
4528
PokemonFap* pokemon_fap = variable_item_get_context(item);
4629

47-
/* Need to read/modify/write the existing stat */
48-
pokerus = pokemon_stat_get(pokemon_fap->pdata, STAT_POKERUS, NONE);
49-
pokerus &= 0x0f;
50-
5130
/* Need to set the new text from the mangled index */
5231
variable_item_set_current_value_text(item, strains[index]);
5332

@@ -58,24 +37,18 @@ static void select_strain_callback(VariableItem* item) {
5837
index = 0x04; // Map this back to the A strain
5938
else
6039
index--;
61-
pokerus |= (index << 4);
62-
if((pokerus & 0xf0) == 0x00) pokerus = 0;
63-
pokemon_stat_set(pokemon_fap->pdata, STAT_POKERUS, NONE, pokerus);
40+
41+
pokerus_set_strain(pokemon_fap->pdata, index);
6442

6543
select_pokerus_rebuild_list(pokemon_fap);
6644
variable_item_list_set_selected_item(pokemon_fap->variable_item_list, 0);
6745
}
6846

6947
static void select_days_callback(VariableItem* item) {
7048
uint8_t index = variable_item_get_current_value_index(item);
71-
uint8_t pokerus;
7249
PokemonFap* pokemon_fap = variable_item_get_context(item);
7350

74-
/* Need to read/modify/write the existing stat */
75-
pokerus = pokemon_stat_get(pokemon_fap->pdata, STAT_POKERUS, NONE);
76-
pokerus &= 0xf0;
77-
pokerus |= index;
78-
pokemon_stat_set(pokemon_fap->pdata, STAT_POKERUS, NONE, pokerus);
51+
pokerus_set_days(pokemon_fap->pdata, index);
7952

8053
select_pokerus_rebuild_list(pokemon_fap);
8154
variable_item_list_set_selected_item(pokemon_fap->variable_item_list, 1);

0 commit comments

Comments
 (0)