diff options
Diffstat (limited to 'src/editor.rs')
| -rw-r--r-- | src/editor.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/editor.rs b/src/editor.rs index 87a8db4..d541fb6 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -1,3 +1,10 @@ +//! Element creation base +//! +//! The actual editor environment sits here. This especially means all tools that require low-level +//! access to the data of items currently being created. While this may be subject to change, there is +//! currently a difference between things that are being created (inside the editor) and things that +//! are part of the environment (the map). + use crate::button::{Button, MouseButton}; use crate::config::Config; use crate::grid::{snap_to_grid, SNAP_SIZE}; @@ -8,6 +15,7 @@ use raylib::core::drawing::RaylibDrawHandle; use raylib::{RaylibHandle, RaylibThread}; use std::collections::HashMap; +/// The editor containing all tools and currently the map of the stuff that has been created. pub struct Editor { map: Map, /// HashMap that matches the ToolType with its proper activation key and of course the tool @@ -18,6 +26,8 @@ pub struct Editor { } impl Editor { + /// Create a new editor with all tools necessary. There should be only one editor per program + /// instance. pub fn new(rl: &mut RaylibHandle, rlt: &RaylibThread, config: Config) -> Self { let map = Map::new(rl, rlt); @@ -74,7 +84,8 @@ impl Editor { } } - /// Get the currently active tool. + /// Get the currently active tool. Since the every tool exists only once, it is entirely indexable + /// by its type, which is what is actually returned. pub fn active(&self) -> ToolType { self.active } @@ -93,6 +104,8 @@ impl Editor { } } + /// Update the internal editor data where necessary and handle selecting different tools, aswell + /// as updating the currently active tool. Should be called once every frame. pub fn update(&mut self, rl: &mut RaylibHandle, transform: &Transform, mouse_blocked: bool) { // Handle keybindings for tool change for (&tool_type, (_, activation_key)) in self.tools.iter() { @@ -175,15 +188,19 @@ impl Editor { } } + /// Draw all tools and in case of the active tool also what is currently being edited by it, if + /// that exists. pub fn draw_tools(&self, rld: &mut RaylibDrawHandle, transform: &Transform) { for (tool, _) in self.tools.values() { tool.draw(rld, transform); } } + /// Get the world containing all finished elements. pub fn map(&self) -> &Map { &self.map } + /// Get the world containing all finished elements mutably. pub fn map_mut(&mut self) -> &mut Map { &mut self.map } |
