Refactor into different crates

This commit is contained in:
hal8174 2025-01-18 17:30:55 +01:00
parent 94473c64e0
commit dfdeae5638
82 changed files with 624 additions and 647 deletions

View file

@ -0,0 +1,10 @@
use factorio_blueprint::{BlueprintString, encode};
use factorio_blueprint_generator::balancer::generate_4_lane_balancer;
fn main() {
let b = BlueprintString::Blueprint(generate_4_lane_balancer());
println!("{}", serde_json::to_string_pretty(&b).unwrap());
println!("{}", encode(&serde_json::to_string(&b).unwrap()));
}

View file

@ -0,0 +1,129 @@
use clap::{Parser, Subcommand};
use factorio_blueprint::{
BlueprintBook, BlueprintBookEntry, BlueprintString, encode,
misc::{Beltspeed, Belttype},
};
use factorio_blueprint_generator::station::basic_unload_station;
#[derive(Parser)]
struct Args {
#[command(subcommand)]
command: Command,
}
#[derive(Subcommand)]
enum Command {
Book,
Single {
locomotives: usize,
length: usize,
outputs: usize,
beltspeed: Beltspeed,
#[arg(default_value = "full")]
belttype: Belttype,
},
}
fn main() {
let args = Args::parse();
match args.command {
Command::Book => {
let mut b = Vec::new();
let layouts = [
(1, 1),
(1, 2),
(1, 4),
(2, 4),
(1, 8),
(2, 8),
(3, 8),
(4, 8),
];
for (i, (locomotives, cargo)) in layouts.into_iter().enumerate() {
let mut inner_b = Vec::new();
let mut j = 0;
for beltspeed in [
Beltspeed::Normal,
Beltspeed::Fast,
Beltspeed::Express,
Beltspeed::Turbo,
] {
let belttypes: &[_] = match beltspeed {
Beltspeed::Normal => &[Belttype::Full, Belttype::Left, Belttype::Right],
_ => &[Belttype::Full],
};
for &belttype in belttypes {
let mut inner_inner_b = Vec::new();
for (l, o) in (0..=(cargo as u32).ilog2()).enumerate() {
let o = 1 << o;
let blueprint =
basic_unload_station(locomotives, cargo, o, beltspeed, belttype);
inner_inner_b.push(BlueprintBookEntry::new(
BlueprintString::Blueprint(blueprint),
l as u32,
));
}
inner_b.push(BlueprintBookEntry::new(
BlueprintString::BlueprintBook(
BlueprintBook::builder()
.blueprints(inner_inner_b)
.active_index(0)
.label(format!("{:?}-{:?}", beltspeed, belttype))
.build(),
),
j,
));
j += 1;
}
}
b.push(BlueprintBookEntry::new(
BlueprintString::BlueprintBook(
BlueprintBook::builder()
.blueprints(inner_b)
.active_index(0)
.label(format!("{locomotives}-{cargo}"))
.build(),
),
i as u32,
));
}
let b = BlueprintString::BlueprintBook(
BlueprintBook::builder()
.blueprints(b)
.active_index(0)
.build(),
);
println!("{}", encode(&serde_json::to_string(&b).unwrap()));
}
Command::Single {
locomotives,
length,
outputs,
beltspeed,
belttype,
} => {
let b = BlueprintString::Blueprint(basic_unload_station(
locomotives,
length,
outputs,
beltspeed,
belttype,
));
// println!("{}", serde_json::to_string_pretty(&b).unwrap());
println!("{}", encode(&serde_json::to_string(&b).unwrap()));
}
}
}

View file

@ -0,0 +1,41 @@
use factorio_blueprint::{BlueprintBook, BlueprintBookEntry, BlueprintString, encode};
use factorio_blueprint_generator::train::generate_train;
fn main() {
let layouts = [
(1, 1),
(1, 2),
(1, 4),
(2, 4),
(1, 8),
(2, 8),
(3, 8),
(4, 8),
];
let mut b = Vec::new();
for (i, (locomotives, wagons)) in layouts.into_iter().enumerate() {
b.push(BlueprintBookEntry::new(
BlueprintString::Blueprint(generate_train(locomotives, wagons, true, false)),
i as u32 * 2,
));
b.push(BlueprintBookEntry::new(
BlueprintString::Blueprint(generate_train(locomotives, wagons, true, true)),
i as u32 * 2 + 1,
));
}
let b = BlueprintString::BlueprintBook(
BlueprintBook::builder()
.blueprints(b)
.active_index(0)
.build(),
);
// let b = BlueprintString::Blueprint(generate_train(1, 2, false, false));
println!("{}", serde_json::to_string_pretty(&b).unwrap());
println!("{}", encode(&serde_json::to_string(&b).unwrap()));
}