pre-api removal
This commit is contained in:
parent
7eb0e0ad64
commit
85881db62f
8 changed files with 95 additions and 15 deletions
27
src/gamelog/builder.rs
Normal file
27
src/gamelog/builder.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
use super::{append_entry, LogFragment};
|
||||
use rltk::prelude::*;
|
||||
|
||||
pub struct Logger {
|
||||
current_colour: RGB,
|
||||
fragments: Vec<LogFragment>,
|
||||
}
|
||||
|
||||
impl Logger {
|
||||
pub fn new() -> Self {
|
||||
Logger { current_colour: RGB::named(rltk::WHITE), fragments: Vec::new() }
|
||||
}
|
||||
|
||||
pub fn colour(mut self, colour: (u8, u8, u8)) -> Self {
|
||||
self.current_colour = RGB::named(colour);
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn append<T: ToString>(mut self, text: T) -> Self {
|
||||
self.fragments.push(LogFragment { colour: self.current_colour, text: text.to_string() });
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn log(self) {
|
||||
append_entry(self.fragments)
|
||||
}
|
||||
}
|
||||
33
src/gamelog/logstore.rs
Normal file
33
src/gamelog/logstore.rs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
use super::LogFragment;
|
||||
use rltk::prelude::*;
|
||||
use std::sync::Mutex;
|
||||
|
||||
lazy_static! {
|
||||
static ref LOG: Mutex<Vec<Vec<LogFragment>>> = Mutex::new(Vec::new());
|
||||
}
|
||||
|
||||
pub fn append_fragment(fragment: LogFragment) {
|
||||
LOG.lock().unwrap().push(vec![fragment]);
|
||||
}
|
||||
|
||||
pub fn append_entry(fragments: Vec<LogFragment>) {
|
||||
LOG.lock().unwrap().push(fragments);
|
||||
}
|
||||
|
||||
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| {
|
||||
log.iter().for_each(|frag| {
|
||||
buf.fg(frag.colour);
|
||||
buf.line_wrap(&frag.text);
|
||||
});
|
||||
buf.ln();
|
||||
});
|
||||
|
||||
return buf;
|
||||
}
|
||||
16
src/gamelog/mod.rs
Normal file
16
src/gamelog/mod.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
use rltk::prelude::*;
|
||||
|
||||
mod builder;
|
||||
pub use builder::*;
|
||||
mod logstore;
|
||||
use logstore::*;
|
||||
pub use logstore::{clear_log, log_display};
|
||||
|
||||
pub struct GameLog {
|
||||
pub entries: Vec<String>,
|
||||
}
|
||||
|
||||
pub struct LogFragment {
|
||||
pub colour: RGB,
|
||||
pub text: String,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue