aboutsummaryrefslogtreecommitdiff
path: root/src/editor.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/editor.rs')
-rw-r--r--src/editor.rs48
1 files changed, 38 insertions, 10 deletions
diff --git a/src/editor.rs b/src/editor.rs
index bbe4f60..e6a2dcb 100644
--- a/src/editor.rs
+++ b/src/editor.rs
@@ -1,12 +1,12 @@
use crate::button::{Button, MouseButton};
use crate::config::Config;
+use crate::grid::{snap_to_grid, SNAP_SIZE};
use crate::map::Map;
use crate::tool::*;
use crate::transform::Transform;
use raylib::core::drawing::RaylibDrawHandle;
use raylib::{RaylibHandle, RaylibThread};
use std::collections::HashMap;
-use crate::grid::{snap_to_grid, SNAP_SIZE};
pub struct Editor {
map: Map,
@@ -14,7 +14,7 @@ pub struct Editor {
/// itself.
tools: HashMap<ToolType, (Box<dyn Tool>, Button)>,
active: ToolType,
- config: Config
+ config: Config,
}
impl Editor {
@@ -56,6 +56,13 @@ impl Editor {
config.tool_activation_keys.deletion,
),
);
+ tools.insert(
+ ToolType::SelectionTool,
+ (
+ Box::new(SelectionTool::new()),
+ config.tool_activation_keys.selection,
+ ),
+ );
assert_eq!(ToolType::NumTools as usize, tools.len());
@@ -63,7 +70,7 @@ impl Editor {
map,
tools,
active: ToolType::RectRoomTool,
- config
+ config,
}
}
@@ -123,23 +130,44 @@ impl Editor {
active_tool.update(&self.map, &snapped_mouse_pos);
// Handle common keybindings many of the tools have.
- if self.config.tool_general_keys.place_single.is_pressed(rl, mouse_blocked) {
+ if self
+ .config
+ .tool_general_keys
+ .place_single
+ .is_pressed(rl, mouse_blocked)
+ {
active_tool.place_single(&mut self.map, &snapped_mouse_pos);
}
- if self.config.tool_general_keys.finish.is_pressed(rl, mouse_blocked) {
+ if self
+ .config
+ .tool_general_keys
+ .finish
+ .is_pressed(rl, mouse_blocked)
+ {
active_tool.finish(&mut self.map);
}
- if self.config.tool_general_keys.abort.is_pressed(rl, mouse_blocked) {
+ if self
+ .config
+ .tool_general_keys
+ .abort
+ .is_pressed(rl, mouse_blocked)
+ {
active_tool.abort();
}
// Handle custom keybindings in case the tool has any.
let latest_button = if let Some(keyboard_key) = rl.get_key_pressed() {
Some(Button::Keyboard(keyboard_key.into()))
- }
- else {
- let mouse_buttons = [Button::Mouse(MouseButton::Left), Button::Mouse(MouseButton::Middle), Button::Mouse(MouseButton::Right)];
- mouse_buttons.iter().find(|button| button.is_pressed(rl, mouse_blocked)).copied()
+ } else {
+ let mouse_buttons = [
+ Button::Mouse(MouseButton::Left),
+ Button::Mouse(MouseButton::Middle),
+ Button::Mouse(MouseButton::Right),
+ ];
+ mouse_buttons
+ .iter()
+ .find(|button| button.is_pressed(rl, mouse_blocked))
+ .copied()
};
if let Some(latest_button) = latest_button {