mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Allow client to read user input
This commit is contained in:
parent
121d9e0d61
commit
3ddc56e4ac
@ -2,9 +2,19 @@ use client::{Client, Event};
|
||||
use common::{clock::Clock, comp};
|
||||
use log::{error, info};
|
||||
use std::time::Duration;
|
||||
use std::io;
|
||||
|
||||
const TPS: u64 = 10; // Low value is okay, just reading messages.
|
||||
|
||||
fn read_input() -> String {
|
||||
let mut buffer = String::new();
|
||||
|
||||
io::stdin().read_line(&mut buffer)
|
||||
.expect("Failed to read input");
|
||||
|
||||
buffer
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Initialize logging.
|
||||
pretty_env_logger::init();
|
||||
@ -20,15 +30,18 @@ fn main() {
|
||||
|
||||
println!("Server info: {:?}", client.server_info);
|
||||
|
||||
// TODO: Remove or move somewhere else, this doesn't work immediately after connecting
|
||||
println!("Ping: {:?}", client.get_ping_ms());
|
||||
|
||||
println!("Players online: {:?}", client.get_players());
|
||||
|
||||
client.register(comp::Player::new("test".to_string(), None));
|
||||
client.send_chat("Hello!".to_string());
|
||||
println!("Enter your username");
|
||||
let mut username = read_input();
|
||||
|
||||
client.register(comp::Player::new(username, None));
|
||||
|
||||
loop {
|
||||
|
||||
// TODO: Make it run on another thread. The client doesn't sync until you won't send another
|
||||
// message.
|
||||
client.send_chat(read_input());
|
||||
let events = match client.tick(comp::Controller::default(), clock.get_last_delta()) {
|
||||
Ok(events) => events,
|
||||
Err(err) => {
|
||||
@ -39,7 +52,7 @@ fn main() {
|
||||
|
||||
for event in events {
|
||||
match event {
|
||||
Event::Chat(msg) => println!("[chat] {}", msg),
|
||||
Event::Chat(msg) => println!("{}", msg),
|
||||
Event::Disconnect => {} // TODO
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user