From a5d3819114a76a7e76aa7144ce3216c3da803ce4 Mon Sep 17 00:00:00 2001 From: hal8174 Date: Sat, 5 Apr 2025 22:07:59 +0200 Subject: [PATCH] Make multistation bin cmd interface useable --- .../src/bin/multistation.rs | 112 ++++++------------ .../src/multistation.rs | 1 + factorio-blueprint/src/abstraction/serde.rs | 2 +- 3 files changed, 41 insertions(+), 74 deletions(-) diff --git a/factorio-blueprint-generator/src/bin/multistation.rs b/factorio-blueprint-generator/src/bin/multistation.rs index 75ec895..72fae24 100644 --- a/factorio-blueprint-generator/src/bin/multistation.rs +++ b/factorio-blueprint-generator/src/bin/multistation.rs @@ -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: -[lu][nfet] + stations: Vec, } 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::>(); + + 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())); } diff --git a/factorio-blueprint-generator/src/multistation.rs b/factorio-blueprint-generator/src/multistation.rs index 11e03ab..82101d6 100644 --- a/factorio-blueprint-generator/src/multistation.rs +++ b/factorio-blueprint-generator/src/multistation.rs @@ -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, diff --git a/factorio-blueprint/src/abstraction/serde.rs b/factorio-blueprint/src/abstraction/serde.rs index af5e28a..cbb87a2 100644 --- a/factorio-blueprint/src/abstraction/serde.rs +++ b/factorio-blueprint/src/abstraction/serde.rs @@ -1,7 +1,7 @@ use factorio_core::prelude::Position; use serde::{ Serialize, - ser::{SerializeMap, SerializeSeq, SerializeTuple}, + ser::{SerializeMap, SerializeSeq}, }; use super::{Blueprint, Entity, EntityKey};