mindustry logic execution, map- and schematic- parsing and rendering
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use std::env::Args;

use mindus::build_registry;
use mindus::{Schematic, SchematicSerializer};

use crate::print_err;

pub fn main(args: Args) {
    let reg = build_registry();
    let mut ss = SchematicSerializer(&reg);
    let mut first = true;
    let mut need_space = false;
    // process schematics from command line
    for curr in args {
        match ss.deserialize_base64(&curr) {
            Ok(s) => {
                if !first || need_space {
                    println!();
                }
                first = false;
                need_space = true;
                println!("Schematic: {curr}");
                print_schematic(&s);
            }
            // continue processing literals & maybe interactive mode
            Err(e) => {
                if need_space {
                    println!();
                }
                first = false;
                need_space = false;
                print_err!(e, "Could not read schematic");
            }
        }
    }
}

pub fn print_schematic(s: &Schematic) {
    if let Some(name) = s.tags.get("name") {
        if !name.is_empty() {
            println!("Name: {name}");
        }
    }
    if let Some(desc) = s.tags.get("description") {
        if !desc.is_empty() {
            println!("Desc: {desc}");
        }
    }
    if let Some(labels) = s.tags.get("labels") {
        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}");
}