Skip to content

Commit 81b53d1

Browse files
committed
Make Commands and World apis consistent (#1703)
Resolves #1253 #1562 This makes the Commands apis consistent with World apis. This moves to a "type state" pattern (like World) where the "current entity" is stored in an `EntityCommands` builder. In general this tends to cuts down on indentation and line count. It comes at the cost of needing to type `commands` more and adding more semicolons to terminate expressions. I also added `spawn_bundle` to Commands because this is a common enough operation that I think its worth providing a shorthand.
1 parent 94f4558 commit 81b53d1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1109
-1161
lines changed

crates/bevy_ecs/src/system/commands.rs

Lines changed: 154 additions & 123 deletions
Large diffs are not rendered by default.

crates/bevy_ecs/src/system/exclusive_system.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ mod tests {
131131
) {
132132
for entity in query.iter() {
133133
*counter += 1;
134-
commands.remove::<f32>(entity);
134+
commands.entity(entity).remove::<f32>();
135135
}
136136
}
137137

crates/bevy_gltf/src/loader.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -296,18 +296,18 @@ fn load_node(
296296
) -> Result<(), GltfError> {
297297
let transform = gltf_node.transform();
298298
let mut gltf_error = None;
299-
let node = world_builder.spawn((
299+
let mut node = world_builder.spawn_bundle((
300300
Transform::from_matrix(Mat4::from_cols_array_2d(&transform.matrix())),
301301
GlobalTransform::identity(),
302302
));
303303

304304
if let Some(name) = gltf_node.name() {
305-
node.with(Name::new(name.to_string()));
305+
node.insert(Name::new(name.to_string()));
306306
}
307307

308308
// create camera node
309309
if let Some(camera) = gltf_node.camera() {
310-
node.with(VisibleEntities {
310+
node.insert(VisibleEntities {
311311
..Default::default()
312312
});
313313

@@ -325,12 +325,12 @@ fn load_node(
325325
..Default::default()
326326
};
327327

328-
node.with(Camera {
328+
node.insert(Camera {
329329
name: Some(base::camera::CAMERA_2D.to_owned()),
330330
projection_matrix: orthographic_projection.get_projection_matrix(),
331331
..Default::default()
332332
});
333-
node.with(orthographic_projection);
333+
node.insert(orthographic_projection);
334334
}
335335
gltf::camera::Projection::Perspective(perspective) => {
336336
let mut perspective_projection: PerspectiveProjection = PerspectiveProjection {
@@ -344,12 +344,12 @@ fn load_node(
344344
if let Some(aspect_ratio) = perspective.aspect_ratio() {
345345
perspective_projection.aspect_ratio = aspect_ratio;
346346
}
347-
node.with(Camera {
347+
node.insert(Camera {
348348
name: Some(base::camera::CAMERA_3D.to_owned()),
349349
projection_matrix: perspective_projection.get_projection_matrix(),
350350
..Default::default()
351351
});
352-
node.with(perspective_projection);
352+
node.insert(perspective_projection);
353353
}
354354
}
355355
}
@@ -374,7 +374,7 @@ fn load_node(
374374
let material_asset_path =
375375
AssetPath::new_ref(load_context.path(), Some(&material_label));
376376

377-
parent.spawn(PbrBundle {
377+
parent.spawn_bundle(PbrBundle {
378378
mesh: load_context.get_handle(mesh_asset_path),
379379
material: load_context.get_handle(material_asset_path),
380380
..Default::default()

crates/bevy_scene/src/command.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ impl Command for SpawnScene {
2020
}
2121

2222
pub trait SpawnSceneCommands {
23-
fn spawn_scene(&mut self, scene: Handle<Scene>) -> &mut Self;
23+
fn spawn_scene(&mut self, scene: Handle<Scene>);
2424
}
2525

2626
impl<'a> SpawnSceneCommands for Commands<'a> {
27-
fn spawn_scene(&mut self, scene_handle: Handle<Scene>) -> &mut Self {
28-
self.add_command(SpawnScene { scene_handle })
27+
fn spawn_scene(&mut self, scene_handle: Handle<Scene>) {
28+
self.add(SpawnScene { scene_handle });
2929
}
3030
}
3131

0 commit comments

Comments
 (0)