Some tweaks to remove some dead code

This commit is contained in:
Timothy Warren 2022-02-10 11:18:21 -05:00
parent 815eacbc9b
commit 73525db8dd
5 changed files with 21 additions and 28 deletions

View File

@ -68,3 +68,9 @@ is used to select a target.
## Makefile
If you want to see what else you can run with Makefile, run `make help`. This will list commands and what they do.
## Changes from tutorial
* Added a macro to register components for `specs`, like was in the tutorial for saving/loading.
* Game state machine is moved to `src/state.rs`
* Colors (Bracket-lib `RGB` struct) have been converted to static values in `src/colors.rs`, to cut down on boilerplate and numbers of ways of generating color values.
* All references to `rltk` have been converted to `bracket_lib`, as `rltk` was a facade in `bracket_lib`

View File

@ -59,6 +59,7 @@ macro_rules! register {
}
}
/// Register the Component Structs with Specs
fn register_components(state: &mut State) {
register!(
state <-

View File

@ -76,6 +76,7 @@ impl Map {
}
}
#[allow(dead_code)]
pub fn clear_content_index(&mut self) {
spatial::clear();
}
@ -111,11 +112,12 @@ impl BaseMap for Map {
}
fn get_available_exits(&self, idx: usize) -> SmallVec<[(usize, f32); 10]> {
const DIAGONAL_COST: f32 = 1.5;
let mut exits = SmallVec::new();
let x = idx as i32 % self.width;
let y = idx as i32 / self.width;
let w = self.width as usize;
let tt = self.tiles[idx];
let w = self.width as usize;
// Cardinal directions
if self.is_exit_valid(x - 1, y) {
@ -133,16 +135,16 @@ impl BaseMap for Map {
// Diagonals
if self.is_exit_valid(x - 1, y - 1) {
exits.push(((idx - w) - 1, tile_cost(tt) * 1.45));
exits.push(((idx - w) - 1, tile_cost(tt) * DIAGONAL_COST));
}
if self.is_exit_valid(x + 1, y - 1) {
exits.push(((idx - w) + 1, tile_cost(tt) * 1.45));
exits.push(((idx - w) + 1, tile_cost(tt) * DIAGONAL_COST));
}
if self.is_exit_valid(x - 1, y + 1) {
exits.push(((idx + w) - 1, tile_cost(tt) * 1.45));
exits.push(((idx + w) - 1, tile_cost(tt) * DIAGONAL_COST));
}
if self.is_exit_valid(x + 1, y + 1) {
exits.push(((idx + w) + 1, tile_cost(tt) * 1.45));
exits.push(((idx + w) + 1, tile_cost(tt) * DIAGONAL_COST));
}
exits

View File

@ -166,22 +166,6 @@ impl BuilderChain {
self
}
pub fn get_map(&self) -> Map {
self.build_data.map.clone()
}
pub fn get_starting_position(&self) -> Option<Position> {
self.build_data.starting_position
}
pub fn get_snapshot_history(&self) -> Vec<Map> {
self.build_data.history.clone()
}
pub fn get_spawn_list(&self) -> &Vec<(usize, String)> {
&self.build_data.spawn_list
}
}
pub trait InitialMapBuilder {

View File

@ -554,12 +554,6 @@ pub fn player_input(gs: &mut State, ctx: &mut BTerm) -> RunState {
VirtualKeyCode::D => return RunState::ShowDropItem,
VirtualKeyCode::R => return RunState::ShowRemoveItem,
// Save and Quit
VirtualKeyCode::Escape => return RunState::SaveGame,
// Cheating!
VirtualKeyCode::Backslash => return RunState::ShowCheatMenu,
// Ranged
VirtualKeyCode::V => {
cycle_target(&mut gs.ecs);
@ -568,6 +562,12 @@ pub fn player_input(gs: &mut State, ctx: &mut BTerm) -> RunState {
}
VirtualKeyCode::F => return fire_on_target(&mut gs.ecs),
// Save and Quit
VirtualKeyCode::Escape => return RunState::SaveGame,
// Cheating!
VirtualKeyCode::Backslash => return RunState::ShowCheatMenu,
_ => return RunState::AwaitingInput,
},
}