mindustry logic execution, map- and schematic- parsing and rendering
Diffstat (limited to 'src/block/mod.rs')
-rw-r--r--src/block/mod.rs20
1 files changed, 8 insertions, 12 deletions
diff --git a/src/block/mod.rs b/src/block/mod.rs
index 5e3bd50..518e059 100644
--- a/src/block/mod.rs
+++ b/src/block/mod.rs
@@ -13,7 +13,6 @@ use crate::data::{self, renderer::*, CompressError};
use crate::data::{DataRead, GridPos, ReadError as DataReadError};
use crate::item::storage::ItemStorage;
use crate::registry::RegistryEntry;
-use crate::utils::Lock;
macro_rules! mods {
($($mod:ident)*) => {
@@ -151,7 +150,7 @@ stater! {
String(String),
Item(Option<crate::item::Type>),
Fluid(Option<crate::fluid::Type>),
- Image(image::RgbImage),
+ Image(Image<Vec<u8>, 1>),
Point(Option<(i32, i32)>),
Bool(bool),
Processor(logic::ProcessorState),
@@ -205,7 +204,7 @@ pub trait BlockLogic {
context: Option<&RenderingContext>,
rot: Rotation,
scale: Scale,
- ) -> ImageHolder {
+ ) -> ImageHolder<4> {
unimplemented!("{name}")
}
@@ -304,7 +303,7 @@ impl SerializeError {
/// a block. put it in stuff!
pub struct Block {
- image: Option<[&'static Lock<RgbaImage>; 3]>,
+ image: Option<[Image<&'static [u8], 4>; 3]>,
name: &'static str,
logic: BlockLogicEnum,
}
@@ -321,7 +320,7 @@ impl Block {
pub(crate) const fn new(
name: &'static str,
logic: BlockLogicEnum,
- image: Option<[&'static Lock<RgbaImage>; 3]>,
+ image: Option<[Image<&'static [u8], 4>; 3]>,
) -> Self {
Self { image, name, logic }
}
@@ -342,19 +341,16 @@ impl Block {
}
/// draw this block, with this state
- /// # Safety
- ///
- /// UB if called before [`warmup`](crate::warmup)
#[must_use]
- pub unsafe fn image(
+ pub fn image(
&self,
state: Option<&State>,
context: Option<&RenderingContext>,
rot: Rotation,
scale: Scale,
- ) -> ImageHolder {
- if let Some(imgs) = self.image {
- return ImageHolder::from(Lock::get(imgs[scale as usize]));
+ ) -> ImageHolder<4> {
+ if let Some(imgs) = &self.image {
+ return ImageHolder::from((imgs[scale as usize]).copy());
}
self.logic.draw(self.name, state, context, rot, scale)
}