This commit is contained in:
griffi-gh 2023-01-15 01:41:29 +01:00
parent c27b226d4d
commit 2fd692c24d
5 changed files with 56 additions and 1 deletions

View file

@ -7,3 +7,5 @@ edition = "2021"
glium = "0.32"
glutin = "*"
image = { version = "0.24", default_features = false, features = ["png"] }
log = "0.4"
env_logger = "0.10"

View file

@ -11,9 +11,13 @@ use assets::Assets;
use display::init_display;
pub fn run() {
log::info!("starting up");
let event_loop = EventLoop::new();
log::info!("initializing display");
let display = init_display(&event_loop);
log::info!("loading assets");
let assets = Assets::load_all_sync(&display);
log::info!("game loaded");
event_loop.run(move |ev, _, control_flow| {
match ev {

View file

@ -2,6 +2,8 @@ use std::{fs, io};
use glium::texture::{RawImage2d, SrgbTexture2d};
fn load_png(file_path: &str, display: &glium::Display) -> SrgbTexture2d {
log::info!("loading texture {}", file_path);
//Load file
let data = fs::read(file_path)
.expect(&format!("Failed to load texture: {}", file_path));

45
src/logging.rs Normal file
View file

@ -0,0 +1,45 @@
//! Custom env_logger options and styling
use env_logger::{fmt::Color, Builder, Env};
use log::Level;
use std::io::Write;
pub fn init() {
let mut env = Env::default();
if cfg!(debug_assertions) {
env = env.filter_or("RUST_LOG", "info");
}
Builder::from_env(env)
.format(|buf, record| {
let mut level_style = buf.style();
level_style.set_color(match record.level() {
Level::Error => Color::Red,
Level::Warn => Color::Yellow,
_ => Color::Blue
}).set_bold(true);
let mut location_style = buf.style();
location_style.set_bold(true);
location_style.set_dimmed(true);
let mut location_line_style = buf.style();
location_line_style.set_dimmed(true);
writeln!(
buf,
"{} {:<50}\t{}{}{}",
level_style.value(match record.level() {
Level::Error => "[e]",
Level::Warn => "[w]",
Level::Info => "[i]",
Level::Debug => "[d]",
Level::Trace => "[t]",
}),
format!("{}", record.args()),
location_style.value(record.module_path().unwrap_or("<unknown>")),
location_line_style.value(" :"),
location_line_style.value(record.line().unwrap_or(0))
)
})
.init();
}

View file

@ -1,5 +1,7 @@
mod game;
mod logging;
fn main() {
logging::init();
game::run();
}