mindustry logic execution, map- and schematic- parsing and rendering
-rw-r--r--mindus/Cargo.toml2
-rw-r--r--mindus/src/data/renderer.rs23
-rw-r--r--mindus/src/exe/draw.rs26
-rw-r--r--mindus/src/exe/map.rs8
-rw-r--r--mindus/src/exe/mod.rs1
5 files changed, 41 insertions, 19 deletions
diff --git a/mindus/Cargo.toml b/mindus/Cargo.toml
index 2b91fe6..7d0aa9c 100644
--- a/mindus/Cargo.toml
+++ b/mindus/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "mindus"
-version = "5.0.5"
+version = "5.0.6"
edition = "2021"
description = "A library for working with mindustry data formats (eg schematics and maps) (fork of plandustry)"
authors = [
diff --git a/mindus/src/data/renderer.rs b/mindus/src/data/renderer.rs
index 5096eff..32e07b4 100644
--- a/mindus/src/data/renderer.rs
+++ b/mindus/src/data/renderer.rs
@@ -136,15 +136,20 @@ impl Renderable for Schematic {
)
};
}
- canvas.as_mut().shadow();
- for x in 0..canvas.width() {
- for y in 0..canvas.height() {
- // canvas has a shadow
- let p2 = unsafe { canvas.pixel(x, y) };
- let p = unsafe { bg.pixel_mut(x, y) };
- let mut p3 = [p[0], p[1], p[2], 255];
- crate::utils::image::blend(&mut p3, p2);
- p.copy_from_slice(&p3[..3]);
+ if self.width * self.height > 2250 {
+ unsafe { bg.overlay(&canvas) };
+ } else {
+ canvas.as_mut().shadow();
+ // this is a slow imageops::overlay style overlay (blending etc)
+ for x in 0..canvas.width() {
+ for y in 0..canvas.height() {
+ // canvas has a shadow
+ let p2 = unsafe { canvas.pixel(x, y) };
+ let p = unsafe { bg.pixel_mut(x, y) };
+ let mut p3 = [p[0], p[1], p[2], 255];
+ crate::utils::image::blend(&mut p3, p2);
+ p.copy_from_slice(&p3[..3]);
+ }
}
}
bg
diff --git a/mindus/src/exe/draw.rs b/mindus/src/exe/draw.rs
index c23703f..1faa4d5 100644
--- a/mindus/src/exe/draw.rs
+++ b/mindus/src/exe/draw.rs
@@ -1,5 +1,5 @@
-use mindus::Renderable;
-use mindus::Schematic;
+use mindus::data::DataRead;
+use mindus::{Renderable, Schematic, Serializable};
use std::env::Args;
use crate::print_err;
@@ -7,9 +7,27 @@ use crate::print_err;
pub fn main(args: Args) {
// process schematics from command line
for curr in args {
- match Schematic::deserialize_base64(&curr) {
+ match if curr.ends_with(".msch") {
+ let Ok(v) = std::fs::read(curr) else {
+ panic!("no file found");
+ };
+ Schematic::deserialize(&mut DataRead::new(&v))
+ } else {
+ match Schematic::deserialize_base64(&curr) {
+ Err(mindus::data::schematic::R64Error::Base64(e)) => {
+ print_err!(e, "Could not read schematic");
+ continue;
+ }
+ Err(mindus::data::schematic::R64Error::Content(e)) => Err(e),
+ Ok(o) => Ok(o),
+ }
+ } {
Ok(s) => {
- s.render().save("x.png");
+ let i = s.render();
+ if let Ok(v) = std::env::var("SAVE") && v == "1" {
+ i.save("x.png");
+ continue;
+ }
}
// continue processing literals & maybe interactive mode
Err(e) => {
diff --git a/mindus/src/exe/map.rs b/mindus/src/exe/map.rs
index 9c879ee..3cec055 100644
--- a/mindus/src/exe/map.rs
+++ b/mindus/src/exe/map.rs
@@ -20,11 +20,9 @@ pub fn main(args: Args) {
Err(e) => print_err!(e, "fail"),
Ok(m) => {
let deser_took = starting_deser.elapsed();
- if let Ok(v) = std::env::var("SAVE") {
- if v == "1" {
- m.render().save("x.png");
- continue;
- }
+ if let Ok(v) = std::env::var("SAVE") && v == "1" {
+ m.render().save("x.png");
+ continue;
}
let starting_render = Instant::now();
for _ in 0..runs {
diff --git a/mindus/src/exe/mod.rs b/mindus/src/exe/mod.rs
index aa49f29..d699f5a 100644
--- a/mindus/src/exe/mod.rs
+++ b/mindus/src/exe/mod.rs
@@ -1,3 +1,4 @@
+#![feature(let_chains)]
mod draw;
mod map;