Przeglądaj źródła

v4 endpoints + double world size

jblanked 1 rok temu
rodzic
commit
ce86800c67
7 zmienionych plików z 81 dodań i 23 usunięć
  1. 58 3
      callback/callback.c
  2. 3 3
      flip_world.h
  3. 6 2
      game/game.c
  4. 8 9
      game/icon.c
  5. 2 2
      game/level.c
  6. 1 1
      game/world.c
  7. 3 3
      game/world.h

+ 58 - 3
callback/callback.c

@@ -748,7 +748,7 @@ static bool fetch_world_list(FlipperHTTP *fhttp)
         STORAGE_EXT_PATH_PREFIX "/apps_data/flip_world/worlds/world_list.json");
 
     fhttp->save_received_data = true;
-    return flipper_http_get_request_with_headers(fhttp, "https://www.flipsocial.net/api/world/v3/list/10/", "{\"Content-Type\":\"application/json\"}");
+    return flipper_http_get_request_with_headers(fhttp, "https://www.flipsocial.net/api/world/v4/list/10/", "{\"Content-Type\":\"application/json\"}");
 }
 // we will load the palyer stats from the API and save them
 // in player_spawn game method, it will load the player stats that we saved
@@ -778,6 +778,61 @@ static bool fetch_player_stats(FlipperHTTP *fhttp)
     return flipper_http_get_request_with_headers(fhttp, url, "{\"Content-Type\":\"application/json\"}");
 }
 
+// static bool fetch_app_update(FlipperHTTP *fhttp)
+// {
+//     if (!fhttp)
+//     {
+//         FURI_LOG_E(TAG, "fhttp is NULL");
+//         easy_flipper_dialog("Error", "fhttp is NULL. Press BACK to return.");
+//         return false;
+//     }
+
+//     return flipper_http_get_request_with_headers(fhttp, "https://www.flipsocial.net/api/app/last-updated/flip_world/", "{\"Content-Type\":\"application/json\"}");
+// }
+
+// static bool parse_app_update(FlipperHTTP *fhttp)
+// {
+//     if (!fhttp)
+//     {
+//         FURI_LOG_E(TAG, "fhttp is NULL");
+//         easy_flipper_dialog("Error", "fhttp is NULL. Press BACK to return.");
+//         return false;
+//     }
+//     if (fhttp->last_response == NULL || strlen(fhttp->last_response) == 0)
+//     {
+//         FURI_LOG_E(TAG, "fhttp->last_response is NULL or empty");
+//         easy_flipper_dialog("Error", "fhttp->last_response is NULL or empty. Press BACK to return.");
+//         return false;
+//     }
+//     bool last_update_available = false;
+//     char last_updated_old[32];
+//     // load the previous last_updated
+//     if (!load_char("last_updated", last_updated_old, sizeof(last_updated_old)))
+//     {
+//         FURI_LOG_E(TAG, "Failed to load last_updated");
+//         // it's okay, we'll just update it
+//     }
+//     // save the new last_updated
+//     save_char("last_updated", fhttp->last_response);
+
+//     // compare the two
+//     if (strlen(last_updated_old) == 0 || !is_str(last_updated_old, fhttp->last_response))
+//     {
+//         last_update_available = true;
+//     }
+
+//     if (last_update_available)
+//     {
+//         easy_flipper_dialog("Update Available", "An update is available. Press OK to update.");
+//         return true;
+//     }
+//     else
+//     {
+//         easy_flipper_dialog("No Update Available", "No update is available. Press OK to continue.");
+//         return false;
+//     }
+// }
+
 static bool start_game_thread(void *context)
 {
     FlipWorldApp *app = (FlipWorldApp *)context;
@@ -931,7 +986,7 @@ static bool _fetch_game(DataLoaderModel *model)
 
         model->fhttp->save_received_data = true;
         char url[128];
-        snprintf(url, sizeof(url), "https://www.flipsocial.net/api/world/v3/get/world/%s/", furi_string_get_cstr(first_world));
+        snprintf(url, sizeof(url), "https://www.flipsocial.net/api/world/v4/get/world/%s/", furi_string_get_cstr(first_world));
         furi_string_free(world_list);
         furi_string_free(first_world);
         return flipper_http_get_request_with_headers(model->fhttp, url, "{\"Content-Type\":\"application/json\"}");
@@ -1542,7 +1597,7 @@ static bool _fetch_worlds(DataLoaderModel *model)
         sizeof(model->fhttp->file_path),
         STORAGE_EXT_PATH_PREFIX "/apps_data/flip_world/worlds/world_list_full.json");
     model->fhttp->save_received_data = true;
-    return flipper_http_get_request_with_headers(model->fhttp, "https://www.flipsocial.net/api/world/v3/get/10/", "{\"Content-Type\":\"application/json\"}");
+    return flipper_http_get_request_with_headers(model->fhttp, "https://www.flipsocial.net/api/world/v4/get/10/", "{\"Content-Type\":\"application/json\"}");
 }
 static char *_parse_worlds(DataLoaderModel *model)
 {

+ 3 - 3
flip_world.h

@@ -4,8 +4,8 @@
 #include <easy_flipper/easy_flipper.h>
 
 // added by Derek Jamison to lower memory usage
-#undef FURI_LOG_E
-#define FURI_LOG_E(tag, msg, ...)
+// #undef FURI_LOG_E
+// #define FURI_LOG_E(tag, msg, ...)
 
 // #undef FURI_LOG_I
 // #define FURI_LOG_I(tag, msg, ...)
@@ -13,7 +13,7 @@
 
 #define TAG "FlipWorld"
 #define VERSION 0.4
-#define VERSION_TAG "FlipWorld v0.4"
+#define VERSION_TAG TAG " " FAP_VERSION
 
 // Define the submenu items for our FlipWorld application
 typedef enum

+ 6 - 2
game/game.c

@@ -13,9 +13,10 @@ static void game_start(GameManager *game_manager, void *ctx)
     GameContext *game_context = ctx;
     game_context->fps = atof_(fps_choices_str[fps_index]);
     game_context->player_context = NULL;
-    game_context->current_level = 0;
     game_context->ended_early = false;
+    game_context->current_level = 0;
     game_context->level_count = 0;
+    game_context->enemy_count = 0;
 
     // set all levels to NULL
     for (int i = 0; i < MAX_LEVELS; i++)
@@ -36,7 +37,10 @@ static void game_start(GameManager *game_manager, void *ctx)
             }
             break;
         }
-        game_context->level_count++;
+        else
+        {
+            game_context->level_count++;
+        }
     }
 
     // imu

+ 8 - 9
game/icon.c

@@ -183,10 +183,10 @@ IconContext *get_icon_context(const char *name)
     {
         return icon_generic_alloc("woman", &I_icon_woman_9x16, 9, 16);
     }
-    // else if (is_str(name, "chest_closed") )
-    // {
-    //     return icon_generic_alloc("chest_closed", &I_icon_chest_closed_16x13px, 16, 13);
-    // }
+    else if (is_str(name, "chest_closed"))
+    {
+        return icon_generic_alloc("chest_closed", &I_icon_chest_closed_16x13px, 16, 13);
+    }
     // else if (is_str(name, "chest_open") )
     // {
     //     return icon_generic_alloc("chest_open", &I_icon_chest_open_16x16px, 16, 16);
@@ -229,7 +229,6 @@ IconContext *get_icon_context(const char *name)
     }
     else if (is_str(name, "lake_right"))
     {
-        // Assuming 11x31
         return icon_generic_alloc("lake_right", &I_icon_lake_right_11x31, 11, 31);
     }
     else if (is_str(name, "lake_top"))
@@ -316,10 +315,10 @@ const char *icon_get_id(const Icon *icon)
     {
         return "woman";
     }
-    // else if (icon == &I_icon_chest_closed_16x13px)
-    // {
-    //     return "chest_closed";
-    // }
+    else if (icon == &I_icon_chest_closed_16x13px)
+    {
+        return "chest_closed";
+    }
     // else if (icon == &I_icon_chest_open_16x16px)
     // {
     //     return "chest_open";

+ 2 - 2
game/level.c

@@ -98,9 +98,9 @@ static void set_world(Level *level, GameManager *manager, char *id)
 }
 static void level_start(Level *level, GameManager *manager, void *context)
 {
-    if (!manager)
+    if (!manager || !level || !context)
     {
-        FURI_LOG_E("Game", "Manager is NULL");
+        FURI_LOG_E("Game", "Manager, level, or context is NULL");
         return;
     }
     GameContext *game_context = game_manager_game_context_get(manager);

+ 1 - 1
game/world.c

@@ -174,7 +174,7 @@ FuriString *fetch_world(const char *name)
     }
 
     char url[256];
-    snprintf(url, sizeof(url), "https://www.flipsocial.net/api/world/v3/get/world/%s/", name);
+    snprintf(url, sizeof(url), "https://www.flipsocial.net/api/world/v4/get/world/%s/", name);
     snprintf(fhttp->file_path, sizeof(fhttp->file_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_world/worlds/%s.json", name);
     fhttp->save_received_data = true;
     if (!flipper_http_get_request_with_headers(fhttp, url, "{\"Content-Type\": \"application/json\"}"))

+ 3 - 3
game/world.h

@@ -4,9 +4,9 @@
 #define SCREEN_WIDTH 128
 #define SCREEN_HEIGHT 64
 
-// World size (3x3)
-#define WORLD_WIDTH 384
-#define WORLD_HEIGHT 192
+// World size (6x6)
+#define WORLD_WIDTH 768
+#define WORLD_HEIGHT 384
 
 // Maximum number of world objects
 #define MAX_WORLD_OBJECTS 25 // any more than that and we may run out of heap when switching worlds