Skip to content

Commit

Permalink
Bevy 0.15 (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
bas-ie authored Dec 3, 2024
1 parent 166df13 commit d6c4b9a
Show file tree
Hide file tree
Showing 16 changed files with 230 additions and 235 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

## [Unreleased]

* Bump `bevy_egui` dev dependency to `0.30`
* Bump `bevy_inspector_egui` dev dependency to `0.27`
* Bump `bevy` dependency to 0.15
* Bump `glam` dependency to 0.29
* Bump `bevy_egui` dev dependency to `0.31`
* Bump `bevy_inspector_egui` dev dependency to `0.28`

## 0.18.0

Expand Down
23 changes: 12 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ serde = ["dep:serde", "glam/serde"]
bevy_reflect = ["dep:bevy_reflect"]

[dependencies]
glam = "0.27"
glam = "0.29"

[dependencies.serde]
version = "1"
Expand All @@ -36,30 +36,31 @@ features = ["derive"]
optional = true

[dependencies.bevy_reflect]
version = "0.14"
version = "0.15"
default-features = false
features = ["glam"]
optional = true

# For lib.rs doctests and examples
[dev-dependencies.bevy]
version = "0.14"
version = "0.15"
features = [
"bevy_asset",
"bevy_winit",
"bevy_core_pipeline",
"bevy_gizmos",
"bevy_pbr",
"bevy_render",
"bevy_sprite",
"bevy_text",
"bevy_window",
"bevy_winit",
"default_font",
"png",
"x11",
"tonemapping_luts",
"bevy_gizmos",
"multi_threaded",
# Faster compilation
"dynamic_linking",
"multi_threaded",
"png",
"tonemapping_luts",
"x11",
]
default-features = false

Expand All @@ -69,8 +70,8 @@ features = ["html_reports"]

[dev-dependencies]
rand = "0.8"
bevy-inspector-egui = "0.27"
bevy_egui = "0.30"
bevy-inspector-egui = "0.28"
bevy_egui = "0.31"
approx = "0.5"

[lints.rust]
Expand Down
35 changes: 17 additions & 18 deletions examples/3d_columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,14 @@ struct HighlightedHexes {

/// 3D Orthogrpahic camera setup
fn setup_camera(mut commands: Commands) {
let transform = Transform::from_xyz(0.0, 60.0, 60.0).looking_at(Vec3::ZERO, Vec3::Y);
commands.spawn(Camera3dBundle {
transform,
..default()
});
let transform = Transform::from_xyz(60.0, 60.0, 00.0).looking_at(Vec3::ZERO, Vec3::Y);
commands.spawn(DirectionalLightBundle {
transform,
..default()
});
commands.spawn((
Camera3d::default(),
Transform::from_xyz(0.0, 60.0, 60.0).looking_at(Vec3::ZERO, Vec3::Y),
));
commands.spawn((
DirectionalLight::default(),
Transform::from_xyz(60.0, 60.0, 00.0).looking_at(Vec3::ZERO, Vec3::Y),
));
}

/// Hex grid setup
Expand All @@ -76,12 +74,11 @@ fn setup_grid(
.map(|hex| {
let pos = layout.hex_to_world_pos(hex);
let id = commands
.spawn(PbrBundle {
transform: Transform::from_xyz(pos.x, hex.length() as f32 / 2.0, pos.y),
mesh: mesh_handle.clone(),
material: default_material.clone(),
..default()
})
.spawn((
Mesh3d(mesh_handle.clone()),
MeshMaterial3d(default_material.clone()),
Transform::from_xyz(pos.x, hex.length() as f32 / 2.0, pos.y),
))
.id();
(hex, id)
})
Expand All @@ -106,7 +103,7 @@ fn animate_rings(
{
commands
.entity(*entity)
.insert(map.default_material.clone());
.insert(MeshMaterial3d(map.default_material.clone()));
}
highlighted_hexes.ring += 1;
if highlighted_hexes.ring > MAP_RADIUS {
Expand All @@ -116,7 +113,9 @@ fn animate_rings(
// Draw a ring
for h in &highlighted_hexes.hexes {
if let Some(e) = map.entities.get(h) {
commands.entity(*e).insert(map.highlighted_material.clone());
commands
.entity(*e)
.insert(MeshMaterial3d(map.highlighted_material.clone()));
}
}
}
Expand Down
35 changes: 16 additions & 19 deletions examples/3d_picking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,14 @@ struct Map {

/// 3D Orthogrpahic camera setup
fn setup_camera(mut commands: Commands) {
let transform = Transform::from_xyz(0.0, 60.0, 60.0).looking_at(Vec3::ZERO, Vec3::Y);
commands.spawn(Camera3dBundle {
transform,
..default()
});
let transform = Transform::from_xyz(60.0, 60.0, 00.0).looking_at(Vec3::ZERO, Vec3::Y);
commands.spawn(DirectionalLightBundle {
transform,
..default()
});
commands.spawn((
Camera3d::default(),
Transform::from_xyz(0.0, 60.0, 60.0).looking_at(Vec3::ZERO, Vec3::Y),
));
commands.spawn((
DirectionalLight::default(),
Transform::from_xyz(60.0, 60.0, 00.0).looking_at(Vec3::ZERO, Vec3::Y),
));
}

/// Hex grid setup
Expand All @@ -70,12 +68,11 @@ fn setup_grid(
.map(|hex| {
let pos = layout.hex_to_world_pos(hex);
let id = commands
.spawn(PbrBundle {
transform: Transform::from_xyz(pos.x, -COLUMN_HEIGHT, pos.y),
mesh: mesh_handle.clone(),
material: default_material.clone_weak(),
..default()
})
.spawn((
Mesh3d(mesh_handle.clone()),
MeshMaterial3d(default_material.clone_weak()),
Transform::from_xyz(pos.x, -COLUMN_HEIGHT, pos.y),
))
.id();
(hex, id)
})
Expand All @@ -99,7 +96,7 @@ fn higlight_hovered(
let (camera, cam_transform) = cameras.single();
let Some(ray) = window
.cursor_position()
.and_then(|p| camera.viewport_to_world(cam_transform, p))
.and_then(|p| camera.viewport_to_world(cam_transform, p).ok())
else {
return;
};
Expand All @@ -114,10 +111,10 @@ fn higlight_hovered(
};
commands
.entity(entity)
.insert(map.highlighted_material.clone_weak());
.insert(MeshMaterial3d(map.highlighted_material.clone_weak()));
commands
.entity(map.entities[&*highlighted])
.insert(map.default_material.clone_weak());
.insert(MeshMaterial3d(map.default_material.clone_weak()));
*highlighted = coord;
}
}
Expand Down
39 changes: 23 additions & 16 deletions examples/a_star.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ struct HexGrid {
pub path_mat: Handle<ColorMaterial>,
}

/// 3D Orthogrpahic camera setup
/// 2D camera setup
fn setup_camera(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
}

fn setup_grid(
Expand Down Expand Up @@ -69,12 +69,11 @@ fn setup_grid(
_ => default_mat.clone(),
};
let entity = commands
.spawn(ColorMesh2dBundle {
mesh: mesh.clone().into(),
material,
transform: Transform::from_xyz(pos.x, pos.y, 0.0),
..default()
})
.spawn((
Mesh2d(mesh.clone()),
MeshMaterial2d(material.clone()),
Transform::from_xyz(pos.x, pos.y, 0.0),
))
.id();
(coord, entity)
})
Expand All @@ -84,9 +83,9 @@ fn setup_grid(
blocked_coords,
path_entities: Default::default(),
layout,
default_mat,
blocked_mat,
path_mat,
default_mat: default_mat.into(),
blocked_mat: blocked_mat.into(),
path_mat: path_mat.into(),
})
}

Expand All @@ -103,7 +102,7 @@ fn handle_input(
let (camera, cam_transform) = cameras.single();
if let Some(pos) = window
.cursor_position()
.and_then(|p| camera.viewport_to_world_2d(cam_transform, p))
.and_then(|p| camera.viewport_to_world_2d(cam_transform, p).ok())
{
let hex_pos = grid.layout.world_pos_to_hex(pos);
let Some(entity) = grid.entities.get(&hex_pos).copied() else {
Expand All @@ -112,11 +111,15 @@ fn handle_input(
if buttons.just_pressed(MouseButton::Left) {
if grid.blocked_coords.contains(&hex_pos) {
grid.blocked_coords.remove(&hex_pos);
commands.entity(entity).insert(grid.default_mat.clone());
commands
.entity(entity)
.insert(MeshMaterial2d(grid.default_mat.clone()));
} else {
grid.blocked_coords.insert(hex_pos);
grid.path_entities.remove(&entity);
commands.entity(entity).insert(grid.blocked_mat.clone());
commands
.entity(entity)
.insert(MeshMaterial2d(grid.blocked_mat.clone()));
}
return;
}
Expand All @@ -126,7 +129,9 @@ fn handle_input(
*current = hex_pos;
let path_to_clear: Vec<_> = grid.path_entities.drain().collect();
for entity in path_to_clear {
commands.entity(entity).insert(grid.default_mat.clone());
commands
.entity(entity)
.insert(MeshMaterial2d(grid.default_mat.clone()));
}
let Some(path) = a_star(Hex::ZERO, hex_pos, |_, h| {
(grid.entities.contains_key(&h) && !grid.blocked_coords.contains(&h)).then_some(1)
Expand All @@ -144,7 +149,9 @@ fn handle_input(
.filter_map(|h| grid.entities.get(&h).copied())
.collect();
for entity in &entities {
commands.entity(*entity).insert(grid.path_mat.clone());
commands
.entity(*entity)
.insert(MeshMaterial2d(grid.path_mat.clone()));
}
grid.path_entities = entities;
}
Expand Down
15 changes: 7 additions & 8 deletions examples/chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ pub fn main() {
.run();
}

/// 3D Orthogrpahic camera setup
/// 2D camera setup
fn setup_camera(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
}

/// Hex grid setup
Expand All @@ -48,12 +48,11 @@ fn setup_grid(
let pos = layout.hex_to_world_pos(hex);
let hex_mod = hex.to_lower_res(CHUNK_SIZE);
let color_index = (hex_mod.x - hex_mod.y).rem_euclid(3);
commands.spawn(ColorMesh2dBundle {
transform: Transform::from_xyz(pos.x, pos.y, 0.0),
mesh: mesh_handle.clone().into(),
material: materials[color_index as usize].clone(),
..default()
});
commands.spawn((
Mesh2d(mesh_handle.clone()),
MeshMaterial2d(materials[color_index as usize].clone()),
Transform::from_xyz(pos.x, pos.y, 0.0),
));
}
}

Expand Down
17 changes: 8 additions & 9 deletions examples/field_of_movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ struct HexGrid {
pub layout: HexLayout,
}

/// 3D Orthogrpahic camera setup
/// 2D camera setup
fn setup_camera(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
}

/// Input interaction
Expand All @@ -53,7 +53,7 @@ fn handle_input(
let (camera, cam_transform) = cameras.single();
if let Some(pos) = window
.cursor_position()
.and_then(|p| camera.viewport_to_world_2d(cam_transform, p))
.and_then(|p| camera.viewport_to_world_2d(cam_transform, p).ok())
{
let hex_pos = grid.layout.world_pos_to_hex(pos);

Expand Down Expand Up @@ -114,12 +114,11 @@ fn setup_grid(
None
};
let entity = commands
.spawn(ColorMesh2dBundle {
mesh: mesh.clone().into(),
material,
transform: Transform::from_xyz(pos.x, pos.y, 0.0),
..default()
})
.spawn((
Mesh2d(mesh.clone()),
MeshMaterial2d(material),
Transform::from_xyz(pos.x, pos.y, 0.0),
))
.id();
(cost, entity)
});
Expand Down
Loading

0 comments on commit d6c4b9a

Please sign in to comment.