extends log builder, swaps away from textblocks
line wrapping no longer works, but in return the message log can easily be swapped between ascending/descending, and spaces/no spaces between entries. realistically nobody wants to read a huge wrapped line anyway so those can just be avoided
This commit is contained in:
parent
b562e093ea
commit
42901b984e
9 changed files with 89 additions and 30 deletions
|
|
@ -7,35 +7,80 @@ pub struct Logger {
|
|||
}
|
||||
|
||||
impl Logger {
|
||||
/// Creates a blank builder for making message log entries.
|
||||
pub fn new() -> Self {
|
||||
Logger { current_colour: RGB::named(rltk::WHITE), fragments: Vec::new() }
|
||||
}
|
||||
|
||||
/// Sets the colour of the current message logger.
|
||||
pub fn colour(mut self, colour: (u8, u8, u8)) -> Self {
|
||||
self.current_colour = RGB::named(colour);
|
||||
return self;
|
||||
}
|
||||
|
||||
/// Appends text in the current colour to the current message logger.
|
||||
pub fn append<T: ToString>(mut self, text: T) -> Self {
|
||||
let mut text_with_space = text.to_string();
|
||||
text_with_space.push_str(" ");
|
||||
self.fragments.push(LogFragment { colour: self.current_colour, text: text_with_space });
|
||||
return self;
|
||||
}
|
||||
|
||||
/// Appends text in the current colour to the current message logger, with no space.
|
||||
#[allow(dead_code)]
|
||||
pub fn append_n<T: ToString>(mut self, text: T) -> Self {
|
||||
self.fragments.push(LogFragment { colour: self.current_colour, text: text.to_string() });
|
||||
return self;
|
||||
}
|
||||
|
||||
/// Appends a period to the current message logger.
|
||||
pub fn period(mut self) -> Self {
|
||||
self.fragments.push(LogFragment { colour: self.current_colour, text: ".".to_string() });
|
||||
return self;
|
||||
}
|
||||
|
||||
/// Pushes the finished log entry.
|
||||
pub fn log(self) {
|
||||
return append_entry(self.fragments);
|
||||
}
|
||||
|
||||
/// Appends text in YELLOW to the current message logger.
|
||||
pub fn npc_name<T: ToString>(mut self, text: T) -> Self {
|
||||
let mut text_with_space = text.to_string();
|
||||
text_with_space.push_str(" ");
|
||||
self.fragments.push(LogFragment { colour: RGB::named(rltk::YELLOW), text: text_with_space });
|
||||
return self;
|
||||
}
|
||||
|
||||
/// Appends text in YELLOW to the current message logger, with no space.
|
||||
pub fn npc_name_n<T: ToString>(mut self, text: T) -> Self {
|
||||
self.fragments.push(LogFragment { colour: RGB::named(rltk::YELLOW), text: text.to_string() });
|
||||
return self;
|
||||
}
|
||||
|
||||
/// Appends text in CYAN to the current message logger.
|
||||
pub fn item_name<T: ToString>(mut self, text: T) -> Self {
|
||||
let mut text_with_space = text.to_string();
|
||||
text_with_space.push_str(" ");
|
||||
self.fragments.push(LogFragment { colour: RGB::named(rltk::CYAN), text: text_with_space });
|
||||
return self;
|
||||
}
|
||||
|
||||
/// Appends text in CYAN to the current message logger, with no space.
|
||||
pub fn item_name_n<T: ToString>(mut self, text: T) -> Self {
|
||||
self.fragments.push(LogFragment { colour: RGB::named(rltk::CYAN), text: text.to_string() });
|
||||
return self;
|
||||
}
|
||||
|
||||
/// Appends text in RED to the current message logger.
|
||||
pub fn damage(mut self, damage: i32) -> Self {
|
||||
self.fragments.push(LogFragment { colour: RGB::named(rltk::RED), text: format!("{} ", damage).to_string() });
|
||||
return self;
|
||||
}
|
||||
|
||||
/// Appends text in RED to the current message logger, with no space.
|
||||
#[allow(dead_code)]
|
||||
pub fn damage_n(mut self, damage: i32) -> Self {
|
||||
self.fragments.push(LogFragment { colour: RGB::named(rltk::RED), text: format!("{}", damage).to_string() });
|
||||
return self;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue