Skip to content

Commit

Permalink
Update to the latest bevy commit (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-blackbird authored Oct 15, 2024
1 parent 64560c2 commit 5d4e626
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 73 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ unsafe_op_in_unsafe_fn = "warn"
unused_qualifications = "warn"

[workspace.dependencies]
bevy = { git = "https://github.com/bevyengine/bevy.git", rev = "9386bd0114c44c9f00a2e9c41db1225aaa78d159" }
bevy = { git = "https://github.com/bevyengine/bevy.git", rev = "af93e78b72c1e435e73c54c9d0ac6260dc170762" }
thiserror = "1"
serde = { version = "1", features = ["derive"] }

Expand Down
6 changes: 3 additions & 3 deletions bevy_widgets/bevy_i-cant-believe-its-not-bsn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct WithChildCommand<B> {

impl<B: Bundle> Command for WithChildCommand<B> {
fn apply(self, world: &mut World) {
let Some(mut entity_mut) = world.get_entity_mut(self.parent_entity) else {
let Ok(mut entity_mut) = world.get_entity_mut(self.parent_entity) else {
#[cfg(debug_assertions)]
panic!("Parent entity not found");

Expand Down Expand Up @@ -177,7 +177,7 @@ impl<B: Bundle, I: IntoIterator<Item = B> + Send + Sync + 'static> Command
for WithChildrenCommand<B, I>
{
fn apply(self, world: &mut World) {
let Some(mut entity_mut) = world.get_entity_mut(self.parent_entity) else {
let Ok(mut entity_mut) = world.get_entity_mut(self.parent_entity) else {
#[cfg(debug_assertions)]
panic!("Parent entity not found");

Expand Down Expand Up @@ -362,7 +362,7 @@ mod tests {
}

let mut world = World::new();
let parent = world.run_system_once(spawn_with_child);
let parent = world.run_system_once(spawn_with_child).unwrap();

assert!(!world.entity(parent).contains::<WithChild<B>>());
assert!(world.entity(parent).contains::<A>());
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_editor/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct UISet;
pub struct RootUINode;

fn ui_setup(mut commands: Commands, theme: Res<Theme>) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);

commands
.spawn(NodeBundle {
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_editor_camera/examples/editor_camera_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ fn main() {

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands
.spawn(Camera2dBundle {
transform: Transform::from_xyz(0.0, 0.0, 10.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
})
.spawn((
Camera2d,
Transform::from_xyz(0.0, 0.0, 10.0).looking_at(Vec3::ZERO, Vec3::Y),
))
.insert(EditorCamera2d {
pan_mouse_buttons: vec![MouseButton::Left, MouseButton::Middle, MouseButton::Right],
bound: Rect {
Expand All @@ -35,8 +35,8 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
..Default::default()
});

commands.spawn(SpriteBundle {
texture: asset_server.load("bevy_bird.png"),
commands.spawn(Sprite {
image: asset_server.load("bevy_bird.png"),
..Default::default()
});
}
116 changes: 54 additions & 62 deletions projects/alien_cake_addict/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ const RESET_FOCUS: [f32; 3] = [
fn setup_cameras(mut commands: Commands, mut game: ResMut<Game>) {
game.camera_should_focus = Vec3::from(RESET_FOCUS);
game.camera_is_focus = game.camera_should_focus;
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(
commands.spawn((
Camera3d::default(),
Transform::from_xyz(
-(BOARD_SIZE_I as f32 / 2.0),
2.0 * BOARD_SIZE_J as f32 / 3.0,
BOARD_SIZE_J as f32 / 2.0 - 0.5,
)
.looking_at(game.camera_is_focus, Vec3::Y),
..default()
});
));
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut game: ResMut<Game>) {
Expand All @@ -121,29 +121,28 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut game: ResMu
game.player.j = BOARD_SIZE_J / 2;
game.player.move_cooldown = Timer::from_seconds(0.3, TimerMode::Once);

commands.spawn(PointLightBundle {
transform: Transform::from_xyz(4.0, 10.0, 4.0),
point_light: PointLight {
commands.spawn((
PointLight {
intensity: 2_000_000.0,
shadows_enabled: true,
range: 30.0,
..default()
},
..default()
});
Transform::from_xyz(4.0, 10.0, 4.0),
));

// spawn the game board
let cell_scene = asset_server.load(GltfAssetLabel::Scene(0).from_asset("models/tile.glb"));
let cell_scene =
asset_server.load(GltfAssetLabel::Scene(0).from_asset("models/AlienCake/tile.glb"));
game.board = (0..BOARD_SIZE_J)
.map(|j| {
(0..BOARD_SIZE_I)
.map(|i| {
let height = rng.gen_range(-0.1..0.1);
commands.spawn(SceneBundle {
transform: Transform::from_xyz(i as f32, height - 0.2, j as f32),
scene: cell_scene.clone(),
..default()
});
commands.spawn((
Transform::from_xyz(i as f32, height - 0.2, j as f32),
SceneRoot(cell_scene.clone()),
));
Cell { height }
})
.collect()
Expand All @@ -153,8 +152,8 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut game: ResMu
// spawn the game character
game.player.entity = Some(
commands
.spawn(SceneBundle {
transform: Transform {
.spawn((
Transform {
translation: Vec3::new(
game.player.i as f32,
game.board[game.player.j][game.player.i].height,
Expand All @@ -163,33 +162,33 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut game: ResMu
rotation: Quat::from_rotation_y(-PI / 2.),
..default()
},
scene: asset_server.load(GltfAssetLabel::Scene(0).from_asset("models/alien.glb")),
..default()
})
SceneRoot(
asset_server
.load(GltfAssetLabel::Scene(0).from_asset("models/AlienCake/alien.glb")),
),
))
.id(),
);

// load the scene for the cake
game.bonus.handle =
asset_server.load(GltfAssetLabel::Scene(0).from_asset("models/cakeBirthday.glb"));
asset_server.load(GltfAssetLabel::Scene(0).from_asset("models/AlienCake/cakeBirthday.glb"));

// scoreboard
commands.spawn(
TextBundle::from_section(
"Score:",
TextStyle {
font_size: 33.0,
color: Color::srgb(0.5, 0.5, 1.0),
..default()
},
)
.with_style(Style {
commands.spawn((
Text::new("Score:"),
TextFont {
font_size: 33.0,
..default()
},
TextColor(Color::srgb(0.5, 0.5, 1.0)),
Style {
position_type: PositionType::Absolute,
top: Val::Px(5.0),
left: Val::Px(5.0),
..default()
}),
);
},
));

commands.insert_resource(Random(rng));
}
Expand Down Expand Up @@ -344,27 +343,23 @@ fn spawn_bonus(
}
game.bonus.entity = Some(
commands
.spawn(SceneBundle {
transform: Transform::from_xyz(
.spawn((
Transform::from_xyz(
game.bonus.i as f32,
game.board[game.bonus.j][game.bonus.i].height + 0.2,
game.bonus.j as f32,
),
scene: game.bonus.handle.clone(),
..default()
})
.with_children(|children| {
children.spawn(PointLightBundle {
point_light: PointLight {
color: Color::srgb(1.0, 1.0, 0.0),
intensity: 500_000.0,
range: 10.0,
..default()
},
transform: Transform::from_xyz(0.0, 2.0, 0.0),
SceneRoot(game.bonus.handle.clone()),
))
.with_child((
PointLight {
color: Color::srgb(1.0, 1.0, 0.0),
intensity: 500_000.0,
range: 10.0,
..default()
});
})
},
Transform::from_xyz(0.0, 2.0, 0.0),
))
.id(),
);
}
Expand All @@ -382,9 +377,8 @@ fn rotate_bonus(game: Res<Game>, time: Res<Time>, mut transforms: Query<&mut Tra
}

// update the score displayed during the game
fn scoreboard_system(game: Res<Game>, mut query: Query<&mut Text>) {
let mut text = query.single_mut();
text.sections[0].value = format!("Sugar Rush: {}", game.score);
fn scoreboard_system(game: Res<Game>, mut display: Single<&mut Text>) {
display.0 = format!("Sugar Rush: {}", game.score);
}

// restart the game when pressing spacebar
Expand All @@ -409,14 +403,12 @@ fn display_score(mut commands: Commands, game: Res<Game>) {
},
..default()
})
.with_children(|parent| {
parent.spawn(TextBundle::from_section(
format!("Cake eaten: {}", game.cake_eaten),
TextStyle {
font_size: 67.0,
color: Color::srgb(0.5, 0.5, 1.0),
..default()
},
));
});
.with_child((
Text::new(format!("Cake eaten: {}", game.cake_eaten)),
TextFont {
font_size: 67.0,
..default()
},
TextColor(Color::srgb(0.5, 0.5, 1.0)),
));
}

0 comments on commit 5d4e626

Please sign in to comment.