Skip to content

Commit

Permalink
Update to Bevy 0.15 (#39)
Browse files Browse the repository at this point in the history
* Initial 0.15 support

More work needed to move things over to required components and to ensure
extraction is done correctly, but gets us to the point where bevy_light_2d
is usable with bevy 0.15.

* Migrate to required components

Required components allow us to move away from bundles (yay!) and into a
much simpler API.

I've always disliked how much of Bevy's internal components we need to
have in our bundles.

* Update README.md example for required components

* Deprecate bundles

We can get away with inserting only components now.

* Update README.md for 0.5

* Update CHANGELOG.md

* Cut first 0.5 release candidate

* Update the build

* Add bevy_window feature flag

* Add tracker links for feature flag workarounds.

* Relax Bevy requirements

* Update CHANGELOG.md
  • Loading branch information
jgayfer authored Dec 5, 2024
1 parent f8e8b2d commit e85390e
Show file tree
Hide file tree
Showing 14 changed files with 185 additions and 153 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.5.0] - 2024-12-04

### Added

- Added required component support for `PointLight2d` (#39).
- Added required component support for `LightOccluder2d` (#39).

### Changed

- Updated Bevy version from `0.14` to `0.15` (#39).
- Deprecated `PointLight2dBundle` in favour of `PointLight2d` (#39).
- Deprecated `LightOccluder2dBundle` in favour of `LightOccluder2d` (#39).

### Migration guide

- Replace all uses of `PointLight2dBundle` with `PointLight2d`.
- Replace all uses of `LightOccluder2dBundle` with `LightOccluder2d`.

## [0.4.2] - 2024-10-25

### Fixed
Expand Down
14 changes: 10 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_light_2d"
version = "0.4.2"
version = "0.5.0"
edition = "2021"
categories = ["game-engines", "graphics", "rendering"]
description = "General purpose 2d lighting for the Bevy game engine."
Expand All @@ -11,22 +11,28 @@ readme = "README.md"
exclude = ["assets/*", "static/*"]

[dependencies]
bevy = { version = "0.14", default-features = false, features = [
bevy = { version = "0.15", default-features = false, features = [
"bevy_render",
"bevy_core_pipeline",
"bevy_winit",
"x11",
# TODO: Remove when https://github.com/bevyengine/bevy/issues/16568 is resolved.
"bevy_window",
# TODO: Remove when https://github.com/bevyengine/bevy/issues/16563 is resolved.
"png"
] }
smallvec = "1.13"

[dev-dependencies]
bevy = { version = "0.14", default-features = false, features = [
bevy = { version = "0.15", default-features = false, features = [
"bevy_render",
"bevy_core_pipeline",
"bevy_winit",
"bevy_sprite",
"png",
"x11"
"x11",
# TODO: Remove when https://github.com/bevyengine/bevy/issues/16568 is resolved.
"bevy_window"
] }

[lints.clippy]
Expand Down
20 changes: 9 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ In the [`basic`](https://github.com/jgayfer/bevy_light_2d/blob/main/examples/bas
```toml
# Cargo.toml
[dependencies]
bevy = "0.14"
bevy_light_2d = "0.4"
bevy = "0.15"
bevy_light_2d = "0.5"
```

```rust
Expand All @@ -41,18 +41,15 @@ fn main() {
App::new()
.add_plugins((DefaultPlugins, Light2dPlugin))
.add_systems(Startup, setup)
.run()
.run();
}

fn setup(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());

commands.spawn(PointLight2dBundle {
point_light: PointLight2d {
radius: 100.0,
intensity: 3.0,
..default()
},
commands.spawn(Camera2d);

commands.spawn(PointLight2d {
intensity: 3.0,
radius: 100.0,
..default()
});
}
Expand All @@ -74,6 +71,7 @@ general application over depth of features.

| bevy | bevy_light_2d |
|------|---------------|
| 0.15 | 0.5 |
| 0.14 | 0.2..0.4 |
| 0.13 | 0.1 |

Expand Down
11 changes: 4 additions & 7 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@ fn main() {
}

fn setup(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);

commands.spawn(PointLight2dBundle {
point_light: PointLight2d {
intensity: 3.0,
radius: 100.0,
..default()
},
commands.spawn(PointLight2d {
intensity: 3.0,
radius: 100.0,
..default()
});
}
59 changes: 28 additions & 31 deletions examples/dungeon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ struct Candle;
struct AnimationTimer(Timer);

fn setup_camera(mut commands: Commands) {
let mut camera = Camera2dBundle::default();
camera.projection.scale = 0.25;
let mut projection = OrthographicProjection::default_2d();
projection.scale = 0.25;
commands.spawn((
camera,
Camera2d,
projection,
AmbientLight2d {
brightness: 0.1,
..default()
Expand All @@ -55,44 +56,44 @@ fn set_clear_color(mut clear_color: ResMut<ClearColor>) {

fn animate_candles(
time: Res<Time>,
mut query: Query<(&mut AnimationTimer, &mut TextureAtlas), With<Candle>>,
mut query: Query<(&mut AnimationTimer, &mut Sprite), With<Candle>>,
) {
for (mut timer, mut atlas) in &mut query {
for (mut timer, mut sprite) in &mut query {
timer.tick(time.delta());
if timer.just_finished() {
atlas.index = (atlas.index + 1) % 4;
if let Some(ref mut texture_atlas) = sprite.texture_atlas {
texture_atlas.index = (texture_atlas.index + 1) % 4;
}
}
}
}

fn spawn_candles(mut commands: Commands, spritesheet: Res<CandleSpritesheet>) {
let light = commands
.spawn((PointLight2dBundle {
transform: Transform::from_xyz(0.0, 4.0, ENTITY_INDEX),
point_light: PointLight2d {
.spawn((
Transform::from_xyz(0.0, 4.0, ENTITY_INDEX),
PointLight2d {
radius: 48.0,
color: Color::Srgba(YELLOW),
intensity: 2.0,
falloff: 4.0,
..default()
},
..default()
},))
))
.id();

commands
.spawn((
Candle,
AnimationTimer(Timer::from_seconds(0.2, TimerMode::Repeating)),
SpriteBundle {
transform: Transform::from_xyz(0., 2., ENTITY_INDEX),
texture: spritesheet.texture.clone(),
..default()
},
TextureAtlas {
layout: spritesheet.layout.clone(),
..default()
},
Sprite::from_atlas_image(
spritesheet.texture.clone(),
TextureAtlas {
layout: spritesheet.layout.clone(),
index: 0,
},
),
Transform::from_xyz(0., 2., ENTITY_INDEX),
))
.add_child(light);
}
Expand Down Expand Up @@ -166,18 +167,14 @@ fn spawn_from_atlas(
texture: Handle<Image>,
) {
commands.spawn((
SpriteBundle {
transform: Transform {
translation,
..default()
},
Sprite::from_atlas_image(
texture,
..default()
},
TextureAtlas {
index: sprite_index,
layout: atlas_handle,
},
TextureAtlas {
index: sprite_index,
layout: atlas_handle,
},
),
Transform::from_translation(translation),
));
}

Expand Down
38 changes: 16 additions & 22 deletions examples/multiple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,53 +10,47 @@ fn main() {

fn setup(mut commands: Commands) {
commands.spawn((
Camera2dBundle::default(),
Camera2d,
AmbientLight2d {
brightness: 0.1,
..default()
},
));

commands.spawn(SpriteBundle {
sprite: Sprite {
custom_size: Some(Vec2::splat(150.)),
color: Color::WHITE,
..default()
},
commands.spawn(Sprite {
custom_size: Some(Vec2::splat(150.)),
color: Color::WHITE,
..default()
});

commands.spawn(PointLight2dBundle {
point_light: PointLight2d {
commands.spawn((
PointLight2d {
color: Color::Srgba(Srgba::RED),
radius: 50.,
intensity: 1.0,
..default()
},
transform: Transform::from_xyz(-50., 25., 0.),
..default()
});
Transform::from_xyz(-50., 25., 0.),
));

commands.spawn(PointLight2dBundle {
point_light: PointLight2d {
commands.spawn((
PointLight2d {
color: Color::WHITE,
radius: 50.,
intensity: 1.0,
falloff: 5.0,
..default()
},
transform: Transform::from_xyz(25., 50., 0.),
..default()
});
Transform::from_xyz(25., 50., 0.),
));

commands.spawn(PointLight2dBundle {
point_light: PointLight2d {
commands.spawn((
PointLight2d {
color: Color::Srgba(Srgba::GREEN),
radius: 75.,
intensity: 1.0,
..default()
},
transform: Transform::from_xyz(-10., -25., 0.),
..default()
});
Transform::from_xyz(-10., -25., 0.),
));
}
Loading

0 comments on commit e85390e

Please sign in to comment.