For operations such as copy&paste or placing Structure
s or Module
s on Blueprint
s one had to be very careful regarding what state of a Structure
is copied.
For example when copying a Belt
, the Belt
‘s direction should be copied, but its cooldown and Item
s should be ignored and default initialized.
This was pretty error prone. Since it was often not clear whether a ‘real’ copy or only a simple one as described above should be performed.
I therefore introduced new Template
types for every Structure
that only contains the values one would expect to be copied in those cases.
In case of the Belt
this now looks like this:
pub struct Belt {
dir: Dir,
input: Option<Item>,
output: Option<Item>,
last_offer: InputOutput,
cooldown: u32,
}
pub struct BeltTemplate {
dir: Dir,
}
This way it becomes impossible to accidentally copy the input
or output
of a Belt
, when the cursor now holds StructureTemplate
instead of Structure
.
I also added conversion functions to allow for easy usage:
impl From<BeltTemplate> for Belt {
...
}
impl From<&Belt> for BeltTemplate {
...
}