Skip to content

Commit e8f7bf2

Browse files
committed
Cleaner initialization
Signed-off-by: Xiyu Oh <xiyu@openrobotics.org>
1 parent 3d451cf commit e8f7bf2

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

crates/rmf_site_editor/src/site/robot_properties.rs

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,21 @@ impl Plugin for RobotPropertiesPlugin {
3737
fn build(&self, app: &mut App) {
3838
// Allows us to toggle Robot as a configurable property
3939
// from the model description inspector
40-
app.world_mut().register_component::<ModelProperty<Robot>>();
41-
let component_id = app
42-
.world()
43-
.components()
44-
.component_id::<ModelProperty<Robot>>()
45-
.unwrap();
46-
app.init_resource::<ModelPropertyData>()
47-
.world_mut()
48-
.resource_mut::<ModelPropertyData>()
49-
.optional
50-
.insert(
51-
component_id,
52-
(
53-
"Robot".to_string(),
54-
|mut e_cmd| {
55-
e_cmd.insert(ModelProperty::<Robot>::default());
56-
},
57-
|mut e_cmd| {
58-
e_cmd.remove::<ModelProperty<Robot>>();
59-
},
60-
),
61-
);
40+
let component_id = app.world_mut().register_component::<ModelProperty<Robot>>();
41+
let mut model_property_data = ModelPropertyData::from_world(app.world_mut());
42+
model_property_data.optional.insert(
43+
component_id,
44+
(
45+
"Robot".to_string(),
46+
|mut e_cmd| {
47+
e_cmd.insert(ModelProperty::<Robot>::default());
48+
},
49+
|mut e_cmd| {
50+
e_cmd.remove::<ModelProperty<Robot>>();
51+
},
52+
),
53+
);
54+
app.insert_resource(model_property_data);
6255
app.add_event::<UpdateRobotPropertyKinds>()
6356
.add_systems(PreUpdate, update_model_instances::<Robot>);
6457
}

0 commit comments

Comments
 (0)