Use multiple console instances so we can render the log in a larger font

This commit is contained in:
Timothy Warren 2022-02-02 09:34:20 -05:00
parent dedbb0927c
commit 4e506cd0be
4 changed files with 25 additions and 10 deletions

View File

@ -10,7 +10,7 @@ use ::serde::{Deserialize, Serialize};
pub use builder::*;
pub use events::*;
use logstore::*;
pub use logstore::{clear_log, clone_log, log_display, restore_log};
pub use logstore::{clear_log, clone_log, print_log, restore_log};
/// A section of colored text for the game log
#[derive(Serialize, Deserialize, Clone)]

View File

@ -3,6 +3,7 @@ use std::sync::Mutex;
use ::rltk::prelude::*;
use super::LogFragment;
use crate::colors;
lazy_static! {
static ref LOG: Mutex<Vec<Vec<LogFragment>>> = Mutex::new(Vec::new());
@ -21,18 +22,24 @@ pub fn clear_log() {
LOG.lock().unwrap().clear();
}
pub fn log_display() -> TextBuilder {
let mut buf = TextBuilder::empty();
LOG.lock().unwrap().iter().rev().take(12).for_each(|log| {
pub fn print_log(console: &mut Box<dyn Console>, pos: Point) {
let mut y = pos.y;
let mut x = pos.x;
LOG.lock().unwrap().iter().rev().take(6).for_each(|log| {
log.iter().for_each(|frag| {
buf.fg(frag.color);
buf.line_wrap(&frag.text);
console.print_color(
x,
y,
frag.color.to_rgba(1.0),
colors::BLACK.to_rgba(1.0),
&frag.text,
);
x += frag.text.len() as i32;
x += 1;
});
buf.ln();
y += 1;
x = pos.x;
});
buf
}
pub fn clone_log() -> Vec<Vec<LogFragment>> {

View File

@ -200,6 +200,8 @@ fn main() -> ::rltk::BError {
let context = RltkBuilder::simple(80, 60)
.unwrap()
.with_title("Roguelike Tutorial")
.with_font("vga8x16.png", 8, 16)
.with_sparse_console(80, 30, "vga8x16.png")
.build()?;
main_loop(context, init_state())

View File

@ -184,6 +184,9 @@ impl GameState for State {
newrunstate = *runstate;
}
ctx.set_active_console(1);
ctx.cls();
ctx.set_active_console(0);
ctx.cls();
particle_system::update_particles(&mut self.ecs, ctx);
@ -201,6 +204,9 @@ impl GameState for State {
if !SHOW_MAPGEN_VISUALIZER {
newrunstate = self.mapgen_next_state.unwrap();
}
ctx.set_active_console(1);
ctx.cls();
ctx.set_active_console(0);
ctx.cls();
if self.mapgen_index < self.mapgen_history.len() {
camera::render_debug_map(&self.mapgen_history[self.mapgen_index], ctx);