pre-api removal
This commit is contained in:
parent
7eb0e0ad64
commit
85881db62f
8 changed files with 95 additions and 15 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -2277,6 +2277,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bracket-lib 0.8.7 (git+https://github.com/amethyst/bracket-lib.git?rev=851f6f08675444fb6fa088b9e67bee9fd75554c6)",
|
"bracket-lib 0.8.7 (git+https://github.com/amethyst/bracket-lib.git?rev=851f6f08675444fb6fa088b9e67bee9fd75554c6)",
|
||||||
"criterion",
|
"criterion",
|
||||||
|
"lazy_static",
|
||||||
"rltk",
|
"rltk",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ specs = { version = "0.16.1", features = ["serde"] }
|
||||||
specs-derive = "0.4.1"
|
specs-derive = "0.4.1"
|
||||||
serde = { version = "1.0.93", features = ["derive"]}
|
serde = { version = "1.0.93", features = ["derive"]}
|
||||||
serde_json = "1.0.39"
|
serde_json = "1.0.39"
|
||||||
|
lazy_static = "1.4.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
criterion = { version = "^0.5" }
|
criterion = { version = "^0.5" }
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
pub struct GameLog {
|
|
||||||
pub entries: Vec<String>,
|
|
||||||
}
|
|
||||||
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,
|
||||||
|
}
|
||||||
17
src/gui.rs
17
src/gui.rs
|
|
@ -1,8 +1,8 @@
|
||||||
use super::{
|
use super::{
|
||||||
gamelog::GameLog, rex_assets::RexAssets, CombatStats, InBackpack, Map, Name, Player, Point, Position, RunState,
|
gamelog, rex_assets::RexAssets, CombatStats, InBackpack, Map, Name, Player, Point, Position, RunState, State,
|
||||||
State, Viewshed,
|
Viewshed,
|
||||||
};
|
};
|
||||||
use rltk::{Rltk, VirtualKeyCode, RGB};
|
use rltk::{Rltk, TextBlock, VirtualKeyCode, RGB};
|
||||||
use specs::prelude::*;
|
use specs::prelude::*;
|
||||||
|
|
||||||
pub fn draw_ui(ecs: &World, ctx: &mut Rltk) {
|
pub fn draw_ui(ecs: &World, ctx: &mut Rltk) {
|
||||||
|
|
@ -18,14 +18,9 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render message log
|
// Render message log
|
||||||
let log = ecs.fetch::<GameLog>();
|
let mut block = TextBlock::new(1, 44, 78, 5);
|
||||||
let mut y = 44;
|
let _ = block.print(&gamelog::log_display());
|
||||||
for s in log.entries.iter().rev() {
|
block.render(&mut rltk::BACKEND_INTERNAL.lock().consoles[0].console);
|
||||||
if y < 49 {
|
|
||||||
ctx.print(2, y, s);
|
|
||||||
}
|
|
||||||
y += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render depth
|
// Render depth
|
||||||
let map = ecs.fetch::<Map>();
|
let map = ecs.fetch::<Map>();
|
||||||
|
|
|
||||||
12
src/main.rs
12
src/main.rs
|
|
@ -32,6 +32,8 @@ mod particle_system;
|
||||||
use particle_system::{ParticleBuilder, DEFAULT_PARTICLE_LIFETIME, LONG_PARTICLE_LIFETIME};
|
use particle_system::{ParticleBuilder, DEFAULT_PARTICLE_LIFETIME, LONG_PARTICLE_LIFETIME};
|
||||||
mod random_table;
|
mod random_table;
|
||||||
mod rex_assets;
|
mod rex_assets;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate lazy_static;
|
||||||
|
|
||||||
// Embedded resources for use in wasm build
|
// Embedded resources for use in wasm build
|
||||||
rltk::embedded_resource!(TERMINAL8X8, "../resources/terminal8x8.jpg");
|
rltk::embedded_resource!(TERMINAL8X8, "../resources/terminal8x8.jpg");
|
||||||
|
|
@ -375,7 +377,7 @@ fn main() -> rltk::BError {
|
||||||
.with_resource_path("resources/")
|
.with_resource_path("resources/")
|
||||||
.with_font("terminal8x8.jpg", 8, 8)
|
.with_font("terminal8x8.jpg", 8, 8)
|
||||||
.with_simple_console(DISPLAYWIDTH, DISPLAYHEIGHT, "terminal8x8.jpg")
|
.with_simple_console(DISPLAYWIDTH, DISPLAYHEIGHT, "terminal8x8.jpg")
|
||||||
.with_simple_console_no_bg(DISPLAYWIDTH, DISPLAYHEIGHT, "terminal8x8.jpg")
|
//.with_simple_console_no_bg(DISPLAYWIDTH, DISPLAYHEIGHT, "terminal8x8.jpg")
|
||||||
.build()?;
|
.build()?;
|
||||||
context.with_post_scanlines(false);
|
context.with_post_scanlines(false);
|
||||||
//context.screen_burn_color(RGB::named((150, 255, 255)));
|
//context.screen_burn_color(RGB::named((150, 255, 255)));
|
||||||
|
|
@ -432,6 +434,14 @@ fn main() -> rltk::BError {
|
||||||
gs.ecs.insert(gamelog::GameLog {
|
gs.ecs.insert(gamelog::GameLog {
|
||||||
entries: vec!["<pretend i wrote a paragraph explaining why you're here>".to_string()],
|
entries: vec!["<pretend i wrote a paragraph explaining why you're here>".to_string()],
|
||||||
});
|
});
|
||||||
|
gamelog::clear_log();
|
||||||
|
gamelog::Logger::new()
|
||||||
|
.append("Welcome!")
|
||||||
|
.colour(rltk::CYAN)
|
||||||
|
.append("(")
|
||||||
|
.append("pretend i wrote a paragraph explaining why you're here")
|
||||||
|
.append(")")
|
||||||
|
.log();
|
||||||
gs.ecs.insert(RunState::MainMenu { menu_selection: gui::MainMenuSelection::NewGame });
|
gs.ecs.insert(RunState::MainMenu { menu_selection: gui::MainMenuSelection::NewGame });
|
||||||
gs.ecs.insert(particle_system::ParticleBuilder::new());
|
gs.ecs.insert(particle_system::ParticleBuilder::new());
|
||||||
gs.ecs.insert(rex_assets::RexAssets::new());
|
gs.ecs.insert(rex_assets::RexAssets::new());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue