mindustry logic execution, map- and schematic- parsing and rendering
add square feature
bendn 2024-08-06
parent c9b1a1c · commit 2c491d8
-rw-r--r--mindus/Cargo.toml15
-rw-r--r--mindus/src/data/renderer.rs19
2 files changed, 23 insertions, 11 deletions
diff --git a/mindus/Cargo.toml b/mindus/Cargo.toml
index 782829b..cf78cfc 100644
--- a/mindus/Cargo.toml
+++ b/mindus/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "mindus"
-version = "5.0.26"
+version = "5.0.27"
edition = "2021"
description = "A library for working with mindustry data formats (eg schematics and maps) (fork of plandustry)"
authors = [
@@ -24,14 +24,23 @@ thiserror = "1.0"
bobbin-bits = "0.1"
enum_dispatch = "0.3"
phf = { version = "0.11", features = ["macros"] }
-fimg = { version = "0.4.33", features = ["scale", "blur", "save"], default-features = false }
+fimg = { version = "0.4.33", features = [
+ "scale",
+ "blur",
+ "save",
+], default-features = false }
[features]
bin = ["fimg/save"]
+square = []
default = ["bin"]
[build-dependencies]
-fimg = { version = "0.4.33", features = ["scale", "blur", "save"], default-features = false }
+fimg = { version = "0.4.33", features = [
+ "scale",
+ "blur",
+ "save",
+], default-features = false }
walkdir = "2"
[[bin]]
diff --git a/mindus/src/data/renderer.rs b/mindus/src/data/renderer.rs
index c2f9eef..b0d7a38 100644
--- a/mindus/src/data/renderer.rs
+++ b/mindus/src/data/renderer.rs
@@ -119,16 +119,19 @@ impl Renderable for Schematic {
};
// fill background
// SAFETY: metal-floor is scalexscale, the output is a multiple of scale
+ let x_fac = cfg!(feature = "square") as u32
+ * self.height.checked_sub(self.width).unwrap_or(0) as u32
+ + 2;
+ let y_fac = cfg!(feature = "square") as u32
+ * self.width.checked_sub(self.height).unwrap_or(0) as u32
+ + 2;
let mut bg = unsafe {
load!("metal-floor", scale).borrow().repeated(
- scale * (self.width + 2) as u32,
- scale * (self.height + 2) as u32,
+ scale * (self.width + x_fac as usize) as u32,
+ scale * (self.height + y_fac as usize) as u32,
)
};
- let mut canvas = Image::alloc(
- scale * (self.width + 2) as u32,
- scale * (self.height + 2) as u32,
- );
+ let mut canvas = Image::alloc(bg.width(), bg.height());
for (GridPos(x, y), tile) in self.block_iter() {
let ctx = tile.block.wants_context().then(|| {
let pctx = PositionContext {
@@ -152,8 +155,8 @@ impl Renderable for Schematic {
scale,
)
.borrow(),
- scale * (x + 1),
- scale * (y + 1),
+ scale * (x + x_fac / 2),
+ scale * (y + y_fac / 2),
)
};
}