mindustry logic execution, map- and schematic- parsing and rendering
Pass block position to config decode function
KosmosPrime 2023-01-13
parent 34a4c31 · commit b39e4a7
-rw-r--r--src/block/logic.rs8
-rw-r--r--src/block/mod.rs7
-rw-r--r--src/block/power.rs3
-rw-r--r--src/block/simple.rs47
-rw-r--r--src/data/schematic.rs2
5 files changed, 31 insertions, 36 deletions
diff --git a/src/block/logic.rs b/src/block/logic.rs
index d426970..e6338a6 100644
--- a/src/block/logic.rs
+++ b/src/block/logic.rs
@@ -8,7 +8,7 @@ use flate2::{Compress, CompressError, Compression, Decompress, DecompressError,
use crate::block::{BlockLogic, DeserializeError, make_register, SerializeError};
use crate::block::simple::{SimpleBlock, state_impl};
-use crate::data::{self, DataRead, DataWrite};
+use crate::data::{self, DataRead, DataWrite, GridPos};
use crate::data::dynamic::{DynData, DynType};
make_register!
@@ -43,7 +43,7 @@ impl BlockLogic for MessageLogic
true
}
- fn data_from_i32(&self, _: i32) -> DynData
+ fn data_from_i32(&self, _: i32, _: GridPos) -> DynData
{
DynData::Empty
}
@@ -88,7 +88,7 @@ impl BlockLogic for SwitchLogic
true
}
- fn data_from_i32(&self, _: i32) -> DynData
+ fn data_from_i32(&self, _: i32, _: GridPos) -> DynData
{
DynData::Empty
}
@@ -136,7 +136,7 @@ impl BlockLogic for ProcessorLogic
true
}
- fn data_from_i32(&self, _: i32) -> DynData
+ fn data_from_i32(&self, _: i32, _: GridPos) -> DynData
{
DynData::Empty
}
diff --git a/src/block/mod.rs b/src/block/mod.rs
index 82ca0a0..2566d08 100644
--- a/src/block/mod.rs
+++ b/src/block/mod.rs
@@ -6,6 +6,7 @@ use std::error::Error;
use std::fmt;
use crate::access::BoxAccess;
+use crate::data::GridPos;
use crate::data::dynamic::{DynData, DynType};
pub mod base;
@@ -26,7 +27,7 @@ pub trait BlockLogic
fn is_symmetric(&self) -> bool;
- fn data_from_i32(&self, config: i32) -> DynData;
+ fn data_from_i32(&self, config: i32, pos: GridPos) -> DynData;
fn deserialize_state(&self, data: DynData) -> Result<Option<Box<dyn Any>>, DeserializeError>;
@@ -146,9 +147,9 @@ impl Block
self.logic.is_symmetric()
}
- pub fn data_from_i32(&self, config: i32) -> DynData
+ pub fn data_from_i32(&self, config: i32, pos: GridPos) -> DynData
{
- self.logic.data_from_i32(config)
+ self.logic.data_from_i32(config, pos)
}
pub fn deserialize_state(&self, data: DynData) -> Result<Option<Box<dyn Any>>, DeserializeError>
diff --git a/src/block/power.rs b/src/block/power.rs
index 1b4d2ff..aa09633 100644
--- a/src/block/power.rs
+++ b/src/block/power.rs
@@ -4,6 +4,7 @@ use std::fmt;
use crate::block::{BlockLogic, DeserializeError, make_register, SerializeError};
use crate::block::simple::{SimpleBlock, state_impl};
+use crate::data::GridPos;
use crate::data::dynamic::{DynData, DynType};
make_register!
@@ -68,7 +69,7 @@ impl BlockLogic for ConnectorBlock
true
}
- fn data_from_i32(&self, _: i32) -> DynData
+ fn data_from_i32(&self, _: i32, _: GridPos) -> DynData
{
DynData::Empty
}
diff --git a/src/block/simple.rs b/src/block/simple.rs
index b45e2bf..46b0b23 100644
--- a/src/block/simple.rs
+++ b/src/block/simple.rs
@@ -1,34 +1,9 @@
use std::any::{Any, type_name};
use crate::block::{BlockLogic, DeserializeError, SerializeError};
+use crate::data::GridPos;
use crate::data::dynamic::DynData;
-macro_rules!gen_state_empty
-{
- () =>
- {
- fn data_from_i32(&self, _: i32) -> DynData
- {
- DynData::Empty
- }
-
- fn deserialize_state(&self, _: DynData) -> Result<Option<Box<dyn Any>>, DeserializeError>
- {
- Ok(None)
- }
-
- fn clone_state(&self, _: &dyn Any) -> Box<dyn Any>
- {
- panic!("{} has no custom state", type_name::<Self>())
- }
-
- fn serialize_state(&self, _: &dyn Any) -> Result<DynData, SerializeError>
- {
- Ok(DynData::Empty)
- }
- };
-}
-
macro_rules!state_impl
{
($vis:vis $type:ty) =>
@@ -84,5 +59,23 @@ impl BlockLogic for SimpleBlock
self.symmetric
}
- gen_state_empty!();
+ fn data_from_i32(&self, _: i32, _: GridPos) -> DynData
+ {
+ DynData::Empty
+ }
+
+ fn deserialize_state(&self, _: DynData) -> Result<Option<Box<dyn Any>>, DeserializeError>
+ {
+ Ok(None)
+ }
+
+ fn clone_state(&self, _: &dyn Any) -> Box<dyn Any>
+ {
+ panic!("{} has no custom state", type_name::<Self>())
+ }
+
+ fn serialize_state(&self, _: &dyn Any) -> Result<DynData, SerializeError>
+ {
+ Ok(DynData::Empty)
+ }
}
diff --git a/src/data/schematic.rs b/src/data/schematic.rs
index eca03a2..b689fd2 100644
--- a/src/data/schematic.rs
+++ b/src/data/schematic.rs
@@ -794,7 +794,7 @@ impl<'l> Serializer<Schematic> for SchematicSerializer<'l>
let block = block_table[idx as usize];
let config = if version < 1
{
- block.data_from_i32(rbuff.read_i32()?)
+ block.data_from_i32(rbuff.read_i32()?, pos)
}
else {DynSerializer.deserialize(&mut rbuff)?};
let rot = Rotation::from(rbuff.read_u8()?);