Convert station to abstraction
This commit is contained in:
parent
2f12802507
commit
e969ba848b
6 changed files with 522 additions and 448 deletions
|
|
@ -82,16 +82,16 @@ pub fn generate_4_lane_balancer2() -> Blueprint {
|
||||||
let splitter_pos = [(0, 0), (2, 0), (1, 1), (1, 4), (0, 7), (2, 7)];
|
let splitter_pos = [(0, 0), (2, 0), (1, 1), (1, 4), (0, 7), (2, 7)];
|
||||||
|
|
||||||
for (x, y) in splitter_pos {
|
for (x, y) in splitter_pos {
|
||||||
b.add_entity(Entity::new(
|
b.add_entity(Entity::new_splitter(
|
||||||
"splitter",
|
Beltspeed::Normal,
|
||||||
Position::new(x, y),
|
Position::new(x, y),
|
||||||
Direction::Up,
|
Direction::Up,
|
||||||
Position::new(2, 1),
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
b.add_path(&balancer_path(), Beltspeed::Normal);
|
b.add_path(&balancer_path(), Beltspeed::Normal);
|
||||||
|
|
||||||
|
b.transform(Transformation::new(Direction::Right, Position::new(0, 0)));
|
||||||
b.to_blueprint()
|
b.to_blueprint()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ fn main() {
|
||||||
let b2 = BlueprintString::Blueprint(generate_4_lane_balancer2());
|
let b2 = BlueprintString::Blueprint(generate_4_lane_balancer2());
|
||||||
|
|
||||||
println!("{}", serde_json::to_string_pretty(&b).unwrap());
|
println!("{}", serde_json::to_string_pretty(&b).unwrap());
|
||||||
println!("{}", serde_json::to_string_pretty(&b).unwrap());
|
println!("{}", serde_json::to_string_pretty(&b2).unwrap());
|
||||||
|
|
||||||
println!("{}", encode(&serde_json::to_string(&b).unwrap()));
|
println!("{}", encode(&serde_json::to_string(&b).unwrap()));
|
||||||
println!("{}", encode(&serde_json::to_string(&b2).unwrap()));
|
println!("{}", encode(&serde_json::to_string(&b2).unwrap()));
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ fn main() {
|
||||||
);
|
);
|
||||||
|
|
||||||
inner_inner_b.push(BlueprintBookEntry::new(
|
inner_inner_b.push(BlueprintBookEntry::new(
|
||||||
BlueprintString::Blueprint(blueprint),
|
BlueprintString::Blueprint(blueprint.to_blueprint()),
|
||||||
l as u32,
|
l as u32,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -119,14 +119,10 @@ fn main() {
|
||||||
beltspeed,
|
beltspeed,
|
||||||
belttype,
|
belttype,
|
||||||
} => {
|
} => {
|
||||||
let b = BlueprintString::Blueprint(basic_station(
|
let b = BlueprintString::Blueprint(
|
||||||
load,
|
basic_station(load, locomotives, length, outputs, beltspeed, belttype)
|
||||||
locomotives,
|
.to_blueprint(),
|
||||||
length,
|
);
|
||||||
outputs,
|
|
||||||
beltspeed,
|
|
||||||
belttype,
|
|
||||||
));
|
|
||||||
|
|
||||||
// println!("{}", serde_json::to_string_pretty(&b).unwrap());
|
// println!("{}", serde_json::to_string_pretty(&b).unwrap());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,27 +1,19 @@
|
||||||
use factorio_blueprint::{BlueprintEntity, BlueprintPosition};
|
use factorio_blueprint::abstraction::{Blueprint, Entity};
|
||||||
use factorio_core::beltoptions::Beltspeed;
|
use factorio_core::{beltoptions::Beltspeed, prelude::*};
|
||||||
|
|
||||||
pub fn merger(
|
pub fn merger(
|
||||||
reverse: bool,
|
reverse: bool,
|
||||||
beltspeed: Beltspeed,
|
beltspeed: Beltspeed,
|
||||||
offset_x: f64,
|
|
||||||
offset_y: f64,
|
|
||||||
outer_offset: u32,
|
|
||||||
intervall: usize,
|
intervall: usize,
|
||||||
outputs: usize,
|
outputs: usize,
|
||||||
lines: usize,
|
lines: usize,
|
||||||
) -> Vec<BlueprintEntity> {
|
) -> Blueprint {
|
||||||
let section_size = lines / outputs;
|
let section_size = lines / outputs;
|
||||||
assert!(lines % outputs == 0);
|
assert!(lines % outputs == 0);
|
||||||
assert!(section_size.is_power_of_two());
|
assert!(section_size.is_power_of_two());
|
||||||
assert!(outputs <= lines);
|
assert!(outputs <= lines);
|
||||||
|
|
||||||
let flip = match reverse {
|
let mut b = Blueprint::new();
|
||||||
true => 8,
|
|
||||||
false => 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut e = Vec::new();
|
|
||||||
|
|
||||||
// output and merging
|
// output and merging
|
||||||
for o in 0..outputs {
|
for o in 0..outputs {
|
||||||
|
|
@ -31,37 +23,30 @@ pub fn merger(
|
||||||
let depth = o + i.count_ones() as usize;
|
let depth = o + i.count_ones() as usize;
|
||||||
|
|
||||||
for j in 0..depth {
|
for j in 0..depth {
|
||||||
let offset = outer_offset + e.len() as u32;
|
b.add_entity(Entity::new_belt(
|
||||||
e.push(
|
stubspeed,
|
||||||
BlueprintEntity::builder(
|
Position::new(
|
||||||
stubspeed.string(),
|
(intervall * (i + o * section_size)) as PositionType,
|
||||||
offset,
|
-(j as PositionType),
|
||||||
BlueprintPosition::new(
|
),
|
||||||
(intervall * (i + o * section_size)) as f64 + offset_x,
|
match reverse {
|
||||||
offset_y - j as f64,
|
true => Direction::Down,
|
||||||
),
|
false => Direction::Up,
|
||||||
)
|
},
|
||||||
.direction(flip)
|
));
|
||||||
.build(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let offset = outer_offset + e.len() as u32;
|
b.add_entity(Entity::new_belt(
|
||||||
e.push(
|
stubspeed,
|
||||||
BlueprintEntity::builder(
|
Position::new(
|
||||||
stubspeed.string(),
|
(intervall * (i + o * section_size)) as PositionType,
|
||||||
offset,
|
-(depth as PositionType),
|
||||||
BlueprintPosition::new(
|
),
|
||||||
(intervall * (i + o * section_size)) as f64 + offset_x,
|
match reverse {
|
||||||
offset_y - depth as f64,
|
true => Direction::Down,
|
||||||
),
|
false => Direction::Left,
|
||||||
)
|
},
|
||||||
.direction(match reverse {
|
));
|
||||||
true => 8,
|
|
||||||
false => 12,
|
|
||||||
})
|
|
||||||
.build(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// merger
|
// merger
|
||||||
|
|
@ -70,53 +55,53 @@ pub fn merger(
|
||||||
let mergespeed = beltspeed.halvings((section_size.ilog2() as usize) - i);
|
let mergespeed = beltspeed.halvings((section_size.ilog2() as usize) - i);
|
||||||
for j in 0..(section_size / p) {
|
for j in 0..(section_size / p) {
|
||||||
let depth = o + j.count_ones() as usize;
|
let depth = o + j.count_ones() as usize;
|
||||||
let offset = outer_offset + e.len() as u32;
|
|
||||||
e.push(
|
b.add_entity(Entity::new_splitter(
|
||||||
BlueprintEntity::builder(
|
mergespeed,
|
||||||
mergespeed.string_splitter(),
|
Position::new(
|
||||||
offset,
|
(intervall * (j * p + o * section_size)) as PositionType
|
||||||
BlueprintPosition::new(
|
- i as PositionType,
|
||||||
(intervall * (j * p + o * section_size)) as f64 - i as f64 + offset_x,
|
0 - i as PositionType - depth as PositionType + !reverse as PositionType,
|
||||||
offset_y - i as f64 + 0.5 - depth as f64,
|
),
|
||||||
|
match reverse {
|
||||||
|
true => Direction::Right,
|
||||||
|
false => Direction::Left,
|
||||||
|
},
|
||||||
|
));
|
||||||
|
|
||||||
|
for l in 0..(7 * p / 2) {
|
||||||
|
b.add_entity(Entity::new_belt(
|
||||||
|
mergespeed.halve(),
|
||||||
|
Position::new(
|
||||||
|
(intervall * (j * p + o * section_size) + l + 1) as PositionType
|
||||||
|
- i as PositionType,
|
||||||
|
0 - i as PositionType - depth as PositionType,
|
||||||
),
|
),
|
||||||
)
|
match reverse {
|
||||||
.direction(12 - flip)
|
true => Direction::Right,
|
||||||
.build(),
|
false => Direction::Left,
|
||||||
);
|
},
|
||||||
e.extend((0..(7 * p / 2)).map(|l| {
|
));
|
||||||
BlueprintEntity::builder(
|
}
|
||||||
mergespeed.halve().string(),
|
|
||||||
offset + 1 + l as u32,
|
|
||||||
BlueprintPosition::new(
|
|
||||||
(intervall * (j * p + o * section_size)) as f64 - i as f64
|
|
||||||
+ offset_x
|
|
||||||
+ l as f64
|
|
||||||
+ 1.0,
|
|
||||||
offset_y - i as f64 - depth as f64,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.direction(12 - flip)
|
|
||||||
.build()
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// connect
|
// connect
|
||||||
let offset = outer_offset + e.len() as u32;
|
|
||||||
let step = o + section_size.ilog2() as usize;
|
let step = o + section_size.ilog2() as usize;
|
||||||
e.extend((0..(7 * o * section_size)).map(|l| {
|
for l in 0..(7 * o * section_size) {
|
||||||
BlueprintEntity::builder(
|
b.add_entity(Entity::new_belt(
|
||||||
beltspeed.string(),
|
beltspeed,
|
||||||
offset + l as u32,
|
Position::new(
|
||||||
BlueprintPosition::new(
|
l as PositionType - section_size.ilog2() as PositionType,
|
||||||
l as f64 + offset_x - section_size.ilog2() as f64,
|
-(step as PositionType),
|
||||||
offset_y - step as f64,
|
|
||||||
),
|
),
|
||||||
)
|
match reverse {
|
||||||
.direction(12 - flip)
|
true => Direction::Right,
|
||||||
.build()
|
false => Direction::Left,
|
||||||
}));
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
e
|
b
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,286 +1,169 @@
|
||||||
use factorio_blueprint::{Blueprint, BlueprintEntity, BlueprintPosition};
|
use factorio_blueprint::abstraction::{Blueprint, ElectricPoleType, Entity, InserterType, Quality};
|
||||||
use factorio_core::beltoptions::{Beltspeed, Belttype};
|
use factorio_core::{
|
||||||
|
beltoptions::{Beltspeed, Belttype},
|
||||||
|
prelude::*,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::binary_merger::merger;
|
use crate::binary_merger::merger;
|
||||||
|
|
||||||
pub fn unloader(beltspeed: Beltspeed, belttype: Belttype) -> (Vec<BlueprintEntity>, f64) {
|
pub fn unloader(beltspeed: Beltspeed, belttype: Belttype) -> (Blueprint, PositionType) {
|
||||||
|
let mut b = Blueprint::new();
|
||||||
|
|
||||||
if beltspeed == Beltspeed::Normal {
|
if beltspeed == Beltspeed::Normal {
|
||||||
let mut e = vec![
|
b.add_entity(Entity::new_belt(
|
||||||
BlueprintEntity::builder(
|
Beltspeed::Fast,
|
||||||
"fast-transport-belt".to_owned(),
|
Position::new(3, -2),
|
||||||
0,
|
Direction::Up,
|
||||||
BlueprintPosition::new(3.5, -1.5),
|
));
|
||||||
)
|
|
||||||
.build(),
|
|
||||||
];
|
|
||||||
|
|
||||||
if belttype.contains_left() {
|
if belttype.contains_left() {
|
||||||
let offset = e.len() as u32;
|
b.add_entity(Entity::new_unknown(
|
||||||
e.extend_from_slice(&[
|
"steel-chest",
|
||||||
BlueprintEntity::builder(
|
Position::new(5, -2),
|
||||||
"steel-chest".to_owned(),
|
Direction::Up,
|
||||||
offset,
|
Position::new(1, 1),
|
||||||
BlueprintPosition::new(5.5, -1.5),
|
));
|
||||||
)
|
b.add_entity(Entity::new_inserter(
|
||||||
.build(),
|
InserterType::Bulk,
|
||||||
BlueprintEntity::builder(
|
None,
|
||||||
"bulk-inserter".to_owned(),
|
Position::new(5, -1),
|
||||||
offset + 1,
|
Direction::Down,
|
||||||
BlueprintPosition::new(5.5, -0.5),
|
));
|
||||||
)
|
|
||||||
.direction(8)
|
b.add_entity(Entity::new_inserter(
|
||||||
.build(),
|
InserterType::Fast,
|
||||||
BlueprintEntity::builder(
|
None,
|
||||||
"fast-inserter".to_owned(),
|
Position::new(4, -2),
|
||||||
offset + 2,
|
Direction::Right,
|
||||||
BlueprintPosition::new(4.5, -1.5),
|
));
|
||||||
)
|
|
||||||
.direction(4)
|
|
||||||
.build(),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if belttype.contains_right() {
|
if belttype.contains_right() {
|
||||||
let offset = e.len() as u32;
|
b.add_entity(Entity::new_unknown(
|
||||||
e.extend_from_slice(&[
|
"steel-chest",
|
||||||
BlueprintEntity::builder(
|
Position::new(1, -2),
|
||||||
"steel-chest".to_owned(),
|
Direction::Up,
|
||||||
offset,
|
Position::new(1, 1),
|
||||||
BlueprintPosition::new(1.5, -1.5),
|
));
|
||||||
)
|
b.add_entity(Entity::new_inserter(
|
||||||
.build(),
|
InserterType::Bulk,
|
||||||
BlueprintEntity::builder(
|
None,
|
||||||
"bulk-inserter".to_owned(),
|
Position::new(1, -1),
|
||||||
offset + 1,
|
Direction::Down,
|
||||||
BlueprintPosition::new(1.5, -0.5),
|
));
|
||||||
)
|
|
||||||
.direction(8)
|
b.add_entity(Entity::new_inserter(
|
||||||
.build(),
|
InserterType::Fast,
|
||||||
BlueprintEntity::builder(
|
None,
|
||||||
"fast-inserter".to_owned(),
|
Position::new(2, -2),
|
||||||
offset + 2,
|
Direction::Left,
|
||||||
BlueprintPosition::new(2.5, -1.5),
|
));
|
||||||
)
|
|
||||||
.direction(12)
|
|
||||||
.build(),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(e, -2.5)
|
(b, -3)
|
||||||
} else {
|
} else {
|
||||||
let (belt_inserter, stack_size, quality) = match beltspeed {
|
let (belt_inserter, stack_size, quality) = match beltspeed {
|
||||||
Beltspeed::Normal => unreachable!(),
|
Beltspeed::Normal => unreachable!(),
|
||||||
Beltspeed::Fast => ("fast-inserter", None, None),
|
Beltspeed::Fast => (InserterType::Fast, None, Quality::Normal),
|
||||||
Beltspeed::Express => ("bulk-inserter", Some(8), None),
|
Beltspeed::Express => (InserterType::Bulk, Some(8), Quality::Normal),
|
||||||
Beltspeed::Turbo => ("fast-inserter", None, Some(String::from("epic"))),
|
Beltspeed::Turbo => (InserterType::Bulk, None, Quality::Epic),
|
||||||
|
};
|
||||||
|
|
||||||
|
b.add_entity(Entity::new_belt(
|
||||||
|
beltspeed,
|
||||||
|
Position::new(3, -4),
|
||||||
|
Direction::Up,
|
||||||
|
));
|
||||||
|
|
||||||
|
let mut s = |x, beltdir| {
|
||||||
|
b.add_entity(Entity::new_belt(beltspeed, Position::new(x, -4), beltdir));
|
||||||
|
b.add_entity(
|
||||||
|
Entity::new_inserter(
|
||||||
|
belt_inserter,
|
||||||
|
stack_size,
|
||||||
|
Position::new(x, -3),
|
||||||
|
Direction::Down,
|
||||||
|
)
|
||||||
|
.quality(quality),
|
||||||
|
);
|
||||||
|
b.add_entity(Entity::new_unknown(
|
||||||
|
"steel-chest",
|
||||||
|
Position::new(x, -2),
|
||||||
|
Direction::Up,
|
||||||
|
Position::new(1, 1),
|
||||||
|
));
|
||||||
|
b.add_entity(Entity::new_inserter(
|
||||||
|
InserterType::Bulk,
|
||||||
|
None,
|
||||||
|
Position::new(x, -1),
|
||||||
|
Direction::Down,
|
||||||
|
));
|
||||||
};
|
};
|
||||||
let mut e = vec![
|
|
||||||
BlueprintEntity::builder(beltspeed.string(), 0, BlueprintPosition::new(3.5, -3.5))
|
|
||||||
.build(),
|
|
||||||
];
|
|
||||||
|
|
||||||
if belttype.contains_left() {
|
if belttype.contains_left() {
|
||||||
let offset = e.len() as u32;
|
s(1, Direction::Right);
|
||||||
e.extend_from_slice(&[
|
s(2, Direction::Right);
|
||||||
BlueprintEntity::builder(
|
|
||||||
"steel-chest".to_owned(),
|
|
||||||
offset,
|
|
||||||
BlueprintPosition::new(1.5, -1.5),
|
|
||||||
)
|
|
||||||
.build(),
|
|
||||||
BlueprintEntity::builder(
|
|
||||||
"bulk-inserter".to_owned(),
|
|
||||||
offset + 1,
|
|
||||||
BlueprintPosition::new(1.5, -0.5),
|
|
||||||
)
|
|
||||||
.direction(8)
|
|
||||||
.build(),
|
|
||||||
BlueprintEntity::builder(
|
|
||||||
belt_inserter.to_owned(),
|
|
||||||
offset + 2,
|
|
||||||
BlueprintPosition::new(1.5, -2.5),
|
|
||||||
)
|
|
||||||
.direction(8)
|
|
||||||
.maybe_override_stack_size(stack_size)
|
|
||||||
.maybe_quality(quality.clone())
|
|
||||||
.build(),
|
|
||||||
BlueprintEntity::builder(
|
|
||||||
beltspeed.string(),
|
|
||||||
offset + 3,
|
|
||||||
BlueprintPosition::new(1.5, -3.5),
|
|
||||||
)
|
|
||||||
.direction(4)
|
|
||||||
.build(),
|
|
||||||
BlueprintEntity::builder(
|
|
||||||
"steel-chest".to_owned(),
|
|
||||||
offset + 4,
|
|
||||||
BlueprintPosition::new(2.5, -1.5),
|
|
||||||
)
|
|
||||||
.build(),
|
|
||||||
BlueprintEntity::builder(
|
|
||||||
"bulk-inserter".to_owned(),
|
|
||||||
offset + 5,
|
|
||||||
BlueprintPosition::new(2.5, -0.5),
|
|
||||||
)
|
|
||||||
.direction(8)
|
|
||||||
.build(),
|
|
||||||
BlueprintEntity::builder(
|
|
||||||
belt_inserter.to_owned(),
|
|
||||||
offset + 6,
|
|
||||||
BlueprintPosition::new(2.5, -2.5),
|
|
||||||
)
|
|
||||||
.direction(8)
|
|
||||||
.maybe_override_stack_size(stack_size)
|
|
||||||
.maybe_quality(quality.clone())
|
|
||||||
.build(),
|
|
||||||
BlueprintEntity::builder(
|
|
||||||
beltspeed.string(),
|
|
||||||
offset + 7,
|
|
||||||
BlueprintPosition::new(2.5, -3.5),
|
|
||||||
)
|
|
||||||
.direction(4)
|
|
||||||
.build(),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if belttype.contains_right() {
|
if belttype.contains_right() {
|
||||||
let offset = e.len() as u32;
|
s(4, Direction::Left);
|
||||||
e.extend_from_slice(&[
|
s(5, Direction::Left);
|
||||||
BlueprintEntity::builder(
|
|
||||||
"steel-chest".to_owned(),
|
|
||||||
offset,
|
|
||||||
BlueprintPosition::new(4.5, -1.5),
|
|
||||||
)
|
|
||||||
.build(),
|
|
||||||
BlueprintEntity::builder(
|
|
||||||
"bulk-inserter".to_owned(),
|
|
||||||
offset + 1,
|
|
||||||
BlueprintPosition::new(4.5, -0.5),
|
|
||||||
)
|
|
||||||
.direction(8)
|
|
||||||
.build(),
|
|
||||||
BlueprintEntity::builder(
|
|
||||||
belt_inserter.to_owned(),
|
|
||||||
offset + 2,
|
|
||||||
BlueprintPosition::new(4.5, -2.5),
|
|
||||||
)
|
|
||||||
.direction(8)
|
|
||||||
.maybe_override_stack_size(stack_size)
|
|
||||||
.maybe_quality(quality.clone())
|
|
||||||
.build(),
|
|
||||||
BlueprintEntity::builder(
|
|
||||||
beltspeed.string(),
|
|
||||||
offset + 3,
|
|
||||||
BlueprintPosition::new(4.5, -3.5),
|
|
||||||
)
|
|
||||||
.direction(12)
|
|
||||||
.build(),
|
|
||||||
BlueprintEntity::builder(
|
|
||||||
"steel-chest".to_owned(),
|
|
||||||
offset + 4,
|
|
||||||
BlueprintPosition::new(5.5, -1.5),
|
|
||||||
)
|
|
||||||
.build(),
|
|
||||||
BlueprintEntity::builder(
|
|
||||||
"bulk-inserter".to_owned(),
|
|
||||||
offset + 5,
|
|
||||||
BlueprintPosition::new(5.5, -0.5),
|
|
||||||
)
|
|
||||||
.direction(8)
|
|
||||||
.build(),
|
|
||||||
BlueprintEntity::builder(
|
|
||||||
belt_inserter.to_owned(),
|
|
||||||
offset + 6,
|
|
||||||
BlueprintPosition::new(5.5, -2.5),
|
|
||||||
)
|
|
||||||
.direction(8)
|
|
||||||
.maybe_override_stack_size(stack_size)
|
|
||||||
.maybe_quality(quality.clone())
|
|
||||||
.build(),
|
|
||||||
BlueprintEntity::builder(
|
|
||||||
beltspeed.string(),
|
|
||||||
offset + 7,
|
|
||||||
BlueprintPosition::new(5.5, -3.5),
|
|
||||||
)
|
|
||||||
.direction(12)
|
|
||||||
.build(),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(e, -4.5)
|
(b, -5)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn one_loader(beltspeed: Beltspeed) -> (Vec<BlueprintEntity>, f64) {
|
pub fn one_loader(beltspeed: Beltspeed) -> (Blueprint, PositionType) {
|
||||||
let (belt_inserter, quality) = match beltspeed {
|
let (belt_inserter, quality) = match beltspeed {
|
||||||
Beltspeed::Normal => ("fast-inserter", None),
|
Beltspeed::Normal => (InserterType::Fast, Quality::Normal),
|
||||||
Beltspeed::Fast => ("bulk-inserter", Some(String::from("uncommon"))),
|
Beltspeed::Fast => (InserterType::Bulk, Quality::Uncommon),
|
||||||
Beltspeed::Express => ("bulk-inserter", Some(String::from("rare"))),
|
Beltspeed::Express => (InserterType::Bulk, Quality::Rare),
|
||||||
Beltspeed::Turbo => ("bulk-inserter", Some(String::from("legendary"))),
|
Beltspeed::Turbo => (InserterType::Bulk, Quality::Legendary),
|
||||||
};
|
};
|
||||||
|
|
||||||
(
|
let mut b = Blueprint::new();
|
||||||
vec![
|
|
||||||
BlueprintEntity::builder(
|
b.add_entity(Entity::new_splitter(
|
||||||
beltspeed.string_splitter(),
|
beltspeed,
|
||||||
0,
|
Position::new(4, -5),
|
||||||
BlueprintPosition::new(4.0, -4.5),
|
Direction::Down,
|
||||||
)
|
));
|
||||||
.direction(8)
|
b.add_entity(Entity::new_belt(
|
||||||
.build(),
|
beltspeed,
|
||||||
BlueprintEntity::builder(beltspeed.string(), 1, BlueprintPosition::new(2.5, -3.5))
|
Position::new(3, -4),
|
||||||
.direction(12)
|
Direction::Left,
|
||||||
.build(),
|
));
|
||||||
BlueprintEntity::builder(beltspeed.string(), 2, BlueprintPosition::new(3.5, -3.5))
|
b.add_entity(Entity::new_belt(
|
||||||
.direction(12)
|
beltspeed,
|
||||||
.build(),
|
Position::new(4, -4),
|
||||||
BlueprintEntity::builder(beltspeed.string(), 3, BlueprintPosition::new(4.5, -3.5))
|
Direction::Right,
|
||||||
.direction(4)
|
));
|
||||||
.build(),
|
|
||||||
BlueprintEntity::builder(beltspeed.string(), 4, BlueprintPosition::new(5.5, -3.5))
|
let mut s = |x, beltdir| {
|
||||||
.direction(4)
|
b.add_entity(Entity::new_belt(beltspeed, Position::new(x, -4), beltdir));
|
||||||
.build(),
|
b.add_entity(
|
||||||
BlueprintEntity::builder(
|
Entity::new_inserter(belt_inserter, None, Position::new(x, -3), Direction::Up)
|
||||||
belt_inserter.to_owned(),
|
.quality(quality),
|
||||||
5,
|
);
|
||||||
BlueprintPosition::new(2.5, -2.5),
|
b.add_entity(Entity::new_unknown(
|
||||||
)
|
"steel-chest",
|
||||||
.maybe_quality(quality.clone())
|
Position::new(x, -2),
|
||||||
.build(),
|
Direction::Up,
|
||||||
BlueprintEntity::builder(
|
Position::new(1, 1),
|
||||||
belt_inserter.to_owned(),
|
));
|
||||||
6,
|
b.add_entity(Entity::new_inserter(
|
||||||
BlueprintPosition::new(5.5, -2.5),
|
InserterType::Bulk,
|
||||||
)
|
None,
|
||||||
.maybe_quality(quality.clone())
|
Position::new(x, -1),
|
||||||
.build(),
|
Direction::Up,
|
||||||
BlueprintEntity::builder(
|
));
|
||||||
"steel-chest".to_owned(),
|
};
|
||||||
7,
|
|
||||||
BlueprintPosition::new(2.5, -1.5),
|
s(2, Direction::Left);
|
||||||
)
|
s(5, Direction::Right);
|
||||||
.build(),
|
|
||||||
BlueprintEntity::builder(
|
(b, -6)
|
||||||
"steel-chest".to_owned(),
|
|
||||||
8,
|
|
||||||
BlueprintPosition::new(5.5, -1.5),
|
|
||||||
)
|
|
||||||
.build(),
|
|
||||||
BlueprintEntity::builder(
|
|
||||||
"bulk-inserter".to_owned(),
|
|
||||||
9,
|
|
||||||
BlueprintPosition::new(2.5, -0.5),
|
|
||||||
)
|
|
||||||
.build(),
|
|
||||||
BlueprintEntity::builder(
|
|
||||||
"bulk-inserter".to_owned(),
|
|
||||||
10,
|
|
||||||
BlueprintPosition::new(5.5, -0.5),
|
|
||||||
)
|
|
||||||
.build(),
|
|
||||||
],
|
|
||||||
-5.5,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn basic_station(
|
pub fn basic_station(
|
||||||
|
|
@ -296,85 +179,87 @@ pub fn basic_station(
|
||||||
assert!(section_size.is_power_of_two());
|
assert!(section_size.is_power_of_two());
|
||||||
assert!(outputs <= length);
|
assert!(outputs <= length);
|
||||||
|
|
||||||
let mut e = Vec::new();
|
let mut blueprint = Blueprint::new();
|
||||||
|
|
||||||
let global_x_offset = locomotives * 7;
|
let global_x_offset = locomotives * 7;
|
||||||
|
|
||||||
// electric poles
|
// electric poles
|
||||||
|
let mut poles = Vec::new();
|
||||||
for l in 1..=(length + locomotives) {
|
for l in 1..=(length + locomotives) {
|
||||||
e.push(
|
poles.push(blueprint.add_entity(Entity::new_electric_pole(
|
||||||
BlueprintEntity::builder(
|
ElectricPoleType::Medium,
|
||||||
"medium-electric-pole".to_owned(),
|
Position::new(7 * l as PositionType, -2),
|
||||||
l as u32 - 1,
|
)));
|
||||||
BlueprintPosition::new((7 * l) as f64 + 0.5, -1.5),
|
}
|
||||||
)
|
|
||||||
.build(),
|
for (&a, &b) in poles.iter().zip(poles[1..].iter()) {
|
||||||
);
|
blueprint.add_wire(a, 5, b, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
// unloader
|
// unloader
|
||||||
let (unloader, output_y) = match load {
|
|
||||||
|
let (_, output_y) = match load {
|
||||||
false => unloader(
|
false => unloader(
|
||||||
beltspeed.halvings((length / outputs).ilog2() as usize),
|
beltspeed.halvings((length / outputs).ilog2() as usize),
|
||||||
belttype,
|
belttype,
|
||||||
),
|
),
|
||||||
true => one_loader(beltspeed.halvings((length / outputs).ilog2() as usize)),
|
true => one_loader(beltspeed.halvings((length / outputs).ilog2() as usize)),
|
||||||
};
|
};
|
||||||
|
|
||||||
let offset = e.len();
|
|
||||||
for l in 0..length {
|
for l in 0..length {
|
||||||
e.extend(unloader.iter().cloned().map(|mut e| {
|
let (mut unloader, _) = match load {
|
||||||
e.position.x += (7 * l + global_x_offset) as f64;
|
false => unloader(
|
||||||
e.entity_number += (offset + unloader.len() * l) as u32;
|
beltspeed.halvings((length / outputs).ilog2() as usize),
|
||||||
e
|
belttype,
|
||||||
}));
|
),
|
||||||
|
true => one_loader(beltspeed.halvings((length / outputs).ilog2() as usize)),
|
||||||
|
};
|
||||||
|
|
||||||
|
unloader.transform(Transformation::new(
|
||||||
|
Direction::Up,
|
||||||
|
Position::new((7 * l + global_x_offset) as PositionType, 0),
|
||||||
|
));
|
||||||
|
|
||||||
|
blueprint.add_blueprint(unloader);
|
||||||
}
|
}
|
||||||
|
|
||||||
// train stop
|
// train stop
|
||||||
let offset = e.len();
|
blueprint.add_entity(Entity::new_unknown(
|
||||||
e.push(
|
"train-stop",
|
||||||
BlueprintEntity::builder(
|
Position::new(0, -2),
|
||||||
"train-stop".to_owned(),
|
Direction::Left,
|
||||||
offset as u32,
|
Position::new(2, 2),
|
||||||
BlueprintPosition::new(1.0, -1.0),
|
));
|
||||||
)
|
|
||||||
.direction(12)
|
|
||||||
.build(),
|
|
||||||
);
|
|
||||||
|
|
||||||
// rails
|
// rails
|
||||||
for l in 0..((length * 7 + global_x_offset + 1) / 2) {
|
for l in 0..((length * 7 + global_x_offset + 1) / 2) {
|
||||||
let offset = e.len() as u32;
|
blueprint.add_entity(Entity::new_unknown(
|
||||||
e.push(
|
"straight-rail",
|
||||||
BlueprintEntity::builder(
|
Position::new(2 * l as PositionType, 0),
|
||||||
"straight-rail".to_owned(),
|
Direction::Right,
|
||||||
offset,
|
Position::new(2, 2),
|
||||||
BlueprintPosition::new(2.0 * l as f64 + 1.0, 1.0),
|
));
|
||||||
)
|
|
||||||
.direction(4)
|
|
||||||
.build(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// output and merging
|
// output and merging
|
||||||
e.extend(merger(
|
|
||||||
load,
|
let mut m = merger(load, beltspeed, 7, outputs, length);
|
||||||
beltspeed,
|
|
||||||
global_x_offset as f64 + 3.5,
|
m.transform(Transformation::new(
|
||||||
output_y,
|
Direction::Up,
|
||||||
e.len() as u32,
|
Position::new(global_x_offset as PositionType + 3, output_y),
|
||||||
7,
|
|
||||||
outputs,
|
|
||||||
length,
|
|
||||||
));
|
));
|
||||||
|
|
||||||
Blueprint::builder()
|
blueprint.add_blueprint(m);
|
||||||
.label("station".to_owned())
|
// e.extend(merger(
|
||||||
.entities(e)
|
// load,
|
||||||
.wires(
|
// beltspeed,
|
||||||
(0..((length + locomotives - 1) as u32))
|
// global_x_offset as f64 + 3.5,
|
||||||
.map(|i| [i, 5, i + 1, 5])
|
// output_y,
|
||||||
.collect(),
|
// e.len() as u32,
|
||||||
)
|
// 7,
|
||||||
.build()
|
// outputs,
|
||||||
|
// length,
|
||||||
|
// ));
|
||||||
|
|
||||||
|
blueprint
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
use factorio_core::{
|
use factorio_core::{
|
||||||
beltoptions::Beltspeed,
|
beltoptions::Beltspeed,
|
||||||
pathfield::PathField,
|
pathfield::PathField,
|
||||||
prelude::{Direction, Position, PositionType},
|
prelude::{Direction, Position, PositionType, Transformable, Transformation},
|
||||||
};
|
};
|
||||||
use std::{collections::HashMap, str::FromStr, sync::atomic::AtomicUsize};
|
use std::{collections::HashMap, sync::atomic::AtomicUsize};
|
||||||
|
|
||||||
use crate::{BlueprintEntity, BlueprintPosition};
|
use crate::{BlueprintEntity, BlueprintPosition};
|
||||||
|
|
||||||
|
|
@ -13,33 +13,220 @@ pub enum UndergroundType {
|
||||||
Output,
|
Output,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
|
pub enum InserterType {
|
||||||
|
Burner,
|
||||||
|
Normal,
|
||||||
|
Fast,
|
||||||
|
Bulk,
|
||||||
|
Stack,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl InserterType {
|
||||||
|
fn string(&self) -> String {
|
||||||
|
match self {
|
||||||
|
InserterType::Burner => "burner-inserter",
|
||||||
|
InserterType::Normal => "inserter",
|
||||||
|
InserterType::Fast => "fast-inserter",
|
||||||
|
InserterType::Bulk => "bulk-inserter",
|
||||||
|
InserterType::Stack => "stack-inserter",
|
||||||
|
}
|
||||||
|
.to_owned()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
|
pub enum ElectricPoleType {
|
||||||
|
Small,
|
||||||
|
Medium,
|
||||||
|
Big,
|
||||||
|
Substation,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ElectricPoleType {
|
||||||
|
fn string(&self) -> String {
|
||||||
|
match self {
|
||||||
|
ElectricPoleType::Small => "small-electric-pole",
|
||||||
|
ElectricPoleType::Medium => "medium-electric-pole",
|
||||||
|
ElectricPoleType::Big => "big-electric-pole",
|
||||||
|
ElectricPoleType::Substation => "substation",
|
||||||
|
}
|
||||||
|
.to_owned()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn size(&self) -> Position {
|
||||||
|
match self {
|
||||||
|
ElectricPoleType::Small | ElectricPoleType::Medium => Position::new(1, 1),
|
||||||
|
ElectricPoleType::Big | ElectricPoleType::Substation => Position::new(2, 2),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
|
pub enum Quality {
|
||||||
|
Normal,
|
||||||
|
Uncommon,
|
||||||
|
Rare,
|
||||||
|
Epic,
|
||||||
|
Legendary,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Entity {
|
pub struct Entity {
|
||||||
name: String,
|
entity: EntityType,
|
||||||
position: Position,
|
position: Position,
|
||||||
direction: Direction,
|
direction: Direction,
|
||||||
size: Position,
|
quality: Quality,
|
||||||
underground_type: Option<UndergroundType>,
|
}
|
||||||
|
|
||||||
|
pub enum EntityType {
|
||||||
|
Belt(Beltspeed),
|
||||||
|
UndergroundBelt(Beltspeed, UndergroundType),
|
||||||
|
Splitter(Beltspeed),
|
||||||
|
ElectricPole(ElectricPoleType),
|
||||||
|
Inserter {
|
||||||
|
inserter_type: InserterType,
|
||||||
|
override_stack_size: Option<u8>,
|
||||||
|
},
|
||||||
|
Unknown {
|
||||||
|
name: String,
|
||||||
|
size: Position,
|
||||||
|
misc: HashMap<String, serde_json::Value>,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Entity {
|
impl Entity {
|
||||||
pub fn new(
|
pub fn new(entity: EntityType, position: Position, direction: Direction) -> Self {
|
||||||
|
Self {
|
||||||
|
entity,
|
||||||
|
position,
|
||||||
|
direction,
|
||||||
|
quality: Quality::Normal,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_belt(beltspeed: Beltspeed, position: Position, direction: Direction) -> Self {
|
||||||
|
Self::new(EntityType::Belt(beltspeed), position, direction)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_underground_belt(
|
||||||
|
beltspeed: Beltspeed,
|
||||||
|
underground_type: UndergroundType,
|
||||||
|
position: Position,
|
||||||
|
direction: Direction,
|
||||||
|
) -> Self {
|
||||||
|
Self::new(
|
||||||
|
EntityType::UndergroundBelt(beltspeed, underground_type),
|
||||||
|
position,
|
||||||
|
direction,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_splitter(beltspeed: Beltspeed, position: Position, direction: Direction) -> Self {
|
||||||
|
Self::new(EntityType::Splitter(beltspeed), position, direction)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_inserter(
|
||||||
|
inserter_type: InserterType,
|
||||||
|
override_stack_size: Option<u8>,
|
||||||
|
position: Position,
|
||||||
|
direction: Direction,
|
||||||
|
) -> Self {
|
||||||
|
Self::new(
|
||||||
|
EntityType::Inserter {
|
||||||
|
inserter_type,
|
||||||
|
override_stack_size,
|
||||||
|
},
|
||||||
|
position,
|
||||||
|
direction,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_electric_pole(electric_pole_type: ElectricPoleType, position: Position) -> Self {
|
||||||
|
Self::new(
|
||||||
|
EntityType::ElectricPole(electric_pole_type),
|
||||||
|
position,
|
||||||
|
Direction::Up,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_unknown(
|
||||||
name: impl AsRef<str>,
|
name: impl AsRef<str>,
|
||||||
position: Position,
|
position: Position,
|
||||||
direction: Direction,
|
direction: Direction,
|
||||||
size: Position,
|
size: Position,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self::new(
|
||||||
name: name.as_ref().to_owned(),
|
EntityType::Unknown {
|
||||||
|
name: name.as_ref().to_owned(),
|
||||||
|
size,
|
||||||
|
misc: HashMap::new(),
|
||||||
|
},
|
||||||
position,
|
position,
|
||||||
direction,
|
direction,
|
||||||
size,
|
)
|
||||||
underground_type: None,
|
}
|
||||||
|
|
||||||
|
pub fn quality(mut self, quality: Quality) -> Self {
|
||||||
|
self.quality = quality;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_name(&self) -> String {
|
||||||
|
match &self.entity {
|
||||||
|
EntityType::Belt(beltspeed) => beltspeed.string(),
|
||||||
|
EntityType::UndergroundBelt(beltspeed, _underground_type) => {
|
||||||
|
beltspeed.string_underground()
|
||||||
|
}
|
||||||
|
EntityType::Splitter(beltspeed) => beltspeed.string_splitter(),
|
||||||
|
EntityType::Unknown {
|
||||||
|
name,
|
||||||
|
size: _,
|
||||||
|
misc: _,
|
||||||
|
} => name.clone(),
|
||||||
|
EntityType::ElectricPole(electric_pole_type) => electric_pole_type.string(),
|
||||||
|
EntityType::Inserter {
|
||||||
|
inserter_type,
|
||||||
|
override_stack_size: _,
|
||||||
|
} => inserter_type.string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn underground_type(mut self, underground_type: UndergroundType) -> Self {
|
pub fn get_maybe_underground_type_string(&self) -> Option<String> {
|
||||||
self.underground_type = Some(underground_type);
|
match &self.entity {
|
||||||
self
|
EntityType::UndergroundBelt(_, underground_type) => match underground_type {
|
||||||
|
UndergroundType::Input => Some(String::from("input")),
|
||||||
|
UndergroundType::Output => Some(String::from("output")),
|
||||||
|
},
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_maybe_override_stack_size(&self) -> Option<u8> {
|
||||||
|
match &self.entity {
|
||||||
|
EntityType::Inserter {
|
||||||
|
inserter_type: _,
|
||||||
|
override_stack_size,
|
||||||
|
} => *override_stack_size,
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn size(&self) -> Position {
|
||||||
|
match &self.entity {
|
||||||
|
EntityType::Splitter(_) => Position::new(2, 1),
|
||||||
|
EntityType::Unknown {
|
||||||
|
name: _,
|
||||||
|
size,
|
||||||
|
misc: _,
|
||||||
|
} => *size,
|
||||||
|
EntityType::ElectricPole(electric_pole_type) => electric_pole_type.size(),
|
||||||
|
_ => Position::new(1, 1),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn transform(&mut self, transform: Transformation) {
|
||||||
|
self.position = self.position.transform(transform);
|
||||||
|
self.direction = self.direction.transform(transform);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -51,6 +238,7 @@ static ENTITY_COUNTER: AtomicUsize = AtomicUsize::new(0);
|
||||||
pub struct Blueprint {
|
pub struct Blueprint {
|
||||||
entities: Vec<(EntityKey, Entity)>,
|
entities: Vec<(EntityKey, Entity)>,
|
||||||
keys: HashMap<EntityKey, usize>,
|
keys: HashMap<EntityKey, usize>,
|
||||||
|
wires: Vec<(EntityKey, u8, EntityKey, u8)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Blueprint {
|
impl Blueprint {
|
||||||
|
|
@ -58,6 +246,7 @@ impl Blueprint {
|
||||||
Self {
|
Self {
|
||||||
entities: Vec::new(),
|
entities: Vec::new(),
|
||||||
keys: HashMap::new(),
|
keys: HashMap::new(),
|
||||||
|
wires: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -79,49 +268,50 @@ impl Blueprint {
|
||||||
for &p in path {
|
for &p in path {
|
||||||
match p {
|
match p {
|
||||||
PathField::Belt { pos, dir } => {
|
PathField::Belt { pos, dir } => {
|
||||||
self.add_entity(Entity::new(
|
self.add_entity(Entity::new_belt(beltspeed, pos, dir));
|
||||||
beltspeed.string(),
|
|
||||||
pos,
|
|
||||||
dir,
|
|
||||||
Position::new(1, 1),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
PathField::Underground { pos, dir, len } => {
|
PathField::Underground { pos, dir, len } => {
|
||||||
self.add_entity(
|
self.add_entity(Entity::new_underground_belt(
|
||||||
Entity::new(
|
beltspeed,
|
||||||
beltspeed.string_underground(),
|
UndergroundType::Input,
|
||||||
pos,
|
pos,
|
||||||
dir,
|
dir,
|
||||||
Position::new(1, 1),
|
));
|
||||||
)
|
self.add_entity(Entity::new_underground_belt(
|
||||||
.underground_type(UndergroundType::Input),
|
beltspeed,
|
||||||
);
|
UndergroundType::Output,
|
||||||
self.add_entity(
|
pos.in_direction(&dir, len as PositionType),
|
||||||
Entity::new(
|
dir,
|
||||||
beltspeed.string_underground(),
|
));
|
||||||
pos.in_direction(&dir, len as PositionType),
|
|
||||||
dir,
|
|
||||||
Position::new(1, 1),
|
|
||||||
)
|
|
||||||
.underground_type(UndergroundType::Output),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn add_wire(&mut self, a: EntityKey, endpoint_a: u8, b: EntityKey, endpoint_b: u8) {
|
||||||
|
self.wires.push((a, endpoint_a, b, endpoint_b));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_blueprint(&mut self, other: Self) {
|
||||||
|
self.entities.extend(other.entities);
|
||||||
|
self.keys.extend(other.keys);
|
||||||
|
self.wires.extend(other.wires);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn to_blueprint(&self) -> super::Blueprint {
|
pub fn to_blueprint(&self) -> super::Blueprint {
|
||||||
let entities = self
|
let entities = self
|
||||||
.entities
|
.entities
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, (_, e))| {
|
.map(|(i, (_, e))| {
|
||||||
|
let size = (e.size() - Position::new(1, 1))
|
||||||
|
.transform(Transformation::new(e.direction, Position::new(0, 0)));
|
||||||
BlueprintEntity::builder(
|
BlueprintEntity::builder(
|
||||||
e.name.clone(),
|
e.get_name(),
|
||||||
i as u32 + 1,
|
i as u32 + 1,
|
||||||
BlueprintPosition::new(
|
BlueprintPosition::new(
|
||||||
e.position.x as f64 + 0.5 * e.size.x as f64,
|
e.position.x as f64 + 0.5 * size.x as f64 + 0.5,
|
||||||
e.position.y as f64 + 0.5 * e.size.y as f64,
|
e.position.y as f64 + 0.5 * size.y as f64 + 0.5,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.direction(match e.direction {
|
.direction(match e.direction {
|
||||||
|
|
@ -130,19 +320,37 @@ impl Blueprint {
|
||||||
Direction::Down => 8,
|
Direction::Down => 8,
|
||||||
Direction::Left => 12,
|
Direction::Left => 12,
|
||||||
})
|
})
|
||||||
.maybe_underground_type(e.underground_type.map(|u| match u {
|
.maybe_underground_type(e.get_maybe_underground_type_string())
|
||||||
UndergroundType::Input => String::from("input"),
|
.maybe_override_stack_size(e.get_maybe_override_stack_size())
|
||||||
UndergroundType::Output => String::from("output"),
|
|
||||||
}))
|
|
||||||
.build()
|
.build()
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
let wires = self
|
||||||
|
.wires
|
||||||
|
.iter()
|
||||||
|
.map(|&(a, endpoint_a, b, endpoint_b)| {
|
||||||
|
[
|
||||||
|
self.keys[&a] as u32 + 1,
|
||||||
|
endpoint_a as u32,
|
||||||
|
self.keys[&b] as u32 + 1,
|
||||||
|
endpoint_b as u32,
|
||||||
|
]
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
super::Blueprint::builder()
|
super::Blueprint::builder()
|
||||||
.label(String::from("test"))
|
.label(String::from("test"))
|
||||||
.entities(entities)
|
.entities(entities)
|
||||||
|
.wires(wires)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn transform(&mut self, transform: Transformation) {
|
||||||
|
for (_, e) in &mut self.entities {
|
||||||
|
e.transform(transform);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Blueprint {
|
impl Default for Blueprint {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue