mindustry logic execution, map- and schematic- parsing and rendering
Diffstat (limited to 'src/block/mod.rs')
| -rw-r--r-- | src/block/mod.rs | 55 |
1 files changed, 41 insertions, 14 deletions
diff --git a/src/block/mod.rs b/src/block/mod.rs index ca20821..642518b 100644 --- a/src/block/mod.rs +++ b/src/block/mod.rs @@ -1,8 +1,8 @@ //! deal with blocks. //! -//! categorized as mindustry categorizes them in its assets folder, for easy drawing -//! with the exception of sandbox. -use image::RgbaImage; +//! categorized as mindustry categorizes them in its assets folder, for easy drawing. +//! +//! with the exception of sandbox, that is. use std::any::Any; use std::borrow::Cow; use std::error::Error; @@ -10,8 +10,10 @@ use std::fmt; use crate::access::BoxAccess; use crate::data::dynamic::{DynData, DynType}; -use crate::data::GridPos; -use crate::item::storage::Storage as ItemStorage; +use crate::data::map::EntityMapping; +use crate::data::renderer::ImageHolder; +use crate::data::{DataRead, GridPos, ReadError as DataReadError}; +use crate::item::storage::ItemStorage; use crate::registry::RegistryEntry; pub mod campaign; @@ -19,6 +21,7 @@ pub mod content; pub mod defense; pub mod distribution; pub mod drills; +pub mod environment; pub mod liquid; pub mod logic; pub mod payload; @@ -50,9 +53,21 @@ pub trait BlockLogic { fn serialize_state(&self, state: &State) -> Result<DynData, SerializeError>; - fn draw(&self, _category: &str, _name: &str, _state: Option<&State>) -> Option<RgbaImage> { + fn draw(&self, _category: &str, _name: &str, _state: Option<&State>) -> Option<ImageHolder> { None } + // TODO: use data + #[allow(unused_variables)] + fn read( + &self, + category: &str, + name: &str, + reg: &BlockRegistry, + mapping: &EntityMapping, + buff: &mut DataRead, + ) -> Result<(), DataReadError> { + Ok(()) + } } // i wish i could derive @@ -66,7 +81,7 @@ macro_rules! impl_block { self.symmetric } - fn create_build_cost(&self) -> Option<$crate::item::storage::Storage> { + fn create_build_cost(&self) -> Option<$crate::item::storage::ItemStorage> { if self.build_cost.is_empty() { None } else { @@ -213,16 +228,16 @@ impl Block { } /// draw this block, with this state - pub fn image(&self, state: Option<&State>) -> RgbaImage { - if let Some(p) = self - .logic - .as_ref() - .draw(&self.category, &self.name, state) - { + pub fn image(&self, state: Option<&State>) -> ImageHolder { + if let Some(p) = self.logic.as_ref().draw(&self.category, &self.name, state) { return p; } use crate::data::renderer::read; - read(&self.category, &self.name, self.get_size()) + ImageHolder::Own(read(&self.category, &self.name, self.get_size())) + } + + pub fn has_building(&self) -> bool { + &self.category != "environment" } /// size. @@ -270,6 +285,17 @@ impl Block { pub(crate) fn serialize_state(&self, state: &State) -> Result<DynData, SerializeError> { self.logic.serialize_state(state) } + + #[doc(hidden)] + pub fn read( + &self, + buff: &mut DataRead, + reg: &BlockRegistry, + mapping: &EntityMapping, + ) -> Result<(), DataReadError> { + self.logic + .read(&self.category, &self.name, reg, mapping, buff) + } } impl fmt::Debug for Block { @@ -455,4 +481,5 @@ fn register(reg: &mut BlockRegistry<'_>) { campaign::register(reg); logic::register(reg); walls::register(reg); + environment::register(reg); } |