Make multistation bin cmd interface useable

This commit is contained in:
hal8174 2025-04-05 22:07:59 +02:00
parent 5be9f81205
commit a5d3819114
3 changed files with 41 additions and 74 deletions

View file

@ -1,4 +1,4 @@
use clap::Parser; use clap::{Parser, ValueEnum};
use factorio_blueprint::{BlueprintString, encode}; use factorio_blueprint::{BlueprintString, encode};
use factorio_blueprint_generator::multistation::{StationSpec, multistation}; use factorio_blueprint_generator::multistation::{StationSpec, multistation};
use factorio_core::beltoptions::Beltspeed; use factorio_core::beltoptions::Beltspeed;
@ -8,83 +8,49 @@ use factorio_core::visualize::Visualize;
struct Args { struct Args {
#[arg(short, long)] #[arg(short, long)]
json: bool, json: bool,
stacker_size: usize,
/// format: <locomotives>-<wagons>[lu][nfet]<lanes>
stations: Vec<String>,
} }
fn main() { fn main() {
let args = Args::parse(); let args = Args::parse();
let stations: Vec<_> = [false, true] let stations = args
.into_iter() .stations
.flat_map(|load| { .iter()
[ .map(|os| {
Beltspeed::Normal, let (locomotives, s) = os.split_once('-').expect("extracting locomotive count");
Beltspeed::Fast,
Beltspeed::Express, let (wagons, s) = s.split_at(s.find(['u', 'l']).expect("extracting wagon count"));
Beltspeed::Turbo,
] let (load, s) = s.split_at_checked(1).expect("extracting direction");
.into_iter()
.flat_map(move |beltspeed| { let (beltspeed, lanes) = s.split_at_checked(1).expect("extracting lanes");
(0..2).flat_map(move |i| {
(0..=i).map(move |j| StationSpec { StationSpec {
locomotives: 1, locomotives: locomotives.parse().expect("parsing locomotive count"),
wagons: 1 << i, wagons: wagons.parse().expect("parsing wagon count"),
load, load: match load {
beltspeed, "l" => true,
lanes: 1 << j, "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);
.collect();
let mut b = multistation( let mut b = multistation(&stations, args.stacker_size).0;
&stations,
// &[
// StationSpec {
// locomotives: 2,
// wagons: 4,
// load: false,
// beltspeed: Beltspeed::Normal,
// lanes: 4,
// },
// StationSpec {
// locomotives: 3,
// wagons: 8,
// load: false,
// beltspeed: Beltspeed::Turbo,
// lanes: 8,
// },
// StationSpec {
// locomotives: 3,
// wagons: 8,
// load: false,
// beltspeed: Beltspeed::Turbo,
// lanes: 4,
// },
// StationSpec {
// locomotives: 3,
// wagons: 8,
// load: false,
// beltspeed: Beltspeed::Turbo,
// lanes: 2,
// },
// StationSpec {
// locomotives: 3,
// wagons: 8,
// load: false,
// beltspeed: Beltspeed::Turbo,
// lanes: 1,
// },
// StationSpec {
// locomotives: 1,
// wagons: 1,
// load: false,
// beltspeed: Beltspeed::Turbo,
// lanes: 1,
// },
// ],
8,
)
.0;
b.connect_power_networks(); b.connect_power_networks();
@ -95,5 +61,5 @@ fn main() {
println!("{}", serde_json::to_string_pretty(&b).unwrap()); println!("{}", serde_json::to_string_pretty(&b).unwrap());
} }
println!("{}", encode(&serde_json::to_string(&b).unwrap())); let _ = std::fs::write("out.bp", encode(&serde_json::to_string(&b).unwrap()));
} }

View file

@ -4,6 +4,7 @@ use factorio_blueprint::abstraction::{
}; };
use factorio_core::{beltoptions::Beltspeed, prelude::*}; use factorio_core::{beltoptions::Beltspeed, prelude::*};
#[derive(Debug, Clone)]
pub struct StationSpec { pub struct StationSpec {
pub locomotives: usize, pub locomotives: usize,
pub wagons: usize, pub wagons: usize,

View file

@ -1,7 +1,7 @@
use factorio_core::prelude::Position; use factorio_core::prelude::Position;
use serde::{ use serde::{
Serialize, Serialize,
ser::{SerializeMap, SerializeSeq, SerializeTuple}, ser::{SerializeMap, SerializeSeq},
}; };
use super::{Blueprint, Entity, EntityKey}; use super::{Blueprint, Entity, EntityKey};