Cleaner code

This commit is contained in:
Syniis 2024-01-27 16:16:30 +01:00
parent b97e27df9a
commit 488922ac94
2 changed files with 8 additions and 11 deletions

View File

@ -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,
),

View File

@ -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"]