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

65 lines
2 KiB
Rust

use clap::{Parser, ValueEnum};
use factorio_blueprint::{BlueprintString, encode};
use factorio_blueprint_generator::multistation::{StationSpec, multistation};
use factorio_core::beltoptions::Beltspeed;
use factorio_core::visualize::Visualize;
#[derive(Parser)]
struct Args {
#[arg(short, long)]
json: bool,
stacker_size: usize,
/// format: <locomotives>-<wagons>[lu][nfet]<lanes>
stations: Vec<String>,
}
fn main() {
let args = Args::parse();
let stations = args
.stations
.iter()
.map(|os| {
let (locomotives, s) = os.split_once('-').expect("extracting locomotive count");
let (wagons, s) = s.split_at(s.find(['u', 'l']).expect("extracting wagon count"));
let (load, s) = s.split_at_checked(1).expect("extracting direction");
let (beltspeed, lanes) = s.split_at_checked(1).expect("extracting lanes");
StationSpec {
locomotives: locomotives.parse().expect("parsing locomotive count"),
wagons: wagons.parse().expect("parsing wagon count"),
load: match load {
"l" => true,
"u" => false,
_ => panic!("unknown directino {load}"),
},
beltspeed: match beltspeed {
"n" => Beltspeed::Normal,
"f" => Beltspeed::Fast,
"e" => Beltspeed::Express,
"t" => Beltspeed::Turbo,
_ => panic!("unknown belt speed {beltspeed}"),
},
lanes: lanes.parse().expect("parsing lane count"),
}
})
.collect::<Vec<_>>();
dbg!(&stations);
let mut b = multistation(&stations, args.stacker_size).0;
b.connect_power_networks();
b.print_visualization();
let b = BlueprintString::Blueprint(b.to_blueprint());
if args.json {
println!("{}", serde_json::to_string_pretty(&b).unwrap());
}
let _ = std::fs::write("out.bp", encode(&serde_json::to_string(&b).unwrap()));
}