gamemstr_common/
action.rs1use serde::{Deserialize, Serialize};
2use uuid::Uuid;
3
4use self::attack::Attack;
5
6pub mod attack;
7
8#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone)]
9pub enum ActionType {
10 Attack(Attack),
11}
12
13#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone)]
14pub struct Action {
15 pub id: String,
16 pub action: ActionType,
17}
18
19impl Action {
20 pub fn new(action: ActionType) -> Self {
21 Self {
22 id: Uuid::new_v4().to_string(),
23 action,
24 }
25 }
26}
27
28#[derive(Serialize, Deserialize, Debug)]
29pub struct ActionRequest {
30 pub action: Option<ActionType>,
31}
32
33impl ActionRequest {
34 pub fn to_action(&self) -> Option<Action> {
35 match &self.action {
36 Some(action) => Some(Action::new(action.clone())),
37 None => None,
38 }
39 }
40}