factorio_blueprint/factorio-blueprint-generator/src/bin/station.rs

132 lines
4.2 KiB
Rust

use clap::{Parser, Subcommand};
use factorio_blueprint::{BlueprintBook, BlueprintBookEntry, BlueprintString, encode};
use factorio_blueprint_generator::station::basic_station;
use factorio_core::beltoptions::{Beltspeed, Belttype};
#[derive(Parser)]
struct Args {
#[command(subcommand)]
command: Command,
}
#[derive(Subcommand)]
enum Command {
Book,
Single {
load: bool,
locomotives: usize,
length: usize,
outputs: usize,
beltspeed: Beltspeed,
#[arg(default_value = "full")]
belttype: Belttype,
},
}
fn main() {
let args = Args::parse();
match args.command {
Command::Book => {
let mut b = Vec::new();
let layouts = [
(1, 1),
(1, 2),
(1, 4),
(2, 4),
(1, 8),
(2, 8),
(3, 8),
(4, 8),
];
for (i, (locomotives, cargo)) in layouts.into_iter().enumerate() {
for load in [false, true] {
let mut inner_b = Vec::new();
for (j, beltspeed) in [
Beltspeed::Normal,
Beltspeed::Fast,
Beltspeed::Express,
Beltspeed::Turbo,
]
.into_iter()
.enumerate()
{
let mut inner_inner_b = Vec::new();
for (l, o) in (0..=(cargo as u32).ilog2()).enumerate() {
let o = 1 << o;
let blueprint = basic_station(
load,
locomotives,
cargo,
o,
beltspeed,
Belttype::Full,
);
inner_inner_b.push(BlueprintBookEntry::new(
BlueprintString::Blueprint(blueprint.to_blueprint()),
l as u32,
));
}
inner_b.push(BlueprintBookEntry::new(
BlueprintString::BlueprintBook(
BlueprintBook::builder()
.blueprints(inner_inner_b)
.active_index(0)
.label(format!("{:?}", beltspeed))
.build(),
),
j as u32,
));
}
b.push(BlueprintBookEntry::new(
BlueprintString::BlueprintBook(
BlueprintBook::builder()
.blueprints(inner_b)
.active_index(0)
.label(format!("{locomotives}-{cargo}-{}", match load {
true => "load",
false => "unload",
}))
.build(),
),
2 * i as u32 + load as u32,
));
}
}
let b = BlueprintString::BlueprintBook(
BlueprintBook::builder()
.blueprints(b)
.active_index(0)
.build(),
);
println!("{}", encode(&serde_json::to_string(&b).unwrap()));
}
Command::Single {
load,
locomotives,
length,
outputs,
beltspeed,
belttype,
} => {
let b = BlueprintString::Blueprint(
basic_station(load, locomotives, length, outputs, beltspeed, belttype)
.to_blueprint(),
);
// println!("{}", serde_json::to_string_pretty(&b).unwrap());
println!("{}", encode(&serde_json::to_string(&b).unwrap()));
}
}
}