@@ -51,7 +51,6 @@ impl Plugin for SlotcarSdfPlugin {
5151fn insert_slotcar_components (
5252 mut commands : Commands ,
5353 mut change_robot_property : EventWriter < Change < ModelProperty < Robot > > > ,
54- is_static : Query < & ModelProperty < IsStatic > , ( With < ModelMarker > , With < Group > ) > ,
5554 robot_property_kinds : Query <
5655 // All 4 components will be present (see sdf_loader.rs)
5756 (
@@ -64,12 +63,15 @@ fn insert_slotcar_components(
6463 ( Without < ModelMarker > , Without < Group > ) ,
6564 > ,
6665 robot_properties : Query <
66+ & IsStatic ,
6767 (
68- Option < & Mobility > ,
69- Option < & PowerSource > ,
70- Option < & PowerDissipation > ,
68+ With < ModelMarker > ,
69+ With < Group > ,
70+ Without < Mobility > ,
71+ Without < Collision > ,
72+ Without < PowerSource > ,
73+ Without < PowerDissipation > ,
7174 ) ,
72- ( With < ModelMarker > , With < Group > ) ,
7375 > ,
7476 model_descriptions : Query < & ModelProperty < Robot > , ( With < ModelMarker > , With < Group > ) > ,
7577 model_instances : ModelPropertyQuery < Robot > ,
@@ -101,13 +103,14 @@ fn insert_slotcar_components(
101103 // from the earlier system. For now we will process data from Battery/
102104 // DifferentialDrive/MechanicalSystem/AmbientSystem in a single system.
103105
104- // Only allow overwriting RobotProperties that are not present
105- let Ok ( ( mobility , power_source , power_dissipation ) ) = robot_properties . get ( desc )
106- else {
106+ let Ok ( is_static ) = robot_properties . get ( desc ) else {
107+ // This description entity has an existing RobotProperty,
108+ // do not allow overwriting
107109 continue ;
108110 } ;
109111
110- if mobility. is_none ( ) && is_static. get ( desc) . is_ok_and ( |is| !is. 0 . 0 ) {
112+ // Only insert Mobility if robot is not static
113+ if !is_static. 0 {
111114 if let Ok ( mobility_value) = serialize_robot_property_from_kind :: <
112115 Mobility ,
113116 DifferentialDrive ,
@@ -117,45 +120,38 @@ fn insert_slotcar_components(
117120 }
118121 }
119122
120- if power_source. is_none ( ) {
121- if let Ok ( power_source_value) =
122- serialize_robot_property_from_kind :: < PowerSource , Battery > ( battery. clone ( ) )
123- {
124- robot
125- . properties
126- . insert ( PowerSource :: label ( ) , power_source_value) ;
127- }
123+ if let Ok ( power_source_value) =
124+ serialize_robot_property_from_kind :: < PowerSource , Battery > ( battery. clone ( ) )
125+ {
126+ robot
127+ . properties
128+ . insert ( PowerSource :: label ( ) , power_source_value) ;
128129 }
129130
130- if power_dissipation. is_none ( ) {
131- let mut power_dissipation_config = Map :: new ( ) ;
132- if let Some ( power_dissipation_map) = power_dissipation_config
133- . entry ( "config" )
134- . or_insert ( Value :: Object ( Map :: new ( ) ) )
135- . as_object_mut ( )
131+ let mut power_dissipation_config = Map :: new ( ) ;
132+ if let Some ( power_dissipation_map) = power_dissipation_config
133+ . entry ( "config" )
134+ . or_insert ( Value :: Object ( Map :: new ( ) ) )
135+ . as_object_mut ( )
136+ {
137+ if let Ok ( mechanical_system_value) =
138+ serialize_robot_property_kind :: < MechanicalSystem > ( mechanical_system. clone ( ) )
136139 {
137- if let Ok ( mechanical_system_value) =
138- serialize_robot_property_kind :: < MechanicalSystem > (
139- mechanical_system. clone ( ) ,
140- )
141- {
142- power_dissipation_map
143- . insert ( MechanicalSystem :: label ( ) , mechanical_system_value) ;
144- }
145- if let Ok ( ambient_system_value) =
146- serialize_robot_property_kind :: < AmbientSystem > ( ambient_system. clone ( ) )
147- {
148- power_dissipation_map
149- . insert ( AmbientSystem :: label ( ) , ambient_system_value) ;
150- }
140+ power_dissipation_map
141+ . insert ( MechanicalSystem :: label ( ) , mechanical_system_value) ;
151142 }
152- if !power_dissipation_config. is_empty ( ) {
153- robot. properties . insert (
154- PowerDissipation :: label ( ) ,
155- Value :: Object ( power_dissipation_config) ,
156- ) ;
143+ if let Ok ( ambient_system_value) =
144+ serialize_robot_property_kind :: < AmbientSystem > ( ambient_system. clone ( ) )
145+ {
146+ power_dissipation_map. insert ( AmbientSystem :: label ( ) , ambient_system_value) ;
157147 }
158148 }
149+ if !power_dissipation_config. is_empty ( ) {
150+ robot. properties . insert (
151+ PowerDissipation :: label ( ) ,
152+ Value :: Object ( power_dissipation_config) ,
153+ ) ;
154+ }
159155
160156 change_robot_property. write ( Change :: new ( ModelProperty ( robot) , desc) ) ;
161157 }
0 commit comments