Skip to content

Commit

Permalink
feat: support multiple tools to craft in reclamation (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangl-cc authored Dec 24, 2024
1 parent cbd714c commit 5493d16
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
11 changes: 6 additions & 5 deletions maa-cli/src/run/preset/reclamation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
/// Method to interactive with the add button when increasing the crafting quantity
///
/// 0: increase the number by clicking the button.
Expand All @@ -74,7 +74,7 @@ impl From<ReclamationParams> 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);
}
Expand Down Expand Up @@ -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,
)),
Expand All @@ -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,
)),
Expand Down
21 changes: 20 additions & 1 deletion maa-cli/src/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,12 @@ impl<const N: usize, T: Into<MAAValue>> From<[T; N]> for MAAValue {
}
}

impl<T: Into<MAAValue>> From<Vec<T>> for MAAValue {
fn from(value: Vec<T>) -> 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.
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 5493d16

Please sign in to comment.