diff options
Diffstat (limited to 'src/tool/wall_tool.rs')
| -rw-r--r-- | src/tool/wall_tool.rs | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/tool/wall_tool.rs b/src/tool/wall_tool.rs index 5eda8e0..31a3770 100644 --- a/src/tool/wall_tool.rs +++ b/src/tool/wall_tool.rs @@ -1,4 +1,6 @@ use super::Tool; +use crate::button::Button; +use crate::config::{ToolKeybindings, WallToolKeybindings}; use crate::grid::snap_to_grid; use crate::map_data::MapData; use crate::math::Vec2; @@ -8,12 +10,14 @@ use raylib::ffi::{Color, MouseButton, Vector2}; use raylib::RaylibHandle; pub struct WallTool { + keybindings: WallToolKeybindings, unfinished_wall: Option<(Vec2<f32>, Vec2<f32>)>, } impl WallTool { - pub fn new() -> Self { + pub fn new(keybindings: WallToolKeybindings) -> Self { Self { + keybindings, unfinished_wall: None, } } @@ -26,17 +30,16 @@ impl Tool for WallTool { *pos2 = snap_to_grid(mouse_pos_m, 0.5); } - if rl.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON) { - if let Some((pos1, pos2)) = self.unfinished_wall { - map_data.walls_mut().push((pos1, pos2)); - self.unfinished_wall = Some((pos2, pos2)); - } else { - let snapped_mouse_pos = snap_to_grid(mouse_pos_m, 0.5); - self.unfinished_wall = Some((snapped_mouse_pos, snapped_mouse_pos)) - } + if self.keybindings.finish_segment.is_pressed(rl) && self.unfinished_wall.is_some() { + let (pos1, pos2) = self.unfinished_wall.unwrap(); + map_data.walls_mut().push((pos1, pos2)); + self.unfinished_wall = Some((pos2, pos2)); + } else if self.keybindings.start_wall.is_pressed(rl) { + let snapped_mouse_pos = snap_to_grid(mouse_pos_m, 0.5); + self.unfinished_wall = Some((snapped_mouse_pos, snapped_mouse_pos)) } - if rl.is_mouse_button_pressed(MouseButton::MOUSE_RIGHT_BUTTON) { + if self.keybindings.abort_segment.is_pressed(rl) { self.unfinished_wall = None; } } @@ -74,4 +77,8 @@ impl Tool for WallTool { ); } } + + fn activation_key(&self) -> Button { + self.keybindings.activation_key() + } } |
