Make multistation bin cmd interface useable
This commit is contained in:
parent
5be9f81205
commit
a5d3819114
3 changed files with 41 additions and 74 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use clap::Parser;
|
||||
use clap::{Parser, ValueEnum};
|
||||
use factorio_blueprint::{BlueprintString, encode};
|
||||
use factorio_blueprint_generator::multistation::{StationSpec, multistation};
|
||||
use factorio_core::beltoptions::Beltspeed;
|
||||
|
|
@ -8,83 +8,49 @@ use factorio_core::visualize::Visualize;
|
|||
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: Vec<_> = [false, true]
|
||||
.into_iter()
|
||||
.flat_map(|load| {
|
||||
[
|
||||
Beltspeed::Normal,
|
||||
Beltspeed::Fast,
|
||||
Beltspeed::Express,
|
||||
Beltspeed::Turbo,
|
||||
]
|
||||
.into_iter()
|
||||
.flat_map(move |beltspeed| {
|
||||
(0..2).flat_map(move |i| {
|
||||
(0..=i).map(move |j| StationSpec {
|
||||
locomotives: 1,
|
||||
wagons: 1 << i,
|
||||
load,
|
||||
beltspeed,
|
||||
lanes: 1 << j,
|
||||
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();
|
||||
let mut b = multistation(
|
||||
&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;
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
dbg!(&stations);
|
||||
|
||||
let mut b = multistation(&stations, args.stacker_size).0;
|
||||
|
||||
b.connect_power_networks();
|
||||
|
||||
|
|
@ -95,5 +61,5 @@ fn main() {
|
|||
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()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ use factorio_blueprint::abstraction::{
|
|||
};
|
||||
use factorio_core::{beltoptions::Beltspeed, prelude::*};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct StationSpec {
|
||||
pub locomotives: usize,
|
||||
pub wagons: usize,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use factorio_core::prelude::Position;
|
||||
use serde::{
|
||||
Serialize,
|
||||
ser::{SerializeMap, SerializeSeq, SerializeTuple},
|
||||
ser::{SerializeMap, SerializeSeq},
|
||||
};
|
||||
|
||||
use super::{Blueprint, Entity, EntityKey};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue