DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

ref: c5c1766120b7f08ce57942f72949431a91c544c6 deck-builder/client/src/api/game/mod.rs -rw-r--r-- 2.0 KiB
c5c17661 — skye fix(client): fix create action api command field 1 year, 7 months ago
                                                                                
18acb7d0 skye
c5909cd0 skye
c5909cd0 skye
c5909cd0 skye
c5909cd0 skye
25673a08 skye
35004e35 skye
8e212372 skye
b530d5c4 skye
18acb7d0 skye
f2af0141 skye
18acb7d0 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
 * 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 serde::{Deserialize, Serialize};
use serde_repr::Deserialize_repr;

use crate::game_status::Card;

use super::user::User;

mod forming;
pub use forming::*;

mod my_games;
pub use my_games::*;

mod join;
pub use join::*;

mod create;
pub use create::*;

mod create_action;
pub use create_action::*;

mod details;
pub use details::*;

#[derive(Deserialize, Serialize, Clone)]
pub enum Command {
    InitSupplyPile { card: Card, amount: usize },
    /// take a card from pile N
    TakeFromPile { index: usize },
    /// draw N amount of cards from deck
    Draw { amount: usize },
    /// discard card from hand in slot N
    Discard { index: usize },
}

#[derive(Deserialize, Serialize, Clone)]
pub struct Action {
    pub id: String,
    pub created_at: String,
    pub updated_at: String,
    pub game_id: String,
    pub invoker: String,
    pub target: String,
    pub command: Command,
    pub seed: u64,
}

impl Action {
    pub fn new(
        game_id: &str,
        invoker: &str,
        target: &str,
        command: &Command,
        seed: u64
    ) -> Self {
        Self {
            id: "".to_string(),
            created_at: "".to_string(),
            updated_at: "".to_string(),
            game_id: game_id.to_string(),
            invoker: invoker.to_string(),
            target: target.to_string(),
            command: command.clone(),
            seed,
        }
    }
}

#[derive(Debug, Deserialize_repr, Clone, PartialEq)]
#[repr(u8)]
pub enum GameState {
    Forming = 0,
    InProgress= 1,
    Finished = 2,
    Cancelled = 3,
}

#[derive(Deserialize, Clone)]
pub struct Game {
    pub id: String,
    pub created_at: String,
    pub updated_at: String,
    pub ended_at: String,
    pub host_id: String,
    pub host: Option<User>,
    pub guest_id: String,
    pub guest: Option<User>,
    pub state: GameState,
    pub turn: u8,
    pub actions: Option<Vec<Action>>,
}