mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Cleaner code
This commit is contained in:
parent
b97e27df9a
commit
488922ac94
@ -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,
|
||||
),
|
||||
|
@ -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"]
|
||||
|
Loading…
Reference in New Issue
Block a user