List locations on empty command

This commit is contained in:
Joshua Barretto 2022-02-17 16:01:18 +00:00
parent b786570470
commit 34871c9355
2 changed files with 27 additions and 12 deletions

View File

@ -3523,23 +3523,36 @@ fn set_skills(skill_set: &mut comp::SkillSet, preset: &str) -> CmdResult<()> {
fn handle_location( fn handle_location(
server: &mut Server, server: &mut Server,
_client: EcsEntity, client: EcsEntity,
target: EcsEntity, target: EcsEntity,
args: Vec<String>, args: Vec<String>,
action: &ChatCommand, _action: &ChatCommand,
) -> CmdResult<()> { ) -> CmdResult<()> {
let loc = if let Some(name) = parse_args!(args, String) { if let Some(name) = parse_args!(args, String) {
match server.state.ecs().read_resource::<Locations>().get(&name) { let loc = server.state.ecs().read_resource::<Locations>().get(&name);
Ok(loc) => loc, match loc {
Err(e) => return Err(e.to_string()), Ok(loc) => position_mut(server, target, "target", |target_pos| {
target_pos.0 = loc;
}),
Err(e) => Err(e.to_string()),
} }
} else { } else {
return Err(action.help_string()); let locations = server.state.ecs().read_resource::<Locations>();
}; let mut locations = locations.iter().map(|s| s.as_str()).collect::<Vec<_>>();
locations.sort_unstable();
position_mut(server, target, "target", |target_pos| { server.notify_client(
target_pos.0 = loc; client,
}) ServerGeneral::server_msg(
ChatType::CommandInfo,
if locations.is_empty() {
"No locations currently exist".to_owned()
} else {
format!("Available locations:\n{}", locations.join(", "))
},
),
);
Ok(())
}
} }
fn handle_create_location( fn handle_create_location(

View File

@ -54,6 +54,8 @@ impl Locations {
.ok_or(LocationError::DoesNotExist(name)) .ok_or(LocationError::DoesNotExist(name))
} }
pub fn iter(&self) -> impl Iterator<Item = &String> { self.locations.keys() }
pub fn remove<'a>(&mut self, name: &'a str) -> Result<(), LocationError<'a>> { pub fn remove<'a>(&mut self, name: &'a str) -> Result<(), LocationError<'a>> {
self.locations self.locations
.remove(name) .remove(name)