mindustry logic execution, map- and schematic- parsing and rendering
-rw-r--r--mindus/Cargo.toml2
-rw-r--r--mindus/src/block/ratios.rs15
-rw-r--r--mindus/src/data/map.rs16
-rw-r--r--mindus/src/data/schematic.rs3
-rw-r--r--mindus/src/lib.rs1
5 files changed, 28 insertions, 9 deletions
diff --git a/mindus/Cargo.toml b/mindus/Cargo.toml
index 12d0510..ea73d18 100644
--- a/mindus/Cargo.toml
+++ b/mindus/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "mindus"
-version = "5.0.23"
+version = "5.0.24"
edition = "2021"
description = "A library for working with mindustry data formats (eg schematics and maps) (fork of plandustry)"
authors = [
diff --git a/mindus/src/block/ratios.rs b/mindus/src/block/ratios.rs
index d0d3c5b..ef59be8 100644
--- a/mindus/src/block/ratios.rs
+++ b/mindus/src/block/ratios.rs
@@ -20,7 +20,7 @@ macro_rules! ratios {
}}
}
pub use ratios;
-#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum Resource {
Item(crate::item::Type),
Fluid(crate::fluid::Type),
@@ -38,12 +38,23 @@ impl const super::ConstFrom<crate::fluid::Type> for Resource {
}
}
-#[derive(Debug, Clone, PartialEq)]
+#[derive(Debug, Clone)]
pub struct Io {
pub input: Cow<'static, [(Resource, f32)]>,
pub output: Cow<'static, [(Resource, f32)]>,
}
+impl PartialEq for Io {
+ fn eq(&self, other: &Self) -> bool {
+ let sort = |mut x: Vec<_>| {
+ x.sort_by_key(|(x, _)| *x);
+ x
+ };
+ sort(self.input.to_vec()) == sort(other.input.to_vec())
+ && sort(self.output.to_vec()) == sort(other.output.to_vec())
+ }
+}
+
impl Io {
fn none() -> Self {
Self {
diff --git a/mindus/src/data/map.rs b/mindus/src/data/map.rs
index fcbed3f..b103431 100644
--- a/mindus/src/data/map.rs
+++ b/mindus/src/data/map.rs
@@ -651,7 +651,8 @@ impl MapReader {
> {
let len = self.buff.read_u32()? as usize;
let rb4 = self.buff.read;
- let map = move || {
+ let map = #[coroutine]
+ move || {
let w = self.buff.read_u16()?;
let h = self.buff.read_u16()?;
yield ThinMapData::Init {
@@ -773,7 +774,9 @@ impl MapReader {
{
let len = self.buff.read_u32()? as usize;
let rb4 = self.buff.read;
- Ok(move || {
+
+ let c = #[coroutine]
+ move || {
let w = self.buff.read_u16()?;
let h = self.buff.read_u16()?;
yield MapData::Init {
@@ -848,7 +851,8 @@ impl MapReader {
debug_assert!(len >= read, "overread; supposed to read {len}; read {read}");
debug_assert!((len - read) == 0, "supposed to read {len}; read {read}");
Ok(())
- })
+ };
+ Ok(c)
}
pub fn entities(
@@ -860,7 +864,8 @@ impl MapReader {
let len = self.buff.read_u32()? as usize;
let rb4 = self.buff.read;
- Ok(move || {
+ let c = #[coroutine]
+ move || {
for _ in 0..self.buff.read_u16()? {
self.buff.skip(2)?;
let _ = self.buff.read_utf()?;
@@ -890,7 +895,8 @@ impl MapReader {
debug_assert!(len >= read, "overread; supposed to read {len}; read {read}");
debug_assert!((len - read) == 0, "supposed to read {len}; read {read}");
Ok(())
- })
+ };
+ Ok(c)
}
pub fn collect_entities(&mut self) -> Result<Vec<Unit>, ReadError> {
diff --git a/mindus/src/data/schematic.rs b/mindus/src/data/schematic.rs
index 3e4aad8..86c6542 100644
--- a/mindus/src/data/schematic.rs
+++ b/mindus/src/data/schematic.rs
@@ -169,6 +169,7 @@ impl Schematic {
/// Ratios of this schematic.
/// ```
+ /// # #![feature(const_trait_impl, effects)]
/// # use mindus::Schematic;
/// # use mindus::block::ratios::ratios;
/// assert_eq!(Schematic::deserialize_base64("bXNjaAF4nEWMSw7CMAxEh9REVSqx5hKcCLFISxaR0o9Sg8rtSTpFePPkmWfDwTWQyY8B5z75VdE9wzrkuGicJwA2+T6kFeb+aNDtym2MW8i4LJ/sNWo4dje8ksa31zmXuyv+Y4BTgRD2iIi9M+xM7WrUgnoNhYpQESpCxfKLrUo9FsISLX6vKgwhhCVK+wX5/BtM").unwrap().ratios(),
@@ -185,7 +186,7 @@ impl Schematic {
/// create a new schematic, erroring if too big
/// ```
/// # use mindus::Schematic;
- /// assert!(Schematic::try_new(500, 500).is_err() == true);
+ /// assert!(Schematic::try_new(5000, 5000).is_err() == true);
/// ```
pub fn try_new(width: usize, height: usize) -> Result<Self, NewError> {
if width > MAX_DIMENSION {
diff --git a/mindus/src/lib.rs b/mindus/src/lib.rs
index eb3e42a..610704b 100644
--- a/mindus/src/lib.rs
+++ b/mindus/src/lib.rs
@@ -1,5 +1,6 @@
//! crate for dealing with mindustry
#![feature(
+ stmt_expr_attributes,
iter_from_coroutine,
generic_arg_infer,
const_trait_impl,