diff --git a/Cargo.lock b/Cargo.lock index f2ac649..8b4a0c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,17 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -35,7 +46,18 @@ dependencies = [ "libc", "num-integer", "num-traits", - "time", + "time 0.1.43", + "winapi", +] + +[[package]] +name = "colored" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd" +dependencies = [ + "atty", + "lazy_static", "winapi", ] @@ -59,6 +81,12 @@ dependencies = [ "libc", ] +[[package]] +name = "itoa" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" + [[package]] name = "lazy_static" version = "1.4.0" @@ -137,6 +165,15 @@ dependencies = [ "libc", ] +[[package]] +name = "num_threads" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44" +dependencies = [ + "libc", +] + [[package]] name = "parking_lot" version = "0.12.0" @@ -258,6 +295,12 @@ dependencies = [ "version-compare", ] +[[package]] +name = "serde" +version = "1.0.151" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97fed41fc1a24994d044e6db6935e69511a1153b52c15eb42493b26fa87feba0" + [[package]] name = "signal-hook-registry" version = "1.4.0" @@ -267,6 +310,19 @@ dependencies = [ "libc", ] +[[package]] +name = "simple_logger" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e190a521c2044948158666916d9e872cbb9984f755e9bb3b5b75a836205affcd" +dependencies = [ + "atty", + "colored", + "log", + "time 0.3.17", + "windows-sys 0.42.0", +] + [[package]] name = "smallvec" version = "1.8.0" @@ -304,6 +360,35 @@ dependencies = [ "winapi", ] +[[package]] +name = "time" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376" +dependencies = [ + "itoa", + "libc", + "num_threads", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" + +[[package]] +name = "time-macros" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d967f99f534ca7e495c575c62638eebc2898a8c84c119b89e250477bc4ba16b2" +dependencies = [ + "time-core", +] + [[package]] name = "tokio" version = "1.23.0" @@ -486,7 +571,9 @@ name = "winelounge" version = "0.1.0" dependencies = [ "chrono", + "log", "rand", "sdl2", + "simple_logger", "tokio", ] diff --git a/Cargo.toml b/Cargo.toml index 13d4711..decec30 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,8 +8,10 @@ default-run = "winelounge" [dependencies] chrono = "0.4" +log = { version = "0.4", features = ["max_level_debug", "release_max_level_warn"] } rand = "0.8" sdl2 = { version = "0.35", features = ["image", "ttf"] } +simple_logger = { version = "4", features = ["colors", "timestamps"], default-features = false } tokio = { version = "1.19", features = ["full"], default-features = false } [profile.release] diff --git a/src/main.rs b/src/main.rs index f6baa13..55583e7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,8 @@ mod net; const GLASS_SPACE: u8 = 5; fn main() { + simple_logger::SimpleLogger::new().env().init().unwrap(); + let sdl_context = sdl2::init().unwrap(); let video_subsystem = sdl_context.video().unwrap(); diff --git a/src/world.rs b/src/world.rs index 2f3a525..f445f76 100644 --- a/src/world.rs +++ b/src/world.rs @@ -1,3 +1,4 @@ +use log::debug; use sdl2::event::Event; use sdl2::keyboard::Keycode; use sdl2::pixels::Color; @@ -107,7 +108,7 @@ impl World { /// Executes a command for world update. pub fn execute_command(&mut self, command: Command) { - println!("{}", command); + debug!("{}", command); match command { Command::SpawnPlayer(player_id, x, y) => &mut {