From 3cad614e78a48f2021e28db9324d2518951f0fe9 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 14 Jan 2022 12:19:46 -0500 Subject: [PATCH] Make color usage consistent through the use of constants --- src/camera.rs | 20 +- src/colors.rs | 94 +++++++ src/damage_system.rs | 7 +- src/gui.rs | 497 +++++++++++-------------------------- src/inventory_system.rs | 19 +- src/lighting_system.rs | 6 +- src/main.rs | 1 + src/map.rs | 4 +- src/map/themes.rs | 85 +++---- src/melee_combat_system.rs | 16 +- src/raws/prop_structs.rs | 3 +- src/raws/rawmaster.rs | 6 +- src/spawner.rs | 10 +- src/trigger_system.rs | 6 +- 14 files changed, 325 insertions(+), 449 deletions(-) create mode 100644 src/colors.rs diff --git a/src/camera.rs b/src/camera.rs index b82ab72..2e6b539 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -1,8 +1,8 @@ -use ::rltk::{Point, Rltk, RGB}; +use ::rltk::{Point, Rltk}; use ::specs::prelude::*; use crate::map::tile_glyph; -use crate::{Hidden, Map, Position, Renderable}; +use crate::{colors, Hidden, Map, Position, Renderable}; const SHOW_BOUNDARIES: bool = false; @@ -42,13 +42,7 @@ pub fn render_camera(ecs: &World, ctx: &mut Rltk) { ctx.set(x, y, fg, bg, glyph); } } else if SHOW_BOUNDARIES { - ctx.set( - x, - y, - RGB::named(rltk::GRAY), - RGB::named(rltk::BLACK), - rltk::to_cp437('·'), - ); + ctx.set(x, y, colors::GRAY, colors::BLACK, rltk::to_cp437('·')); } x += 1; } @@ -114,13 +108,7 @@ pub fn render_debug_map(map: &Map, ctx: &mut Rltk) { ctx.set(x, y, fg, bg, glyph); } } else if SHOW_BOUNDARIES { - ctx.set( - x, - y, - RGB::named(rltk::GRAY), - RGB::named(rltk::BLACK), - rltk::to_cp437('·'), - ); + ctx.set(x, y, colors::GRAY, colors::BLACK, rltk::to_cp437('·')); } x += 1; } diff --git a/src/colors.rs b/src/colors.rs new file mode 100644 index 0000000..9897608 --- /dev/null +++ b/src/colors.rs @@ -0,0 +1,94 @@ +//! Color constants to replace more verbose methods of defining colors in the game. +//! These constants replace the `::rltk::RGB` constructor functions +use ::rltk::RGB; + +const fn new(r: f32, g: f32, b: f32) -> RGB { + RGB { r, g, b } +} + +//Grays + +/// HEX: #000 +/// RGB: (0, 0, 0) +pub const BLACK: RGB = new(0., 0., 0.); + +/// RGB: (102, 102, 102) +pub const DARK_GRAY: RGB = new(0.4, 0.4, 0.4); + +/// HEX: #999 +/// RGB: (153, 153, 153) +pub const BOX_GRAY: RGB = new(0.6, 0.6, 0.6); + +/// RGB: (190, 190, 190) +pub const GRAY: RGB = new(0.745, 0.745, 0.745); + +/// HEX: #CCC +/// RGB: (204, 204, 204) +pub const ATTR_GRAY: RGB = new(0.8, 0.8, 0.8); + +/// Hex: #DDD +/// RGB: (221, 221, 221) +pub const LIGHT_GRAY: RGB = new(0.86667, 0.86667, 0.86667); + +/// Hex: #FFF +/// RGB: (255, 255, 255) +pub const WHITE: RGB = new(1., 1., 1.); + +// Non-grays + +/// RGB: (191, 0, 0) +pub const BLOOD: RGB = new(0.75, 0., 0.); + +/// HEX: #00F +/// RGB: (0, 0, 255) +pub const BLUE: RGB = new(0., 0., 1.); + +/// RGB: (210, 105, 30) +pub const CHOCOLATE: RGB = new(0.83253, 0.41176, 0.11765); + +/// HEX: #0FF +/// RGB: (0, 255, 255) +pub const CYAN: RGB = new(0., 1., 1.); + +/// RGB: (0, 128, 128) +pub const DEFAULT_FLOOR: RGB = new(0., 0.5, 0.5); + +/// RGB: (51, 51, 255) +pub const DEEP_WATER: RGB = new(0.2, 0.2, 1.0); + +/// RGB: (0, 153, 0) +pub const FOREST_GREEN: RGB = new(0., 0.6, 0.); + +/// RGB: (255, 215, 0) +pub const GOLD: RGB = new(1., 0.84314, 0.); + +/// HEX: #0F0 +/// RGB: (0, 255, 0) +pub const GREEN: RGB = new(0., 1., 0.); + +/// Hex: #F0F +/// RGB: (255, 0, 255) +pub const MAGENTA: RGB = new(1., 0., 1.); + +/// RGB: (128, 128, 128) +pub const MID_GRAY: RGB = new(0.5, 0.5, 0.5); + +/// RGB: (0, 0, 128) +pub const NAVY_BLUE: RGB = new(0., 0., 0.50196); + +/// RGB: (255, 165, 0) +pub const ORANGE: RGB = new(1., 0.647, 0.); + +/// Hex: #F00 +/// RGB: (255, 0, 0) +pub const RED: RGB = new(1., 0., 0.); + +/// RGB: (255, 255, 128) +pub const TORCH_LIGHT: RGB = new(1., 1., 0.5); + +/// RGB: (245, 222, 179) +pub const WHEAT: RGB = new(0.96078, 0.87059, 0.70196); + +/// Hex: #FF0 +/// RGB: (255, 255, 0) +pub const YELLOW: RGB = new(1., 1., 0.); diff --git a/src/damage_system.rs b/src/damage_system.rs index 33821ec..6a7c029 100644 --- a/src/damage_system.rs +++ b/src/damage_system.rs @@ -1,6 +1,5 @@ use ::rltk::{Point, RandomNumberGenerator}; use ::specs::prelude::*; -use rltk::RGB; use crate::components::{ Attributes, Equipped, InBackpack, LootTable, Name, Player, Pools, Position, SufferDamage, @@ -9,7 +8,7 @@ use crate::game_log::GameLog; use crate::gamesystem::{mana_at_level, player_hp_at_level}; use crate::particle_system::ParticleBuilder; use crate::raws::{self, SpawnType, RAWS}; -use crate::{spatial, Map, RunState}; +use crate::{colors, spatial, Map, RunState}; pub struct DamageSystem {} @@ -93,8 +92,8 @@ impl<'a> System<'a> for DamageSystem { particles.request( player_pos.x, player_pos.y - 1, - RGB::named(rltk::GOLD), - RGB::named(rltk::BLACK), + colors::GOLD, + colors::BLACK, rltk::to_cp437('░'), 400.0, ); diff --git a/src/gui.rs b/src/gui.rs index 7b4dee1..82785ce 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -9,7 +9,7 @@ use crate::components::{ }; use crate::game_log::GameLog; use crate::rex_assets::RexAssets; -use crate::{camera, Equipped, Hidden, Map, RunState, State, VendorMode}; +use crate::{camera, colors, Equipped, Hidden, Map, RunState, State, VendorMode}; pub fn draw_hollow_box( console: &mut Rltk, @@ -39,35 +39,32 @@ pub fn draw_hollow_box( pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { use rltk::to_cp437; - let box_gray: RGB = RGB::from_hex("#999999").expect("Ooops"); - let black = RGB::named(rltk::BLACK); - let white = RGB::named(rltk::WHITE); - draw_hollow_box(ctx, 0, 0, 79, 59, box_gray, black); // Overall box - draw_hollow_box(ctx, 0, 0, 49, 45, box_gray, black); // Map box - draw_hollow_box(ctx, 0, 45, 79, 14, box_gray, black); // Log box - draw_hollow_box(ctx, 49, 0, 30, 8, box_gray, black); // Top-right panel + draw_hollow_box(ctx, 0, 0, 79, 59, colors::BOX_GRAY, colors::BLACK); // Overall box + draw_hollow_box(ctx, 0, 0, 49, 45, colors::BOX_GRAY, colors::BLACK); // Map box + draw_hollow_box(ctx, 0, 45, 79, 14, colors::BOX_GRAY, colors::BLACK); // Log box + draw_hollow_box(ctx, 49, 0, 30, 8, colors::BOX_GRAY, colors::BLACK); // Top-right panel - ctx.set(0, 45, box_gray, black, to_cp437('├')); - ctx.set(49, 8, box_gray, black, to_cp437('├')); - ctx.set(49, 0, box_gray, black, to_cp437('┬')); - ctx.set(49, 45, box_gray, black, to_cp437('┴')); - ctx.set(79, 8, box_gray, black, to_cp437('┤')); - ctx.set(79, 45, box_gray, black, to_cp437('┤')); + ctx.set(0, 45, colors::BOX_GRAY, colors::BLACK, to_cp437('├')); + ctx.set(49, 8, colors::BOX_GRAY, colors::BLACK, to_cp437('├')); + ctx.set(49, 0, colors::BOX_GRAY, colors::BLACK, to_cp437('┬')); + ctx.set(49, 45, colors::BOX_GRAY, colors::BLACK, to_cp437('┴')); + ctx.set(79, 8, colors::BOX_GRAY, colors::BLACK, to_cp437('┤')); + ctx.set(79, 45, colors::BOX_GRAY, colors::BLACK, to_cp437('┤')); // Draw the town name let map = ecs.fetch::(); let name_length = map.name.len() + 2; let x_pos = (22 - (name_length / 2)) as i32; - ctx.set(x_pos, 0, box_gray, black, to_cp437('┤')); + ctx.set(x_pos, 0, colors::BOX_GRAY, colors::BLACK, to_cp437('┤')); ctx.set( x_pos + name_length as i32, 0, - box_gray, - black, + colors::BOX_GRAY, + colors::BLACK, to_cp437('├'), ); - ctx.print_color(x_pos + 1, 0, white, black, &map.name); + ctx.print_color(x_pos + 1, 0, colors::WHITE, colors::BLACK, &map.name); std::mem::drop(map); // Draw stats @@ -83,17 +80,17 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { player_pools.mana.current, player_pools.mana.max ); let xp = format!("Level: {}", player_pools.level); - ctx.print_color(50, 1, white, black, &health); - ctx.print_color(50, 2, white, black, &mana); - ctx.print_color(50, 3, white, black, &xp); + ctx.print_color(50, 1, colors::WHITE, colors::BLACK, &health); + ctx.print_color(50, 2, colors::WHITE, colors::BLACK, &mana); + ctx.print_color(50, 3, colors::WHITE, colors::BLACK, &xp); ctx.draw_bar_horizontal( 64, 1, 14, player_pools.hit_points.current, player_pools.hit_points.max, - RGB::named(rltk::RED), - RGB::named(rltk::BLACK), + colors::RED, + colors::BLACK, ); ctx.draw_bar_horizontal( 64, @@ -101,8 +98,8 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { 14, player_pools.mana.current, player_pools.mana.max, - RGB::named(rltk::BLUE), - RGB::named(rltk::BLACK), + colors::BLUE, + colors::BLACK, ); let xp_level_start = (player_pools.level - 1) * 1000; ctx.draw_bar_horizontal( @@ -111,8 +108,8 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { 14, player_pools.xp - xp_level_start, 1000, - RGB::named(rltk::GOLD), - black, + colors::GOLD, + colors::BLACK, ); // Attributes @@ -127,8 +124,8 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { ctx.print_color( 50, 9, - white, - black, + colors::WHITE, + colors::BLACK, &format!( "{:.0} lbs ({} lbs max)", player_pools.total_weight, @@ -138,8 +135,8 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { ctx.print_color( 50, 10, - white, - black, + colors::WHITE, + colors::BLACK, &format!( "Initiative Penalty: {:.0}", player_pools.total_initiative_penalty @@ -148,8 +145,8 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { ctx.print_color( 50, 11, - RGB::named(rltk::GOLD), - black, + colors::GOLD, + colors::BLACK, &format!("Gold: {:.1}", player_pools.gold), ); @@ -159,22 +156,20 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { let name = ecs.read_storage::(); for (equipped_by, item_name) in (&equipped, &name).join() { if equipped_by.owner == *player_entity { - ctx.print_color(50, y, white, black, &item_name.name); + ctx.print_color(50, y, colors::WHITE, colors::BLACK, &item_name.name); y += 1; } } // Consumables y += 1; - let green = RGB::from_f32(0.0, 1.0, 0.0); - let yellow = RGB::named(rltk::YELLOW); let consumables = ecs.read_storage::(); let backpack = ecs.read_storage::(); let mut index = 1; for (carried_by, _consumable, item_name) in (&backpack, &consumables, &name).join() { if carried_by.owner == *player_entity && index < 10 { - ctx.print_color(50, y, yellow, black, &format!("↑{}", index)); - ctx.print_color(53, y, green, black, &item_name.name); + ctx.print_color(50, y, colors::YELLOW, colors::BLACK, &format!("↑{}", index)); + ctx.print_color(53, y, colors::GREEN, colors::BLACK, &item_name.name); y += 1; index += 1; } @@ -184,10 +179,10 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { let hunger = ecs.read_storage::(); let hc = hunger.get(*player_entity).unwrap(); match hc.state { - HungerState::WellFed => ctx.print_color(50, 44, RGB::named(rltk::GREEN), black, "Well Fed"), + HungerState::WellFed => ctx.print_color(50, 44, colors::GREEN, colors::BLACK, "Well Fed"), HungerState::Normal => {} - HungerState::Hungry => ctx.print_color(50, 44, RGB::named(rltk::ORANGE), black, "Hungry"), - HungerState::Starving => ctx.print_color(50, 44, RGB::named(rltk::RED), black, "Starving"), + HungerState::Hungry => ctx.print_color(50, 44, colors::ORANGE, colors::BLACK, "Hungry"), + HungerState::Starving => ctx.print_color(50, 44, colors::RED, colors::BLACK, "Starving"), } // Draw the log @@ -204,27 +199,25 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { } fn draw_attribute(name: &str, attribute: &Attribute, y: i32, ctx: &mut Rltk) { - let black = RGB::named(rltk::BLACK); - let attr_gray = RGB::from_hex("#CCCCCC").expect("Oops"); - ctx.print_color(50, y, attr_gray, black, name); + ctx.print_color(50, y, colors::ATTR_GRAY, colors::BLACK, name); let color = match attribute.modifiers.cmp(&0) { - Ordering::Less => RGB::from_f32(1.0, 0.0, 0.0), - Ordering::Equal => RGB::named(rltk::WHITE), - Ordering::Greater => RGB::from_f32(0.0, 1.0, 0.0), + Ordering::Less => colors::RED, + Ordering::Equal => colors::WHITE, + Ordering::Greater => colors::GREEN, }; ctx.print_color( 67, y, color, - black, + colors::BLACK, &format!("{}", attribute.base + attribute.modifiers), ); - ctx.print_color(73, y, color, black, &format!("{}", attribute.bonus)); + ctx.print_color(73, y, color, colors::BLACK, &format!("{}", attribute.bonus)); if attribute.bonus > 0 { - ctx.set(72, y, color, black, rltk::to_cp437('+')); + ctx.set(72, y, color, colors::BLACK, rltk::to_cp437('+')); } } @@ -257,16 +250,22 @@ impl Tooltip { } fn render(&self, ctx: &mut Rltk, x: i32, y: i32) { - let box_gray = RGB::from_hex("#999999").expect("Oops"); - let light_gray = RGB::from_hex("#DDDDDD").expect("Oops"); - let white = RGB::named(rltk::WHITE); - let black = RGB::named(rltk::BLACK); - - ctx.draw_box(x, y, self.width() - 1, self.height() - 1, white, box_gray); + ctx.draw_box( + x, + y, + self.width() - 1, + self.height() - 1, + colors::WHITE, + colors::BOX_GRAY, + ); for (i, s) in self.lines.iter().enumerate() { - let col = if i == 0 { white } else { light_gray }; - ctx.print_color(x + 1, y + i as i32 + 1, col, black, &s); + let col = if i == 0 { + colors::WHITE + } else { + colors::LIGHT_GRAY + }; + ctx.print_color(x + 1, y + i as i32 + 1, col, colors::BLACK, &s); } } } @@ -352,9 +351,6 @@ fn draw_tooltips(ecs: &World, ctx: &mut Rltk) { return; } - let box_gray = RGB::from_hex("#999999").expect("Oops"); - let white = RGB::named(rltk::WHITE); - let arrow; let arrow_x; let arrow_y = mouse_pos.1; @@ -367,7 +363,7 @@ fn draw_tooltips(ecs: &World, ctx: &mut Rltk) { arrow = to_cp437('←'); arrow_x = mouse_pos.0 + 1; } - ctx.set(arrow_x, arrow_y, white, box_gray, arrow); + ctx.set(arrow_x, arrow_y, colors::WHITE, colors::BOX_GRAY, arrow); let mut total_height = 0; for tt in tip_boxes.iter() { @@ -414,21 +410,15 @@ pub fn show_inventory(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option y - 2, 31, (count + 3) as i32, - RGB::named(rltk::WHITE), - RGB::named(rltk::BLACK), - ); - ctx.print_color( - 18, - y - 2, - RGB::named(rltk::YELLOW), - RGB::named(rltk::BLACK), - "Inventory", + colors::WHITE, + colors::BLACK, ); + ctx.print_color(18, y - 2, colors::YELLOW, colors::BLACK, "Inventory"); ctx.print_color( 18, y + count as i32 + 1, - RGB::named(rltk::YELLOW), - RGB::named(rltk::BLACK), + colors::YELLOW, + colors::BLACK, "ESCAPE to cancel", ); @@ -439,27 +429,15 @@ pub fn show_inventory(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option .join() .filter(|item| item.1.owner == *player_entity) { - ctx.set( - 17, - y, - RGB::named(rltk::WHITE), - RGB::named(rltk::BLACK), - rltk::to_cp437('('), - ); + ctx.set(17, y, colors::WHITE, colors::BLACK, rltk::to_cp437('(')); ctx.set( 18, y, - RGB::named(rltk::YELLOW), - RGB::named(rltk::BLACK), + colors::YELLOW, + colors::BLACK, 97 + j as rltk::FontCharType, ); - ctx.set( - 19, - y, - RGB::named(rltk::WHITE), - RGB::named(rltk::BLACK), - rltk::to_cp437(')'), - ); + ctx.set(19, y, colors::WHITE, colors::BLACK, rltk::to_cp437(')')); ctx.print(21, y, &name.name.to_string()); equippable.push(entity); @@ -502,21 +480,15 @@ pub fn drop_item_menu(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option y - 2, 31, (count + 3) as i32, - RGB::named(rltk::WHITE), - RGB::named(rltk::BLACK), - ); - ctx.print_color( - 18, - y - 2, - RGB::named(rltk::YELLOW), - RGB::named(rltk::BLACK), - "Drop Which Item?", + colors::WHITE, + colors::BLACK, ); + ctx.print_color(18, y - 2, colors::YELLOW, colors::BLACK, "Drop Which Item?"); ctx.print_color( 18, y + count as i32 + 1, - RGB::named(rltk::YELLOW), - RGB::named(rltk::BLACK), + colors::YELLOW, + colors::BLACK, "ESCAPE to cancel", ); @@ -527,27 +499,15 @@ pub fn drop_item_menu(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option .join() .filter(|item| item.1.owner == *player_entity) { - ctx.set( - 17, - y, - RGB::named(rltk::WHITE), - RGB::named(rltk::BLACK), - rltk::to_cp437('('), - ); + ctx.set(17, y, colors::WHITE, colors::BLACK, rltk::to_cp437('(')); ctx.set( 18, y, - RGB::named(rltk::YELLOW), - RGB::named(rltk::BLACK), + colors::YELLOW, + colors::BLACK, 97 + j as rltk::FontCharType, ); - ctx.set( - 19, - y, - RGB::named(rltk::WHITE), - RGB::named(rltk::BLACK), - rltk::to_cp437(')'), - ); + ctx.set(19, y, colors::WHITE, colors::BLACK, rltk::to_cp437(')')); ctx.print(21, y, &name.name.to_string()); equippable.push(entity); @@ -590,21 +550,21 @@ pub fn remove_item_menu(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Opti y - 2, 31, (count + 3) as i32, - RGB::named(rltk::WHITE), - RGB::named(rltk::BLACK), + colors::WHITE, + colors::BLACK, ); ctx.print_color( 18, y - 2, - RGB::named(rltk::YELLOW), - RGB::named(rltk::BLACK), + colors::YELLOW, + colors::BLACK, "Remove Which Item?", ); ctx.print_color( 18, y + count as i32 + 1, - RGB::named(rltk::YELLOW), - RGB::named(rltk::BLACK), + colors::YELLOW, + colors::BLACK, "ESCAPE to cancel", ); @@ -615,27 +575,15 @@ pub fn remove_item_menu(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Opti .join() .filter(|item| item.1.owner == *player_entity) { - ctx.set( - 17, - y, - RGB::named(rltk::WHITE), - RGB::named(rltk::BLACK), - rltk::to_cp437('('), - ); + ctx.set(17, y, colors::WHITE, colors::BLACK, rltk::to_cp437('(')); ctx.set( 18, y, - RGB::named(rltk::YELLOW), - RGB::named(rltk::BLACK), + colors::YELLOW, + colors::BLACK, 97 + j as rltk::FontCharType, ); - ctx.set( - 19, - y, - RGB::named(rltk::WHITE), - RGB::named(rltk::BLACK), - rltk::to_cp437(')'), - ); + ctx.set(19, y, colors::WHITE, colors::BLACK, rltk::to_cp437(')')); ctx.print(21, y, &name.name.to_string()); @@ -673,13 +621,7 @@ pub fn ranged_target( let player_pos = gs.ecs.fetch::(); let viewsheds = gs.ecs.read_storage::(); - ctx.print_color( - 5, - 0, - RGB::named(rltk::YELLOW), - RGB::named(rltk::BLACK), - "Select Target:", - ); + ctx.print_color(5, 0, colors::YELLOW, colors::BLACK, "Select Target:"); // Highlight available target cells let mut available_cells = Vec::new(); @@ -695,7 +637,7 @@ pub fn ranged_target( && screen_y > 1 && screen_y < (max_y - min_y) - 1 { - ctx.set_bg(screen_x, screen_y, RGB::named(rltk::BLUE)); + ctx.set_bg(screen_x, screen_y, colors::BLUE); available_cells.push(idx); } } @@ -717,7 +659,7 @@ pub fn ranged_target( } if valid_target { - ctx.set_bg(mouse_pos.0, mouse_pos.1, RGB::named(rltk::CYAN)); + ctx.set_bg(mouse_pos.0, mouse_pos.1, colors::CYAN); if ctx.left_click { return ( ItemMenuResult::Selected, @@ -725,7 +667,7 @@ pub fn ranged_target( ); } } else { - ctx.set_bg(mouse_pos.0, mouse_pos.1, RGB::named(rltk::RED)); + ctx.set_bg(mouse_pos.0, mouse_pos.1, colors::RED); if ctx.left_click { return (ItemMenuResult::Cancel, None); } @@ -753,31 +695,14 @@ pub fn main_menu(gs: &mut State, ctx: &mut Rltk) -> MainMenuResult { let assets = gs.ecs.fetch::(); ctx.render_xp_sprite(&assets.menu, 0, 0); - ctx.draw_box_double( - 24, - 18, - 31, - 10, - RGB::named(rltk::WHEAT), - RGB::named(rltk::BLACK), - ); + ctx.draw_box_double(24, 18, 31, 10, colors::WHEAT, colors::BLACK); - ctx.print_color_centered( - 20, - RGB::named(rltk::YELLOW), - RGB::named(rltk::BLACK), - "Rust Roguelike Tutorial", - ); - ctx.print_color_centered( - 21, - RGB::named(rltk::CYAN), - RGB::named(rltk::BLACK), - "by Herbert Wolverson", - ); + ctx.print_color_centered(20, colors::YELLOW, colors::BLACK, "Rust Roguelike Tutorial"); + ctx.print_color_centered(21, colors::CYAN, colors::BLACK, "by Herbert Wolverson"); ctx.print_color_centered( 22, - RGB::named(rltk::GRAY), - RGB::named(rltk::BLACK), + colors::GRAY, + colors::BLACK, "Use Up/Down Arrows and Enter", ); @@ -787,50 +712,25 @@ pub fn main_menu(gs: &mut State, ctx: &mut Rltk) -> MainMenuResult { } = *runstate { if selection == MainMenuSelection::NewGame { - ctx.print_color_centered( - y, - RGB::named(rltk::MAGENTA), - RGB::named(rltk::BLACK), - "Begin New Game", - ); + ctx.print_color_centered(y, colors::MAGENTA, colors::BLACK, "Begin New Game"); } else { - ctx.print_color_centered( - y, - RGB::named(rltk::WHITE), - RGB::named(rltk::BLACK), - "Begin New Game", - ); + ctx.print_color_centered(y, colors::WHITE, colors::BLACK, "Begin New Game"); } y += 1; if save_exists { if selection == MainMenuSelection::LoadGame { - ctx.print_color_centered( - y, - RGB::named(rltk::MAGENTA), - RGB::named(rltk::BLACK), - "Load Game", - ); + ctx.print_color_centered(y, colors::MAGENTA, colors::BLACK, "Load Game"); } else { - ctx.print_color_centered( - y, - RGB::named(rltk::WHITE), - RGB::named(rltk::BLACK), - "Load Game", - ); + ctx.print_color_centered(y, colors::WHITE, colors::BLACK, "Load Game"); } y += 1; } if selection == MainMenuSelection::Quit { - ctx.print_color_centered( - y, - RGB::named(rltk::MAGENTA), - RGB::named(rltk::BLACK), - "Quit", - ); + ctx.print_color_centered(y, colors::MAGENTA, colors::BLACK, "Quit"); } else { - ctx.print_color_centered(y, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK), "Quit"); + ctx.print_color_centered(y, colors::WHITE, colors::BLACK, "Quit"); } return match ctx.key { @@ -889,29 +789,24 @@ pub enum GameOverResult { } pub fn game_over(ctx: &mut Rltk) -> GameOverResult { - ctx.print_color_centered( - 15, - RGB::named(rltk::YELLOW), - RGB::named(rltk::BLACK), - "Your journey has ended!", - ); + ctx.print_color_centered(15, colors::YELLOW, colors::BLACK, "Your journey has ended!"); ctx.print_color_centered( 17, - RGB::named(rltk::WHITE), - RGB::named(rltk::BLACK), + colors::WHITE, + colors::BLACK, "One day, we'll tell you all about how you did.", ); ctx.print_color_centered( 18, - RGB::named(rltk::WHITE), - RGB::named(rltk::BLACK), + colors::WHITE, + colors::BLACK, "That day, sadly, is not in this chapter...", ); ctx.print_color_centered( 20, - RGB::named(rltk::MAGENTA), - RGB::named(rltk::BLACK), + colors::MAGENTA, + colors::BLACK, "Press any key to return to the menu.", ); @@ -939,118 +834,40 @@ pub fn show_cheat_mode(_gs: &mut State, ctx: &mut Rltk) -> CheatMenuResult { y - 2, 31, (count + 3) as i32, - RGB::named(rltk::WHITE), - RGB::named(rltk::BLACK), - ); - ctx.print_color( - 18, - y - 2, - RGB::named(rltk::YELLOW), - RGB::named(rltk::BLACK), - "Cheating!", + colors::WHITE, + colors::BLACK, ); + ctx.print_color(18, y - 2, colors::YELLOW, colors::BLACK, "Cheating!"); ctx.print_color( 18, y + count as i32 + 1, - RGB::named(rltk::YELLOW), - RGB::named(rltk::BLACK), + colors::YELLOW, + colors::BLACK, "ESCAPE to cancel", ); - ctx.set( - 17, - y, - RGB::named(rltk::WHITE), - RGB::named(rltk::BLACK), - rltk::to_cp437('('), - ); - ctx.set( - 18, - y, - RGB::named(rltk::YELLOW), - RGB::named(rltk::BLACK), - rltk::to_cp437('T'), - ); - ctx.set( - 19, - y, - RGB::named(rltk::WHITE), - RGB::named(rltk::BLACK), - rltk::to_cp437(')'), - ); + ctx.set(17, y, colors::WHITE, colors::BLACK, rltk::to_cp437('(')); + ctx.set(18, y, colors::YELLOW, colors::BLACK, rltk::to_cp437('T')); + ctx.set(19, y, colors::WHITE, colors::BLACK, rltk::to_cp437(')')); ctx.print(21, y, "Teleport to next level"); y += 1; - ctx.set( - 17, - y, - RGB::named(rltk::WHITE), - RGB::named(rltk::BLACK), - rltk::to_cp437('('), - ); - ctx.set( - 18, - y, - RGB::named(rltk::YELLOW), - RGB::named(rltk::BLACK), - rltk::to_cp437('H'), - ); - ctx.set( - 19, - y, - RGB::named(rltk::WHITE), - RGB::named(rltk::BLACK), - rltk::to_cp437(')'), - ); + ctx.set(17, y, colors::WHITE, colors::BLACK, rltk::to_cp437('(')); + ctx.set(18, y, colors::YELLOW, colors::BLACK, rltk::to_cp437('H')); + ctx.set(19, y, colors::WHITE, colors::BLACK, rltk::to_cp437(')')); ctx.print(21, y, "Heal all wounds"); y += 1; - ctx.set( - 17, - y, - RGB::named(rltk::WHITE), - RGB::named(rltk::BLACK), - rltk::to_cp437('('), - ); - ctx.set( - 18, - y, - RGB::named(rltk::YELLOW), - RGB::named(rltk::BLACK), - rltk::to_cp437('R'), - ); - ctx.set( - 19, - y, - RGB::named(rltk::WHITE), - RGB::named(rltk::BLACK), - rltk::to_cp437(')'), - ); + ctx.set(17, y, colors::WHITE, colors::BLACK, rltk::to_cp437('(')); + ctx.set(18, y, colors::YELLOW, colors::BLACK, rltk::to_cp437('R')); + ctx.set(19, y, colors::WHITE, colors::BLACK, rltk::to_cp437(')')); ctx.print(21, y, "Reveal the map"); y += 1; - ctx.set( - 17, - y, - RGB::named(rltk::WHITE), - RGB::named(rltk::BLACK), - rltk::to_cp437('('), - ); - ctx.set( - 18, - y, - RGB::named(rltk::YELLOW), - RGB::named(rltk::BLACK), - rltk::to_cp437('G'), - ); - ctx.set( - 19, - y, - RGB::named(rltk::WHITE), - RGB::named(rltk::BLACK), - rltk::to_cp437(')'), - ); + ctx.set(17, y, colors::WHITE, colors::BLACK, rltk::to_cp437('(')); + ctx.set(18, y, colors::YELLOW, colors::BLACK, rltk::to_cp437('G')); + ctx.set(19, y, colors::WHITE, colors::BLACK, rltk::to_cp437(')')); ctx.print(21, y, "God Mode (No Death)"); match ctx.key { @@ -1099,21 +916,21 @@ fn vendor_sell_menu( y - 2, 51, (count + 3) as i32, - RGB::named(rltk::WHITE), - RGB::named(rltk::BLACK), + colors::WHITE, + colors::BLACK, ); ctx.print_color( 18, y - 2, - RGB::named(rltk::YELLOW), - RGB::named(rltk::BLACK), + colors::YELLOW, + colors::BLACK, "Sell Which Item? (space to switch to buy mode)", ); ctx.print_color( 18, y + count as i32 + 1, - RGB::named(rltk::YELLOW), - RGB::named(rltk::BLACK), + colors::YELLOW, + colors::BLACK, "ESCAPE to cancel", ); @@ -1123,27 +940,15 @@ fn vendor_sell_menu( .filter(|item| item.1.owner == *player_entity) .enumerate() { - ctx.set( - 17, - y, - RGB::named(rltk::WHITE), - RGB::named(rltk::BLACK), - rltk::to_cp437('('), - ); + ctx.set(17, y, colors::WHITE, colors::BLACK, rltk::to_cp437('(')); ctx.set( 18, y, - RGB::named(rltk::YELLOW), - RGB::named(rltk::BLACK), + colors::YELLOW, + colors::BLACK, 97 + j as rltk::FontCharType, ); - ctx.set( - 19, - y, - RGB::named(rltk::WHITE), - RGB::named(rltk::BLACK), - rltk::to_cp437(')'), - ); + ctx.set(19, y, colors::WHITE, colors::BLACK, rltk::to_cp437(')')); ctx.print(21, y, &name.name.to_string()); ctx.print(50, y, &format!("{:.1} gp", item.base_value * 0.8)); @@ -1194,46 +999,34 @@ fn vendor_buy_menu( y - 2, 51, (count + 3) as i32, - RGB::named(rltk::WHITE), - RGB::named(rltk::BLACK), + colors::WHITE, + colors::BLACK, ); ctx.print_color( 18, y - 2, - RGB::named(rltk::YELLOW), - RGB::named(rltk::BLACK), + colors::YELLOW, + colors::BLACK, "Buy Which Item? (space to switch to sell mode)", ); ctx.print_color( 18, y + count as i32 + 1, - RGB::named(rltk::YELLOW), - RGB::named(rltk::BLACK), + colors::YELLOW, + colors::BLACK, "ESCAPE to cancel", ); for (j, sale) in inventory.iter().enumerate() { - ctx.set( - 17, - y, - RGB::named(rltk::WHITE), - RGB::named(rltk::BLACK), - rltk::to_cp437('('), - ); + ctx.set(17, y, colors::WHITE, colors::BLACK, rltk::to_cp437('(')); ctx.set( 18, y, - RGB::named(rltk::YELLOW), - RGB::named(rltk::BLACK), + colors::YELLOW, + colors::BLACK, 97 + j as rltk::FontCharType, ); - ctx.set( - 19, - y, - RGB::named(rltk::WHITE), - RGB::named(rltk::BLACK), - rltk::to_cp437(')'), - ); + ctx.set(19, y, colors::WHITE, colors::BLACK, rltk::to_cp437(')')); ctx.print(21, y, &sale.0); ctx.print(50, y, &format!("{:.1} gp", sale.1 * 1.2)); diff --git a/src/inventory_system.rs b/src/inventory_system.rs index 2141604..bed9f7a 100644 --- a/src/inventory_system.rs +++ b/src/inventory_system.rs @@ -1,10 +1,9 @@ -use ::rltk::RGB; use ::specs::prelude::*; use crate::components::*; use crate::game_log::GameLog; use crate::particle_system::ParticleBuilder; -use crate::{spatial, Map, RunState}; +use crate::{colors, spatial, Map, RunState}; pub struct ItemCollectionSystem {} @@ -149,8 +148,8 @@ impl<'a> System<'a> for ItemUseSystem { particle_builder.request( tile_idx.x, tile_idx.y, - RGB::named(rltk::ORANGE), - RGB::named(rltk::BLACK), + colors::ORANGE, + colors::BLACK, rltk::to_cp437('░'), 200.0, ); @@ -264,8 +263,8 @@ impl<'a> System<'a> for ItemUseSystem { particle_builder.request( pos.x, pos.y, - RGB::named(rltk::GREEN), - RGB::named(rltk::BLACK), + colors::GREEN, + colors::BLACK, rltk::to_cp437('♥'), 200.0, ); @@ -296,8 +295,8 @@ impl<'a> System<'a> for ItemUseSystem { particle_builder.request( pos.x, pos.y, - RGB::named(rltk::RED), - RGB::named(rltk::BLACK), + colors::RED, + colors::BLACK, rltk::to_cp437('‼'), 200.0, ); @@ -333,8 +332,8 @@ impl<'a> System<'a> for ItemUseSystem { particle_builder.request( pos.x, pos.y, - RGB::named(rltk::MAGENTA), - RGB::named(rltk::BLACK), + colors::MAGENTA, + colors::BLACK, rltk::to_cp437('?'), 200.0, ); diff --git a/src/lighting_system.rs b/src/lighting_system.rs index 1918e96..ed674da 100644 --- a/src/lighting_system.rs +++ b/src/lighting_system.rs @@ -1,8 +1,9 @@ -use ::rltk::{Point, RGB}; +use ::rltk::Point; use ::specs::prelude::*; use rltk::DistanceAlg; use super::{LightSource, Map, Position, Viewshed}; +use crate::colors; pub struct LightingSystem {} @@ -22,9 +23,8 @@ impl<'a> System<'a> for LightingSystem { return; } - let black = RGB::from_f32(0., 0., 0.); for l in map.light.iter_mut() { - *l = black; + *l = colors::BLACK; } for (viewshed, pos, light) in (&viewshed, &positions, &lighting).join() { diff --git a/src/main.rs b/src/main.rs index 9daf74a..fcbb661 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ mod ai; pub mod camera; +mod colors; mod components; mod damage_system; mod game_log; diff --git a/src/map.rs b/src/map.rs index 215093d..5bd0223 100644 --- a/src/map.rs +++ b/src/map.rs @@ -12,7 +12,7 @@ pub use themes::*; pub use tiletype::{tile_opaque, tile_walkable, TileType}; use crate::map::tiletype::tile_cost; -use crate::spatial; +use crate::{colors, spatial}; #[derive(Default, Serialize, Deserialize, Clone)] pub struct Map { @@ -68,7 +68,7 @@ impl Map { view_blocked: HashSet::new(), name: name.to_string(), outdoors: true, - light: vec![RGB::from_f32(0., 0., 0.); map_tile_count], + light: vec![colors::BLACK; map_tile_count], } } } diff --git a/src/map/themes.rs b/src/map/themes.rs index afc8ce1..e9c0a28 100644 --- a/src/map/themes.rs +++ b/src/map/themes.rs @@ -1,6 +1,7 @@ use ::rltk::{to_cp437, FontCharType, RGB}; use super::{Map, TileType}; +use crate::colors; pub fn tile_glyph(idx: usize, map: &Map) -> (FontCharType, RGB, RGB) { let (glyph, mut fg, mut bg) = match map.depth { @@ -10,12 +11,12 @@ pub fn tile_glyph(idx: usize, map: &Map) -> (FontCharType, RGB, RGB) { }; if map.bloodstains.contains(&idx) { - bg = RGB::from_f32(0.7, 0., 0.); + bg = colors::BLOOD; } if !map.visible_tiles[idx] { fg = fg.to_greyscale(); - bg = RGB::from_f32(0., 0., 0.); + bg = colors::BLACK; } else if !map.outdoors { fg = fg * map.light[idx]; bg = bg * map.light[idx]; @@ -25,77 +26,77 @@ pub fn tile_glyph(idx: usize, map: &Map) -> (FontCharType, RGB, RGB) { } fn get_limestone_cavern_glyph(idx: usize, map: &Map) -> (FontCharType, RGB, RGB) { - let bg = RGB::from_f32(0., 0., 0.); + let bg = colors::BLACK; let (glyph, fg) = match map.tiles[idx] { - TileType::Wall => (to_cp437('▒'), RGB::from_f32(0.7, 0.7, 0.7)), - TileType::Bridge => (to_cp437('.'), RGB::named(rltk::CHOCOLATE)), - TileType::Road => (to_cp437('≡'), RGB::named(rltk::YELLOW)), - TileType::Grass => (to_cp437('"'), RGB::named(rltk::GREEN)), - TileType::ShallowWater => (to_cp437('░'), RGB::named(rltk::CYAN)), - TileType::DeepWater => (to_cp437('▓'), RGB::from_f32(0.2, 0.2, 1.0)), - TileType::Gravel => (to_cp437(';'), RGB::from_f32(0.5, 0.5, 0.5)), - TileType::DownStairs => (to_cp437('>'), RGB::from_f32(0., 1.0, 1.0)), - TileType::UpStairs => (to_cp437('<'), RGB::from_f32(0., 1.0, 1.0)), - TileType::Stalactite => (to_cp437('╨'), RGB::from_f32(0.5, 0.5, 0.5)), - TileType::Stalagmite => (to_cp437('╥'), RGB::from_f32(0.5, 0.5, 0.5)), - _ => (to_cp437('░'), RGB::from_f32(0.4, 0.4, 0.4)), + TileType::Wall => (to_cp437('▒'), colors::GRAY), + TileType::Bridge => (to_cp437('.'), colors::CHOCOLATE), + TileType::Road => (to_cp437('≡'), colors::YELLOW), + TileType::Grass => (to_cp437('"'), colors::GREEN), + TileType::ShallowWater => (to_cp437('░'), colors::CYAN), + TileType::DeepWater => (to_cp437('▓'), colors::DEEP_WATER), + TileType::Gravel => (to_cp437(';'), colors::MID_GRAY), + TileType::DownStairs => (to_cp437('>'), colors::CYAN), + TileType::UpStairs => (to_cp437('<'), colors::CYAN), + TileType::Stalactite => (to_cp437('╨'), colors::MID_GRAY), + TileType::Stalagmite => (to_cp437('╥'), colors::MID_GRAY), + _ => (to_cp437('░'), colors::DARK_GRAY), }; (glyph, fg, bg) } fn get_forest_glyph(idx: usize, map: &Map) -> (FontCharType, RGB, RGB) { - let bg = RGB::from_f32(0., 0., 0.); + let bg = colors::BLACK; let (glyph, fg) = match map.tiles[idx] { - TileType::Wall => (to_cp437('♣'), RGB::from_f32(0.0, 0.6, 0.0)), - TileType::Bridge => (to_cp437('.'), RGB::named(rltk::CHOCOLATE)), - TileType::Road => (to_cp437('≡'), RGB::named(rltk::YELLOW)), - TileType::Grass => (to_cp437('"'), RGB::named(rltk::GREEN)), - TileType::ShallowWater => (to_cp437('~'), RGB::named(rltk::CYAN)), - TileType::DeepWater => (to_cp437('~'), RGB::named(rltk::BLUE)), - TileType::Gravel => (to_cp437(';'), RGB::from_f32(0.5, 0.5, 0.5)), - TileType::DownStairs => (to_cp437('>'), RGB::from_f32(0., 1.0, 1.0)), - TileType::UpStairs => (to_cp437('<'), RGB::from_f32(0., 1.0, 1.0)), - _ => (to_cp437('"'), RGB::from_f32(0.0, 0.6, 0.0)), + TileType::Wall => (to_cp437('♣'), colors::FOREST_GREEN), + TileType::Bridge => (to_cp437('.'), colors::CHOCOLATE), + TileType::Road => (to_cp437('≡'), colors::YELLOW), + TileType::Grass => (to_cp437('"'), colors::GREEN), + TileType::ShallowWater => (to_cp437('~'), colors::CYAN), + TileType::DeepWater => (to_cp437('~'), colors::DEEP_WATER), + TileType::Gravel => (to_cp437(';'), colors::MID_GRAY), + TileType::DownStairs => (to_cp437('>'), colors::CYAN), + TileType::UpStairs => (to_cp437('<'), colors::CYAN), + _ => (to_cp437('"'), colors::FOREST_GREEN), }; (glyph, fg, bg) } fn get_tile_glyph_default(idx: usize, map: &Map) -> (rltk::FontCharType, RGB, RGB) { - let mut bg = RGB::from_f32(0., 0., 0.); + let mut bg = colors::BLACK; let (glyph, mut fg) = match map.tiles[idx] { - TileType::Floor => (to_cp437('.'), RGB::from_f32(0., 0.5, 0.5)), - TileType::WoodFloor => (to_cp437('░'), RGB::named(rltk::CHOCOLATE)), + TileType::Floor => (to_cp437('.'), colors::DEFAULT_FLOOR), + TileType::WoodFloor => (to_cp437('░'), colors::CHOCOLATE), TileType::Wall => { let x = idx as i32 % map.width; let y = idx as i32 / map.width; - (wall_glyph(&*map, x, y), RGB::from_f32(0., 1.0, 0.)) + (wall_glyph(&*map, x, y), colors::GREEN) } - TileType::DownStairs => (to_cp437('>'), RGB::from_f32(0., 1.0, 1.0)), - TileType::Bridge => (to_cp437('.'), RGB::named(rltk::CHOCOLATE)), - TileType::Road => (to_cp437('≡'), RGB::named(rltk::GRAY)), - TileType::Grass => (to_cp437('"'), RGB::named(rltk::GREEN)), - TileType::ShallowWater => (to_cp437('~'), RGB::named(rltk::CYAN)), - TileType::DeepWater => (to_cp437('~'), RGB::named(rltk::NAVY_BLUE)), - TileType::Gravel => (to_cp437(';'), RGB::named(rltk::GRAY)), - TileType::UpStairs => (to_cp437('<'), RGB::from_f32(0., 1.0, 1.0)), - TileType::Stalactite => (to_cp437('╨'), RGB::from_f32(0.5, 0.5, 0.5)), - TileType::Stalagmite => (to_cp437('╥'), RGB::from_f32(0.5, 0.5, 0.5)), + TileType::DownStairs => (to_cp437('>'), colors::CYAN), + TileType::Bridge => (to_cp437('.'), colors::CHOCOLATE), + TileType::Road => (to_cp437('≡'), colors::GRAY), + TileType::Grass => (to_cp437('"'), colors::GREEN), + TileType::ShallowWater => (to_cp437('~'), colors::CYAN), + TileType::DeepWater => (to_cp437('~'), colors::DEEP_WATER), + TileType::Gravel => (to_cp437(';'), colors::GRAY), + TileType::UpStairs => (to_cp437('<'), colors::CYAN), + TileType::Stalactite => (to_cp437('╨'), colors::MID_GRAY), + TileType::Stalagmite => (to_cp437('╥'), colors::MID_GRAY), }; if map.bloodstains.contains(&idx) { - bg = RGB::from_f32(0.75, 0., 0.); + bg = colors::BLOOD; } if !map.visible_tiles[idx] { fg = fg.to_greyscale(); // Don't show bloodstains out of visual range - bg = RGB::from_f32(0., 0., 0.); + bg = colors::BLACK; } (glyph, fg, bg) diff --git a/src/melee_combat_system.rs b/src/melee_combat_system.rs index 8f5ee81..86d30ed 100644 --- a/src/melee_combat_system.rs +++ b/src/melee_combat_system.rs @@ -1,4 +1,4 @@ -use ::rltk::{RandomNumberGenerator, RGB}; +use ::rltk::RandomNumberGenerator; use ::specs::prelude::*; use crate::components::{ @@ -8,7 +8,7 @@ use crate::components::{ use crate::game_log::GameLog; use crate::gamesystem::skill_bonus; use crate::particle_system::ParticleBuilder; -use crate::{EquipmentSlot, NaturalAttackDefense, Position, WeaponAttribute}; +use crate::{colors, EquipmentSlot, NaturalAttackDefense, Position, WeaponAttribute}; pub struct MeleeCombatSystem {} @@ -171,8 +171,8 @@ impl<'a> System<'a> for MeleeCombatSystem { particle_builder.request( pos.x, pos.y, - RGB::named(rltk::ORANGE), - RGB::named(rltk::BLACK), + colors::ORANGE, + colors::BLACK, rltk::to_cp437('‼'), 200.0, ); @@ -187,8 +187,8 @@ impl<'a> System<'a> for MeleeCombatSystem { particle_builder.request( pos.x, pos.y, - RGB::named(rltk::BLUE), - RGB::named(rltk::BLACK), + colors::BLUE, + colors::BLACK, rltk::to_cp437('‼'), 200.0, ); @@ -203,8 +203,8 @@ impl<'a> System<'a> for MeleeCombatSystem { particle_builder.request( pos.x, pos.y, - RGB::named(rltk::CYAN), - RGB::named(rltk::BLACK), + colors::CYAN, + colors::BLACK, rltk::to_cp437('‼'), 200.0, ); diff --git a/src/raws/prop_structs.rs b/src/raws/prop_structs.rs index e50c629..38d8dc2 100644 --- a/src/raws/prop_structs.rs +++ b/src/raws/prop_structs.rs @@ -1,8 +1,9 @@ use std::collections::HashMap; +use ::serde::Deserialize; + use super::mob_structs::MobLight; use super::Renderable; -use ::serde::Deserialize; #[derive(Deserialize, Debug)] pub struct Prop { diff --git a/src/raws/rawmaster.rs b/src/raws/rawmaster.rs index 7eaf082..d21bc8e 100644 --- a/src/raws/rawmaster.rs +++ b/src/raws/rawmaster.rs @@ -204,8 +204,8 @@ fn get_renderable_component( ) -> crate::components::Renderable { crate::components::Renderable { glyph: rltk::to_cp437(renderable.glyph.chars().next().unwrap()), - fg: rltk::RGB::from_hex(&renderable.fg).expect("Invalid RGB"), - bg: rltk::RGB::from_hex(&renderable.bg).expect("Invalid RGB"), + fg: RGB::from_hex(&renderable.fg).expect("Invalid color"), + bg: RGB::from_hex(&renderable.bg).expect("Invalid color"), render_order: renderable.order, } } @@ -486,7 +486,7 @@ pub fn spawn_named_mob( if let Some(light) = &mob_template.light { eb = eb.with(LightSource { range: light.range, - color: RGB::from_hex(&light.color).expect("Bad color"), + color: RGB::from_hex(&light.color).expect("Invalid color"), }); } diff --git a/src/spawner.rs b/src/spawner.rs index 16ea2c3..4add02d 100644 --- a/src/spawner.rs +++ b/src/spawner.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use ::rltk::{RandomNumberGenerator, RGB}; +use ::rltk::RandomNumberGenerator; use ::specs::prelude::*; use ::specs::saveload::{MarkedBuilder, SimpleMarker}; @@ -8,7 +8,7 @@ use crate::components::*; use crate::gamesystem::{mana_at_level, player_hp_at_level}; use crate::random_table::RandomTable; use crate::raws::{get_spawn_table_for_depth, spawn_named_entity, SpawnType, RAWS}; -use crate::{Map, Rect, TileType}; +use crate::{colors, Map, Rect, TileType}; /// Spawns the player and returns their entity object pub fn player(ecs: &mut World, player_x: i32, player_y: i32) -> Entity { @@ -20,8 +20,8 @@ pub fn player(ecs: &mut World, player_x: i32, player_y: i32) -> Entity { }) .with(Renderable { glyph: rltk::to_cp437('@'), - fg: RGB::named(rltk::YELLOW), - bg: RGB::named(rltk::BLACK), + fg: colors::YELLOW, + bg: colors::BLACK, render_order: 0, }) .with(Player {}) @@ -49,7 +49,7 @@ pub fn player(ecs: &mut World, player_x: i32, player_y: i32) -> Entity { god_mode: false, }) .with(LightSource { - color: RGB::from_f32(1.0, 1.0, 0.5), + color: colors::TORCH_LIGHT, range: 8, }) .with(Initiative { current: 0 }) diff --git a/src/trigger_system.rs b/src/trigger_system.rs index 38177a3..e59074b 100644 --- a/src/trigger_system.rs +++ b/src/trigger_system.rs @@ -6,7 +6,7 @@ use crate::components::{ }; use crate::game_log::GameLog; use crate::particle_system::ParticleBuilder; -use crate::{spatial, Map}; +use crate::{colors, spatial, Map}; pub struct TriggerSystem {} @@ -67,8 +67,8 @@ impl<'a> System<'a> for TriggerSystem { particle_builder.request( pos.x, pos.y, - rltk::RGB::named(rltk::ORANGE), - rltk::RGB::named(rltk::BLACK), + colors::ORANGE, + colors::BLACK, rltk::to_cp437('‼'), 200.0, );