maa_framework/
diff_task.rs

1use std::fmt::Debug;
2
3use derive_builder::Builder;
4use serde::{ser::SerializeSeq, Serialize};
5use serde_json::Value;
6use serde_with::skip_serializing_none;
7
8#[derive(Serialize, Debug, Clone)]
9#[serde(untagged)]
10pub enum List<T: Debug + Clone + Serialize> {
11    Single(T),
12    Multiple(Vec<T>),
13}
14
15#[derive(Serialize, Debug, Clone)]
16pub enum Recognition {
17    DirectHit,
18    TemplateMatch,
19    FeatureMatch,
20    ColorMatch,
21    OCR,
22    NeuralNetworkClassify,
23    NeuralNetworkDetect,
24    Custom,
25}
26
27#[derive(Serialize, Debug, Clone)]
28pub enum Action {
29    DoNothing,
30    Click,
31    Swipe,
32    Key,
33    StartApp,
34    StopApp,
35    Custom,
36}
37
38#[derive(Serialize, Debug, Clone)]
39pub enum Order {
40    Horizontal,
41    Vertical,
42    Score,
43    Random,
44    Area,
45}
46
47#[derive(Serialize, Debug, Clone)]
48pub enum Detector {
49    SIFT,
50    KAZE,
51    AKAZE,
52    ORB,
53    BRISK,
54}
55
56#[derive(Serialize, Debug, Clone)]
57#[serde(untagged)]
58pub enum WaitFreezes {
59    Time(u32),
60    Object {
61        time: u32,
62        target: Target,
63        target_offset: [i32; 4],
64        threshold: f32,
65        method: u32,
66    },
67}
68
69#[derive(Debug, Clone)]
70pub enum Target {
71    True,
72    Task(String),
73    Area([u32; 4]),
74}
75
76impl Serialize for Target {
77    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
78    where
79        S: serde::Serializer,
80    {
81        match self {
82            Target::True => serializer.serialize_bool(true),
83            Target::Task(task) => serializer.serialize_str(task),
84            Target::Area(area) => {
85                let mut seq = serializer.serialize_seq(Some(4))?;
86                for e in area.iter() {
87                    seq.serialize_element(e)?;
88                }
89                seq.end()
90            }
91        }
92    }
93}
94
95#[derive(Serialize, Debug, Clone)]
96#[serde(untagged)]
97pub enum Variant<T, S> {
98    Left(T),
99    Right(S),
100}
101
102#[skip_serializing_none]
103#[derive(Serialize, Default, Builder, Debug, Clone)]
104#[builder(default)]
105pub struct DiffTask {
106    pub recognition: Option<Recognition>,
107    pub action: Option<Action>,
108    pub next: Option<Vec<String>>,
109    pub is_sub: Option<bool>,
110    pub inverse: Option<bool>,
111    pub enabled: Option<bool>,
112    pub timeout: Option<u32>,
113    pub timeout_next: Option<Vec<String>>,
114    pub times_limit: Option<u32>,
115    pub runout_next: Option<Vec<String>>,
116    pub pre_delay: Option<u32>,
117    pub post_delay: Option<u32>,
118    pub pre_wait_freezes: Option<WaitFreezes>,
119    pub post_wait_freezes: Option<WaitFreezes>,
120    pub focus: Option<bool>,
121    pub roi: Option<List<[u32; 4]>>,
122    pub template: Option<List<String>>,
123    pub threshold: Option<List<f32>>,
124    pub method: Option<u32>,
125    pub green_mask: Option<bool>,
126    pub order_by: Option<Order>,
127    pub index: Option<u32>,
128    pub count: Option<u32>,
129    pub detector: Option<Detector>,
130    pub ratio: Option<f32>,
131    pub lower: Option<List<Vec<u32>>>,
132    pub upper: Option<List<Vec<u32>>>,
133    pub connected: Option<bool>,
134    pub expected: Option<List<Variant<String, u32>>>,
135    pub input_text: Option<String>,
136    pub only_rec: Option<bool>,
137    pub model: Option<String>,
138    pub cls_size: Option<u32>,
139    pub labels: Option<Vec<String>>,
140    pub custom_recognition: Option<String>,
141    pub custom_recognition_param: Option<Value>,
142    pub target: Option<Target>,
143    pub target_offset: Option<[i32; 4]>,
144    pub begin: Option<Target>,
145    pub begin_offset: Option<[i32; 4]>,
146    pub end: Option<Target>,
147    pub end_offset: Option<[i32; 4]>,
148    pub duration: Option<u32>,
149    pub key: Option<List<u32>>,
150    pub package: Option<String>,
151    pub custom_action: Option<String>,
152    pub custom_action_param: Option<Value>,
153}