diff options
| author | Arne Dußin | 2020-11-01 17:44:51 +0100 |
|---|---|---|
| committer | Arne Dußin | 2020-11-01 17:44:51 +0100 |
| commit | 2db23f3213ff1bb2fe0cf005e922536da7ff5cd7 (patch) | |
| tree | 912b6d829ea8c8c28a2ed257e70e0fd6814bef50 /src/main.rs | |
| parent | a6be14ada463cb5a3fc0a810b8b341093abbb68d (diff) | |
| download | graf_karto-2db23f3213ff1bb2fe0cf005e922536da7ff5cd7.tar.gz graf_karto-2db23f3213ff1bb2fe0cf005e922536da7ff5cd7.zip | |
Refactor a major part of the project
In order to be able to save and load the map, a major rework of the code
seemed necessary, since Vector2 and Rectangle of raylib do not implement
serialize, and it seems cleanest to use the serialize/deserialize traits
of serde, to save for instance to RON. ToolShed was renamed to Editor,
since it should better show, that it does quite a bit more than harbour
tools. The map data is now centrally saved in the editor, instead of
decentralised in the tool structs.
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs index 723a1fd..9ba63e0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,17 +1,18 @@ +pub mod editor; pub mod grid; +pub mod map_data; pub mod math; pub mod tool; pub mod transform; -pub use transform::Transform; - +use editor::Editor; use raylib::prelude::*; -use tool::{Tool, ToolShed}; +use transform::Transform; fn main() { let (mut rl, thread) = raylib::init().resizable().title("Hello there!").build(); - let mut tool_shed = ToolShed::new(); + let mut editor = Editor::new(); let mut transform = Transform::new(); let mut last_mouse_pos = rl.get_mouse_position(); @@ -21,7 +22,7 @@ fn main() { // Move the canvas together with the mouse if rl.is_mouse_button_down(MouseButton::MOUSE_MIDDLE_BUTTON) { - transform.move_by_px(rl.get_mouse_position() - last_mouse_pos); + transform.move_by_px((rl.get_mouse_position() - last_mouse_pos).into()); } // Handle scrolling of the canvas @@ -31,7 +32,7 @@ fn main() { transform.try_zoom_out(); } - tool_shed.update(&rl, &transform); + editor.update(&rl, &transform); // Update the last mouse position last_mouse_pos = rl.get_mouse_position(); @@ -42,7 +43,7 @@ fn main() { d.clear_background(Color::BLACK); grid::draw_grid(&mut d, screen_width, screen_height, &transform); - tool_shed.draw_tools(&mut d, &transform); + editor.draw_tools(&mut d, &transform); } } } |
