DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

78241f7b03ec01ef95152797c3c6a821aa4bdc69 — skye 1 year, 7 months ago c6ba0da
feat(client): update action api call, create event
M client/src/api/game/create_action.rs => client/src/api/game/create_action.rs +5 -8
@@ 24,16 24,13 @@ struct CreateActionPost {

pub fn create_action(
    no: &NetworkingOptions,
    game_id: &str,
    invoker: &str,
    target: &str,
    command: &Command
    action: &Action,
) -> CreateActionResponse {
    let res = post_request_auth!(no, "/game/action", &CreateActionPost {
        game_id: game_id.to_string(),
        invoker: invoker.to_string(),
        target: target.to_string(),
        command: command.clone(),
        game_id: action.game_id.to_string(),
        invoker: action.invoker.to_string(),
        target: action.target.to_string(),
        command: action.command.clone(),
    });

    Ok(res.json().unwrap())

M client/src/plugins/async_tasks/mod.rs => client/src/plugins/async_tasks/mod.rs +11 -0
@@ 29,6 29,9 @@ pub use req_game_mygames::GameMyGamesCallEvent;
mod req_game_details;
pub use req_game_details::GameDetailsCallEvent;

mod req_game_action_create;
pub use req_game_action_create::GameActionCreateCallEvent;

mod parse_game_status;
pub use parse_game_status::ParseGameStatusEvent;



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


@@ 51,6 55,11 @@ impl Plugin for AsyncTasksPlugin {
                req_login::handle_call,
                req_register::start_call,
                req_register::handle_call,
            )
            .chain()
            )
            .add_systems(
            (
                req_game_create::start_call,
                req_game_create::handle_call,
                req_game_join::start_call,


@@ 61,6 70,8 @@ impl Plugin for AsyncTasksPlugin {
                req_game_mygames::handle_call,
                req_game_details::start_call,
                req_game_details::handle_call,
                req_game_action_create::start_call,
                req_game_action_create::handle_call,
            )
            .chain()
            )

A client/src/plugins/async_tasks/req_game_action_create.rs => client/src/plugins/async_tasks/req_game_action_create.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::{
    async_task_start_call, async_task_handle_call,
    api::{self, game::{Action, CreateActionResponse}},
    NetworkingOptions, plugins::GameData,
};

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

use super::ParseGameStatusEvent;

#[derive(Component)]
pub struct GameActionCreateCall(Task<CreateActionResponse>);

#[derive(Clone)]
pub struct GameActionCreateCallEvent {
    pub action: Action,
}

async_task_start_call!(GameActionCreateCallEvent, GameActionCreateCall, |ev, no| {
    let res = api::game::create_action(&no, &ev.action);

    res
});

async_task_handle_call!(GameActionCreateCall, |_u0, _u1, response, _game_data, _u2| {
    match response {
        Err(_err) => panic!("login failed, handle me"),
        Ok(resp) => {
            info!("created action {}", resp.id);
        }
    }
});