Add subfactory cmd utility
This commit is contained in:
parent
ff8795cea5
commit
cfc132f2d7
2 changed files with 62 additions and 1 deletions
60
factorio-blueprint-generator/src/bin/subfactory.rs
Normal file
60
factorio-blueprint-generator/src/bin/subfactory.rs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
use clap::Parser;
|
||||
use factorio_blueprint::{abstraction::serde::AbstractBlueprintString, encode};
|
||||
use factorio_blueprint_generator::subfactory::SubFactory;
|
||||
|
||||
#[derive(Parser)]
|
||||
struct Args {
|
||||
#[arg(short, long)]
|
||||
json: bool,
|
||||
|
||||
/// connection-format <item-name>:[f64]
|
||||
#[arg(short)]
|
||||
inputs: Vec<String>,
|
||||
|
||||
#[arg(short)]
|
||||
outputs: Vec<String>,
|
||||
|
||||
#[command(subcommand)]
|
||||
subfactory: SubFactory,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = Args::parse();
|
||||
|
||||
let inputs = args
|
||||
.inputs
|
||||
.iter()
|
||||
.map(|s| {
|
||||
let (a, f) = s.split_once(':').unwrap();
|
||||
|
||||
(a, f.parse().unwrap())
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let outputs = args
|
||||
.outputs
|
||||
.iter()
|
||||
.map(|s| {
|
||||
let (a, f) = s.split_once(':').unwrap();
|
||||
|
||||
(a, f.parse().unwrap())
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
dbg!(&inputs);
|
||||
dbg!(&outputs);
|
||||
|
||||
let (b, m, i, o) = args.subfactory.get_subfactory(&inputs, &outputs);
|
||||
|
||||
dbg!(m);
|
||||
dbg!(i);
|
||||
dbg!(o);
|
||||
|
||||
let b = AbstractBlueprintString { blueprint: &b };
|
||||
|
||||
if args.json {
|
||||
println!("{}", serde_json::to_string_pretty(&b).unwrap());
|
||||
}
|
||||
|
||||
std::fs::write("out.bp", encode(&serde_json::to_string(&b).unwrap())).unwrap();
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
use assembling_line::assembly_line_2_input;
|
||||
use clap::Subcommand;
|
||||
use factorio_blueprint::abstraction::Blueprint;
|
||||
use factorio_core::{
|
||||
beltoptions::{Beltspeed, Belttype},
|
||||
|
|
@ -9,7 +10,7 @@ use serde::{Deserialize, Serialize};
|
|||
|
||||
pub mod assembling_line;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Subcommand)]
|
||||
pub enum SubFactory {
|
||||
AssemblingLine {
|
||||
num_machines: usize,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue