2022-01-21 15:55:13 -05:00
|
|
|
/// A struct to hold the player's game log.
|
2021-11-19 19:52:15 -05:00
|
|
|
#[derive(Default)]
|
2021-11-01 14:46:45 -04:00
|
|
|
pub struct GameLog {
|
|
|
|
pub entries: Vec<String>,
|
|
|
|
}
|
2021-11-05 14:32:14 -04:00
|
|
|
|
|
|
|
impl GameLog {
|
2022-01-21 15:55:13 -05:00
|
|
|
/// Convenience constructor that adds the first
|
|
|
|
/// entry to the game log.
|
2021-11-05 14:32:14 -04:00
|
|
|
pub fn new<S: ToString>(first_entry: S) -> Self {
|
2021-11-19 19:52:15 -05:00
|
|
|
let mut log = GameLog::default();
|
|
|
|
log.append(first_entry);
|
|
|
|
|
|
|
|
log
|
2021-11-05 14:32:14 -04:00
|
|
|
}
|
2021-11-18 15:25:29 -05:00
|
|
|
|
2022-01-21 15:55:13 -05:00
|
|
|
/// Convenience method for adding an entry to the game log.
|
|
|
|
/// Generic on the [`ToString`] trait so that [`&str`], [`String`],
|
|
|
|
/// and `&String` types, all work without more type juggling
|
|
|
|
/// at the call site.
|
2021-11-19 11:30:25 -05:00
|
|
|
pub fn append<S: ToString>(&mut self, s: S) {
|
2021-11-18 15:25:29 -05:00
|
|
|
self.entries.push(s.to_string());
|
|
|
|
}
|
2021-11-05 14:32:14 -04:00
|
|
|
}
|