DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

1904a6d315db0911d22dbe459cfd39ac77c5b2ca — Jonni Liljamo 1 year, 4 months ago d2c8914 dev
feat(client): sorta kinda check for end conditions
2 files changed, 19 insertions(+), 4 deletions(-)

M client/src/game_status/parser.rs
M client/src/plugins/async_tasks/parse_game_status.rs
M client/src/game_status/parser.rs => client/src/game_status/parser.rs +0 -3
@@ 95,9 95,6 @@ pub fn parse(game: &Game) -> Result<GameStatus, ()> {
        parse_action(&action, game, &mut game_status);
    }

    // TODO: check for end conditions, declare one player as winner.
    // update game state in API to ended, set ended date (in API).

    Ok(game_status)
}


M client/src/plugins/async_tasks/parse_game_status.rs => client/src/plugins/async_tasks/parse_game_status.rs +19 -1
@@ 18,6 18,8 @@ use bevy::{
};
use futures_lite::future;

use super::GameEndCallEvent;

#[derive(Component)]
pub struct ParseGameStatus(Task<GameStatus>);



@@ 39,6 41,7 @@ pub fn handle_call(
    mut commands: Commands,
    mut tasks: Query<(Entity, &mut ParseGameStatus)>,
    mut game_data: ResMut<GameData>,
    mut eg_ev_w: EventWriter<GameEndCallEvent>,
    mut frg_ev_w: EventWriter<FinishedRefreshGameEvent>,
) {
    if let Ok((entity, mut task)) = tasks.get_single_mut() {


@@ 46,7 49,22 @@ pub fn handle_call(
            game_data.game_status = Some(response);
            game_data.locked = false;

            frg_ev_w.send(FinishedRefreshGameEvent);
            // NOTE: checking for end conditions
            let mut empty_piles = 0;
            for pile in &game_data.game_status.as_ref().unwrap().supply_piles {
                if pile.amount == 0 {
                    empty_piles += 1;
                }
            }
            if empty_piles >= 2 {
                // end me daddy
                eg_ev_w.send(GameEndCallEvent {
                    game_id: game_data.game.as_ref().unwrap().id.clone(),
                });
            } else {
                // dont end me daddy
                frg_ev_w.send(FinishedRefreshGameEvent);
            }

            // remove the task
            commands.entity(entity).remove::<ParseGameStatus>();