mindustry logic execution, map- and schematic- parsing and rendering
-rw-r--r--src/data/schematic.rs16
-rw-r--r--src/exe/print.rs9
2 files changed, 25 insertions, 0 deletions
diff --git a/src/data/schematic.rs b/src/data/schematic.rs
index ea0d335..0b9f9a0 100644
--- a/src/data/schematic.rs
+++ b/src/data/schematic.rs
@@ -12,6 +12,7 @@ use crate::block::{self, Block, BlockRegistry, Rotation};
use crate::data::{self, DataRead, DataWrite, GridPos, Serializer};
use crate::data::base64;
use crate::data::dynamic::{self, DynData, DynSerializer};
+use crate::item::storage::Storage as ItemStorage;
use crate::registry::RegistryEntry;
pub const MAX_DIMENSION: u16 = 128;
@@ -434,6 +435,21 @@ impl<'l> Schematic<'l>
{
self.blocks.iter()
}
+
+ pub fn compute_total_cost(&self) -> (ItemStorage, bool)
+ {
+ let mut cost = ItemStorage::new();
+ let mut sandbox = false;
+ for &Placement{block, ..} in self.blocks.iter()
+ {
+ if let Some(curr) = block.get_build_cost()
+ {
+ cost.add_all(curr, u32::MAX);
+ }
+ else {sandbox = true;}
+ }
+ (cost, sandbox)
+ }
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
diff --git a/src/exe/print.rs b/src/exe/print.rs
index 1fb4801..1cafc56 100644
--- a/src/exe/print.rs
+++ b/src/exe/print.rs
@@ -158,5 +158,14 @@ fn print_schematic(s: &Schematic)
{
if !labels.is_empty() && labels != "[]" {println!("Tags: {:?}", labels);}
}
+ let (cost, sandbox) = s.compute_total_cost();
+ if !cost.is_empty()
+ {
+ println!("Build cost: {cost}{}", if sandbox {" (Sandbox only)"} else {""});
+ }
+ else if sandbox
+ {
+ println!("Can only be built in the Sandbox");
+ }
println!("\n{s}");
}