Add schedules and output as blueprint book
This commit is contained in:
parent
6ac0cab8d5
commit
3beab0c64d
3 changed files with 127 additions and 26 deletions
|
|
@ -1,9 +1,39 @@
|
|||
use factorio_blueprint::blueprint::{train::generate_train, BlueprintString};
|
||||
use factorio_blueprint::blueprint::{
|
||||
train::generate_train, BlueprintBook, BlueprintBookEntry, BlueprintString,
|
||||
};
|
||||
|
||||
fn main() {
|
||||
let b = generate_train(2, 4, true, true);
|
||||
let layouts = [
|
||||
(1, 1),
|
||||
(1, 2),
|
||||
(1, 4),
|
||||
(2, 4),
|
||||
(1, 8),
|
||||
(2, 8),
|
||||
(3, 8),
|
||||
(4, 8),
|
||||
];
|
||||
|
||||
let b = BlueprintString::Blueprint(b);
|
||||
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)
|
||||
.version(562949954797573)
|
||||
.build(),
|
||||
);
|
||||
|
||||
println!("{}", serde_json::to_string_pretty(&b).unwrap());
|
||||
|
||||
|
|
|
|||
|
|
@ -12,10 +12,13 @@ pub enum BlueprintString {
|
|||
Blueprint(Blueprint),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Builder)]
|
||||
pub struct BlueprintBook {
|
||||
#[builder(skip = "blueprint-book".to_owned())]
|
||||
item: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
label: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
label_color: Option<BlueprintColor>,
|
||||
blueprints: Vec<BlueprintBookEntry>,
|
||||
active_index: i32,
|
||||
|
|
@ -29,6 +32,12 @@ pub struct BlueprintBookEntry {
|
|||
index: u32,
|
||||
}
|
||||
|
||||
impl BlueprintBookEntry {
|
||||
pub fn new(entry: BlueprintString, index: u32) -> Self {
|
||||
Self { entry, index }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Builder)]
|
||||
pub struct Blueprint {
|
||||
#[builder(skip = "blueprint".to_owned())]
|
||||
|
|
@ -47,7 +56,7 @@ pub struct Blueprint {
|
|||
icons: Vec<BlueprintIcon>,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
#[builder(default)]
|
||||
schedules: Vec<BlueprintSchedule>,
|
||||
schedules: Vec<serde_json::Value>,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
#[builder(default)]
|
||||
stock_connections: Vec<BlueprintStockConnection>,
|
||||
|
|
@ -268,27 +277,6 @@ pub struct BlueprintIcon {
|
|||
signal: BlueprintSignalID,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct BlueprintSchedule {
|
||||
schedule: Vec<BlueprintScheduleRecord>,
|
||||
locomotives: Vec<u64>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct BlueprintScheduleRecord {
|
||||
station: String,
|
||||
wait_conditions: Vec<BlueprintWaitCondition>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct BlueprintWaitCondition {
|
||||
#[serde(rename = "type")]
|
||||
condition_type: String,
|
||||
compare_type: String,
|
||||
ticks: Option<u64>,
|
||||
condition: Option<()>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct BlueprintTile {
|
||||
name: String,
|
||||
|
|
|
|||
|
|
@ -69,10 +69,93 @@ pub fn generate_train(locomotives: u32, wagons: u32, rails: bool, fluid: bool) -
|
|||
);
|
||||
}
|
||||
|
||||
let cargotype = if fluid {
|
||||
"[virtual-signal=signal-L]"
|
||||
} else {
|
||||
"[virtual-signal=signal-C]"
|
||||
};
|
||||
|
||||
let schedule = serde_json::json!({
|
||||
"locomotives": [1],
|
||||
"schedule": {
|
||||
"group": format!("{cargotype}[virtual-signal=signal-{locomotives}][virtual-signal=signal-{wagons}]"),
|
||||
"interrupts": [
|
||||
{
|
||||
"name": format!("{cargotype}[virtual-signal=signal-{locomotives}][virtual-signal=signal-{wagons}][virtual-signal=signal-L]"),
|
||||
"conditions": [
|
||||
{
|
||||
"compare_type": "and",
|
||||
"station": format!("{cargotype}[virtual-signal=signal-{locomotives}][virtual-signal=signal-{wagons}][virtual-signal=signal-L]"),
|
||||
"type": "specific_destination_not_full"
|
||||
},
|
||||
{
|
||||
"compare_type": "and",
|
||||
"type": "empty"
|
||||
}
|
||||
],
|
||||
"inside_interrupt": false,
|
||||
"targets": [
|
||||
{
|
||||
"station": format!("{cargotype}[virtual-signal=signal-{locomotives}][virtual-signal=signal-{wagons}][virtual-signal=signal-L]"),
|
||||
"wait_conditions": [
|
||||
{
|
||||
"compare_type": "and",
|
||||
"type": "full"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": format!("{cargotype}[virtual-signal=signal-{locomotives}][virtual-signal=signal-{wagons}][virtual-signal=signal-U]"),
|
||||
"conditions": [
|
||||
{
|
||||
"type": "item_count",
|
||||
"compare_type": "and",
|
||||
"condition": {
|
||||
"comparator": "≠",
|
||||
"constant": 0,
|
||||
"first_signal": {
|
||||
"name": "signal-item-parameter",
|
||||
"type": "virtual",
|
||||
}
|
||||
},
|
||||
}
|
||||
],
|
||||
"targets": [
|
||||
{
|
||||
"station": format!("{cargotype}[virtual-signal=signal-{locomotives}][virtual-signal=signal-{wagons}][virtual-signal=signal-U][virtual-signal=signal-item-parameter]"),
|
||||
"wait_conditions": [
|
||||
{
|
||||
"type": "item_count",
|
||||
"compare_type": "and",
|
||||
"condition": {
|
||||
"comparator": "=",
|
||||
"constant": 0,
|
||||
"first_signal": {
|
||||
"name": "signal-item-parameter",
|
||||
"type": "virtual"
|
||||
}
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"records": [
|
||||
{
|
||||
"station": "Depot"
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
Blueprint::builder()
|
||||
.label("train".to_string())
|
||||
.entities(e)
|
||||
.stock_connections(stock_connections)
|
||||
.schedules(vec![schedule])
|
||||
.version(562949954797573)
|
||||
.snap_to_grid(BlueprintPosition::new(
|
||||
4.0,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue