Add automatic distribution

This commit is contained in:
hal8174 2025-03-31 23:28:18 +02:00
parent 721e83006d
commit aee56af22f
5 changed files with 386 additions and 14 deletions

View file

@ -140,7 +140,11 @@ pub struct Entity {
pub enum EntityType {
Belt(Beltspeed),
UndergroundBelt(Beltspeed, UndergroundType),
Splitter(Beltspeed),
Splitter {
beltspeed: Beltspeed,
input_priority_left: Option<bool>,
output_priority_left: Option<bool>,
},
ElectricPole(ElectricPoleType),
Inserter {
inserter_type: InserterType,
@ -203,9 +207,34 @@ impl Entity {
}
pub fn new_splitter(beltspeed: Beltspeed, position: Position, direction: Direction) -> Self {
Self::new(EntityType::Splitter(beltspeed), position, direction)
Self::new(
EntityType::Splitter {
beltspeed,
input_priority_left: None,
output_priority_left: None,
},
position,
direction,
)
}
pub fn new_splitter_with_priority(
beltspeed: Beltspeed,
position: Position,
direction: Direction,
input_priority_left: Option<bool>,
output_priority_left: Option<bool>,
) -> Self {
Self::new(
EntityType::Splitter {
beltspeed,
input_priority_left,
output_priority_left,
},
position,
direction,
)
}
pub fn new_inserter(
inserter_type: InserterType,
override_stack_size: Option<u8>,
@ -288,7 +317,11 @@ impl Entity {
EntityType::UndergroundBelt(beltspeed, _underground_type) => {
beltspeed.string_underground()
}
EntityType::Splitter(beltspeed) => beltspeed.string_splitter(),
EntityType::Splitter {
beltspeed,
input_priority_left: _,
output_priority_left: _,
} => beltspeed.string_splitter(),
EntityType::Unknown {
name,
size: _,
@ -340,9 +373,38 @@ impl Entity {
}
}
pub fn get_maybe_input_priority(&self) -> Option<String> {
match self.entity {
EntityType::Splitter {
beltspeed: _,
input_priority_left,
output_priority_left: _,
} => match input_priority_left {
Some(true) => Some("left".to_string()),
Some(false) => Some("right".to_string()),
None => None,
},
_ => None,
}
}
pub fn get_maybe_output_priority(&self) -> Option<String> {
match self.entity {
EntityType::Splitter {
beltspeed: _,
input_priority_left: _,
output_priority_left,
} => match output_priority_left {
Some(true) => Some("left".to_string()),
Some(false) => Some("right".to_string()),
None => None,
},
_ => None,
}
}
pub fn size(&self) -> Position {
match &self.entity {
EntityType::Splitter(_) => Position::new(4, 2),
EntityType::Splitter { .. } => Position::new(4, 2),
EntityType::Unknown {
name: _,
size,
@ -416,7 +478,7 @@ impl Entity {
);
}
},
EntityType::Splitter(_beltspeed) => (),
EntityType::Splitter { .. } => (),
EntityType::ElectricPole(electric_pole_type) => match electric_pole_type {
ElectricPoleType::Small => v.add_symbol(
(self.position - Position::new(1, 1)) / 2 + offset,
@ -473,6 +535,7 @@ pub struct EntityKey(usize);
static ENTITY_COUNTER: AtomicUsize = AtomicUsize::new(0);
#[derive(Clone)]
pub struct Blueprint {
entities: Vec<(EntityKey, Entity)>,
keys: HashMap<EntityKey, usize>,
@ -566,6 +629,8 @@ impl Blueprint {
.maybe_underground_type(e.get_maybe_underground_type_string())
.maybe_override_stack_size(e.get_maybe_override_stack_size())
.maybe_recipe(e.get_maybe_recipe())
.maybe_input_priority(e.get_maybe_input_priority())
.maybe_output_priority(e.get_maybe_output_priority())
.build()
})
.collect();