Adds the ability to change time with /time with HH:MM format. e.g. 12:43

This commit is contained in:
Christoffer Lantz 2019-07-26 15:43:39 +02:00
parent c077c54690
commit dbe9c5d696
2 changed files with 10 additions and 6 deletions

View File

@ -18,3 +18,4 @@ ron = "0.5.1"
serde = "1.0"
serde_derive = "1.0"
rand = "0.5.6"
chrono = "0.4.7"

View File

@ -9,6 +9,7 @@ use common::{
npc::{get_npc_name, NpcKind},
state::TimeOfDay,
};
use chrono::{NaiveTime, Timelike};
use rand::Rng;
use specs::{Builder, Entity as EcsEntity, Join};
use vek::*;
@ -217,12 +218,14 @@ fn handle_time(server: &mut Server, entity: EcsEntity, args: String, action: &Ch
Some("dusk") => 17.0 * 3600.0,
Some(n) => match n.parse() {
Ok(n) => n,
Err(_) => {
server.clients.notify(
entity,
ServerMsg::private(format!("'{}' is not a time!", n)),
);
return;
Err(_) => match NaiveTime::parse_from_str(n, "%H:%M") {
Ok(time) => time.num_seconds_from_midnight() as f64,
Err(_) => {
server
.clients
.notify(entity, ServerMsg::private(format!("'{}' is not a valid time.", n)));
return;
}
}
},
None => {