[FL-2183] [FL-2209] Dolphin Deeds, Level up, assets generation, refactoring (#965)
* Desktop: cleanup headers * Get loader pubsub via record * [FL-2183] Dolphin refactoring 2022.01 * Restruct animations assets structure * Rename assets * Cleanup headers * Update Recording animation * Add BadBattery animation * Provide loader's pubsub via record * Fix load/unload animations * Scripts: add flipper format support, initial dolphin packager rework. Assets: internal and external dolphin. * Sync internal meta.txt and manifest.txt * Reorder, rename dolphin assets * Split essential generated assets * Add ReadMe for dolphin assets * Separate essential blocking animations * Scripts: full dolphin validation before packaging * Assets, Scripts: dolphin external resources packer * Github: update codeowners * Scripts: proper slots handling in dolphin animation meta * Scripts: correct frames enumeration and fix compiled assets. * [FL-2209] Add Dolphin Deeds points and many more * Remove excess frame_rate * Change dolphin assets directory * Scripts: add internal resource support to dolphin compiler * Scripts: add internal assets generation, renaming * Scripts: correct assert, renaming * Code cleanup, documentation, fixes * Update Levelup animations * Rename essential -> blocking * Fix Unlocked hint * Scripts: rewrite Templite compiller, replace regexps with token parser, split block types into code and variable blocks. Update dolphin templates. * Documentation: add key combos description and use information * Scripts: cleanup templit, more debug info and add dev comment Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -1,14 +1,65 @@
|
||||
#include "dolphin_deed.h"
|
||||
#include <furi.h>
|
||||
|
||||
static const DolphinDeedWeight dolphin_deed_weights[DolphinDeedMax] = {
|
||||
{1, -1, 60},
|
||||
{1, -1, 60},
|
||||
{1, -1, 60},
|
||||
{-1, 1, 60},
|
||||
static const DolphinDeedWeight dolphin_deed_weights[] = {
|
||||
{1, DolphinAppSubGhz}, // DolphinDeedSubGhzReceiverInfo
|
||||
{3, DolphinAppSubGhz}, // DolphinDeedSubGhzSave
|
||||
{1, DolphinAppSubGhz}, // DolphinDeedSubGhzRawRec
|
||||
{2, DolphinAppSubGhz}, // DolphinDeedSubGhzAddManually
|
||||
{2, DolphinAppSubGhz}, // DolphinDeedSubGhzSend
|
||||
{1, DolphinAppSubGhz}, // DolphinDeedSubGhzFrequencyAnalyzer
|
||||
|
||||
{1, DolphinAppRfid}, // DolphinDeedRfidRead
|
||||
{3, DolphinAppRfid}, // DolphinDeedRfidReadSuccess
|
||||
{3, DolphinAppRfid}, // DolphinDeedRfidSave
|
||||
{2, DolphinAppRfid}, // DolphinDeedRfidEmulate
|
||||
{2, DolphinAppRfid}, // DolphinDeedRfidAdd
|
||||
|
||||
{1, DolphinAppNfc}, // DolphinDeedNfcRead
|
||||
{3, DolphinAppNfc}, // DolphinDeedNfcReadSuccess
|
||||
{3, DolphinAppNfc}, // DolphinDeedNfcSave
|
||||
{2, DolphinAppNfc}, // DolphinDeedNfcEmulate
|
||||
{2, DolphinAppNfc}, // DolphinDeedNfcAdd
|
||||
|
||||
{1, DolphinAppIr}, // DolphinDeedIrSend
|
||||
{3, DolphinAppIr}, // DolphinDeedIrLearnSuccess
|
||||
{3, DolphinAppIr}, // DolphinDeedIrSave
|
||||
{2, DolphinAppIr}, // DolphinDeedIrBruteForce
|
||||
|
||||
{1, DolphinAppIbutton}, // DolphinDeedIbuttonRead
|
||||
{3, DolphinAppIbutton}, // DolphinDeedIbuttonReadSuccess
|
||||
{3, DolphinAppIbutton}, // DolphinDeedIbuttonSave
|
||||
{2, DolphinAppIbutton}, // DolphinDeedIbuttonEmulate
|
||||
{2, DolphinAppIbutton}, // DolphinDeedIbuttonAdd
|
||||
|
||||
{3, DolphinAppBadusb}, // DolphinDeedBadUsbPlayScript
|
||||
{3, DolphinAppU2f}, // DolphinDeedU2fAuthorized
|
||||
};
|
||||
|
||||
const DolphinDeedWeight* dolphin_deed_weight(DolphinDeed deed) {
|
||||
furi_assert(deed < DolphinDeedMax);
|
||||
return &dolphin_deed_weights[deed];
|
||||
static uint8_t dolphin_deed_limits[] = {
|
||||
15, // DolphinAppSubGhz
|
||||
15, // DolphinAppRfid
|
||||
15, // DolphinAppNfc
|
||||
15, // DolphinAppIr
|
||||
15, // DolphinAppIbutton
|
||||
15, // DolphinAppBadusb
|
||||
15, // DolphinAppU2f
|
||||
};
|
||||
|
||||
_Static_assert(COUNT_OF(dolphin_deed_weights) == DolphinDeedMAX, "dolphin_deed_weights size error");
|
||||
_Static_assert(COUNT_OF(dolphin_deed_limits) == DolphinAppMAX, "dolphin_deed_limits size error");
|
||||
|
||||
uint8_t dolphin_deed_get_weight(DolphinDeed deed) {
|
||||
furi_check(deed < DolphinDeedMAX);
|
||||
return dolphin_deed_weights[deed].icounter;
|
||||
}
|
||||
|
||||
DolphinApp dolphin_deed_get_app(DolphinDeed deed) {
|
||||
furi_check(deed < DolphinDeedMAX);
|
||||
return dolphin_deed_weights[deed].app;
|
||||
}
|
||||
|
||||
uint8_t dolphin_deed_get_app_limit(DolphinApp app) {
|
||||
furi_check(app < DolphinAppMAX);
|
||||
return dolphin_deed_limits[app];
|
||||
}
|
||||
|
@@ -2,23 +2,73 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* Countable deed that affects icounter*/
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
// iButton
|
||||
DolphinDeedIButtonRead,
|
||||
DolphinDeedIButtonWrite,
|
||||
DolphinDeedIButtonEmulate,
|
||||
// for debug
|
||||
DolphinDeedWrong,
|
||||
// Special value, do not use
|
||||
DolphinDeedMax
|
||||
DolphinAppSubGhz,
|
||||
DolphinAppRfid,
|
||||
DolphinAppNfc,
|
||||
DolphinAppIr,
|
||||
DolphinAppIbutton,
|
||||
DolphinAppBadusb,
|
||||
DolphinAppU2f,
|
||||
DolphinAppMAX,
|
||||
} DolphinApp;
|
||||
|
||||
typedef enum {
|
||||
DolphinDeedSubGhzReceiverInfo,
|
||||
DolphinDeedSubGhzSave,
|
||||
DolphinDeedSubGhzRawRec,
|
||||
DolphinDeedSubGhzAddManually,
|
||||
DolphinDeedSubGhzSend,
|
||||
DolphinDeedSubGhzFrequencyAnalyzer,
|
||||
|
||||
DolphinDeedRfidRead,
|
||||
DolphinDeedRfidReadSuccess,
|
||||
DolphinDeedRfidSave,
|
||||
DolphinDeedRfidEmulate,
|
||||
DolphinDeedRfidAdd,
|
||||
|
||||
DolphinDeedNfcRead,
|
||||
DolphinDeedNfcReadSuccess,
|
||||
DolphinDeedNfcSave,
|
||||
DolphinDeedNfcEmulate,
|
||||
DolphinDeedNfcAdd,
|
||||
|
||||
DolphinDeedIrSend,
|
||||
DolphinDeedIrLearnSuccess,
|
||||
DolphinDeedIrSave,
|
||||
DolphinDeedIrBruteForce,
|
||||
|
||||
DolphinDeedIbuttonRead,
|
||||
DolphinDeedIbuttonReadSuccess,
|
||||
DolphinDeedIbuttonSave,
|
||||
DolphinDeedIbuttonEmulate,
|
||||
DolphinDeedIbuttonAdd,
|
||||
|
||||
DolphinDeedBadUsbPlayScript,
|
||||
|
||||
DolphinDeedU2fAuthorized,
|
||||
|
||||
DolphinDeedMAX
|
||||
} DolphinDeed;
|
||||
|
||||
typedef struct {
|
||||
int32_t icounter; // how many icounter get by Deed
|
||||
int32_t butthurt; // how many icounter get by Deed
|
||||
uint32_t limit_value; // how many deeds in limit interval
|
||||
uint32_t limit_interval; // interval, in minutes
|
||||
uint8_t icounter;
|
||||
DolphinApp app;
|
||||
} DolphinDeedWeight;
|
||||
|
||||
const DolphinDeedWeight* dolphin_deed_weight(DolphinDeed deed);
|
||||
typedef struct {
|
||||
DolphinApp app;
|
||||
uint8_t icounter_limit;
|
||||
} DolphinDeedLimits;
|
||||
|
||||
DolphinApp dolphin_deed_get_app(DolphinDeed deed);
|
||||
uint8_t dolphin_deed_get_app_limit(DolphinApp app);
|
||||
uint8_t dolphin_deed_get_weight(DolphinDeed deed);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@@ -1,4 +1,5 @@
|
||||
#include "dolphin_state.h"
|
||||
#include "dolphin/helpers/dolphin_deed.h"
|
||||
#include <stdint.h>
|
||||
#include <storage/storage.h>
|
||||
#include <furi.h>
|
||||
@@ -10,9 +11,8 @@
|
||||
#define DOLPHIN_STATE_PATH "/int/dolphin.state"
|
||||
#define DOLPHIN_STATE_HEADER_MAGIC 0xD0
|
||||
#define DOLPHIN_STATE_HEADER_VERSION 0x01
|
||||
#define DOLPHIN_LVL_THRESHOLD 20.0f
|
||||
#define LEVEL2_THRESHOLD 20
|
||||
#define LEVEL3_THRESHOLD 100
|
||||
#define LEVEL2_THRESHOLD 735
|
||||
#define LEVEL3_THRESHOLD 2940
|
||||
#define BUTTHURT_MAX 14
|
||||
#define BUTTHURT_MIN 0
|
||||
|
||||
@@ -125,50 +125,68 @@ uint32_t dolphin_state_xp_to_levelup(uint32_t icounter) {
|
||||
return threshold - icounter;
|
||||
}
|
||||
|
||||
bool dolphin_state_on_deed(DolphinState* dolphin_state, DolphinDeed deed) {
|
||||
const DolphinDeedWeight* deed_weight = dolphin_deed_weight(deed);
|
||||
int32_t icounter = dolphin_state->data.icounter + deed_weight->icounter;
|
||||
bool level_up = false;
|
||||
bool mood_changed = false;
|
||||
|
||||
if(icounter <= 0) {
|
||||
icounter = 0;
|
||||
if(dolphin_state->data.icounter == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
void dolphin_state_on_deed(DolphinState* dolphin_state, DolphinDeed deed) {
|
||||
DolphinApp app = dolphin_deed_get_app(deed);
|
||||
int8_t weight_limit =
|
||||
dolphin_deed_get_app_limit(app) - dolphin_state->data.icounter_daily_limit[app];
|
||||
uint8_t deed_weight = CLAMP(dolphin_deed_get_weight(deed), weight_limit, 0);
|
||||
|
||||
uint8_t xp_to_levelup = dolphin_state_xp_to_levelup(dolphin_state->data.icounter);
|
||||
if(xp_to_levelup) {
|
||||
level_up = true;
|
||||
dolphin_state->data.icounter += MIN(xp_to_levelup, deed_weight->icounter);
|
||||
deed_weight = MIN(xp_to_levelup, deed_weight);
|
||||
dolphin_state->data.icounter += deed_weight;
|
||||
dolphin_state->data.icounter_daily_limit[app] += deed_weight;
|
||||
}
|
||||
|
||||
uint32_t new_butthurt = CLAMP(
|
||||
((int32_t)dolphin_state->data.butthurt) + deed_weight->butthurt,
|
||||
BUTTHURT_MAX,
|
||||
BUTTHURT_MIN);
|
||||
/* decrease butthurt:
|
||||
* 0 deeds accumulating --> 0 butthurt
|
||||
* +1....+15 deeds accumulating --> -1 butthurt
|
||||
* +16...+30 deeds accumulating --> -1 butthurt
|
||||
* +31...+45 deeds accumulating --> -1 butthurt
|
||||
* +46...... deeds accumulating --> -1 butthurt
|
||||
* -4 butthurt per day is maximum
|
||||
* */
|
||||
uint8_t butthurt_icounter_level_old = dolphin_state->data.butthurt_daily_limit / 15 +
|
||||
!!(dolphin_state->data.butthurt_daily_limit % 15);
|
||||
dolphin_state->data.butthurt_daily_limit =
|
||||
CLAMP(dolphin_state->data.butthurt_daily_limit + deed_weight, 46, 0);
|
||||
uint8_t butthurt_icounter_level_new = dolphin_state->data.butthurt_daily_limit / 15 +
|
||||
!!(dolphin_state->data.butthurt_daily_limit % 15);
|
||||
int32_t new_butthurt = ((int32_t)dolphin_state->data.butthurt) -
|
||||
(butthurt_icounter_level_old != butthurt_icounter_level_new);
|
||||
new_butthurt = CLAMP(new_butthurt, BUTTHURT_MAX, BUTTHURT_MIN);
|
||||
|
||||
if(!!dolphin_state->data.butthurt != !!new_butthurt) {
|
||||
mood_changed = true;
|
||||
}
|
||||
dolphin_state->data.butthurt = new_butthurt;
|
||||
dolphin_state->data.timestamp = dolphin_state_timestamp();
|
||||
dolphin_state->dirty = true;
|
||||
|
||||
return level_up || mood_changed;
|
||||
FURI_LOG_D(
|
||||
TAG,
|
||||
"icounter %d, butthurt %d",
|
||||
dolphin_state->data.icounter,
|
||||
dolphin_state->data.butthurt);
|
||||
}
|
||||
|
||||
void dolphin_state_butthurted(DolphinState* dolphin_state) {
|
||||
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) {
|
||||
furi_assert(dolphin_state_is_levelup(dolphin_state->data.icounter));
|
||||
++dolphin_state->data.icounter;
|
||||
dolphin_state->dirty = true;
|
||||
}
|
||||
|
||||
void dolphin_state_clear_limits(DolphinState* dolphin_state) {
|
||||
furi_assert(dolphin_state);
|
||||
|
||||
for(int i = 0; i < DolphinAppMAX; ++i) {
|
||||
dolphin_state->data.icounter_daily_limit[i] = 0;
|
||||
}
|
||||
dolphin_state->data.butthurt_daily_limit = 0;
|
||||
dolphin_state->dirty = true;
|
||||
}
|
||||
|
@@ -7,10 +7,8 @@
|
||||
|
||||
typedef struct DolphinState DolphinState;
|
||||
typedef struct {
|
||||
uint32_t limit_ibutton;
|
||||
uint32_t limit_nfc;
|
||||
uint32_t limit_ir;
|
||||
uint32_t limit_rfid;
|
||||
uint8_t icounter_daily_limit[DolphinAppMAX];
|
||||
uint8_t butthurt_daily_limit;
|
||||
|
||||
uint32_t flags;
|
||||
uint32_t icounter;
|
||||
@@ -31,11 +29,11 @@ bool dolphin_state_save(DolphinState* dolphin_state);
|
||||
|
||||
bool dolphin_state_load(DolphinState* dolphin_state);
|
||||
|
||||
void dolphin_state_clear(DolphinState* dolphin_state);
|
||||
void dolphin_state_clear_limits(DolphinState* dolphin_state);
|
||||
|
||||
uint64_t dolphin_state_timestamp();
|
||||
|
||||
bool dolphin_state_on_deed(DolphinState* dolphin_state, DolphinDeed deed);
|
||||
void dolphin_state_on_deed(DolphinState* dolphin_state, DolphinDeed deed);
|
||||
|
||||
void dolphin_state_butthurted(DolphinState* dolphin_state);
|
||||
|
||||
|
Reference in New Issue
Block a user