|
@@ -661,6 +661,33 @@ static bool fetch_world_list(FlipperHTTP *fhttp)
|
|
|
fhttp->save_received_data = true;
|
|
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/v3/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
|
|
|
|
|
+static bool fetch_player_stats(FlipperHTTP *fhttp)
|
|
|
|
|
+{
|
|
|
|
|
+ if (!fhttp)
|
|
|
|
|
+ {
|
|
|
|
|
+ FURI_LOG_E(TAG, "fhttp is NULL");
|
|
|
|
|
+ easy_flipper_dialog("Error", "fhttp is NULL. Press BACK to return.");
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ char username[64];
|
|
|
|
|
+ if (!load_char("Flip-Social-Username", username, sizeof(username)))
|
|
|
|
|
+ {
|
|
|
|
|
+ FURI_LOG_E(TAG, "Failed to load Flip-Social-Username");
|
|
|
|
|
+ easy_flipper_dialog("Error", "Failed to load saved username. Go to settings to update.");
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ char url[128];
|
|
|
|
|
+ snprintf(url, sizeof(url), "https://www.flipsocial.net/api/user/game-stats/%s/", username);
|
|
|
|
|
+ snprintf(
|
|
|
|
|
+ fhttp->file_path,
|
|
|
|
|
+ sizeof(fhttp->file_path),
|
|
|
|
|
+ STORAGE_EXT_PATH_PREFIX "/apps_data/flip_world/data/player/player_stats.json");
|
|
|
|
|
+
|
|
|
|
|
+ fhttp->save_received_data = true;
|
|
|
|
|
+ return flipper_http_get_request_with_headers(fhttp, url, "{\"Content-Type\":\"application/json\"}");
|
|
|
|
|
+}
|
|
|
static bool start_game_thread(void *context)
|
|
static bool start_game_thread(void *context)
|
|
|
{
|
|
{
|
|
|
FlipWorldApp *app = (FlipWorldApp *)context;
|
|
FlipWorldApp *app = (FlipWorldApp *)context;
|
|
@@ -688,31 +715,8 @@ static bool start_game_thread(void *context)
|
|
|
furi_thread_start(thread);
|
|
furi_thread_start(thread);
|
|
|
thread_id = furi_thread_get_id(thread);
|
|
thread_id = furi_thread_get_id(thread);
|
|
|
game_thread_running = true;
|
|
game_thread_running = true;
|
|
|
- // view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu);
|
|
|
|
|
- // view_dispatcher_send_custom_event(app->view_dispatcher, FlipWorldCustomEventPlay);
|
|
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
-static bool flip_world_fetch_world_list(DataLoaderModel *model)
|
|
|
|
|
-{
|
|
|
|
|
- return fetch_world_list(model->fhttp);
|
|
|
|
|
-}
|
|
|
|
|
-static char *flip_world_parse_world_list(DataLoaderModel *model)
|
|
|
|
|
-{
|
|
|
|
|
- FlipWorldApp *app = (FlipWorldApp *)model->parser_context;
|
|
|
|
|
-
|
|
|
|
|
- if (!start_game_thread(app))
|
|
|
|
|
- {
|
|
|
|
|
- FURI_LOG_E(TAG, "Failed to start game thread");
|
|
|
|
|
- easy_flipper_dialog("Error", "Failed to start game thread. Press BACK to return.");
|
|
|
|
|
- view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu); // just go back to the main menu for now
|
|
|
|
|
- return "Failed to start game thread";
|
|
|
|
|
- }
|
|
|
|
|
- return "Game starting... please wait :D";
|
|
|
|
|
-}
|
|
|
|
|
-void flip_world_world_list_switch_to_view(FlipWorldApp *app)
|
|
|
|
|
-{
|
|
|
|
|
- return flip_world_generic_switch_to_view(app, "Fetching World List..", flip_world_fetch_world_list, flip_world_parse_world_list, 1, callback_to_submenu, FlipWorldViewLoader);
|
|
|
|
|
-}
|
|
|
|
|
// combine register, login, and world list fetch into one function to switch to the loader view
|
|
// combine register, login, and world list fetch into one function to switch to the loader view
|
|
|
static bool flip_world_fetch_game(DataLoaderModel *model)
|
|
static bool flip_world_fetch_game(DataLoaderModel *model)
|
|
|
{
|
|
{
|
|
@@ -1033,6 +1037,15 @@ void callback_submenu_choices(void *context, uint32_t index)
|
|
|
return fhttp->state != ISSUE;
|
|
return fhttp->state != ISSUE;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ bool fetch_player_stats_i()
|
|
|
|
|
+ {
|
|
|
|
|
+ return fetch_player_stats(fhttp);
|
|
|
|
|
+ }
|
|
|
|
|
+ bool parse_player_stats_i()
|
|
|
|
|
+ {
|
|
|
|
|
+ return fhttp->state != ISSUE;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
Loading *loading;
|
|
Loading *loading;
|
|
|
int32_t loading_view_id = 987654321; // Random ID
|
|
int32_t loading_view_id = 987654321; // Random ID
|
|
|
|
|
|
|
@@ -1051,7 +1064,8 @@ void callback_submenu_choices(void *context, uint32_t index)
|
|
|
view_dispatcher_switch_to_view(app->view_dispatcher, loading_view_id);
|
|
view_dispatcher_switch_to_view(app->view_dispatcher, loading_view_id);
|
|
|
|
|
|
|
|
// Make the request
|
|
// Make the request
|
|
|
- if (!flipper_http_process_response_async(fhttp, fetch_world_list_i, parse_world_list_i))
|
|
|
|
|
|
|
+ if (!flipper_http_process_response_async(fhttp, fetch_world_list_i, parse_world_list_i) ||
|
|
|
|
|
+ !flipper_http_process_response_async(fhttp, fetch_player_stats_i, parse_player_stats_i))
|
|
|
{
|
|
{
|
|
|
FURI_LOG_E(HTTP_TAG, "Failed to make request");
|
|
FURI_LOG_E(HTTP_TAG, "Failed to make request");
|
|
|
view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu);
|
|
view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu);
|