Skip to content

Commit

Permalink
init state
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackhr-arch committed Mar 6, 2025
1 parent 3e6672d commit b3dbacd
Show file tree
Hide file tree
Showing 3 changed files with 836 additions and 38 deletions.
11 changes: 10 additions & 1 deletion crates/maa-server/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ async fn main() {
println!("Add task StartUp");
let mut payload = NewTaskRequest::default();
payload.set_task_type(TaskType::Fight.into());
payload.task_params = r#""#.to_owned();
payload.task_params = r#" { "stage": "1-7" } "#.to_owned();
let id = taskclient
.append_task(make_request(payload, &session_id))
.await
Expand All @@ -105,6 +105,15 @@ async fn main() {
.await
.unwrap();
println!("Deactive task Fight");
let mut payload = NewTaskRequest::default();
payload.set_task_type(TaskType::Fight.into());
payload.task_params = r#" { "stage": "1-7" } "#.to_owned();
taskclient
.append_task(make_request(payload, &session_id))
.await
.unwrap()
.into_inner();
println!("Add task Fight 1-7");
taskclient
.start_tasks(make_request((), &session_id))
.await
Expand Down
69 changes: 61 additions & 8 deletions crates/maa-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ pub mod task {
if let Some(touch_mode) = TryInto::<TouchMode>::try_into(self.touch_mode).ok() {
tracing::debug!("Setting touch mode to {}", touch_mode.to_str());
asst.set_instance_option(InstanceOptionKey::TouchMode, touch_mode.to_str())
.map_err(|_| {
format!("Failed to set touch mode to {}", touch_mode.to_str())
})?;
.map_err(|_| format!("Failed to set touch mode to {}", touch_mode.to_str()))?;
}
if self.deployment_with_pause {
tracing::debug!(
Expand Down Expand Up @@ -132,11 +130,6 @@ pub mod core {

pub mod utils {
pub fn load_core() -> Result<(), String> {
if maa_sys::binding::loaded() {
tracing::debug!("MaaCore already loaded");
return Ok(());
}

use maa_dirs::MAA_CORE_LIB;
if let Some(lib_dir) = maa_dirs::find_library() {
tracing::debug!("Loading MaaCore from: {}", lib_dir.display());
Expand Down Expand Up @@ -326,3 +319,63 @@ pub mod utils {
resource_dirs
}
}

pub mod callback {
use maa_types::primitive::AsstMsgId;

#[repr(i32)]
#[derive(Debug, Clone, Copy)]
pub enum AsstMsg {
/* Global Info */
InternalError = 0,
InitFailed = 1,
ConnectionInfo = 2,
AllTasksCompleted = 3,
AsyncCallInfo = 4,
Destroyed = 5,

/* TaskChain Info */
TaskChainError = 10000,
TaskChainStart = 10001,
TaskChainCompleted = 10002,
TaskChainExtraInfo = 10003,
TaskChainStopped = 10004,

/* SubTask Info */
SubTaskError = 20000,
SubTaskStart = 20001,
SubTaskCompleted = 20002,
SubTaskExtraInfo = 20003,
SubTaskStopped = 20004,

/* Unknown */
Unknown = -1,
}

impl From<AsstMsgId> for AsstMsg {
fn from(msg: AsstMsgId) -> Self {
match msg {
0 => AsstMsg::InternalError,
1 => AsstMsg::InitFailed,
2 => AsstMsg::ConnectionInfo,
3 => AsstMsg::AllTasksCompleted,
4 => AsstMsg::AsyncCallInfo,
5 => AsstMsg::Destroyed,

10000 => AsstMsg::TaskChainError,
10001 => AsstMsg::TaskChainStart,
10002 => AsstMsg::TaskChainCompleted,
10003 => AsstMsg::TaskChainExtraInfo,
10004 => AsstMsg::TaskChainStopped,

20000 => AsstMsg::SubTaskError,
20001 => AsstMsg::SubTaskStart,
20002 => AsstMsg::SubTaskCompleted,
20003 => AsstMsg::SubTaskExtraInfo,
20004 => AsstMsg::SubTaskStopped,

_ => AsstMsg::Unknown,
}
}
}
}
Loading

0 comments on commit b3dbacd

Please sign in to comment.