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(
|
ServerChatCommand::GiveItem => cmd(
|
||||||
vec![
|
vec![
|
||||||
AssetPath("item", "common.items", ITEM_SPECS.clone(), Required),
|
AssetPath("item", "common.items.", ITEM_SPECS.clone(), Required),
|
||||||
Integer("num", 1, Optional),
|
Integer("num", 1, Optional),
|
||||||
],
|
],
|
||||||
"Give yourself some items.\nFor an example or to auto complete use Tab.",
|
"Give yourself some items.\nFor an example or to auto complete use Tab.",
|
||||||
@ -649,7 +649,7 @@ impl ServerChatCommand {
|
|||||||
vec![
|
vec![
|
||||||
AssetPath(
|
AssetPath(
|
||||||
"entity_config",
|
"entity_config",
|
||||||
"common.entity",
|
"common.entity.",
|
||||||
ENTITY_CONFIGS.clone(),
|
ENTITY_CONFIGS.clone(),
|
||||||
Required,
|
Required,
|
||||||
),
|
),
|
||||||
|
@ -222,7 +222,7 @@ fn preproccess_command(
|
|||||||
could_be_entity_target = true;
|
could_be_entity_target = true;
|
||||||
}
|
}
|
||||||
if let Some(ArgumentSpec::AssetPath(_, prefix, _, _)) = cmd_args.get(i) {
|
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) {
|
if could_be_entity_target && arg.starts_with(ClientEntityTarget::PREFIX) {
|
||||||
let target_str = arg.trim_start_matches(ClientEntityTarget::PREFIX);
|
let target_str = arg.trim_start_matches(ClientEntityTarget::PREFIX);
|
||||||
@ -597,17 +597,14 @@ impl TabComplete for ArgumentSpec {
|
|||||||
.map(|c| c.to_string())
|
.map(|c| c.to_string())
|
||||||
.collect(),
|
.collect(),
|
||||||
ArgumentSpec::AssetPath(_, prefix, paths, _) => {
|
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
|
paths
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|path| {
|
.map(|path| path.as_str().split('.').take(depth).join("."))
|
||||||
path.as_str()
|
|
||||||
.strip_prefix(&(prefix.to_string() + "."))
|
|
||||||
.map(|stripped| stripped.split('.').take(depth).join("."))
|
|
||||||
})
|
|
||||||
.dedup()
|
.dedup()
|
||||||
.filter(|string| string.starts_with(part))
|
.filter(|string| string.starts_with(&part_with_prefix))
|
||||||
.map(|c| c.to_string())
|
.filter_map(|c| Some(c.strip_prefix(prefix)?.to_string()))
|
||||||
.collect()
|
.collect()
|
||||||
},
|
},
|
||||||
ArgumentSpec::Boolean(_, part, _) => ["true", "false"]
|
ArgumentSpec::Boolean(_, part, _) => ["true", "false"]
|
||||||
|
Loading…
Reference in New Issue
Block a user