DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

ref: c5909cd025c1f7ffec7b02fa467ed4a82c2ae6b2 deck-builder/client/src/game_status/mod.rs -rw-r--r-- 1.3 KiB
c5909cd0 — skye feat(client): semi initial game state and parser 1 year, 5 months ago
                                                                                
cd13a21d skye
c5909cd0 skye
cd13a21d skye
c5909cd0 skye
cd13a21d skye
c5909cd0 skye
cd13a21d skye
c5909cd0 skye
cd13a21d skye
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * 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 std::collections::HashMap;

use serde::{Deserialize, Serialize};

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

mod parser;

#[derive(Deserialize, Serialize, Clone)]
pub struct CardAction {
    pub target: String,
    pub command: Command,
    pub seed: u64,
}

#[derive(Deserialize, Serialize, Clone)]
pub struct Card {
    pub name: String,
    pub cost: u32,
    /// if set, use this?
    //vp_cost: Option<u32>,
    pub actions: Vec<CardAction>,
}

/// a supply pile holds an amount of some card
pub struct SupplyPile {
    /// the card type that the supply pile holds
    pub card: Card,
    /// the amount of cards currently in the pile
    pub amount: usize,
}

pub struct PlayerStatus {
    pub hand: Vec<Card>,
    pub deck: Vec<Card>,
    pub discard: Vec<Card>,
}

/// constructed from a vector of [`Action`]s
pub struct GameStatus {
    pub supply_piles: Vec<SupplyPile>,
    /// player ids mapped to statuses
    pub players: HashMap<String, PlayerStatus>,
}

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