Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/flipperzero-firmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Kharisov <albkharisov@gmail.com>2021-11-29 15:51:15 +0300
committerGitHub <noreply@github.com>2021-11-29 15:51:15 +0300
commitd86125c7f7b73330d75316f5996de94cee373bfd (patch)
treee77dfdb73d10a1f0a388a2317bdea876bf4f845a /applications/dolphin
parentcf591ef7ebc024a0af74e26f4b645758e44ae4bb (diff)
Fix butthurt and battery (#850)
* Fix butthurt and battery
Diffstat (limited to 'applications/dolphin')
-rw-r--r--applications/dolphin/dolphin.c1
-rw-r--r--applications/dolphin/helpers/dolphin_state.c30
2 files changed, 22 insertions, 9 deletions
diff --git a/applications/dolphin/dolphin.c b/applications/dolphin/dolphin.c
index f6871c04..9f9fe508 100644
--- a/applications/dolphin/dolphin.c
+++ b/applications/dolphin/dolphin.c
@@ -88,7 +88,6 @@ static void dolphin_check_butthurt(DolphinState* state) {
float diff_time = difftime(state->data.timestamp, dolphin_state_timestamp());
if((fabs(diff_time)) > DOLPHIN_TIMEGATE) {
- FURI_LOG_I("DolphinState", "Increasing butthurt");
dolphin_state_butthurted(state);
}
}
diff --git a/applications/dolphin/helpers/dolphin_state.c b/applications/dolphin/helpers/dolphin_state.c
index 13b8ca95..2878edf5 100644
--- a/applications/dolphin/helpers/dolphin_state.c
+++ b/applications/dolphin/helpers/dolphin_state.c
@@ -12,6 +12,8 @@
#define DOLPHIN_LVL_THRESHOLD 20.0f
#define LEVEL2_THRESHOLD 20
#define LEVEL3_THRESHOLD 100
+#define BUTTHURT_MAX 14
+#define BUTTHURT_MIN 0
DolphinState* dolphin_state_alloc() {
return furi_alloc(sizeof(DolphinState));
@@ -44,20 +46,27 @@ bool dolphin_state_save(DolphinState* dolphin_state) {
}
bool dolphin_state_load(DolphinState* dolphin_state) {
- bool loaded = saved_struct_load(
+ bool success = saved_struct_load(
DOLPHIN_STATE_PATH,
&dolphin_state->data,
sizeof(DolphinStoreData),
DOLPHIN_STATE_HEADER_MAGIC,
DOLPHIN_STATE_HEADER_VERSION);
- if(!loaded) {
+ if(success) {
+ if((dolphin_state->data.butthurt > BUTTHURT_MAX) ||
+ (dolphin_state->data.butthurt < BUTTHURT_MIN)) {
+ success = false;
+ }
+ }
+
+ if(!success) {
FURI_LOG_W(TAG, "Reset dolphin-state");
memset(dolphin_state, 0, sizeof(*dolphin_state));
dolphin_state->dirty = true;
}
- return loaded;
+ return success;
}
uint64_t dolphin_state_timestamp() {
@@ -124,8 +133,10 @@ bool dolphin_state_on_deed(DolphinState* dolphin_state, DolphinDeed deed) {
dolphin_state->data.icounter += MIN(xp_to_levelup, deed_weight->icounter);
}
- uint32_t new_butthurt =
- CLAMP(((int32_t)dolphin_state->data.butthurt) + deed_weight->butthurt, 14, 0);
+ uint32_t new_butthurt = CLAMP(
+ ((int32_t)dolphin_state->data.butthurt) + deed_weight->butthurt,
+ BUTTHURT_MAX,
+ BUTTHURT_MIN);
if(!!dolphin_state->data.butthurt != !!new_butthurt) {
mood_changed = true;
@@ -138,9 +149,12 @@ bool dolphin_state_on_deed(DolphinState* dolphin_state, DolphinDeed deed) {
}
void dolphin_state_butthurted(DolphinState* dolphin_state) {
- dolphin_state->data.butthurt++;
- dolphin_state->data.timestamp = dolphin_state_timestamp();
- dolphin_state->dirty = true;
+ if(dolphin_state->data.butthurt < BUTTHURT_MAX) {
+ dolphin_state->data.butthurt++;
+ FURI_LOG_I("DolphinState", "Increasing butthurt");
+ dolphin_state->data.timestamp = dolphin_state_timestamp();
+ dolphin_state->dirty = true;
+ }
}
void dolphin_state_increase_level(DolphinState* dolphin_state) {