From 5493d16436460055d1f4c2f210225dfece5b0248 Mon Sep 17 00:00:00 2001 From: Loong <40141251+wangl-cc@users.noreply.github.com> Date: Tue, 24 Dec 2024 12:44:25 +0000 Subject: [PATCH] feat: support multiple tools to craft in reclamation (#353) --- maa-cli/src/run/preset/reclamation.rs | 11 ++++++----- maa-cli/src/value/mod.rs | 21 ++++++++++++++++++++- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/maa-cli/src/run/preset/reclamation.rs b/maa-cli/src/run/preset/reclamation.rs index 9065c47a..26342062 100644 --- a/maa-cli/src/run/preset/reclamation.rs +++ b/maa-cli/src/run/preset/reclamation.rs @@ -49,7 +49,7 @@ pub struct ReclamationParams { mode: i32, /// Name of tool to craft in mode 1 #[arg(short = 'C', long, default_value = "荧光棒")] - tool_to_craft: String, + tools_to_craft: Vec, /// Method to interactive with the add button when increasing the crafting quantity /// /// 0: increase the number by clicking the button. @@ -74,7 +74,7 @@ impl From for MAAValue { value.insert("mode", params.mode); if params.mode == 1 { - value.insert("tool_to_craft", params.tool_to_craft); + value.insert("tools_to_craft", params.tools_to_craft); value.insert("increase_mode", params.increase_mode); value.insert("num_craft_batches", params.num_craft_batches); } @@ -135,7 +135,7 @@ mod tests { assert_eq!( parse(["maa", "reclamation", "Tales"]), base_params.join(object!( - "tool_to_craft" => "荧光棒", + "tools_to_craft" => ["荧光棒"], "increase_mode" => 0, "num_craft_batches" => 16, )), @@ -150,13 +150,14 @@ mod tests { "reclamation", "Tales", "-m1", - "-CSomething", + "-CFoo", + "-CBar", "--increase-mode=1", "--num-craft-batches=32" ]), base_params.join(object!( "mode" => 1, - "tool_to_craft" => "Something", + "tools_to_craft" => ["Foo", "Bar"], "increase_mode" => 1, "num_craft_batches" => 32, )), diff --git a/maa-cli/src/value/mod.rs b/maa-cli/src/value/mod.rs index 7ab70eb4..4b66ee55 100644 --- a/maa-cli/src/value/mod.rs +++ b/maa-cli/src/value/mod.rs @@ -386,6 +386,12 @@ impl> From<[T; N]> for MAAValue { } } +impl> From> for MAAValue { + fn from(value: Vec) -> Self { + Self::Array(value.into_iter().map(Into::into).collect()) + } +} + /// Try to convert the value to given type /// /// If the value is not convertible to the type, None will be returned. @@ -755,7 +761,20 @@ mod tests { } #[test] - fn try_from() { + fn value_from_others() { + // Array + assert_eq!( + MAAValue::from([1, 2]), + MAAValue::Array(vec![1.into(), 2.into()]) + ); + assert_eq!( + MAAValue::from(vec![1, 2]), + MAAValue::Array(vec![1.into(), 2.into()]) + ); + } + + #[test] + fn try_from_value() { // Bool assert_eq!(bool::try_from_value(&true.into()), Some(true)); assert_eq!(i32::try_from_value(&true.into()), None);