Refactor StationSpec

This commit is contained in:
hal8174 2025-05-10 22:22:35 +02:00
parent a98e2cfb2b
commit d26449195b
5 changed files with 570 additions and 410 deletions

View file

@ -2,8 +2,8 @@ use clap::Parser;
use factorio_blueprint::abstraction::serde::AbstractBlueprintString;
use factorio_blueprint::abstraction::{ChestType, InserterType, Quality};
use factorio_blueprint::encode;
use factorio_blueprint_generator::multistation::{StationSpec, multistation};
use factorio_blueprint_generator::station::StationBasicSpec;
use factorio_blueprint_generator::multistation::multistation;
use factorio_blueprint_generator::station::StationSpec;
use factorio_core::beltoptions::{Beltspeed, Belttype};
use factorio_core::visualize::Visualize;
@ -38,55 +38,57 @@ fn main() {
.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 (wagons, s) = s.split_at(s.find(['u', 'l', 'e']).expect("extracting wagon count"));
let (load, s) = s.split_at_checked(1).expect("extracting direction");
let (beltspeed, s) = s.split_at_checked(1).expect("extracting lanes");
match load {
"l" | "u" => {
let (beltspeed, s) = s.split_at_checked(1).expect("extracting lanes");
let lanes = s.trim_end_matches(['r', 'l', 's']);
let lanes = s.trim_end_matches(['r', 'l', 's']);
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"),
belttype: if s.contains('l') {
Belttype::Left
} else if s.contains('r') {
Belttype::Right
} else {
Belttype::Full
},
stacked: s.contains('s'),
StationSpec::new_belt(
locomotives.parse().expect("parsing locomotive count"),
wagons.parse().expect("parsing wagon count"),
format!("test"),
match load {
"l" => true,
"u" => false,
_ => panic!("unknown directino {load}"),
},
match beltspeed {
"n" => Beltspeed::Normal,
"f" => Beltspeed::Fast,
"e" => Beltspeed::Express,
"t" => Beltspeed::Turbo,
_ => panic!("unknown belt speed {beltspeed}"),
},
lanes.parse().expect("parsing lane count"),
if s.contains('l') {
Belttype::Left
} else if s.contains('r') {
Belttype::Right
} else {
Belttype::Full
},
s.contains('s'),
)
}
"e" => StationSpec::new_empty(
locomotives.parse().expect("parsing locomotive count"),
wagons.parse().expect("parsing wagon count"),
format!("test"),
s.parse().expect("Unable to parse space"),
),
_ => panic!("unknown station type"),
}
})
.collect::<Vec<_>>();
dbg!(&stations);
let mut b = multistation(
&stations,
args.stacker_size,
&StationBasicSpec {
inserter_type: args.wagon_inserter_type,
inserter_quality: args.wagon_inserter_quality,
chest_type: args.chest_type,
chest_quality: args.chest_quality,
},
)
.0;
let mut b = multistation(&stations, args.stacker_size).0;
b.connect_power_networks();

View file

@ -1,9 +1,6 @@
use clap::{Parser, Subcommand};
use factorio_blueprint::{BlueprintBook, BlueprintBookEntry, BlueprintString, encode};
use factorio_blueprint_generator::{
multistation::StationSpec,
station::{StationBasicSpec, basic_station},
};
use factorio_blueprint_generator::station::{StationSpec, station};
use factorio_core::beltoptions::{Beltspeed, Belttype};
#[derive(Parser)]
@ -65,18 +62,16 @@ fn main() {
for (l, o) in (0..=(cargo as u32).ilog2()).enumerate() {
let o = 1 << o;
let blueprint = basic_station(
&StationSpec {
locomotives,
wagons: cargo,
load,
beltspeed,
lanes: o,
belttype: Belttype::Full,
stacked: false,
},
&factorio_blueprint_generator::station::StationBasicSpec::default(),
);
let blueprint = station(&StationSpec::new_belt(
locomotives,
cargo,
format!("test"),
load,
beltspeed,
o,
Belttype::Full,
false,
));
inner_inner_b.push(BlueprintBookEntry::new(
BlueprintString::Blueprint(blueprint.to_blueprint()),
@ -136,18 +131,16 @@ fn main() {
belttype,
} => {
let b = BlueprintString::Blueprint(
basic_station(
&StationSpec {
locomotives,
wagons: length,
load,
beltspeed,
lanes: outputs,
belttype,
stacked: false,
},
&StationBasicSpec::default(),
)
station(&StationSpec::new_belt(
locomotives,
length,
format!("test"),
load,
beltspeed,
outputs,
belttype,
false,
))
.to_blueprint(),
);