DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

ca0db06a36aaeb1b6fe04d35850f67e1b0a2ec3f — Jonni Liljamo 1 year, 7 months ago db0a37d
feat(client): correct state button behaviour
M client/src/game_status/mod.rs => client/src/game_status/mod.rs +1 -0
@@ 55,6 55,7 @@ pub enum PlayerState {

#[derive(Clone)]
pub struct PlayerStatus {
    pub turn_n: usize,
    pub display_name: String,
    pub state: PlayerState,
    pub plays: i16,

M client/src/game_status/parser.rs => client/src/game_status/parser.rs +2 -0
@@ 51,6 51,7 @@ pub fn parse(game: &Game) -> Result<GameStatus, ()> {
    game_status.players.insert(
        game.host_id.clone(),
        PlayerStatus {
            turn_n: 0,
            display_name: game.host.as_ref().unwrap().username.clone(),
            state: PlayerState::Idle,
            plays: 0,


@@ 66,6 67,7 @@ pub fn parse(game: &Game) -> Result<GameStatus, ()> {
    game_status.players.insert(
        game.guest_id.clone(),
        PlayerStatus {
            turn_n: 1,
            display_name: game.guest.as_ref().unwrap().username.clone(),
            state: PlayerState::Idle,
            plays: 0,

M client/src/plugins/game/ui/state_button.rs => client/src/plugins/game/ui/state_button.rs +43 -17
@@ 20,7 20,8 @@ pub struct StateButtonPlugin;
impl Plugin for StateButtonPlugin {
    fn build(&self, app: &mut App) {
        app.add_system(setup_state_button.in_schedule(OnEnter(AppState::InGame)))
            .add_system(update_state_button);
            .add_system(update_state_button)
            .add_system(interact_state_button);
    }
}



@@ 81,25 82,13 @@ fn setup_state_button(mut commands: Commands, asset_server: Res<AssetServer>) {
}

fn update_state_button(
    mut interaction_query: Query<
        (
            &Interaction,
            &mut BackgroundColor,
            &mut Visibility,
            &Children,
        ),
        (Changed<Interaction>, With<StateButton>),
    >,
    mut button_query: Query<(&mut Visibility, &Children), With<StateButton>>,
    mut text_query: Query<&mut Text>,
    mut game_data: ResMut<GameData>,
    game_data: Res<GameData>,
    global: Res<Global>,
    mut gac_ev_w: EventWriter<GameActionCreateCallEvent>,
) {
    for (interaction, mut color, mut visibility, children) in &mut interaction_query {
    for (mut visibility, children) in &mut button_query {
        // NOTE: horrible clones because of borrow funnies
        let Some(game) = game_data.clone().game else {
            return;
        };
        let Some(status) = game_data.clone().game_status else {
            return;
        };


@@ 123,6 112,30 @@ fn update_state_button(
            }
        }
        *visibility = Visibility::Inherited;
    }
}

fn interact_state_button(
    mut interaction_query: Query<
        (&Interaction, &mut BackgroundColor),
        (Changed<Interaction>, With<StateButton>),
    >,
    mut game_data: ResMut<GameData>,
    global: Res<Global>,
    mut gac_ev_w: EventWriter<GameActionCreateCallEvent>,
) {
    for (interaction, mut color) in &mut interaction_query {
        // NOTE: horrible clones because of borrow funnies
        let Some(game) = game_data.clone().game else {
            return;
        };
        let Some(status) = game_data.clone().game_status else {
            return;
        };
        let Some(user) = &global.user else {
            return;
        };
        let player = status.players.get(&user.id).unwrap();

        if game_data.locked {
            // input locked rn, so don't show any signs of interactivity


@@ 149,11 162,24 @@ fn update_state_button(
                        });
                    }
                    PlayerState::BuyPhase => {
                        let next_turn_n: usize = if (player.turn_n + 1) > (status.players.len() - 1)
                        {
                            0
                        } else {
                            player.turn_n + 1
                        };

                        let next_player = status
                            .players
                            .iter()
                            .find(|np| np.1.turn_n == next_turn_n)
                            .unwrap();

                        gac_ev_w.send(GameActionCreateCallEvent {
                            action: Action::new(
                                &game.id,
                                &user.id,
                                &user.id,
                                next_player.0,
                                &Command::EndTurn {},
                                seed_gen!(),
                            ),