Prototype subfactory interface
This commit is contained in:
parent
f4a6173a9f
commit
82394cc342
5 changed files with 119 additions and 3 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use clap::Parser;
|
||||
use factorio_blueprint::{BlueprintString, encode};
|
||||
use factorio_blueprint_generator::assembly::assembly_line_2_input;
|
||||
use factorio_blueprint_generator::subfactory::assembling_line::assembly_line_2_input;
|
||||
use factorio_core::beltoptions::Beltspeed;
|
||||
use factorio_core::visualize::Visualize;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
assembly::assembly_line_2_input,
|
||||
multistation::{StationSpec, multistation},
|
||||
subfactory::assembling_line::assembly_line_2_input,
|
||||
};
|
||||
use factorio_blueprint::abstraction::{Blueprint, Entity};
|
||||
use factorio_core::{beltoptions::Beltspeed, prelude::*, visualize::Visualize};
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
pub mod assembly;
|
||||
pub mod balancer;
|
||||
pub mod binary_merger;
|
||||
pub mod factory;
|
||||
pub mod multistation;
|
||||
pub mod station;
|
||||
pub mod subfactory;
|
||||
pub mod train;
|
||||
|
|
|
|||
116
factorio-blueprint-generator/src/subfactory.rs
Normal file
116
factorio-blueprint-generator/src/subfactory.rs
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
use factorio_blueprint::abstraction::Blueprint;
|
||||
use factorio_core::beltoptions::{Beltspeed, Belttype};
|
||||
use factorio_layout::MacroBlock;
|
||||
|
||||
pub mod assembling_line;
|
||||
|
||||
pub enum SubFactory {
|
||||
AssemblingLine {
|
||||
num_machines: usize,
|
||||
machine: String,
|
||||
recipe: Option<String>,
|
||||
},
|
||||
DoubleAssemblingLine {
|
||||
num_machines: usize,
|
||||
machine: String,
|
||||
recipe: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
enum BeltConnection {
|
||||
Full(String),
|
||||
Split { left: String, right: String },
|
||||
}
|
||||
|
||||
impl SubFactory {
|
||||
fn get_subfactory(
|
||||
&self,
|
||||
inputs: &[(&str, f64)],
|
||||
outputs: &[(&str, f64)],
|
||||
) -> (
|
||||
Blueprint,
|
||||
MacroBlock,
|
||||
Vec<BeltConnection>,
|
||||
Vec<BeltConnection>,
|
||||
) {
|
||||
match self {
|
||||
SubFactory::AssemblingLine {
|
||||
num_machines,
|
||||
machine,
|
||||
recipe,
|
||||
} => todo!(),
|
||||
SubFactory::DoubleAssemblingLine {
|
||||
num_machines,
|
||||
machine,
|
||||
recipe,
|
||||
} => {
|
||||
assert!(outputs.len() == 1);
|
||||
assert!(inputs.len() <= 4);
|
||||
|
||||
if inputs.len() > 1 {
|
||||
let mut inputs = inputs.to_vec();
|
||||
inputs.sort_by(|a, b| b.1.total_cmp(&a.1));
|
||||
let (input1, belttype1, input2, belttype2) = if let Some(
|
||||
&[
|
||||
(input1, amount1),
|
||||
(input2, amount2),
|
||||
(input3, amount3),
|
||||
(input4, amount4),
|
||||
],
|
||||
) = inputs.first_chunk()
|
||||
{
|
||||
(
|
||||
BeltConnection::Split {
|
||||
left: input1.to_owned(),
|
||||
right: input2.to_owned(),
|
||||
},
|
||||
Beltspeed::from_items_per_second(2.0 * f64::max(amount1, amount2)),
|
||||
BeltConnection::Split {
|
||||
left: input3.to_owned(),
|
||||
right: input4.to_owned(),
|
||||
},
|
||||
Beltspeed::from_items_per_second(2.0 * f64::max(amount3, amount4)),
|
||||
)
|
||||
} else if let Some(&[(input1, amount1), (input2, amount2), (input3, amount3)]) =
|
||||
inputs.first_chunk()
|
||||
{
|
||||
(
|
||||
BeltConnection::Full(input1.to_owned()),
|
||||
Beltspeed::from_items_per_second(amount1),
|
||||
BeltConnection::Split {
|
||||
left: input2.to_owned(),
|
||||
right: input3.to_owned(),
|
||||
},
|
||||
Beltspeed::from_items_per_second(2.0 * f64::max(amount2, amount3)),
|
||||
)
|
||||
} else if let Some(&[(input1, amount1), (input2, amount2)]) =
|
||||
inputs.first_chunk()
|
||||
{
|
||||
(
|
||||
BeltConnection::Full(input1.to_owned()),
|
||||
Beltspeed::from_items_per_second(amount1),
|
||||
BeltConnection::Full(input2.to_owned()),
|
||||
Beltspeed::from_items_per_second(amount2),
|
||||
)
|
||||
} else {
|
||||
unreachable!()
|
||||
};
|
||||
|
||||
(
|
||||
todo!(),
|
||||
todo!(),
|
||||
vec![input1, input2],
|
||||
vec![BeltConnection::Full(outputs[0].0.to_owned())],
|
||||
)
|
||||
} else {
|
||||
(
|
||||
todo!(),
|
||||
todo!(),
|
||||
vec![BeltConnection::Full(inputs[0].0.to_owned())],
|
||||
vec![BeltConnection::Full(outputs[0].0.to_owned())],
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue