From 488922ac94243cec4c7bc797ca7c43bd4871ca0d Mon Sep 17 00:00:00 2001 From: Syniis Date: Sat, 27 Jan 2024 16:16:30 +0100 Subject: [PATCH] Cleaner code --- common/src/cmd.rs | 4 ++-- voxygen/src/cmd.rs | 15 ++++++--------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/common/src/cmd.rs b/common/src/cmd.rs index 235cbe7182..e67074a5de 100644 --- a/common/src/cmd.rs +++ b/common/src/cmd.rs @@ -537,7 +537,7 @@ impl ServerChatCommand { ), ServerChatCommand::GiveItem => cmd( vec![ - AssetPath("item", "common.items", ITEM_SPECS.clone(), Required), + AssetPath("item", "common.items.", ITEM_SPECS.clone(), Required), Integer("num", 1, Optional), ], "Give yourself some items.\nFor an example or to auto complete use Tab.", @@ -649,7 +649,7 @@ impl ServerChatCommand { vec![ AssetPath( "entity_config", - "common.entity", + "common.entity.", ENTITY_CONFIGS.clone(), Required, ), diff --git a/voxygen/src/cmd.rs b/voxygen/src/cmd.rs index 4b618a947c..27c5611cfc 100644 --- a/voxygen/src/cmd.rs +++ b/voxygen/src/cmd.rs @@ -222,7 +222,7 @@ fn preproccess_command( could_be_entity_target = true; } if let Some(ArgumentSpec::AssetPath(_, prefix, _, _)) = cmd_args.get(i) { - *arg = prefix.to_string() + "." + arg; + *arg = prefix.to_string() + arg; } if could_be_entity_target && arg.starts_with(ClientEntityTarget::PREFIX) { let target_str = arg.trim_start_matches(ClientEntityTarget::PREFIX); @@ -597,17 +597,14 @@ impl TabComplete for ArgumentSpec { .map(|c| c.to_string()) .collect(), ArgumentSpec::AssetPath(_, prefix, paths, _) => { - let depth = part.split('.').count(); + let part_with_prefix = prefix.to_string() + part; + let depth = part_with_prefix.split('.').count(); paths .iter() - .filter_map(|path| { - path.as_str() - .strip_prefix(&(prefix.to_string() + ".")) - .map(|stripped| stripped.split('.').take(depth).join(".")) - }) + .map(|path| path.as_str().split('.').take(depth).join(".")) .dedup() - .filter(|string| string.starts_with(part)) - .map(|c| c.to_string()) + .filter(|string| string.starts_with(&part_with_prefix)) + .filter_map(|c| Some(c.strip_prefix(prefix)?.to_string())) .collect() }, ArgumentSpec::Boolean(_, part, _) => ["true", "false"]