From 73525db8dd5e7678b9483ed16a73adc78b184c80 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 10 Feb 2022 11:18:21 -0500 Subject: [PATCH] Some tweaks to remove some dead code --- README.md | 8 +++++++- src/main.rs | 1 + src/map.rs | 12 +++++++----- src/map_builders.rs | 16 ---------------- src/player.rs | 12 ++++++------ 5 files changed, 21 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index c1e666f..6921b03 100644 --- a/README.md +++ b/README.md @@ -67,4 +67,10 @@ 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. \ No newline at end of file +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` \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index d5f1baf..ed55bb9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -59,6 +59,7 @@ macro_rules! register { } } +/// Register the Component Structs with Specs fn register_components(state: &mut State) { register!( state <- diff --git a/src/map.rs b/src/map.rs index cd48d3f..1319046 100644 --- a/src/map.rs +++ b/src/map.rs @@ -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 diff --git a/src/map_builders.rs b/src/map_builders.rs index 62e3f65..f449f5d 100644 --- a/src/map_builders.rs +++ b/src/map_builders.rs @@ -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 { - self.build_data.starting_position - } - - pub fn get_snapshot_history(&self) -> Vec { - self.build_data.history.clone() - } - - pub fn get_spawn_list(&self) -> &Vec<(usize, String)> { - &self.build_data.spawn_list - } } pub trait InitialMapBuilder { diff --git a/src/player.rs b/src/player.rs index 8a0e553..fa04071 100644 --- a/src/player.rs +++ b/src/player.rs @@ -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, }, }