From 65ec5c1b15ff7453523fbd4f09a7ddce5bbace28 Mon Sep 17 00:00:00 2001 From: Llywelwyn Date: Mon, 25 Sep 2023 20:50:30 +0100 Subject: [PATCH] cleanup --- src/gamelog/logstore.rs | 9 +++++++++ src/gamelog/mod.rs | 2 +- src/main.rs | 18 ++---------------- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/gamelog/logstore.rs b/src/gamelog/logstore.rs index 930be62..bfceaf9 100644 --- a/src/gamelog/logstore.rs +++ b/src/gamelog/logstore.rs @@ -5,11 +5,20 @@ use std::collections::BTreeMap; use notan::prelude::*; use notan::text::CreateText; use crate::consts::{ TILESIZE, FONTSIZE }; +use crate::consts::visuals::VIEWPORT_W; lazy_static! { pub static ref LOG: Mutex>> = Mutex::new(BTreeMap::new()); } +/// Render with defaults, to avoid having to pass so many args. +pub fn render(draw: bool, gfx: &mut Graphics, font: ¬an::draw::Font) { + if draw { + render_log(gfx, &font, &(TILESIZE, TILESIZE * 8.0 + 4.0), (VIEWPORT_W as f32) * TILESIZE); + } +} + +/// Render with specific params. pub fn render_log(gfx: &mut Graphics, font: ¬an::draw::Font, pos: &(f32, f32), width: f32) { let mut text = gfx.create_text(); let log = LOG.lock().unwrap(); diff --git a/src/gamelog/mod.rs b/src/gamelog/mod.rs index 5ae498d..4569ad1 100644 --- a/src/gamelog/mod.rs +++ b/src/gamelog/mod.rs @@ -2,7 +2,7 @@ mod builder; pub use builder::*; mod logstore; use logstore::*; -pub use logstore::{ LOG, clear_log, clone_log, render_log, restore_log, setup_log }; +pub use logstore::{ LOG, clear_log, clone_log, render, render_log, restore_log, setup_log }; mod events; pub use events::*; diff --git a/src/main.rs b/src/main.rs index 2b9bbde..b5a2d27 100644 --- a/src/main.rs +++ b/src/main.rs @@ -437,7 +437,7 @@ fn draw_bg(_ecs: &World, draw: &mut Draw, atlas: &HashMap) { draw_spritebox(sidebox, draw, atlas); } -fn draw(app: &mut App, gfx: &mut Graphics, gs: &mut State) { +fn draw(_app: &mut App, gfx: &mut Graphics, gs: &mut State) { let mut draw = gfx.create_draw(); draw.clear(Color::BLACK); let mut log = false; @@ -481,21 +481,7 @@ fn draw(app: &mut App, gfx: &mut Graphics, gs: &mut State) { _ => {} } gfx.render(&draw); - if log { - gamelog::render_log( - gfx, - &gs.font, - &(TILESIZE, TILESIZE * 8.0 + 4.0), - (VIEWPORT_W as f32) * TILESIZE - ); - } -} - -fn idx_to_px(idx: usize, map: &Map) -> (f32, f32) { - ( - ((idx % (map.width as usize)) as f32) * (TILESIZE as f32), - ((idx / (map.width as usize)) as f32) * (TILESIZE as f32), - ) + gamelog::render(log, gfx, &gs.font); } fn update(ctx: &mut App, state: &mut State) {