DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

89bbb3e7d988f5064e775a6a398c5b53096fa186 — skye 1 year, 7 months ago c06dcb8
feat(client): change parser to just take &Game
M client/src/game_status/mod.rs => client/src/game_status/mod.rs +3 -3
@@ 10,7 10,7 @@ use std::collections::HashMap;

use serde::{Deserialize, Serialize};

use crate::api::game::{Action, Command};
use crate::api::game::{Action, Command, Game};

mod parser;



@@ 55,8 55,8 @@ pub struct GameStatus {
}

impl GameStatus {
    pub fn new(actions: &Vec<Action>) -> Self {
        match parser::parse(actions) {
    pub fn new(game: &Game) -> Self {
        match parser::parse(game) {
            Ok(res) => res,
            Err(_) => panic!("parsing actions failed"),
        }

M client/src/game_status/parser.rs => client/src/game_status/parser.rs +16 -4
@@ 9,17 9,29 @@
use std::collections::HashMap;
use fastrand::Rng;

use crate::{api::game::{Action, Command}, game_status::SupplyPile};
use crate::{api::game::{Action, Command, Game}, game_status::SupplyPile};

use super::{GameStatus, PlayerStatus, Card};

pub fn parse(actions_init: &Vec<Action>) -> Result<GameStatus, ()> {
pub fn parse(game: &Game) -> Result<GameStatus, ()> {
    let mut game_status = GameStatus {
        actions: actions_init.to_vec(),
        actions: game.actions.as_ref().unwrap().to_vec(),
        supply_piles: vec![],
        players: HashMap::new(),
        players: HashMap::new()
    };

    game_status.players.insert(game.host_id.clone(), PlayerStatus {
        hand: vec![],
        deck: vec![],
        discard: vec![]
    });

    game_status.players.insert(game.guest_id.clone(), PlayerStatus {
        hand: vec![],
        deck: vec![],
        discard: vec![]
    });

    for action in &game_status.actions {
        // the one who invoked the action
        let invoker = game_status.players.get_mut(&action.invoker)

M client/src/plugins/async_tasks/parse_game_status.rs => client/src/plugins/async_tasks/parse_game_status.rs +1 -1
@@ 29,7 29,7 @@ pub fn start_call(
        let thread_pool = AsyncComputeTaskPool::get();
        let ev = ev.clone();
        let task = thread_pool.spawn(async move {
            let res = GameStatus::new(&ev.game.actions.unwrap());
            let res = GameStatus::new(&ev.game);

            res
        });