parent
cf591ef7eb
commit
d86125c7f7
@ -88,7 +88,6 @@ static void dolphin_check_butthurt(DolphinState* state) {
|
|||||||
float diff_time = difftime(state->data.timestamp, dolphin_state_timestamp());
|
float diff_time = difftime(state->data.timestamp, dolphin_state_timestamp());
|
||||||
|
|
||||||
if((fabs(diff_time)) > DOLPHIN_TIMEGATE) {
|
if((fabs(diff_time)) > DOLPHIN_TIMEGATE) {
|
||||||
FURI_LOG_I("DolphinState", "Increasing butthurt");
|
|
||||||
dolphin_state_butthurted(state);
|
dolphin_state_butthurted(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
#define DOLPHIN_LVL_THRESHOLD 20.0f
|
#define DOLPHIN_LVL_THRESHOLD 20.0f
|
||||||
#define LEVEL2_THRESHOLD 20
|
#define LEVEL2_THRESHOLD 20
|
||||||
#define LEVEL3_THRESHOLD 100
|
#define LEVEL3_THRESHOLD 100
|
||||||
|
#define BUTTHURT_MAX 14
|
||||||
|
#define BUTTHURT_MIN 0
|
||||||
|
|
||||||
DolphinState* dolphin_state_alloc() {
|
DolphinState* dolphin_state_alloc() {
|
||||||
return furi_alloc(sizeof(DolphinState));
|
return furi_alloc(sizeof(DolphinState));
|
||||||
@ -44,20 +46,27 @@ bool dolphin_state_save(DolphinState* dolphin_state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool dolphin_state_load(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_PATH,
|
||||||
&dolphin_state->data,
|
&dolphin_state->data,
|
||||||
sizeof(DolphinStoreData),
|
sizeof(DolphinStoreData),
|
||||||
DOLPHIN_STATE_HEADER_MAGIC,
|
DOLPHIN_STATE_HEADER_MAGIC,
|
||||||
DOLPHIN_STATE_HEADER_VERSION);
|
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");
|
FURI_LOG_W(TAG, "Reset dolphin-state");
|
||||||
memset(dolphin_state, 0, sizeof(*dolphin_state));
|
memset(dolphin_state, 0, sizeof(*dolphin_state));
|
||||||
dolphin_state->dirty = true;
|
dolphin_state->dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return loaded;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t dolphin_state_timestamp() {
|
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);
|
dolphin_state->data.icounter += MIN(xp_to_levelup, deed_weight->icounter);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t new_butthurt =
|
uint32_t new_butthurt = CLAMP(
|
||||||
CLAMP(((int32_t)dolphin_state->data.butthurt) + deed_weight->butthurt, 14, 0);
|
((int32_t)dolphin_state->data.butthurt) + deed_weight->butthurt,
|
||||||
|
BUTTHURT_MAX,
|
||||||
|
BUTTHURT_MIN);
|
||||||
|
|
||||||
if(!!dolphin_state->data.butthurt != !!new_butthurt) {
|
if(!!dolphin_state->data.butthurt != !!new_butthurt) {
|
||||||
mood_changed = true;
|
mood_changed = true;
|
||||||
@ -138,9 +149,12 @@ bool dolphin_state_on_deed(DolphinState* dolphin_state, DolphinDeed deed) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void dolphin_state_butthurted(DolphinState* dolphin_state) {
|
void dolphin_state_butthurted(DolphinState* dolphin_state) {
|
||||||
|
if(dolphin_state->data.butthurt < BUTTHURT_MAX) {
|
||||||
dolphin_state->data.butthurt++;
|
dolphin_state->data.butthurt++;
|
||||||
|
FURI_LOG_I("DolphinState", "Increasing butthurt");
|
||||||
dolphin_state->data.timestamp = dolphin_state_timestamp();
|
dolphin_state->data.timestamp = dolphin_state_timestamp();
|
||||||
dolphin_state->dirty = true;
|
dolphin_state->dirty = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void dolphin_state_increase_level(DolphinState* dolphin_state) {
|
void dolphin_state_increase_level(DolphinState* dolphin_state) {
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#include <gui/view.h>
|
#include <gui/view.h>
|
||||||
|
|
||||||
#define POWER_OFF_TIMEOUT 90
|
#define POWER_OFF_TIMEOUT 90
|
||||||
#define POWER_BATTERY_WELL_LEVEL 99
|
#define POWER_BATTERY_WELL_LEVEL 70
|
||||||
|
|
||||||
bool power_is_battery_well(PowerInfo* info) {
|
bool power_is_battery_well(PowerInfo* info) {
|
||||||
return info->health > POWER_BATTERY_WELL_LEVEL;
|
return info->health > POWER_BATTERY_WELL_LEVEL;
|
||||||
@ -172,6 +172,7 @@ static void power_check_battery_level_change(Power* power) {
|
|||||||
int32_t power_srv(void* p) {
|
int32_t power_srv(void* p) {
|
||||||
(void)p;
|
(void)p;
|
||||||
Power* power = power_alloc();
|
Power* power = power_alloc();
|
||||||
|
power_update_info(power);
|
||||||
furi_record_create("power", power);
|
furi_record_create("power", power);
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
|
Loading…
Reference in New Issue
Block a user