DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

d2c89141eae4f0932cab1f98147b0085f1e07290 — Jonni Liljamo 1 year, 7 months ago 0bf106d
feat(client): end game endpoint call
A client/src/api/game/end.rs => client/src/api/game/end.rs +18 -0
@@ 0,0 1,18 @@
/*
 * This file is part of laurelin_client
 * Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
 *
 * Licensed under GPL-3.0-only.
 * See LICENSE for licensing information.
 */

use crate::{post_request_auth, NetworkingOptions};

// NOTE: this response isn't actually used
pub type EndResponse = Result<String, ()>;

pub fn end(no: &NetworkingOptions, game_id: &str) -> EndResponse {
    let res = post_request_auth!(no, &format!("/game/{}/end", &game_id), &{});

    Ok(res.text().unwrap())
}

M client/src/api/game/mod.rs => client/src/api/game/mod.rs +3 -0
@@ 35,6 35,9 @@ pub use create_action::*;
mod details;
pub use details::*;

mod end;
pub use end::*;

#[derive(Deserialize, Serialize, Clone, PartialEq)]
pub enum Command {
    InitSupplyPile {

M client/src/plugins/async_tasks/mod.rs => client/src/plugins/async_tasks/mod.rs +6 -0
@@ 32,6 32,9 @@ pub use req_game_details::GameDetailsCallEvent;
mod req_game_action_create;
pub use req_game_action_create::GameActionCreateCallEvent;

mod req_game_end;
pub use req_game_end::GameEndCallEvent;

mod parse_game_status;
pub use parse_game_status::ParseGameStatusEvent;



@@ 47,6 50,7 @@ impl Plugin for AsyncTasksPlugin {
            .add_event::<GameMyGamesCallEvent>()
            .add_event::<GameDetailsCallEvent>()
            .add_event::<GameActionCreateCallEvent>()
            .add_event::<GameEndCallEvent>()
            .add_event::<ParseGameStatusEvent>()
            .add_systems(
                (


@@ 71,6 75,8 @@ impl Plugin for AsyncTasksPlugin {
                    req_game_details::handle_call,
                    req_game_action_create::start_call,
                    req_game_action_create::handle_call,
                    req_game_end::start_call,
                    req_game_end::handle_call,
                )
                    .chain(),
            )

A client/src/plugins/async_tasks/req_game_end.rs => client/src/plugins/async_tasks/req_game_end.rs +41 -0
@@ 0,0 1,41 @@
/*
 * This file is part of laurelin_client
 * Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
 *
 * Licensed under GPL-3.0-only.
 * See LICENSE for licensing information.
 */

use crate::{
    api::{self, game::EndResponse},
    async_task_handle_call, async_task_start_call,
    plugins::menu::MenuData,
    NetworkingOptions,
};

use bevy::{
    prelude::*,
    tasks::{AsyncComputeTaskPool, Task},
};
use futures_lite::future;

#[derive(Component)]
pub struct GameEndCall(Task<EndResponse>);

#[derive(Clone)]
pub struct GameEndCallEvent {
    pub game_id: String,
}

async_task_start_call!(GameEndCallEvent, GameEndCall, |ev, no| {
    api::game::end(&no, &ev.game_id)
});

async_task_handle_call!(GameEndCall, |response, _menu_data| {
    match response {
        Err(_err) => panic!("game end failed, handle me"),
        Ok(resp) => {
            info!("ended game {}", resp);
        }
    }
});