Remove game when another Flipper does a join.
This commit is contained in:
parent
fda2fbcdbb
commit
97b7900a99
@ -20,10 +20,10 @@ Completed work:
|
|||||||
- Receiving a Join game does an ACK (to cause game on joiner to start).
|
- Receiving a Join game does an ACK (to cause game on joiner to start).
|
||||||
- Log game results & contact info onto SD card.
|
- Log game results & contact info onto SD card.
|
||||||
- Allow viewing past games/scores.
|
- Allow viewing past games/scores.
|
||||||
|
- A join ACK removes it from the list of available games.
|
||||||
|
|
||||||
Remaining work (for subghz version):
|
Remaining work (for subghz version):
|
||||||
|
|
||||||
- A join ACK removes it from the list of available games.
|
|
||||||
- Config - Allow changing hard-coded CONTACT_INFO message.
|
- Config - Allow changing hard-coded CONTACT_INFO message.
|
||||||
- Refactor the code, so it has less duplication.
|
- Refactor the code, so it has less duplication.
|
||||||
- Write tutorial.
|
- Write tutorial.
|
||||||
|
@ -1247,6 +1247,54 @@ static void remote_games_add(GameContext* game_context, GameEvent* game_event) {
|
|||||||
furi_mutex_release(game_context->mutex);
|
furi_mutex_release(game_context->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void remote_games_remove(GameContext* game_context, GameEvent* game_event) {
|
||||||
|
furi_assert(game_context);
|
||||||
|
furi_assert(game_event);
|
||||||
|
|
||||||
|
FURI_LOG_I(TAG, "Removing game number %d.", game_event->game_number);
|
||||||
|
|
||||||
|
GameInfo* game = remote_games_find(game_context, game_event->game_number + 1);
|
||||||
|
if(game && game->game_number == game_event->game_number) {
|
||||||
|
// We found the game, so remove it from the list.
|
||||||
|
FURI_LOG_I(TAG, "Found game to remove.");
|
||||||
|
|
||||||
|
// Check to see if the currently selected game is this game.
|
||||||
|
if(game_context->data->remote_selected_game == game) {
|
||||||
|
if(game_context->data->remote_selected_game->next_game) {
|
||||||
|
// Move to next available game.
|
||||||
|
game_context->data->remote_selected_game =
|
||||||
|
game_context->data->remote_selected_game->next_game;
|
||||||
|
} else {
|
||||||
|
// Move to first game.
|
||||||
|
game_context->data->remote_selected_game = game_context->data->remote_games;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(game_context->data->remote_selected_game == game) {
|
||||||
|
game_context->data->remote_selected_game = NULL;
|
||||||
|
FURI_LOG_I(TAG, "Clearing remote_selected_game.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove the game from the list.
|
||||||
|
GameInfo* game_previous = remote_games_find(game_context, game->game_number);
|
||||||
|
if(!game_previous) {
|
||||||
|
game_context->data->remote_games = game->next_game;
|
||||||
|
if(game->sender_name) {
|
||||||
|
furi_string_free(game->sender_name);
|
||||||
|
}
|
||||||
|
free(game);
|
||||||
|
} else {
|
||||||
|
game_previous->next_game = game->next_game;
|
||||||
|
if(game->sender_name) {
|
||||||
|
furi_string_free(game->sender_name);
|
||||||
|
}
|
||||||
|
free(game);
|
||||||
|
}
|
||||||
|
|
||||||
|
FURI_LOG_I(TAG, "Done removing game.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Saves a game result to the file system.
|
// Saves a game result to the file system.
|
||||||
// @param game_context pointer to a GameContext.
|
// @param game_context pointer to a GameContext.
|
||||||
static void save_result(GameContext* game_context) {
|
static void save_result(GameContext* game_context) {
|
||||||
@ -1868,12 +1916,15 @@ int32_t rock_paper_scissors_app(void* p) {
|
|||||||
// Take ownership of the name and contact
|
// Take ownership of the name and contact
|
||||||
event.sender_name = NULL;
|
event.sender_name = NULL;
|
||||||
event.sender_contact = NULL;
|
event.sender_contact = NULL;
|
||||||
|
} else {
|
||||||
|
remote_games_remove(game_context, &event);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
FURI_LOG_T(
|
FURI_LOG_T(
|
||||||
TAG,
|
TAG,
|
||||||
"Remote joining another Flipper on game %03u.",
|
"Remote joining another Flipper on game %03u.",
|
||||||
event.game_number);
|
event.game_number);
|
||||||
|
remote_games_remove(game_context, &event);
|
||||||
}
|
}
|
||||||
furi_mutex_release(game_context->mutex);
|
furi_mutex_release(game_context->mutex);
|
||||||
} else {
|
} else {
|
||||||
|
@ -419,6 +419,7 @@ static bool remote_games_has_previous(GameContext* game_context);
|
|||||||
static void remote_games_next(GameContext* game_context);
|
static void remote_games_next(GameContext* game_context);
|
||||||
static void remote_games_previous(GameContext* game_context);
|
static void remote_games_previous(GameContext* game_context);
|
||||||
static void remote_games_add(GameContext* game_context, GameEvent* game_event);
|
static void remote_games_add(GameContext* game_context, GameEvent* game_event);
|
||||||
|
static void remote_games_remove(GameContext* game_context, GameEvent* game_event);
|
||||||
|
|
||||||
// Saves a game result to the file system.
|
// Saves a game result to the file system.
|
||||||
// @param game_context pointer to a GameContext.
|
// @param game_context pointer to a GameContext.
|
||||||
|
Loading…
Reference in New Issue
Block a user