Skip to main content

manabrew_protocol/prompts/
common.rs

1use serde::{Deserialize, Serialize};
2use ts_rs::TS;
3
4use crate::game::TargetingIntent;
5
6#[derive(Debug, Clone, Serialize, Deserialize, TS)]
7#[serde(rename_all = "camelCase")]
8#[ts(export, export_to = "prompts/common.ts")]
9pub struct PromptPresentation {
10    pub title: String,
11    #[serde(default, skip_serializing_if = "Option::is_none")]
12    #[ts(optional)]
13    pub description: Option<String>,
14    #[serde(default, skip_serializing_if = "Option::is_none")]
15    #[ts(optional)]
16    pub text: Option<String>,
17    #[serde(default, skip_serializing_if = "Option::is_none")]
18    #[ts(optional)]
19    pub source_card_id: Option<String>,
20    #[serde(default)]
21    pub targets: Vec<TargetRef>,
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize, TS)]
25#[serde(rename_all = "camelCase")]
26#[ts(export, export_to = "prompts/common.ts")]
27pub struct PlayOptionDto {
28    pub card_id: String,
29    pub mode: String,
30    pub mode_label: String,
31}
32
33#[derive(Debug, Clone, Copy, Serialize, Deserialize, TS, PartialEq, Eq)]
34#[ts(export, export_to = "prompts/common.ts")]
35pub enum ManaColor {
36    #[serde(rename = "W")]
37    White,
38    #[serde(rename = "U")]
39    Blue,
40    #[serde(rename = "B")]
41    Black,
42    #[serde(rename = "R")]
43    Red,
44    #[serde(rename = "G")]
45    Green,
46    #[serde(rename = "C")]
47    Colorless,
48}
49
50#[derive(Debug, Clone, Copy, Serialize, Deserialize, TS, PartialEq, Eq)]
51#[serde(rename_all = "camelCase")]
52#[ts(export, export_to = "prompts/common.ts")]
53pub struct Mana {
54    pub color: ManaColor,
55    pub amount: i32,
56}
57
58#[derive(Debug, Clone, Serialize, Deserialize, TS)]
59#[serde(rename_all = "camelCase")]
60#[ts(export, export_to = "prompts/common.ts")]
61pub struct ActivatableAbilityInfo {
62    pub card_id: String,
63    pub ability_index: usize,
64    pub description: String,
65    pub is_mana_ability: bool,
66    #[serde(default, skip_serializing_if = "Option::is_none")]
67    #[ts(optional)]
68    pub cost: Option<String>,
69    #[serde(default, skip_serializing_if = "Option::is_none")]
70    #[ts(optional)]
71    pub produced_mana: Option<Vec<Mana>>,
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize, TS)]
75#[serde(
76    tag = "type",
77    rename_all = "camelCase",
78    rename_all_fields = "camelCase"
79)]
80#[ts(export, export_to = "prompts/common.ts")]
81pub enum AvailableActionKind {
82    Cast {
83        card_id: String,
84        mode: String,
85        mode_label: String,
86    },
87    ActivateAbility(ActivatableAbilityInfo),
88    UndoMana {
89        card_id: String,
90    },
91    Delve {
92        card_id: String,
93    },
94    Undelve {
95        card_id: String,
96    },
97}
98
99#[derive(Debug, Clone, Serialize, Deserialize, TS)]
100#[ts(export, export_to = "prompts/common.ts")]
101pub struct AvailableAction {
102    pub id: String,
103    #[serde(flatten)]
104    #[ts(flatten)]
105    pub kind: AvailableActionKind,
106}
107
108#[derive(Debug, Clone, Serialize, Deserialize, TS)]
109#[serde(rename_all = "camelCase")]
110#[ts(export, export_to = "prompts/common.ts")]
111pub enum AttackTargetKind {
112    Player,
113    Planeswalker,
114    Battle,
115}
116
117#[derive(Debug, Clone, Serialize, Deserialize, TS)]
118#[serde(rename_all = "camelCase")]
119#[ts(export, export_to = "prompts/common.ts")]
120pub struct AttackTargetDto {
121    pub id: String,
122    pub label: String,
123    pub kind: AttackTargetKind,
124}
125
126#[derive(Debug, Clone, Serialize, Deserialize, TS)]
127#[serde(rename_all = "camelCase")]
128#[ts(export, export_to = "prompts/common.ts")]
129pub struct BlockAssignment {
130    pub blocker_id: String,
131    pub attacker_id: String,
132}
133
134#[derive(Debug, Clone, Serialize, Deserialize, TS)]
135#[serde(rename_all = "camelCase")]
136#[ts(export, export_to = "prompts/common.ts")]
137pub struct AttackAssignment {
138    pub attacker_id: String,
139    pub target_id: String,
140}
141
142#[derive(Debug, Clone, Serialize, Deserialize, TS)]
143#[serde(rename_all = "camelCase")]
144#[ts(export, export_to = "prompts/common.ts")]
145pub struct CombatDamageAssignmentEntry {
146    pub assignee_id: String,
147    pub damage: i32,
148}
149
150#[derive(Debug, Clone, Serialize, Deserialize, TS)]
151#[serde(
152    tag = "kind",
153    rename_all = "camelCase",
154    rename_all_fields = "camelCase"
155)]
156#[ts(export, export_to = "prompts/common.ts")]
157pub enum TargetAnyChoice {
158    Player { player_id: String },
159    Card { card_id: String },
160    None,
161}
162
163#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, TS)]
164#[serde(rename_all = "camelCase")]
165#[ts(export, export_to = "prompts/common.ts")]
166pub enum TargetKind {
167    Player,
168    Card,
169    Spell,
170}
171
172#[derive(Debug, Clone, Serialize, Deserialize, TS)]
173#[serde(rename_all = "camelCase")]
174#[ts(export, export_to = "prompts/common.ts")]
175pub struct TargetRef {
176    pub kind: TargetKind,
177    pub id: String,
178    #[serde(default, skip_serializing_if = "Option::is_none")]
179    #[ts(optional)]
180    pub intent: Option<TargetingIntent>,
181    #[serde(default, skip_serializing_if = "Option::is_none")]
182    #[ts(optional)]
183    pub oracle: Option<String>,
184}
185
186impl TargetRef {
187    pub fn card(id: String) -> Self {
188        Self {
189            kind: TargetKind::Card,
190            id,
191            intent: None,
192            oracle: None,
193        }
194    }
195
196    pub fn player(id: String) -> Self {
197        Self {
198            kind: TargetKind::Player,
199            id,
200            intent: None,
201            oracle: None,
202        }
203    }
204
205    pub fn spell(id: String) -> Self {
206        Self {
207            kind: TargetKind::Spell,
208            id,
209            intent: None,
210            oracle: None,
211        }
212    }
213}