Skip to content

Commit

Permalink
feat: support client type for closedown command (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangl-cc authored Aug 17, 2024
1 parent 848bc81 commit 9b8d033
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 13 deletions.
1 change: 1 addition & 0 deletions maa-cli/completions/maa.fish
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ complete -c maa -n "__fish_seen_subcommand_from $run_commands" -f # prevent fish
complete -c maa -n "__fish_seen_subcommand_from run" -f -a "$(maa list)"
complete -c maa -n "__fish_seen_subcommand_from startup" -f -a "$clients"
complete -c maa -n "__fish_seen_subcommand_from startup" -f -l account -d 'Account to login' -r
complete -c maa -n "__fish_seen_subcommand_from closedown" -f -a "$clients"
complete -c maa -n "__fish_seen_subcommand_from fight" -f -s m -l medicine -d 'Medicine to use' -r
complete -c maa -n "__fish_seen_subcommand_from roguelike" -a "phantom mizuki sami sarkaz"

Expand Down
2 changes: 1 addition & 1 deletion maa-cli/docs/en-US/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ After installing and configuring MaaCore, you can run tasks. maa-cli supports tw
### Predefined tasks

- `maa startup [client]`: start the game client and enter the main screen, the `client` is the client type of game, leave it empty to don't start the game;
- `maa closedown`: close the game client;
- `maa closedown [client]`: close the game client, the `client` is the client type of game, default is `Official`;
- `maa fight [stage]`: run a "fight" task, the `stage` is the stage to fight, like `1-7`, `CE-6`, etc.; if not given, the user will be prompted to input one;
- `maa copilot <maa_uri>`: run a "copilot" task, the `maa_uri` is the URI of a copilot task; it can be `maa://1234` or local file path;
- `maa roguelike [theme]`: run a "roguelike" task, the `theme` is the theme of roguelike, and available themes are `Phantom`, `Mizuki`, `Sami` and `Sarkaz`.
Expand Down
4 changes: 2 additions & 2 deletions maa-cli/docs/ja-JP/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ maa init

对于常见任务,maa-cli 提供了一些预定义的任务:

- `maa startup [client]`: 启动游戏并进入主界面,`[client]` 是客户端类型,如果留空则不会启动游戏客户端
- `maa closedown`: 关闭游戏客户端;
- `maa startup [client]`: 启动游戏并进入主界面,`[client]` 是客户端类型,如果留空则不会启动游戏客户端
- `maa closedown [client]`: 关闭游戏客户端`[client]` 是客户端类型,默认为 `Official`
- `maa fight [stage]`: 运行战斗任务,`[stage]` 是关卡名称,例如 `1-7`;留空选择上次或者当前关卡;
- `maa copilot <maa_uri>`: 运行自动战斗任务,其中 `<maa_uri>` 是作业的 URI,其可以是 `maa://1234` 或者本地文件路径 `./1234.json`
- `maa roguelike [theme]`: 自动集成战略,`[theme]` 是集成战略的主题,可选值为 `Phantom``Mizuki``Sami` 以及 `Sarkaz`
Expand Down
4 changes: 2 additions & 2 deletions maa-cli/docs/ko-KR/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ MaaCore의 설치 및 구성을 완료하면 작업을 실행할 준비가 된
일반적인 작업에 대해 maa-cli는 몇 가지 사전 정의 작업을 제공합니다:

- `maa startup [client]`: 게임을 시작하고 메인 화면으로 이동합니다. `[client]`는 클라이언트 유형이며, 생략하면 게임 클라이언트를 시작하지 않습니다.
- `maa closedown`: 게임 클라이언트를 종료합니다.
- `maa closedown [client]`: 게임 클라이언트를 종료합니다. `[client]`는 클라이언트 유형이며, 기본값은 `Official`입니다.
- `maa fight [stage]`: 전투 작업을 실행합니다. `[stage]`는 스테이지 이름이며, 예를 들어 `1-7`입니다. 생략하면 이전 또는 현재 스테이지를 선택합니다.
- `maa copilot <maa_uri>`: 자동 전투 작업을 실행합니다. `<maa_uri>`는 작업의 URI로 `maa://1234` 또는 로컬 파일 경로 `./1234.json`일 수 있습니다.
- `maa roguelike [theme]`: 자동 통합 전략을 실행합니다. `[theme]`는 통합 전략의 주제이며, 선택 가능한 값은 `Phantom`, `Mizuki`, `Sami`, `Sarkaz`입니다.
Expand All @@ -61,7 +61,7 @@ MAA가 지원하는 작업이 많기 때문에, maa-cli는 모든 작업에 대

미리 정의된 작업이든 사용자 정의 작업이든, maa-cli는 작업이 종료되면 작업 요약 정보를 출력합니다. 여기에는 각 하위 작업의 실행 시간(시작 시간, 종료 시간, 실행 기간)이 포함됩니다. 일부 작업의 경우 결과 요약도 출력됩니다:

- `fight` 작업: 스테이지 이름, 실행 횟수, 사용된 약물 수량 및 드롭 통계.
- `fight` 작업: 스테이지 이름, 실행 횟수, 사용된 약물 수량 및 드롭 통계.
- `infrast`: 각 시설에 배치된 오퍼레이터, 제조소 및 무역소의 경우 생성된 아이템 유형 포함.
- `recruit`: 각 모집의 태그, 별 등급 및 상태, 총 모집 횟수.
- `roguelike`: 탐험 횟수, 투자 횟수.
Expand Down
4 changes: 2 additions & 2 deletions maa-cli/docs/zh-CN/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ maa init

对于常见任务,maa-cli 提供了一些预定义的任务:

- `maa startup [client]`: 启动游戏并进入主界面,`[client]` 是客户端类型,如果留空则不会启动游戏客户端
- `maa closedown`: 关闭游戏客户端;
- `maa startup [client]`: 启动游戏并进入主界面,`[client]` 是客户端类型,如果留空则不会启动游戏客户端
- `maa closedown [client]`: 关闭游戏客户端`[client]` 是客户端类型,默认为 `Official`
- `maa fight [stage]`: 运行战斗任务,`[stage]` 是关卡名称,例如 `1-7`;留空选择上次或者当前关卡;
- `maa copilot <maa_uri>`: 运行自动战斗任务,其中 `<maa_uri>` 是作业的 URI,其可以是 `maa://1234` 或者本地文件路径 `./1234.json`
- `maa roguelike [theme]`: 自动集成战略,`[theme]` 是集成战略的主题,可选值为 `Phantom``Mizuki``Sami` 以及 `Sarkaz`
Expand Down
4 changes: 2 additions & 2 deletions maa-cli/docs/zh-TW/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ maa init

对于常见任务,maa-cli 提供了一些预定义的任务:

- `maa startup [client]`: 启动游戏并进入主界面,`[client]` 是客户端类型,如果留空则不会启动游戏客户端
- `maa closedown`: 关闭游戏客户端;
- `maa startup [client]`: 启动游戏并进入主界面,`[client]` 是客户端类型,如果留空则不会启动游戏客户端
- `maa closedown [client]`: 关闭游戏客户端`[client]` 是客户端类型,默认为 `Official`
- `maa fight [stage]`: 运行战斗任务,`[stage]` 是关卡名称,例如 `1-7`;留空选择上次或者当前关卡;
- `maa copilot <maa_uri>`: 运行自动战斗任务,其中 `<maa_uri>` 是作业的 URI,其可以是 `maa://1234` 或者本地文件路径 `./1234.json`
- `maa roguelike [theme]`: 自动集成战略,`[theme]` 是集成战略的主题,可选值为 `Phantom``Mizuki``Sami` 以及 `Sarkaz`
Expand Down
15 changes: 15 additions & 0 deletions maa-cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ pub(crate) enum Command {
/// Close game client
#[command(name = "closedown")]
CloseDown {
/// Client type of the game client
///
/// The client type of the game client, used to close the game client.
/// If not specified, default to the Official client.
#[arg(default_value = "Official")]
client: config::task::ClientType,
#[command(flatten)]
common: run::CommonArgs,
},
Expand Down Expand Up @@ -594,6 +600,15 @@ mod test {
assert_matches!(
parse_from(["maa", "closedown"]).command,
Command::CloseDown {
client: config::task::ClientType::Official,
common: run::CommonArgs { .. }
}
);

assert_matches!(
parse_from(["maa", "closedown", "YoStarEN"]).command,
Command::CloseDown {
client: config::task::ClientType::YoStarEN,
common: run::CommonArgs { .. }
}
);
Expand Down
4 changes: 3 additions & 1 deletion maa-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ fn main() -> Result<()> {
account,
common,
} => run::run(|_| run::preset::startup(client, account), common)?,
Command::CloseDown { common } => run::run(|_| run::preset::closedown(), common)?,
Command::CloseDown { client, common } => {
run::run(|_| run::preset::closedown(client), common)?
}
Command::Fight {
stage,
medicine,
Expand Down
18 changes: 15 additions & 3 deletions maa-cli/src/run/preset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ pub fn startup(client: Option<ClientType>, account: Option<String>) -> Result<Ta
Ok(task_config)
}

pub fn closedown() -> Result<TaskConfig> {
pub fn closedown(client: ClientType) -> Result<TaskConfig> {
let mut task_config = TaskConfig::new();

task_config.push(Task::new_with_default(CloseDown, object!()));
task_config.push(Task::new_with_default(
CloseDown,
object!("client_type" => client.to_str()),
));

Ok(task_config)
}
Expand Down Expand Up @@ -107,13 +110,22 @@ mod tests {

#[test]
fn test_closedown() {
let task_config = closedown().unwrap();
let task_config = closedown(ClientType::YoStarEN).unwrap();
let tasks = task_config.tasks();

assert_eq!(tasks.len(), 1);
let closedown_task = tasks.first().unwrap();

assert_eq!(closedown_task.task_type(), CloseDown);
assert_eq!(
closedown_task
.params()
.get("client_type")
.unwrap()
.as_str()
.unwrap(),
"YoStarEN"
);
}

#[test]
Expand Down

0 comments on commit 9b8d033

Please sign in to comment.