Multiple Fixes

by hedger
This commit is contained in:
MX
2023-07-05 17:59:09 +03:00
parent 255830ffab
commit 000bc845a8
9 changed files with 53 additions and 43 deletions

View File

@@ -5,7 +5,6 @@
#include <input/input.h> #include <input/input.h>
#include <notification/notification.h> #include <notification/notification.h>
#include <notification/notification_messages.h> #include <notification/notification_messages.h>
#include <gui/canvas_i.h>
#include "bomberduck_icons.h" #include "bomberduck_icons.h"
#include <dolphin/dolphin.h> #include <dolphin/dolphin.h>

View File

@@ -1 +0,0 @@
3

View File

Before

Width:  |  Height:  |  Size: 113 B

After

Width:  |  Height:  |  Size: 113 B

View File

Before

Width:  |  Height:  |  Size: 116 B

After

Width:  |  Height:  |  Size: 116 B

View File

Before

Width:  |  Height:  |  Size: 116 B

After

Width:  |  Height:  |  Size: 116 B

View File

@@ -3,7 +3,6 @@
#include <flappy_bird_icons.h> #include <flappy_bird_icons.h>
#include <furi.h> #include <furi.h>
#include <gui/gui.h> #include <gui/gui.h>
#include <gui/icon_animation_i.h>
#include <input/input.h> #include <input/input.h>
#include <dolphin/dolphin.h> #include <dolphin/dolphin.h>
@@ -30,6 +29,19 @@ typedef enum {
EventTypeKey, EventTypeKey,
} EventType; } EventType;
typedef enum {
BirdState0 = 0,
BirdState1,
BirdState2,
BirdStateMAX
} BirdState;
const Icon* bird_states[BirdStateMAX] = {
&I_bird_01,
&I_bird_02,
&I_bird_03,
};
typedef struct { typedef struct {
int x; int x;
int y; int y;
@@ -38,7 +50,6 @@ typedef struct {
typedef struct { typedef struct {
float gravity; float gravity;
POINT point; POINT point;
IconAnimation* sprite;
} BIRD; } BIRD;
typedef struct { typedef struct {
@@ -93,7 +104,6 @@ static void flappy_game_state_init(GameState* const game_state) {
bird.gravity = 0.0f; bird.gravity = 0.0f;
bird.point.x = 15; bird.point.x = 15;
bird.point.y = 32; bird.point.y = 32;
bird.sprite = icon_animation_alloc(&A_bird);
game_state->debug = DEBUG; game_state->debug = DEBUG;
game_state->bird = bird; game_state->bird = bird;
@@ -106,7 +116,6 @@ static void flappy_game_state_init(GameState* const game_state) {
} }
static void flappy_game_state_free(GameState* const game_state) { static void flappy_game_state_free(GameState* const game_state) {
icon_animation_free(game_state->bird.sprite);
free(game_state); free(game_state);
} }
@@ -224,14 +233,14 @@ static void flappy_game_render_callback(Canvas* const canvas, void* ctx) {
} }
// Switch animation // Switch animation
game_state->bird.sprite->frame = 1; BirdState bird_state = BirdState1;
if(game_state->bird.gravity < -0.5) if(game_state->bird.gravity < -0.5)
game_state->bird.sprite->frame = 0; bird_state = BirdState0;
else if(game_state->bird.gravity > 0.5) else if(game_state->bird.gravity > 0.5)
game_state->bird.sprite->frame = 2; bird_state = BirdState2;
canvas_draw_icon_animation( canvas_draw_icon(
canvas, game_state->bird.point.x, game_state->bird.point.y, game_state->bird.sprite); canvas, game_state->bird.point.x, game_state->bird.point.y, bird_states[bird_state]);
canvas_set_font(canvas, FontSecondary); canvas_set_font(canvas, FontSecondary);
char buffer[12]; char buffer[12];

View File

@@ -14,7 +14,6 @@
#include <input/input.h> #include <input/input.h>
#include <notification/notification.h> #include <notification/notification.h>
#include <notification/notification_messages.h> #include <notification/notification_messages.h>
#include <gui/canvas_i.h>
#include <dolphin/dolphin.h> #include <dolphin/dolphin.h>
#define Y_FIELD_SIZE 6 #define Y_FIELD_SIZE 6

View File

@@ -6,7 +6,6 @@
#include <notification/notification_messages.h> #include <notification/notification_messages.h>
#include <dialogs/dialogs.h> #include <dialogs/dialogs.h>
#include <m-string.h>
#include <dolphin/dolphin.h> #include <dolphin/dolphin.h>

View File

@@ -679,7 +679,7 @@ static bool swd_apscan_test(AppFSM* const ctx, uint32_t ap) {
static void swd_script_log(ScriptContext* ctx, FuriLogLevel level, const char* format, ...) { static void swd_script_log(ScriptContext* ctx, FuriLogLevel level, const char* format, ...) {
bool commandline = false; bool commandline = false;
ScriptContext* cur = ctx; ScriptContext* cur = ctx;
char buffer[256]; FuriString* buffer = furi_string_alloc();
va_list argp; va_list argp;
va_start(argp, format); va_start(argp, format);
@@ -704,17 +704,19 @@ static void swd_script_log(ScriptContext* ctx, FuriLogLevel level, const char* f
break; break;
} }
strcpy(buffer, prefix); furi_string_cat_str(buffer, prefix);
size_t pos = strlen(buffer); furi_string_cat_printf(buffer, format, argp);
vsnprintf(&buffer[pos], sizeof(buffer) - pos - 2, format, argp); furi_string_cat_str(buffer, "\n");
strcat(buffer, "\n");
if(!usb_uart_tx_data(ctx->app->uart, (uint8_t*)buffer, strlen(buffer))) { if(!usb_uart_tx_data(
ctx->app->uart, (uint8_t*)furi_string_get_cstr(buffer), furi_string_size(buffer))) {
DBGS("Sending via USB failed"); DBGS("Sending via USB failed");
} }
} else { } else {
LOG(buffer); LOG(furi_string_get_cstr(buffer));
} }
va_end(argp); va_end(argp);
furi_string_free(buffer);
} }
/* read characters until newline was read */ /* read characters until newline was read */
@@ -939,41 +941,44 @@ static bool swd_scriptfunc_goto(ScriptContext* ctx) {
return true; return true;
} }
#include <toolbox/path.h>
static bool swd_scriptfunc_call(ScriptContext* ctx) { static bool swd_scriptfunc_call(ScriptContext* ctx) {
DBGS("call"); DBGS("call");
swd_script_skip_whitespace(ctx); swd_script_skip_whitespace(ctx);
/* fetch previous file directory */ /* fetch previous file directory */
char filename[MAX_FILE_LENGTH]; FuriString* filepath = furi_string_alloc();
strncpy(filename, ctx->filename, sizeof(filename)); path_extract_dirname(ctx->filename, filepath);
char* path = strrchr(filename, '/'); // strncpy(filename, ctx->filename, sizeof(filename));
path[1] = '\000';
/* append filename */ char filename[MAX_FILE_LENGTH] = {};
if(!swd_script_get_string(ctx, &path[1], sizeof(filename) - strlen(path))) { bool success = false;
swd_script_log(ctx, FuriLogLevelError, "failed to parse filename"); do {
return false; /* append filename */
} if(!swd_script_get_string(ctx, filename, sizeof(filename))) {
swd_script_log(ctx, FuriLogLevelError, "failed to parse filename");
break;
}
swd_script_seek_newline(ctx); swd_script_seek_newline(ctx);
/* append extension */
furi_string_cat_str(filepath, ".swd");
/* append extension */ bool ret = swd_execute_script(ctx->app, furi_string_get_cstr(filepath));
if(strlen(filename) + 5 >= sizeof(filename)) {
swd_script_log(ctx, FuriLogLevelError, "name too long");
return false;
}
strcat(filename, ".swd"); if(!ret) {
swd_script_log(
ctx, FuriLogLevelError, "failed to exec '%s'", furi_string_get_cstr(filepath));
break;
}
bool ret = swd_execute_script(ctx->app, filename); success = true;
} while(false);
furi_string_free(filepath);
if(!ret) { return success;
swd_script_log(ctx, FuriLogLevelError, "failed to exec '%s'", filename);
return false;
}
return true;
} }
static bool swd_scriptfunc_status(ScriptContext* ctx) { static bool swd_scriptfunc_status(ScriptContext* ctx) {