Replace rltk with bracket_lib, removing one layer of module redirection

This commit is contained in:
Timothy Warren 2022-02-04 14:09:48 -05:00
parent 1c4be360a3
commit 8f10289ed6
71 changed files with 194 additions and 171 deletions

View File

@ -8,17 +8,17 @@ edition = "2021"
[features] [features]
debug = [] debug = []
default = ["rltk/opengl", "rltk/serde", "rltk/threaded"] default = ["bracket-lib/opengl", "bracket-lib/serde", "bracket-lib/threaded"]
curses = ["rltk/curses", "rltk/serde"] curses = ["bracket-lib/curses", "bracket-lib/serde"]
# WebAssembly Build # WebAssembly Build
wasm = ["getrandom/js", "rltk/opengl", "rltk/serde"] wasm = ["getrandom/js", "bracket-lib/opengl", "bracket-lib/serde"]
[dependencies] [dependencies]
getrandom = { version = "0.2.4", optional = true } getrandom = { version = "0.2.4", optional = true }
lazy_static = "1.4.0" lazy_static = "1.4.0"
regex = "1.5.4" regex = "1.5.4"
rltk = { version = "0.8.1", default-features = false } bracket-lib = { version = "0.8.1", default-features = false }
specs = { version = "0.16.1", features = ["serde"] } 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"] }

View File

@ -1,6 +1,6 @@
//! Color constants to replace more verbose methods of defining colors in the game. //! Color constants to replace more verbose methods of defining colors in the game.
//! These constants replace the `::rltk::RGB` constructor functions //! These constants replace the `::bracket_lib::RGB` constructor functions
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
const fn new(r: f32, g: f32, b: f32) -> RGB { const fn new(r: f32, g: f32, b: f32) -> RGB {
RGB { r, g, b } RGB { r, g, b }

View File

@ -5,7 +5,7 @@ mod tags;
use std::collections::HashMap; use std::collections::HashMap;
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::serde::{Deserialize, Serialize}; use ::serde::{Deserialize, Serialize};
use ::specs::error::NoError; use ::specs::error::NoError;
use ::specs::prelude::*; use ::specs::prelude::*;
@ -45,7 +45,7 @@ impl From<Position> for Point {
#[derive(Component, ConvertSaveload, Clone)] #[derive(Component, ConvertSaveload, Clone)]
pub struct Renderable { pub struct Renderable {
pub glyph: rltk::FontCharType, pub glyph: FontCharType,
pub fg: RGB, pub fg: RGB,
pub bg: RGB, pub bg: RGB,
pub render_order: i32, pub render_order: i32,

View File

@ -1,3 +1,4 @@
use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use crate::components::{ use crate::components::{
@ -118,7 +119,7 @@ pub fn delete_the_dead(ecs: &mut World) {
ecs.read_storage::<AreaOfEffect>().get(spell_entity) ecs.read_storage::<AreaOfEffect>().get(spell_entity)
{ {
Targets::Tiles { Targets::Tiles {
tiles: aoe_tiles(&map, rltk::Point::new(pos.x, pos.y), aoe.radius), tiles: aoe_tiles(&map, Point::new(pos.x, pos.y), aoe.radius),
} }
} else { } else {
Targets::Tile { Targets::Tile {

View File

@ -9,7 +9,7 @@ mod triggers;
use std::collections::{HashSet, VecDeque}; use std::collections::{HashSet, VecDeque};
use std::sync::Mutex; use std::sync::Mutex;
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
pub use targeting::*; pub use targeting::*;

View File

@ -1,4 +1,4 @@
use ::rltk::Point; use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use ::specs::saveload::{MarkedBuilder, SimpleMarker}; use ::specs::saveload::{MarkedBuilder, SimpleMarker};
@ -26,7 +26,7 @@ pub fn inflict_damage(ecs: &mut World, damage: &EffectSpawner, target: Entity) {
add_effect( add_effect(
None, None,
EffectType::Particle { EffectType::Particle {
glyph: rltk::to_cp437('‼'), glyph: to_cp437('‼'),
fg: colors::ORANGE, fg: colors::ORANGE,
bg: colors::BLACK, bg: colors::BLACK,
lifespan: 200.0, lifespan: 200.0,
@ -139,7 +139,7 @@ pub fn death(ecs: &mut World, effect: &EffectSpawner, target: Entity) {
add_effect( add_effect(
None, None,
EffectType::Particle { EffectType::Particle {
glyph: ::rltk::to_cp437('░'), glyph: to_cp437('░'),
fg: colors::GOLD, fg: colors::GOLD,
bg: colors::BLACK, bg: colors::BLACK,
lifespan: 400.0, lifespan: 400.0,
@ -165,7 +165,7 @@ pub fn heal_damage(ecs: &mut World, heal: &EffectSpawner, target: Entity) {
add_effect( add_effect(
None, None,
EffectType::Particle { EffectType::Particle {
glyph: ::rltk::to_cp437('‼'), glyph: to_cp437('‼'),
fg: colors::GREEN, fg: colors::GREEN,
bg: colors::BLACK, bg: colors::BLACK,
lifespan: 200.0, lifespan: 200.0,
@ -184,7 +184,7 @@ pub fn restore_mana(ecs: &mut World, mana: &EffectSpawner, target: Entity) {
add_effect( add_effect(
None, None,
EffectType::Particle { EffectType::Particle {
glyph: ::rltk::to_cp437('‼'), glyph: to_cp437('‼'),
fg: colors::BLUE, fg: colors::BLUE,
bg: colors::BLACK, bg: colors::BLACK,
lifespan: 200.0, lifespan: 200.0,

View File

@ -1,3 +1,4 @@
use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use crate::components::{Equipped, InBackpack, Position}; use crate::components::{Equipped, InBackpack, Position};
@ -13,8 +14,8 @@ pub fn entity_position(ecs: &World, target: Entity) -> Option<i32> {
None None
} }
pub fn aoe_tiles(map: &Map, target: ::rltk::Point, radius: i32) -> Vec<i32> { pub fn aoe_tiles(map: &Map, target: Point, radius: i32) -> Vec<i32> {
let mut blast_tiles = ::rltk::field_of_view(target, radius, &*map); let mut blast_tiles = field_of_view(target, radius, &*map);
blast_tiles.retain(|p| p.x > 0 && p.x < map.width - 1 && p.y > 0 && p.y < map.height - 1); blast_tiles.retain(|p| p.x > 0 && p.x < map.width - 1 && p.y > 0 && p.y < map.height - 1);
let mut result = Vec::new(); let mut result = Vec::new();
for t in blast_tiles.iter() { for t in blast_tiles.iter() {

View File

@ -1,4 +1,4 @@
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use super::{add_effect, EffectType, Targets}; use super::{add_effect, EffectType, Targets};
@ -352,7 +352,7 @@ fn spawn_line_particles(ecs: &World, start: i32, end: i32, part: &SpawnParticleL
let map = ecs.fetch::<Map>(); let map = ecs.fetch::<Map>();
let start_pt = Point::new(start % map.width, end / map.width); let start_pt = Point::new(start % map.width, end / map.width);
let end_pt = Point::new(end % map.width, end / map.width); let end_pt = Point::new(end % map.width, end / map.width);
let line = ::rltk::line2d(LineAlg::Bresenham, start_pt, end_pt); let line = line2d(LineAlg::Bresenham, start_pt, end_pt);
for pt in line.iter() { for pt in line.iter() {
add_effect( add_effect(
None, None,

View File

@ -5,7 +5,7 @@ mod builder;
mod events; mod events;
mod logstore; mod logstore;
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::serde::{Deserialize, Serialize}; use ::serde::{Deserialize, Serialize};
pub use builder::*; pub use builder::*;
pub use events::*; pub use events::*;

View File

@ -1,4 +1,4 @@
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use super::{append_entry, LogFragment}; use super::{append_entry, LogFragment};
use crate::colors; use crate::colors;

View File

@ -1,6 +1,6 @@
use std::sync::Mutex; use std::sync::Mutex;
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use super::LogFragment; use super::LogFragment;
use crate::colors; use crate::colors;

View File

@ -1,4 +1,4 @@
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use super::{menu_box, menu_option}; use super::{menu_box, menu_option};
use crate::{colors, State}; use crate::{colors, State};
@ -13,7 +13,7 @@ pub enum CheatMenuResult {
GodMode, GodMode,
} }
pub fn show_cheat_mode(_gs: &mut State, ctx: &mut Rltk) -> CheatMenuResult { pub fn show_cheat_mode(_gs: &mut State, ctx: &mut BTerm) -> CheatMenuResult {
let mut draw_batch = DrawBatch::new(); let mut draw_batch = DrawBatch::new();
let count = 4; let count = 4;
let mut y = (25 - (count / 2)) as i32; let mut y = (25 - (count / 2)) as i32;

View File

@ -1,11 +1,11 @@
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use super::{get_item_display_name, item_result_menu, ItemMenuResult}; use super::{get_item_display_name, item_result_menu, ItemMenuResult};
use crate::components::InBackpack; use crate::components::InBackpack;
use crate::State; use crate::State;
pub fn drop_item_menu(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option<Entity>) { pub fn drop_item_menu(gs: &mut State, ctx: &mut BTerm) -> (ItemMenuResult, Option<Entity>) {
let mut draw_batch = DrawBatch::new(); let mut draw_batch = DrawBatch::new();
let player_entity = gs.ecs.fetch::<Entity>(); let player_entity = gs.ecs.fetch::<Entity>();

View File

@ -1,4 +1,4 @@
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use crate::{colors, gamelog}; use crate::{colors, gamelog};
@ -8,7 +8,7 @@ pub enum GameOverResult {
QuitToMenu, QuitToMenu,
} }
pub fn game_over(ctx: &mut Rltk) -> GameOverResult { pub fn game_over(ctx: &mut BTerm) -> GameOverResult {
let mut draw_batch = DrawBatch::new(); let mut draw_batch = DrawBatch::new();
draw_batch.print_color_centered( draw_batch.print_color_centered(
15, 15,

View File

@ -1,6 +1,6 @@
use std::cmp::Ordering; use std::cmp::Ordering;
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use super::{draw_tooltips, get_item_color, get_item_display_name}; use super::{draw_tooltips, get_item_color, get_item_display_name};
@ -38,7 +38,7 @@ fn draw_attribute(name: &str, attribute: &Attribute, y: i32, draw_batch: &mut Dr
draw_batch.set( draw_batch.set(
Point::new(72, y), Point::new(72, y),
ColorPair::new(color, colors::BLACK), ColorPair::new(color, colors::BLACK),
rltk::to_cp437('+'), to_cp437('+'),
); );
} }
} }
@ -358,7 +358,7 @@ fn status(ecs: &World, draw_batch: &mut DrawBatch, player_entity: &Entity) {
} }
} }
pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { pub fn draw_ui(ecs: &World, ctx: &mut BTerm) {
let mut draw_batch = DrawBatch::new(); let mut draw_batch = DrawBatch::new();
let player_entity = ecs.fetch::<Entity>(); let player_entity = ecs.fetch::<Entity>();
@ -375,7 +375,7 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) {
status(ecs, &mut draw_batch, &player_entity); status(ecs, &mut draw_batch, &player_entity);
gamelog::print_log( gamelog::print_log(
&mut ::rltk::BACKEND_INTERNAL.lock().consoles[1].console, &mut BACKEND_INTERNAL.lock().consoles[1].console,
Point::new(1, 23), Point::new(1, 23),
); );
draw_tooltips(ecs, ctx); draw_tooltips(ecs, ctx);

View File

@ -1,11 +1,11 @@
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use super::{get_item_display_name, item_result_menu, ItemMenuResult}; use super::{get_item_display_name, item_result_menu, ItemMenuResult};
use crate::components::{Equipped, InBackpack, Item, Name, ObfuscatedName}; use crate::components::{Equipped, InBackpack, Item, Name, ObfuscatedName};
use crate::{MasterDungeonMap, State}; use crate::{MasterDungeonMap, State};
pub fn identify_menu(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option<Entity>) { pub fn identify_menu(gs: &mut State, ctx: &mut BTerm) -> (ItemMenuResult, Option<Entity>) {
let mut draw_batch = DrawBatch::new(); let mut draw_batch = DrawBatch::new();
let player_entity = gs.ecs.fetch::<Entity>(); let player_entity = gs.ecs.fetch::<Entity>();

View File

@ -1,11 +1,11 @@
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use super::{get_item_display_name, item_result_menu, ItemMenuResult}; use super::{get_item_display_name, item_result_menu, ItemMenuResult};
use crate::components::InBackpack; use crate::components::InBackpack;
use crate::State; use crate::State;
pub fn show_inventory(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option<Entity>) { pub fn show_inventory(gs: &mut State, ctx: &mut BTerm) -> (ItemMenuResult, Option<Entity>) {
let mut draw_batch = DrawBatch::new(); let mut draw_batch = DrawBatch::new();
let player_entity = gs.ecs.fetch::<Entity>(); let player_entity = gs.ecs.fetch::<Entity>();

View File

@ -1,4 +1,4 @@
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use crate::components::{Consumable, CursedItem, MagicItem, MagicItemClass, Name, ObfuscatedName}; use crate::components::{Consumable, CursedItem, MagicItem, MagicItemClass, Name, ObfuscatedName};

View File

@ -1,4 +1,4 @@
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use crate::rex_assets::RexAssets; use crate::rex_assets::RexAssets;
use crate::{colors, RunState, State}; use crate::{colors, RunState, State};
@ -16,7 +16,7 @@ pub enum MainMenuResult {
Selected { selected: MainMenuSelection }, Selected { selected: MainMenuSelection },
} }
pub fn main_menu(gs: &mut State, ctx: &mut Rltk) -> MainMenuResult { pub fn main_menu(gs: &mut State, ctx: &mut BTerm) -> MainMenuResult {
let mut draw_batch = DrawBatch::new(); let mut draw_batch = DrawBatch::new();
let save_exists = crate::saveload_system::does_save_exist(); let save_exists = crate::saveload_system::does_save_exist();
let runstate = gs.ecs.fetch::<RunState>(); let runstate = gs.ecs.fetch::<RunState>();

View File

@ -1,4 +1,4 @@
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use crate::colors; use crate::colors;
@ -26,7 +26,7 @@ pub fn menu_option<T: ToString>(
draw_batch: &mut DrawBatch, draw_batch: &mut DrawBatch,
x: i32, x: i32,
y: i32, y: i32,
hotkey: ::rltk::FontCharType, hotkey: FontCharType,
text: T, text: T,
) { ) {
draw_batch.set( draw_batch.set(
@ -86,7 +86,7 @@ pub fn item_result_menu<S: ToString>(
Some(key) => match key { Some(key) => match key {
VirtualKeyCode::Escape => (ItemMenuResult::Cancel, None), VirtualKeyCode::Escape => (ItemMenuResult::Cancel, None),
_ => { _ => {
let selection = ::rltk::letter_to_option(key); let selection = letter_to_option(key);
if selection > -1 && selection < count as i32 { if selection > -1 && selection < count as i32 {
return ( return (
ItemMenuResult::Selected, ItemMenuResult::Selected,

View File

@ -1,4 +1,4 @@
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use super::ItemMenuResult; use super::ItemMenuResult;
@ -7,7 +7,7 @@ use crate::{camera, colors, State};
pub fn ranged_target( pub fn ranged_target(
gs: &mut State, gs: &mut State,
ctx: &mut Rltk, ctx: &mut BTerm,
range: i32, range: i32,
) -> (ItemMenuResult, Option<Point>) { ) -> (ItemMenuResult, Option<Point>) {
let (min_x, max_x, min_y, max_y) = camera::get_screen_bounds(&gs.ecs, ctx); let (min_x, max_x, min_y, max_y) = camera::get_screen_bounds(&gs.ecs, ctx);

View File

@ -1,11 +1,11 @@
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use super::{get_item_display_name, item_result_menu, ItemMenuResult}; use super::{get_item_display_name, item_result_menu, ItemMenuResult};
use crate::components::{CursedItem, Equipped, InBackpack, Item, Name}; use crate::components::{CursedItem, Equipped, InBackpack, Item, Name};
use crate::{MasterDungeonMap, State}; use crate::{MasterDungeonMap, State};
pub fn remove_curse_menu(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option<Entity>) { pub fn remove_curse_menu(gs: &mut State, ctx: &mut BTerm) -> (ItemMenuResult, Option<Entity>) {
let player_entity = gs.ecs.fetch::<Entity>(); let player_entity = gs.ecs.fetch::<Entity>();
let equipped = gs.ecs.read_storage::<Equipped>(); let equipped = gs.ecs.read_storage::<Equipped>();
let backpack = gs.ecs.read_storage::<InBackpack>(); let backpack = gs.ecs.read_storage::<InBackpack>();

View File

@ -1,11 +1,11 @@
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use super::{get_item_display_name, item_result_menu, ItemMenuResult}; use super::{get_item_display_name, item_result_menu, ItemMenuResult};
use crate::components::InBackpack; use crate::components::InBackpack;
use crate::State; use crate::State;
pub fn remove_item_menu(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option<Entity>) { pub fn remove_item_menu(gs: &mut State, ctx: &mut BTerm) -> (ItemMenuResult, Option<Entity>) {
let mut draw_batch = DrawBatch::new(); let mut draw_batch = DrawBatch::new();
let player_entity = gs.ecs.fetch::<Entity>(); let player_entity = gs.ecs.fetch::<Entity>();

View File

@ -1,4 +1,4 @@
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use super::get_item_display_name; use super::get_item_display_name;
@ -54,7 +54,7 @@ impl Tooltip {
} }
} }
pub fn draw_tooltips(ecs: &World, ctx: &mut Rltk) { pub fn draw_tooltips(ecs: &World, ctx: &mut BTerm) {
let mut draw_batch = DrawBatch::new(); let mut draw_batch = DrawBatch::new();
let (min_x, _max_x, min_y, _max_y) = camera::get_screen_bounds(ecs, ctx); let (min_x, _max_x, min_y, _max_y) = camera::get_screen_bounds(ecs, ctx);

View File

@ -1,4 +1,4 @@
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use super::{get_item_color, get_item_display_name, menu_box}; use super::{get_item_color, get_item_display_name, menu_box};
@ -17,7 +17,7 @@ pub enum VendorResult {
fn vendor_sell_menu( fn vendor_sell_menu(
gs: &mut State, gs: &mut State,
ctx: &mut Rltk, ctx: &mut BTerm,
_vendor: Entity, _vendor: Entity,
_mode: VendorMode, _mode: VendorMode,
) -> (VendorResult, Option<Entity>, Option<String>, Option<f32>) { ) -> (VendorResult, Option<Entity>, Option<String>, Option<f32>) {
@ -93,7 +93,7 @@ fn vendor_sell_menu(
VirtualKeyCode::Space => (VendorResult::BuyMode, None, None, None), VirtualKeyCode::Space => (VendorResult::BuyMode, None, None, None),
VirtualKeyCode::Escape => (VendorResult::Cancel, None, None, None), VirtualKeyCode::Escape => (VendorResult::Cancel, None, None, None),
_ => { _ => {
let selection = rltk::letter_to_option(key); let selection = letter_to_option(key);
if selection > -1 && selection < count as i32 { if selection > -1 && selection < count as i32 {
return ( return (
VendorResult::Sell, VendorResult::Sell,
@ -110,7 +110,7 @@ fn vendor_sell_menu(
fn vendor_buy_menu( fn vendor_buy_menu(
gs: &mut State, gs: &mut State,
ctx: &mut Rltk, ctx: &mut BTerm,
vendor: Entity, vendor: Entity,
_mode: VendorMode, _mode: VendorMode,
) -> (VendorResult, Option<Entity>, Option<String>, Option<f32>) { ) -> (VendorResult, Option<Entity>, Option<String>, Option<f32>) {
@ -171,7 +171,7 @@ fn vendor_buy_menu(
VirtualKeyCode::Space => (VendorResult::SellMode, None, None, None), VirtualKeyCode::Space => (VendorResult::SellMode, None, None, None),
VirtualKeyCode::Escape => (VendorResult::Cancel, None, None, None), VirtualKeyCode::Escape => (VendorResult::Cancel, None, None, None),
_ => { _ => {
let selection = ::rltk::letter_to_option(key); let selection = letter_to_option(key);
if selection > -1 && selection < count as i32 { if selection > -1 && selection < count as i32 {
return ( return (
VendorResult::Buy, VendorResult::Buy,
@ -189,7 +189,7 @@ fn vendor_buy_menu(
pub fn show_vendor_menu( pub fn show_vendor_menu(
gs: &mut State, gs: &mut State,
ctx: &mut Rltk, ctx: &mut BTerm,
vendor: Entity, vendor: Entity,
mode: VendorMode, mode: VendorMode,
) -> (VendorResult, Option<Entity>, Option<String>, Option<f32>) { ) -> (VendorResult, Option<Entity>, Option<String>, Option<f32>) {

View File

@ -25,7 +25,7 @@ mod spawner;
mod state; mod state;
mod systems; mod systems;
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use ::specs::saveload::{SimpleMarker, SimpleMarkerAllocator}; use ::specs::saveload::{SimpleMarker, SimpleMarkerAllocator};
use components::*; use components::*;
@ -184,8 +184,8 @@ fn init_state() -> State {
} }
/// The entry point /// The entry point
fn main() -> ::rltk::BError { fn main() -> BError {
let context = RltkBuilder::simple(80, 60) let context = BTermBuilder::simple(80, 60)
.unwrap() .unwrap()
.with_title("Roguelike Tutorial") .with_title("Roguelike Tutorial")
.with_font("vga8x16.png", 8, 16) .with_font("vga8x16.png", 8, 16)

View File

@ -6,7 +6,7 @@ mod tiletype;
use std::collections::HashSet; use std::collections::HashSet;
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::serde::{Deserialize, Serialize}; use ::serde::{Deserialize, Serialize};
pub use dungeon::*; pub use dungeon::*;
pub use themes::*; pub use themes::*;
@ -153,7 +153,7 @@ impl BaseMap for Map {
let p1 = Point::new(idx1 % w, idx1 / w); let p1 = Point::new(idx1 % w, idx1 / w);
let p2 = Point::new(idx2 % w, idx2 / w); let p2 = Point::new(idx2 % w, idx2 / w);
::rltk::DistanceAlg::Pythagoras.distance2d(p1, p2) DistanceAlg::Pythagoras.distance2d(p1, p2)
} }
} }

View File

@ -1,5 +1,5 @@
//! Handle rendering of the viewport //! Handle rendering of the viewport
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use crate::components::{Hidden, Position, Renderable, Target, TileSize}; use crate::components::{Hidden, Position, Renderable, Target, TileSize};
@ -15,7 +15,7 @@ const SHOW_BOUNDARIES: bool = true;
const SHOW_BOUNDARIES: bool = false; const SHOW_BOUNDARIES: bool = false;
/// Get the rectangle representing the current viewport /// Get the rectangle representing the current viewport
pub fn get_screen_bounds(ecs: &World, _ctx: &mut Rltk) -> (i32, i32, i32, i32) { pub fn get_screen_bounds(ecs: &World, _ctx: &mut BTerm) -> (i32, i32, i32, i32) {
let player_pos = ecs.fetch::<Point>(); let player_pos = ecs.fetch::<Point>();
// let (x_chars, y_chars) = ctx.get_char_size(); // let (x_chars, y_chars) = ctx.get_char_size();
let (x_chars, y_chars) = (48, 44); let (x_chars, y_chars) = (48, 44);
@ -32,7 +32,7 @@ pub fn get_screen_bounds(ecs: &World, _ctx: &mut Rltk) -> (i32, i32, i32, i32) {
} }
/// Render the current viewport /// Render the current viewport
pub fn render_camera(ecs: &World, ctx: &mut Rltk) { pub fn render_camera(ecs: &World, ctx: &mut BTerm) {
let mut draw_batch = DrawBatch::new(); let mut draw_batch = DrawBatch::new();
let map = ecs.fetch::<Map>(); let map = ecs.fetch::<Map>();
let (min_x, max_x, min_y, max_y) = get_screen_bounds(ecs, ctx); let (min_x, max_x, min_y, max_y) = get_screen_bounds(ecs, ctx);
@ -53,7 +53,7 @@ pub fn render_camera(ecs: &World, ctx: &mut Rltk) {
draw_batch.set( draw_batch.set(
Point::new(x, y), Point::new(x, y),
ColorPair::new(colors::GRAY, colors::BLACK), ColorPair::new(colors::GRAY, colors::BLACK),
rltk::to_cp437('·'), to_cp437('·'),
); );
} }
} }
@ -121,12 +121,12 @@ pub fn render_camera(ecs: &World, ctx: &mut Rltk) {
draw_batch.set( draw_batch.set(
Point::new(entity_screen_x - 1, entity_screen_y), Point::new(entity_screen_x - 1, entity_screen_y),
ColorPair::new(colors::RED, colors::YELLOW), ColorPair::new(colors::RED, colors::YELLOW),
::rltk::to_cp437('['), to_cp437('['),
); );
draw_batch.set( draw_batch.set(
Point::new(entity_screen_x + 1, entity_screen_y), Point::new(entity_screen_x + 1, entity_screen_y),
ColorPair::new(colors::RED, colors::YELLOW), ColorPair::new(colors::RED, colors::YELLOW),
::rltk::to_cp437(']'), to_cp437(']'),
); );
} }
} }
@ -136,7 +136,7 @@ pub fn render_camera(ecs: &World, ctx: &mut Rltk) {
.expect("Failed to batch draw the camera"); .expect("Failed to batch draw the camera");
} }
pub fn render_debug_map(map: &Map, ctx: &mut Rltk) { pub fn render_debug_map(map: &Map, ctx: &mut BTerm) {
let player_pos = Point::new(map.width / 2, map.height / 2); let player_pos = Point::new(map.width / 2, map.height / 2);
let (x_chars, y_chars) = ctx.get_char_size(); let (x_chars, y_chars) = ctx.get_char_size();
@ -160,7 +160,7 @@ pub fn render_debug_map(map: &Map, ctx: &mut Rltk) {
ctx.set(x, y, fg, bg, glyph); ctx.set(x, y, fg, bg, glyph);
} }
} else if SHOW_BOUNDARIES { } else if SHOW_BOUNDARIES {
ctx.set(x, y, colors::GRAY, colors::BLACK, rltk::to_cp437('·')); ctx.set(x, y, colors::GRAY, colors::BLACK, to_cp437('·'));
} }
} }
} }

View File

@ -1,7 +1,7 @@
//! Functionality that is common to all the currently generated maps. //! Functionality that is common to all the currently generated maps.
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use ::rltk::Point; use ::bracket_lib::prelude::*;
use ::serde::{Deserialize, Serialize}; use ::serde::{Deserialize, Serialize};
use ::specs::prelude::*; use ::specs::prelude::*;

View File

@ -1,5 +1,5 @@
//! Different looks for the same set of [`TileType`]s //! Different looks for the same set of [`TileType`]s
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use super::{Map, TileType}; use super::{Map, TileType};
use crate::colors; use crate::colors;

View File

@ -345,7 +345,7 @@ pub fn random_builder(new_depth: i32, width: i32, height: i32) -> BuilderChain {
pub fn level_builder(new_depth: i32, width: i32, height: i32) -> BuilderChain { pub fn level_builder(new_depth: i32, width: i32, height: i32) -> BuilderChain {
#[cfg(feature = "debug")] #[cfg(feature = "debug")]
::rltk::console::log(format!("Depth: {}", new_depth)); ::bracket_lib::prelude::console::log(format!("Depth: {}", new_depth));
match new_depth { match new_depth {
1 => town_builder(new_depth, width, height), 1 => town_builder(new_depth, width, height),

View File

@ -1,4 +1,4 @@
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use super::{BuilderMap, MetaMapBuilder}; use super::{BuilderMap, MetaMapBuilder};
use crate::{map, TileType}; use crate::{map, TileType};

View File

@ -1,3 +1,5 @@
use ::bracket_lib::prelude::*;
use crate::map_builders::{BuilderMap, MetaMapBuilder}; use crate::map_builders::{BuilderMap, MetaMapBuilder};
use crate::{map, Position}; use crate::{map, Position};
@ -50,12 +52,12 @@ impl AreaStartingPosition {
if map::tile_walkable(*tiletype) { if map::tile_walkable(*tiletype) {
available_floors.push(( available_floors.push((
idx, idx,
rltk::DistanceAlg::PythagorasSquared.distance2d( DistanceAlg::PythagorasSquared.distance2d(
rltk::Point::new( Point::new(
idx as i32 % build_data.map.width, idx as i32 % build_data.map.width,
idx as i32 / build_data.map.width, idx as i32 / build_data.map.width,
), ),
rltk::Point::new(seed_x, seed_y), Point::new(seed_x, seed_y),
), ),
)); ));
} }

View File

@ -1,3 +1,5 @@
use ::bracket_lib::prelude::*;
use crate::map_builders::{BuilderMap, MetaMapBuilder}; use crate::map_builders::{BuilderMap, MetaMapBuilder};
use crate::TileType; use crate::TileType;
@ -22,7 +24,7 @@ impl CullUnreachable {
build_data.map.populate_blocked(); build_data.map.populate_blocked();
let map_starts: Vec<usize> = vec![start_idx]; let map_starts: Vec<usize> = vec![start_idx];
let dijkstra_map = rltk::DijkstraMap::new( let dijkstra_map = DijkstraMap::new(
build_data.map.width as usize, build_data.map.width as usize,
build_data.map.height as usize, build_data.map.height as usize,
&map_starts, &map_starts,

View File

@ -1,7 +1,11 @@
use ::bracket_lib::prelude::*;
use super::{ use super::{
AreaEndingPosition, AreaStartingPosition, BspInteriorBuilder, BuilderChain, CullUnreachable, AreaEndingPosition, AreaStartingPosition, BspInteriorBuilder, BuilderChain, BuilderMap,
VoronoiSpawning, XEnd, XStart, YEnd, YStart, CullUnreachable, InitialMapBuilder, VoronoiSpawning, XEnd, XStart, YEnd, YStart,
}; };
use crate::rng::roll_dice;
use crate::TileType;
pub fn dark_elf_city(new_depth: i32, width: i32, height: i32) -> BuilderChain { pub fn dark_elf_city(new_depth: i32, width: i32, height: i32) -> BuilderChain {
let mut chain = BuilderChain::new(new_depth, width, height, "Dark Elven City"); let mut chain = BuilderChain::new(new_depth, width, height, "Dark Elven City");

View File

@ -1,3 +1,5 @@
use ::bracket_lib::prelude::*;
use crate::map_builders::{BuilderMap, MetaMapBuilder}; use crate::map_builders::{BuilderMap, MetaMapBuilder};
use crate::TileType; use crate::TileType;
@ -22,7 +24,7 @@ impl DistantExit {
build_data.map.populate_blocked(); build_data.map.populate_blocked();
let map_starts: Vec<usize> = vec![start_idx]; let map_starts: Vec<usize> = vec![start_idx];
let dijkstra_map = rltk::DijkstraMap::new( let dijkstra_map = DijkstraMap::new(
build_data.map.width as usize, build_data.map.width as usize,
build_data.map.height as usize, build_data.map.height as usize,
&map_starts, &map_starts,

View File

@ -1,3 +1,5 @@
use ::bracket_lib::prelude::*;
use super::common::{paint, Symmetry}; use super::common::{paint, Symmetry};
use crate::components::Position; use crate::components::Position;
use crate::map_builders::{BuilderMap, InitialMapBuilder, MetaMapBuilder}; use crate::map_builders::{BuilderMap, InitialMapBuilder, MetaMapBuilder};
@ -207,10 +209,10 @@ impl DLABuilder {
let mut prev_y = digger_y; let mut prev_y = digger_y;
let mut digger_idx = build_data.map.xy_idx(digger_x, digger_y); let mut digger_idx = build_data.map.xy_idx(digger_x, digger_y);
let mut path = rltk::line2d( let mut path = line2d(
rltk::LineAlg::Bresenham, LineAlg::Bresenham,
rltk::Point::new(digger_x, digger_y), Point::new(digger_x, digger_y),
rltk::Point::new(starting_position.x, starting_position.y), Point::new(starting_position.x, starting_position.y),
); );
while build_data.map.tiles[digger_idx] == TileType::Wall && !path.is_empty() { while build_data.map.tiles[digger_idx] == TileType::Wall && !path.is_empty() {

View File

@ -1,4 +1,4 @@
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use super::{ use super::{
AreaEndingPosition, AreaStartingPosition, BspCorridors, BspDungeonBuilder, BuilderChain, AreaEndingPosition, AreaStartingPosition, BspCorridors, BspDungeonBuilder, BuilderChain,

View File

@ -1,3 +1,5 @@
use ::bracket_lib::prelude::*;
use super::{ use super::{
AreaStartingPosition, BuilderChain, CellularAutomataBuilder, CullUnreachable, MetaMapBuilder, AreaStartingPosition, BuilderChain, CellularAutomataBuilder, CullUnreachable, MetaMapBuilder,
VoronoiSpawning, XStart, YStart, VoronoiSpawning, XStart, YStart,
@ -40,12 +42,12 @@ impl YellowBrickRoad {
if map::tile_walkable(*tiletype) { if map::tile_walkable(*tiletype) {
available_floors.push(( available_floors.push((
idx, idx,
rltk::DistanceAlg::PythagorasSquared.distance2d( DistanceAlg::PythagorasSquared.distance2d(
rltk::Point::new( Point::new(
idx as i32 % build_data.map.width, idx as i32 % build_data.map.width,
idx as i32 / build_data.map.width, idx as i32 / build_data.map.width,
), ),
rltk::Point::new(seed_x, seed_y), Point::new(seed_x, seed_y),
), ),
)); ));
} }
@ -86,7 +88,7 @@ impl YellowBrickRoad {
let end_idx = build_data.map.xy_idx(end_x, end_y); let end_idx = build_data.map.xy_idx(end_x, end_y);
build_data.map.populate_blocked(); build_data.map.populate_blocked();
let path = rltk::a_star_search(start_idx, end_idx, &build_data.map); let path = a_star_search(start_idx, end_idx, &build_data.map);
for idx in path.steps.iter() { for idx in path.steps.iter() {
let x = *idx as i32 % build_data.map.width; let x = *idx as i32 % build_data.map.width;
@ -119,7 +121,7 @@ impl YellowBrickRoad {
let (stream_x, stream_y) = self.find_exit(build_data, stream_startx, stream_starty); let (stream_x, stream_y) = self.find_exit(build_data, stream_startx, stream_starty);
let stream_idx = build_data.map.xy_idx(stream_x, stream_y) as usize; let stream_idx = build_data.map.xy_idx(stream_x, stream_y) as usize;
let stream = rltk::a_star_search(stairs_idx, stream_idx, &build_data.map); let stream = a_star_search(stairs_idx, stream_idx, &build_data.map);
for tile in stream.steps.iter() { for tile in stream.steps.iter() {
if build_data.map.tiles[*tile as usize] == TileType::Floor { if build_data.map.tiles[*tile as usize] == TileType::Floor {
build_data.map.tiles[*tile as usize] = TileType::ShallowWater; build_data.map.tiles[*tile as usize] = TileType::ShallowWater;

View File

@ -4,6 +4,8 @@ pub mod prefab_sections;
use std::collections::HashSet; use std::collections::HashSet;
use ::bracket_lib::prelude::*;
use crate::map_builders::{BuilderMap, InitialMapBuilder, MetaMapBuilder}; use crate::map_builders::{BuilderMap, InitialMapBuilder, MetaMapBuilder};
use crate::rng::roll_dice; use crate::rng::roll_dice;
use crate::{Position, TileType}; use crate::{Position, TileType};
@ -137,14 +139,17 @@ impl PrefabBuilder {
} }
_ => { _ => {
#[cfg(feature = "debug")] #[cfg(feature = "debug")]
::rltk::console::log(format!("Unknown glyph loading map: {}", (ch as u8) as char)); ::bracket_lib::prelude::console::log(format!(
"Unknown glyph loading map: {}",
(ch as u8) as char
));
} }
} }
} }
#[allow(dead_code)] #[allow(dead_code)]
fn load_rex_map(&mut self, path: &str, build_data: &mut BuilderMap) { fn load_rex_map(&mut self, path: &str, build_data: &mut BuilderMap) {
let xp_file = rltk::rex::XpFile::from_resource(path).unwrap(); let xp_file = XpFile::from_resource(path).unwrap();
for layer in &xp_file.layers { for layer in &xp_file.layers {
for y in 0..layer.height { for y in 0..layer.height {

View File

@ -1,3 +1,5 @@
use ::bracket_lib::prelude::*;
use super::{BuilderMap, MetaMapBuilder}; use super::{BuilderMap, MetaMapBuilder};
use crate::rng::roll_dice; use crate::rng::roll_dice;
use crate::{Rect, TileType}; use crate::{Rect, TileType};
@ -30,13 +32,12 @@ impl RoomDrawer {
fn circle(&mut self, build_data: &mut BuilderMap, room: &Rect) { fn circle(&mut self, build_data: &mut BuilderMap, room: &Rect) {
let radius = i32::min(room.x2 - room.x1, room.y2 - room.y1) as f32 / 2.0; let radius = i32::min(room.x2 - room.x1, room.y2 - room.y1) as f32 / 2.0;
let center = room.center(); let center = room.center();
let center_pt = rltk::Point::new(center.0, center.1); let center_pt = Point::new(center.0, center.1);
for y in room.y1..=room.y2 { for y in room.y1..=room.y2 {
for x in room.x1..=room.x2 { for x in room.x1..=room.x2 {
let idx = build_data.map.xy_idx(x, y); let idx = build_data.map.xy_idx(x, y);
let distance = let distance = DistanceAlg::Pythagoras.distance2d(center_pt, Point::new(x, y));
rltk::DistanceAlg::Pythagoras.distance2d(center_pt, rltk::Point::new(x, y));
if idx > 0 if idx > 0
&& idx < ((build_data.map.width * build_data.map.height) - 1) as usize && idx < ((build_data.map.width * build_data.map.height) - 1) as usize

View File

@ -1,3 +1,5 @@
use ::bracket_lib::prelude::*;
use super::{BuilderMap, MetaMapBuilder}; use super::{BuilderMap, MetaMapBuilder};
use crate::Rect; use crate::Rect;
@ -35,17 +37,14 @@ impl RoomSorter {
RoomSort::TopMost => rooms.sort_by(|a, b| a.y1.cmp(&b.y1)), RoomSort::TopMost => rooms.sort_by(|a, b| a.y1.cmp(&b.y1)),
RoomSort::BottomMost => rooms.sort_by(|a, b| b.y2.cmp(&a.y2)), RoomSort::BottomMost => rooms.sort_by(|a, b| b.y2.cmp(&a.y2)),
RoomSort::Central => { RoomSort::Central => {
let map_center = let map_center = Point::new(build_data.map.width / 2, build_data.map.height / 2);
rltk::Point::new(build_data.map.width / 2, build_data.map.height / 2);
let center_sort = |a: &Rect, b: &Rect| { let center_sort = |a: &Rect, b: &Rect| {
let a_center = a.center(); let a_center = a.center();
let a_center_pt = rltk::Point::new(a_center.0, a_center.1); let a_center_pt = Point::new(a_center.0, a_center.1);
let b_center = b.center(); let b_center = b.center();
let b_center_pt = rltk::Point::new(b_center.0, b_center.1); let b_center_pt = Point::new(b_center.0, b_center.1);
let distance_a = let distance_a = DistanceAlg::Pythagoras.distance2d(a_center_pt, map_center);
rltk::DistanceAlg::Pythagoras.distance2d(a_center_pt, map_center); let distance_b = DistanceAlg::Pythagoras.distance2d(b_center_pt, map_center);
let distance_b =
rltk::DistanceAlg::Pythagoras.distance2d(b_center_pt, map_center);
distance_a.partial_cmp(&distance_b).unwrap() distance_a.partial_cmp(&distance_b).unwrap()
}; };

View File

@ -1,5 +1,7 @@
use std::collections::HashSet; use std::collections::HashSet;
use ::bracket_lib::prelude::*;
use super::{BuilderMap, MetaMapBuilder}; use super::{BuilderMap, MetaMapBuilder};
use crate::{Rect, TileType}; use crate::{Rect, TileType};
@ -31,14 +33,14 @@ impl StraightLineCorridors {
for (i, room) in rooms.iter().enumerate() { for (i, room) in rooms.iter().enumerate() {
let mut room_distance: Vec<(usize, f32)> = Vec::new(); let mut room_distance: Vec<(usize, f32)> = Vec::new();
let room_center = room.center(); let room_center = room.center();
let room_center_pt = rltk::Point::new(room_center.0, room_center.1); let room_center_pt = Point::new(room_center.0, room_center.1);
for (j, other_room) in rooms.iter().enumerate() { for (j, other_room) in rooms.iter().enumerate() {
if i != j && !connected.contains(&j) { if i != j && !connected.contains(&j) {
let other_center = other_room.center(); let other_center = other_room.center();
let other_center_pt = rltk::Point::new(other_center.0, other_center.1); let other_center_pt = Point::new(other_center.0, other_center.1);
let distance = let distance =
rltk::DistanceAlg::Pythagoras.distance2d(room_center_pt, other_center_pt); DistanceAlg::Pythagoras.distance2d(room_center_pt, other_center_pt);
room_distance.push((j, distance)); room_distance.push((j, distance));
} }
@ -47,10 +49,10 @@ impl StraightLineCorridors {
if !room_distance.is_empty() { if !room_distance.is_empty() {
room_distance.sort_by(|a, b| a.1.partial_cmp(&b.1).unwrap()); room_distance.sort_by(|a, b| a.1.partial_cmp(&b.1).unwrap());
let dest_center = rooms[room_distance[0].0].center(); let dest_center = rooms[room_distance[0].0].center();
let line = rltk::line2d( let line = line2d(
rltk::LineAlg::Bresenham, LineAlg::Bresenham,
room_center_pt, room_center_pt,
rltk::Point::new(dest_center.0, dest_center.1), Point::new(dest_center.0, dest_center.1),
); );
let mut corridor = Vec::new(); let mut corridor = Vec::new();

View File

@ -1,5 +1,7 @@
use std::collections::HashSet; use std::collections::HashSet;
use ::bracket_lib::prelude::*;
use super::common::draw_corridor; use super::common::draw_corridor;
use super::{BuilderMap, MetaMapBuilder}; use super::{BuilderMap, MetaMapBuilder};
use crate::Rect; use crate::Rect;
@ -32,14 +34,14 @@ impl NearestCorridors {
for (i, room) in rooms.iter().enumerate() { for (i, room) in rooms.iter().enumerate() {
let mut room_distance: Vec<(usize, f32)> = Vec::new(); let mut room_distance: Vec<(usize, f32)> = Vec::new();
let room_center = room.center(); let room_center = room.center();
let room_center_pt = rltk::Point::new(room_center.0, room_center.1); let room_center_pt = Point::new(room_center.0, room_center.1);
for (j, other_room) in rooms.iter().enumerate() { for (j, other_room) in rooms.iter().enumerate() {
if i != j && !connected.contains(&j) { if i != j && !connected.contains(&j) {
let other_center = other_room.center(); let other_center = other_room.center();
let other_center_pt = rltk::Point::new(other_center.0, other_center.1); let other_center_pt = Point::new(other_center.0, other_center.1);
let distance = let distance =
rltk::DistanceAlg::Pythagoras.distance2d(room_center_pt, other_center_pt); DistanceAlg::Pythagoras.distance2d(room_center_pt, other_center_pt);
room_distance.push((j, distance)); room_distance.push((j, distance));
} }

View File

@ -1,6 +1,6 @@
use std::collections::HashSet; use std::collections::HashSet;
use ::rltk::Point; use ::bracket_lib::prelude::*;
use super::{BuilderChain, BuilderMap, InitialMapBuilder}; use super::{BuilderChain, BuilderMap, InitialMapBuilder};
use crate::rng::roll_dice; use crate::rng::roll_dice;
@ -272,7 +272,7 @@ impl TownBuilder {
for r in roads.iter() { for r in roads.iter() {
nearest_roads.push(( nearest_roads.push((
*r, *r,
::rltk::DistanceAlg::PythagorasSquared.distance2d( DistanceAlg::PythagorasSquared.distance2d(
door_pt, door_pt,
Point::new( Point::new(
*r as i32 % build_data.map.width, *r as i32 % build_data.map.width,
@ -284,7 +284,7 @@ impl TownBuilder {
nearest_roads.sort_by(|a, b| a.1.partial_cmp(&b.1).unwrap()); nearest_roads.sort_by(|a, b| a.1.partial_cmp(&b.1).unwrap());
let destination = nearest_roads[0].0; let destination = nearest_roads[0].0;
let path = ::rltk::a_star_search(*door_idx, destination, &build_data.map); let path = a_star_search(*door_idx, destination, &build_data.map);
if path.success { if path.success {
for step in path.steps.iter() { for step in path.steps.iter() {
let idx = *step as usize; let idx = *step as usize;

View File

@ -1,3 +1,5 @@
use ::bracket_lib::prelude::*;
use crate::map_builders::{BuilderMap, InitialMapBuilder}; use crate::map_builders::{BuilderMap, InitialMapBuilder};
use crate::rng::roll_dice; use crate::rng::roll_dice;
use crate::TileType; use crate::TileType;
@ -45,13 +47,13 @@ impl VoronoiCellBuilder {
#[allow(clippy::map_entry)] #[allow(clippy::map_entry)]
fn build(&mut self, build_data: &mut BuilderMap) { fn build(&mut self, build_data: &mut BuilderMap) {
// Make a Voronoi diagram. We'll do this the hard way to learn about the technique! // Make a Voronoi diagram. We'll do this the hard way to learn about the technique!
let mut voronoi_seeds: Vec<(usize, rltk::Point)> = Vec::new(); let mut voronoi_seeds: Vec<(usize, Point)> = Vec::new();
while voronoi_seeds.len() < self.n_seeds { while voronoi_seeds.len() < self.n_seeds {
let vx = roll_dice(1, build_data.map.width - 1); let vx = roll_dice(1, build_data.map.width - 1);
let vy = roll_dice(1, build_data.map.height - 1); let vy = roll_dice(1, build_data.map.height - 1);
let vidx = build_data.map.xy_idx(vx, vy); let vidx = build_data.map.xy_idx(vx, vy);
let candidate = (vidx, rltk::Point::new(vx, vy)); let candidate = (vidx, Point::new(vx, vy));
if !voronoi_seeds.contains(&candidate) { if !voronoi_seeds.contains(&candidate) {
voronoi_seeds.push(candidate); voronoi_seeds.push(candidate);
} }
@ -67,15 +69,16 @@ impl VoronoiCellBuilder {
for (seed, pos) in voronoi_seeds.iter().enumerate() { for (seed, pos) in voronoi_seeds.iter().enumerate() {
let distance = match self.distance_algorithm { let distance = match self.distance_algorithm {
DistanceAlgorithm::Pythagoras => rltk::DistanceAlg::PythagorasSquared DistanceAlgorithm::Pythagoras => {
.distance2d(rltk::Point::new(x, y), pos.1), DistanceAlg::PythagorasSquared.distance2d(Point::new(x, y), pos.1)
}
DistanceAlgorithm::Manhattan => { DistanceAlgorithm::Manhattan => {
rltk::DistanceAlg::Manhattan.distance2d(rltk::Point::new(x, y), pos.1) DistanceAlg::Manhattan.distance2d(Point::new(x, y), pos.1)
} }
DistanceAlgorithm::Chebyshev => { DistanceAlgorithm::Chebyshev => {
rltk::DistanceAlg::Chebyshev.distance2d(rltk::Point::new(x, y), pos.1) DistanceAlg::Chebyshev.distance2d(Point::new(x, y), pos.1)
} }
}; };
voronoi_distance[seed] = (seed, distance); voronoi_distance[seed] = (seed, distance);

View File

@ -1,6 +1,6 @@
use std::collections::HashMap; use std::collections::HashMap;
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use crate::map_builders::{BuilderMap, MetaMapBuilder}; use crate::map_builders::{BuilderMap, MetaMapBuilder};
use crate::rng::roll_dice; use crate::rng::roll_dice;

View File

@ -67,7 +67,7 @@ pub fn build_patterns(
// Dedupe // Dedupe
if dedupe { if dedupe {
#[cfg(feature = "debug")] #[cfg(feature = "debug")]
::rltk::console::log(format!( ::bracket_lib::prelude::console::log(format!(
"Pre de-duplication, there are {} patterns", "Pre de-duplication, there are {} patterns",
patterns.len() patterns.len()
)); ));
@ -77,7 +77,7 @@ pub fn build_patterns(
patterns.extend(set.into_iter()); patterns.extend(set.into_iter());
#[cfg(feature = "debug")] #[cfg(feature = "debug")]
::rltk::console::log(format!("There are {} patterns", patterns.len())); ::bracket_lib::prelude::console::log(format!("There are {} patterns", patterns.len()));
} }
patterns patterns

View File

@ -195,7 +195,7 @@ impl Solver {
if possible_options.is_empty() { if possible_options.is_empty() {
#[cfg(feature = "debug")] #[cfg(feature = "debug")]
::rltk::console::log("Oh no! It's not possible!"); ::bracket_lib::prelude::console::log("Oh no! It's not possible!");
self.possible = false; self.possible = false;

View File

@ -1,7 +1,7 @@
//! Player-related functionality //! Player-related functionality
use std::cmp::{max, min}; use std::cmp::{max, min};
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use crate::components::{ use crate::components::{
@ -217,7 +217,7 @@ pub fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World) -> RunState
blocks_visibility.remove(potential_target); blocks_visibility.remove(potential_target);
blocks_movement.remove(potential_target); blocks_movement.remove(potential_target);
let glyph = renderables.get_mut(potential_target).unwrap(); let glyph = renderables.get_mut(potential_target).unwrap();
glyph.glyph = rltk::to_cp437('/'); glyph.glyph = to_cp437('/');
viewshed.dirty = true; viewshed.dirty = true;
return Some(RunState::Ticking); return Some(RunState::Ticking);
@ -454,7 +454,7 @@ fn use_spell_hotkey(gs: &mut State, key: i32) -> RunState {
RunState::Ticking RunState::Ticking
} }
pub fn player_input(gs: &mut State, ctx: &mut Rltk) -> RunState { pub fn player_input(gs: &mut State, ctx: &mut BTerm) -> RunState {
// Hotkeys // Hotkeys
if (ctx.shift || ctx.control) && ctx.key.is_some() { if (ctx.shift || ctx.control) && ctx.key.is_some() {
let key: Option<i32> = match ctx.key.unwrap() { let key: Option<i32> = match ctx.key.unwrap() {

View File

@ -11,7 +11,7 @@ mod weapon_traits;
use std::sync::Mutex; use std::sync::Mutex;
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::serde::Deserialize; use ::serde::Deserialize;
pub use faction_structs::*; pub use faction_structs::*;
use item_structs::*; use item_structs::*;
@ -44,7 +44,7 @@ lazy_static! {
pub fn load_raws() { pub fn load_raws() {
link_resource!(RAW_FILE, "../raws/spawns.json"); link_resource!(RAW_FILE, "../raws/spawns.json");
let raw_data = ::rltk::embedding::EMBED let raw_data = EMBED
.lock() .lock()
.get_resource("../raws/spawns.json".to_string()) .get_resource("../raws/spawns.json".to_string())
.unwrap(); .unwrap();

View File

@ -1,7 +1,7 @@
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use ::bracket_lib::prelude::*;
use ::regex::Regex; use ::regex::Regex;
use ::rltk::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use ::specs::saveload::{MarkedBuilder, SimpleMarker}; use ::specs::saveload::{MarkedBuilder, SimpleMarker};
@ -379,7 +379,7 @@ fn get_renderable_component(
renderable: &super::item_structs::Renderable, renderable: &super::item_structs::Renderable,
) -> crate::components::Renderable { ) -> crate::components::Renderable {
crate::components::Renderable { crate::components::Renderable {
glyph: rltk::to_cp437(renderable.glyph.chars().next().unwrap()), glyph: to_cp437(renderable.glyph.chars().next().unwrap()),
fg: RGB::from_hex(&renderable.fg).expect("Invalid color"), fg: RGB::from_hex(&renderable.fg).expect("Invalid color"),
bg: RGB::from_hex(&renderable.bg).expect("Invalid color"), bg: RGB::from_hex(&renderable.bg).expect("Invalid color"),
render_order: renderable.order, render_order: renderable.order,
@ -407,7 +407,7 @@ pub fn string_to_slot(slot: &str) -> EquipmentSlot {
fn parse_particle_line(n: &str) -> SpawnParticleLine { fn parse_particle_line(n: &str) -> SpawnParticleLine {
let tokens: Vec<_> = n.split(';').collect(); let tokens: Vec<_> = n.split(';').collect();
SpawnParticleLine { SpawnParticleLine {
glyph: rltk::to_cp437(tokens[0].chars().next().unwrap()), glyph: to_cp437(tokens[0].chars().next().unwrap()),
color: RGB::from_hex(tokens[1]).expect("Invalid hex rgb color"), color: RGB::from_hex(tokens[1]).expect("Invalid hex rgb color"),
lifetime_ms: tokens[2].parse::<f32>().unwrap(), lifetime_ms: tokens[2].parse::<f32>().unwrap(),
} }
@ -416,7 +416,7 @@ fn parse_particle_line(n: &str) -> SpawnParticleLine {
fn parse_particle(n: &str) -> SpawnParticleBurst { fn parse_particle(n: &str) -> SpawnParticleBurst {
let tokens: Vec<_> = n.split(';').collect(); let tokens: Vec<_> = n.split(';').collect();
SpawnParticleBurst { SpawnParticleBurst {
glyph: rltk::to_cp437(tokens[0].chars().next().unwrap()), glyph: to_cp437(tokens[0].chars().next().unwrap()),
color: RGB::from_hex(tokens[1]).expect("Invalid hex rgb color"), color: RGB::from_hex(tokens[1]).expect("Invalid hex rgb color"),
lifetime_ms: tokens[2].parse::<f32>().unwrap(), lifetime_ms: tokens[2].parse::<f32>().unwrap(),
} }

View File

@ -1,5 +1,4 @@
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::rltk::rex::XpFile;
embedded_resource!(SMALL_DUNGEON, "../resources/SmallDungeon_80x50.xp"); embedded_resource!(SMALL_DUNGEON, "../resources/SmallDungeon_80x50.xp");
embedded_resource!(WFC_DEMO_IMAGE1, "../resources/wfc-demo1.xp"); embedded_resource!(WFC_DEMO_IMAGE1, "../resources/wfc-demo1.xp");

View File

@ -1,6 +1,6 @@
use std::sync::Mutex; use std::sync::Mutex;
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
lazy_static! { lazy_static! {
static ref RNG: Mutex<RandomNumberGenerator> = Mutex::new(RandomNumberGenerator::new()); static ref RNG: Mutex<RandomNumberGenerator> = Mutex::new(RandomNumberGenerator::new());

View File

@ -2,7 +2,7 @@
use std::fs::{self, File}; use std::fs::{self, File};
use std::path::Path; use std::path::Path;
use ::rltk::Point; use ::bracket_lib::prelude::*;
use ::specs::error::NoError; use ::specs::error::NoError;
use ::specs::prelude::*; use ::specs::prelude::*;
use ::specs::saveload::{ use ::specs::saveload::{

View File

@ -1,7 +1,7 @@
//! Spawns things //! Spawns things
use std::collections::HashMap; use std::collections::HashMap;
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use ::specs::saveload::{MarkedBuilder, SimpleMarker}; use ::specs::saveload::{MarkedBuilder, SimpleMarker};

View File

@ -1,5 +1,5 @@
//! Game state //! Game state
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use crate::components::*; use crate::components::*;
@ -147,7 +147,7 @@ impl State {
impl GameState for State { impl GameState for State {
/// The big, nasty, state machine handler /// The big, nasty, state machine handler
fn tick(&mut self, ctx: &mut Rltk) { fn tick(&mut self, ctx: &mut BTerm) {
let mut newrunstate; let mut newrunstate;
{ {
let runstate = self.ecs.fetch::<RunState>(); let runstate = self.ecs.fetch::<RunState>();
@ -556,7 +556,7 @@ impl GameState for State {
} }
damage_system::delete_the_dead(&mut self.ecs); damage_system::delete_the_dead(&mut self.ecs);
::rltk::render_draw_buffer(ctx).expect("Failed to render the Rltk buffer"); render_draw_buffer(ctx).expect("Failed to render the draw buffer");
if SHOW_FPS { if SHOW_FPS {
ctx.print(1, 59, &format!("FPS: {}", ctx.fps)); ctx.print(1, 59, &format!("FPS: {}", ctx.fps));
} }

View File

@ -1,4 +1,4 @@
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use crate::components::{ApplyMove, MyTurn, Position, WantsToApproach}; use crate::components::{ApplyMove, MyTurn, Position, WantsToApproach};

View File

@ -1,6 +1,6 @@
use std::collections::HashMap; use std::collections::HashMap;
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use crate::components::{ApplyMove, Chasing, MyTurn, Position, TileSize}; use crate::components::{ApplyMove, Chasing, MyTurn, Position, TileSize};

View File

@ -1,3 +1,4 @@
use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use crate::components::{ApplyMove, MoveMode, Movement, MyTurn, Position}; use crate::components::{ApplyMove, MoveMode, Movement, MyTurn, Position};
@ -70,7 +71,7 @@ impl<'a> System<'a> for DefaultMoveAI {
let target_y = roll_dice(1, map.height - 2); let target_y = roll_dice(1, map.height - 2);
let idx = map.xy_idx(target_x, target_y); let idx = map.xy_idx(target_x, target_y);
if tile_walkable(map.tiles[idx]) { if tile_walkable(map.tiles[idx]) {
let path = ::rltk::a_star_search( let path = a_star_search(
map.xy_idx(pos.x, pos.y) as i32, map.xy_idx(pos.x, pos.y) as i32,
map.xy_idx(target_x, target_y) as i32, map.xy_idx(target_x, target_y) as i32,
&*map, &*map,

View File

@ -1,4 +1,4 @@
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use crate::components::{ApplyMove, MyTurn, Position, WantsToFlee}; use crate::components::{ApplyMove, MyTurn, Position, WantsToFlee};

View File

@ -1,4 +1,4 @@
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use crate::components::{ use crate::components::{

View File

@ -1,4 +1,4 @@
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use crate::components::{MyTurn, Name, Quips, Viewshed}; use crate::components::{MyTurn, Name, Quips, Viewshed};

View File

@ -1,5 +1,6 @@
use std::collections::HashSet; use std::collections::HashSet;
use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use crate::components::{Confusion, MyTurn, StatusEffect}; use crate::components::{Confusion, MyTurn, StatusEffect};
@ -40,7 +41,7 @@ impl<'a> System<'a> for TurnStatusSystem {
add_effect( add_effect(
None, None,
EffectType::Particle { EffectType::Particle {
glyph: ::rltk::to_cp437('?'), glyph: to_cp437('?'),
fg: colors::CYAN, fg: colors::CYAN,
bg: colors::BLACK, bg: colors::BLACK,
lifespan: 200.0, lifespan: 200.0,

View File

@ -1,4 +1,4 @@
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use crate::components::{ use crate::components::{

View File

@ -1,4 +1,4 @@
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use crate::components::{LightSource, Position, Viewshed}; use crate::components::{LightSource, Position, Viewshed};

View File

@ -1,3 +1,4 @@
use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use crate::components::{ use crate::components::{
@ -198,7 +199,7 @@ impl<'a> System<'a> for MeleeCombatSystem {
add_effect( add_effect(
None, None,
EffectType::Particle { EffectType::Particle {
glyph: rltk::to_cp437('‼'), glyph: to_cp437('‼'),
fg: colors::BLUE, fg: colors::BLUE,
bg: colors::BLACK, bg: colors::BLACK,
lifespan: 200.0, lifespan: 200.0,
@ -217,7 +218,7 @@ impl<'a> System<'a> for MeleeCombatSystem {
add_effect( add_effect(
None, None,
EffectType::Particle { EffectType::Particle {
glyph: rltk::to_cp437('‼'), glyph: to_cp437('‼'),
fg: colors::CYAN, fg: colors::CYAN,
bg: colors::BLACK, bg: colors::BLACK,
lifespan: 200.0, lifespan: 200.0,

View File

@ -1,9 +1,9 @@
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use crate::components::{ParticleLifetime, Position, Renderable}; use crate::components::{ParticleLifetime, Position, Renderable};
pub fn update_particles(ecs: &mut World, ctx: &Rltk) { pub fn update_particles(ecs: &mut World, ctx: &BTerm) {
let mut dead_particles: Vec<Entity> = Vec::new(); let mut dead_particles: Vec<Entity> = Vec::new();
{ {
// Age out particles // Age out particles
@ -42,7 +42,7 @@ struct ParticleRequest {
y: i32, y: i32,
fg: RGB, fg: RGB,
bg: RGB, bg: RGB,
glyph: rltk::FontCharType, glyph: FontCharType,
lifetime: f32, lifetime: f32,
} }
@ -62,7 +62,7 @@ impl ParticleBuilder {
y: i32, y: i32,
fg: RGB, fg: RGB,
bg: RGB, bg: RGB,
glyph: rltk::FontCharType, glyph: FontCharType,
lifetime: f32, lifetime: f32,
) { ) {
self.requests.push(ParticleRequest { self.requests.push(ParticleRequest {

View File

@ -1,4 +1,4 @@
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use crate::components::{ use crate::components::{
@ -75,11 +75,7 @@ impl<'a> System<'a> for RangedCombatSystem {
bg: colors::BLACK, bg: colors::BLACK,
lifespan: 300.0, lifespan: 300.0,
speed: 50.0, speed: 50.0,
path: ::rltk::line2d( path: line2d(LineAlg::Bresenham, Point::from(*apos), Point::from(*dpos)),
LineAlg::Bresenham,
Point::from(*apos),
Point::from(*dpos),
),
}, },
Targets::Tile { Targets::Tile {
tile_idx: map.xy_idx(apos.x, apos.y) as i32, tile_idx: map.xy_idx(apos.x, apos.y) as i32,
@ -221,7 +217,7 @@ impl<'a> System<'a> for RangedCombatSystem {
add_effect( add_effect(
None, None,
EffectType::Particle { EffectType::Particle {
glyph: rltk::to_cp437('‼'), glyph: to_cp437('‼'),
fg: colors::BLUE, fg: colors::BLUE,
bg: colors::BLACK, bg: colors::BLACK,
lifespan: 200.0, lifespan: 200.0,
@ -240,7 +236,7 @@ impl<'a> System<'a> for RangedCombatSystem {
add_effect( add_effect(
None, None,
EffectType::Particle { EffectType::Particle {
glyph: rltk::to_cp437('‼'), glyph: to_cp437('‼'),
fg: colors::CYAN, fg: colors::CYAN,
bg: colors::BLACK, bg: colors::BLACK,
lifespan: 200.0, lifespan: 200.0,

View File

@ -1,3 +1,4 @@
use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use crate::components::{AreaOfEffect, EntityMoved, EntryTrigger, Name, Position}; use crate::components::{AreaOfEffect, EntityMoved, EntryTrigger, Name, Position};
@ -45,11 +46,7 @@ impl<'a> System<'a> for TriggerSystem {
EffectType::TriggerFire { trigger: entity_id }, EffectType::TriggerFire { trigger: entity_id },
if let Some(aoe) = area_of_effect.get(entity_id) { if let Some(aoe) = area_of_effect.get(entity_id) {
Targets::Tiles { Targets::Tiles {
tiles: aoe_tiles( tiles: aoe_tiles(&*map, Point::from(*pos), aoe.radius),
&*map,
::rltk::Point::from(*pos),
aoe.radius,
),
} }
} else { } else {
Targets::Tile { Targets::Tile {

View File

@ -1,4 +1,4 @@
use ::rltk::prelude::*; use ::bracket_lib::prelude::*;
use ::specs::prelude::*; use ::specs::prelude::*;
use crate::components::{BlocksVisibility, Hidden, Name}; use crate::components::{BlocksVisibility, Hidden, Name};