From 796821331ffe8263eac5f9b91a4d629ee4b67ecf Mon Sep 17 00:00:00 2001 From: Alejandro Date: Thu, 6 Oct 2022 21:03:42 +0200 Subject: [PATCH 1/2] updated to furistring --- minesweeper.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/minesweeper.c b/minesweeper.c index a24f8c2..044ce85 100644 --- a/minesweeper.c +++ b/minesweeper.c @@ -79,12 +79,12 @@ static void render_callback(Canvas* const canvas, void* ctx) { if (minesweeper_state == NULL) { return; } - string_t tempStr; - string_init(tempStr); - string_printf(tempStr, "Mines: %d", MINECOUNT - minesweeper_state->flags_set); + FuriString* tempStr; + tempStr = furi_string_alloc(); + furi_string_cat_printf(tempStr, "Mines: %d", MINECOUNT - minesweeper_state->flags_set); canvas_set_font(canvas, FontSecondary); - canvas_draw_str_aligned(canvas, 0, 0, AlignLeft, AlignTop, string_get_cstr(tempStr)); - string_clear(tempStr); + canvas_draw_str_aligned(canvas, 0, 0, AlignLeft, AlignTop, furi_string_get_cstr(tempStr)); + furi_string_free(tempStr); int seconds = 0; int minutes = 0; if (minesweeper_state->game_started) { @@ -93,9 +93,9 @@ static void render_callback(Canvas* const canvas, void* ctx) { minutes = (int) seconds / 60; seconds = seconds % 60; } - string_printf(tempStr, "%01d:%02d", minutes, seconds); - canvas_draw_str_aligned(canvas, 128, 0, AlignRight, AlignTop, string_get_cstr(tempStr)); - string_clear(tempStr); + furi_string_cat_printf(tempStr, "%01d:%02d", minutes, seconds); + canvas_draw_str_aligned(canvas, 128, 0, AlignRight, AlignTop, furi_string_get_cstr(tempStr)); + furi_string_free(tempStr); for (int y = 0; y < PLAYFIELD_HEIGHT; y++) { for (int x = 0; x < PLAYFIELD_WIDTH; x++) { @@ -217,7 +217,7 @@ static void render_callback(Canvas* const canvas, void* ctx) { } } } - string_clear(tempStr); + furi_string_free(tempStr); release_mutex((ValueMutex*)ctx, minesweeper_state); } @@ -285,8 +285,8 @@ static bool game_lost(Minesweeper* minesweeper_state) { static bool game_won(Minesweeper* minesweeper_state) { DialogsApp *dialogs = furi_record_open(RECORD_DIALOGS); - string_t tempStr; - string_init(tempStr); + FuriString* tempStr; + tempStr = furi_string_alloc(); int seconds = 0; int minutes = 0; @@ -297,17 +297,16 @@ static bool game_won(Minesweeper* minesweeper_state) { DialogMessage* message = dialog_message_alloc(); const char* header_text = "Game won!"; - string_printf(tempStr, "Minefield cleared in %01d:%02d", minutes, seconds); + furi_string_cat_printf(tempStr, "Minefield cleared in %01d:%02d", minutes, seconds); dialog_message_set_header(message, header_text, 64, 3, AlignCenter, AlignTop); - dialog_message_set_text(message, string_get_cstr(tempStr), 64, 32, AlignCenter, AlignCenter); + dialog_message_set_text(message, furi_string_get_cstr(tempStr), 64, 32, AlignCenter, AlignCenter); dialog_message_set_buttons(message, NULL, "Play again", NULL); // TODO: create icon dialog_message_set_icon(message, NULL, 72, 17); DialogMessageButton choice = dialog_message_show(dialogs, message); dialog_message_free(message); - string_clear(tempStr); - string_reset(tempStr); + furi_string_free(tempStr); furi_record_close(RECORD_DIALOGS); return choice == DialogMessageButtonCenter; } @@ -513,5 +512,4 @@ int32_t minesweeper_app(void* p) { free(minesweeper_state); return 0; -} - +} \ No newline at end of file From eafcf9f673d11dbb2658d91aead2853fe6d4c041 Mon Sep 17 00:00:00 2001 From: Alejandro <45500329+Alejandro12120@users.noreply.github.com> Date: Thu, 6 Oct 2022 21:30:08 +0200 Subject: [PATCH 2/2] Update minesweeper.c --- minesweeper.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/minesweeper.c b/minesweeper.c index 044ce85..1abb91d 100644 --- a/minesweeper.c +++ b/minesweeper.c @@ -81,7 +81,7 @@ static void render_callback(Canvas* const canvas, void* ctx) { } FuriString* tempStr; tempStr = furi_string_alloc(); - furi_string_cat_printf(tempStr, "Mines: %d", MINECOUNT - minesweeper_state->flags_set); + furi_string_printf(tempStr, "Mines: %d", MINECOUNT - minesweeper_state->flags_set); canvas_set_font(canvas, FontSecondary); canvas_draw_str_aligned(canvas, 0, 0, AlignLeft, AlignTop, furi_string_get_cstr(tempStr)); furi_string_free(tempStr); @@ -93,7 +93,7 @@ static void render_callback(Canvas* const canvas, void* ctx) { minutes = (int) seconds / 60; seconds = seconds % 60; } - furi_string_cat_printf(tempStr, "%01d:%02d", minutes, seconds); + furi_string_printf(tempStr, "%01d:%02d", minutes, seconds); canvas_draw_str_aligned(canvas, 128, 0, AlignRight, AlignTop, furi_string_get_cstr(tempStr)); furi_string_free(tempStr); @@ -512,4 +512,4 @@ int32_t minesweeper_app(void* p) { free(minesweeper_state); return 0; -} \ No newline at end of file +}