//! Main map editor module. //! //! The entry point is responsible for maintaining the lifetime of the editor //! and human interactions with it, but is otherwise not permitted to directly //! edit it. pub mod block; pub mod state; use crate::durandal::image::*; use super::{color, draw::*}; impl MapEditor { /// Opens the editor with a new empty map. #[inline] pub fn open_new(&mut self) { *self = MapEditor::Opened(state::OpenMap::default()); } /// Draws the screen for this editor state. pub fn draw(&self, d: &mut D, im: &I) where D: DrawArea, I: CacheImage { let dw = d.w(); let dh = d.h(); let iw = im.w(); let ih = im.h(); match self { MapEditor::Closed => { let tx_top = "Map Required To Proceed"; let tx_bot = "CAS.qterm//CyberAcme Systems Inc."; d.clear(Color16::new(0, 0, 0)); d.image((dw / 2 - iw / 2, dh / 2 - ih / 2), im); d.rect(Rect{x: 0, y: 0, w: dw, h: 18}, color::DARK_RED); d.text((4, 14), tx_top, color::RED); d.rect(Rect{x: 0, y: dh - 18, w: dw, h: 18}, color::DARK_RED); d.text((4, dh - 4), tx_bot, color::RED); } MapEditor::Opened(st) => { let text = &format!("tool: {:?}", st.tool); d.clear(Color16::new(0, 0, 0)); d.text((dw/2, dh/2), text, color::RED); } } } /// Returns `true` if `self` is closed. #[inline] pub fn is_closed(&self) -> bool { match self { MapEditor::Closed => true, MapEditor::Opened(_) => false, } } /// Returns `true` if `self` is opened. #[inline] pub fn is_opened(&self) -> bool { match self { MapEditor::Closed => false, MapEditor::Opened(_) => true, } } } impl Default for MapEditor { #[inline] fn default() -> Self {MapEditor::Closed} } /// An entire map editor, which may be opened or closed. pub enum MapEditor { Closed, Opened(state::OpenMap), } // EOF