Skip to content

Commit f44a281

Browse files
alxgnonneocturneTrouv
authored
feat!: upgrade to bevy and bevy_ecs_tilemap 0.15 (#340)
To keep up with the bevy ecosystem, this change makes bevy_ecs_ldtk compatible with bevy 0.15. Aside from the dependency breaking changes, this also introduces some breaking changes to bevy_ecs_ldtk itself, which are covered in the new migration guide in the book. --------- Co-authored-by: Matthias Schiffer <mschiffer@universe-factory.net> Co-authored-by: Trevor Lovell <trevorlovelldesign@gmail.com>
1 parent f59e5e5 commit f44a281

Some content is hidden

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

42 files changed

+524
-444
lines changed

Cargo.toml

+7-5
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ members = ["macros"]
1515

1616
[dependencies]
1717
bevy_ecs_ldtk_macros = { version = "0.10.0", optional = true, path = "macros" }
18-
bevy_ecs_tilemap = { version = "0.14.0", default-features = false}
19-
bevy = { version = "0.14", default-features = false, features = ["bevy_sprite"] }
18+
bevy_ecs_tilemap = { version = "0.15.0", default-features = false }
19+
bevy = { version = "0.15", default-features = false, features = [
20+
"bevy_sprite",
21+
] }
2022
derive-getters = "0.3.0"
2123
serde = { version = "1.0", features = ["derive"] }
2224
serde_json = "1.0"
@@ -27,11 +29,11 @@ derive_more = "0.99.17"
2729
path-clean = "1.0.1"
2830

2931
[dev-dependencies]
30-
bevy = "0.14"
31-
bevy_rapier2d = "0.27.0"
32+
bevy = "0.15"
33+
bevy_rapier2d = "0.28.0"
3234
fake = { version = "2.8.0", features = ["uuid"] }
3335
rand = "0.8"
34-
bevy-inspector-egui = "0.25"
36+
bevy-inspector-egui = "0.28"
3537

3638
[features]
3739
default = ["derive", "render", "internal_levels"]

book/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@
3232
- [Migration Guides](how-to-guides/migration-guides/README.md)
3333
- [Migrate from 0.8 to 0.9](how-to-guides/migration-guides/migrate-from-0.8-to-0.9.md)
3434
- [Migrate from 0.9 to 0.10](how-to-guides/migration-guides/migrate-from-0.9-to-0.10.md)
35+
- [Migrate from 0.10 to 0.11](how-to-guides/migration-guides/migrate-from-0.10-to-0.11.md)
3536
---
3637
[API Reference](api-reference.md).

book/src/explanation/anatomy-of-the-world.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ Naturally, this can only occur in Tile/AutoTile layers (or IntGrid layers with A
4040
## Level backgrounds
4141
LDtk allows you to supply a background color and a background image for individual levels.
4242
`bevy_ecs_ldtk` renders these by default.
43-
The background color is spawned as a normal bevy [`SpriteBundle`](https://docs.rs/bevy/latest/bevy/prelude/struct.SpriteBundle.html), as a child of the level entity.
44-
The background image, if it exists, is also spawned as a `SpriteBundle`.
43+
The background color is spawned as a normal bevy [`Sprite`](https://docs.rs/bevy/latest/bevy/prelude/struct.Sprite.html), as a child of the level entity.
44+
The background image, if it exists, is also spawned as a `Sprite`.
4545

4646
These background sprites can be disabled (not spawned) using the settings resource [`LdtkSettings`](https://docs.rs/bevy_ecs_ldtk/0.10.0/bevy_ecs_ldtk/prelude/struct.LdtkSettings.html): <!-- x-release-please-version -->
4747
```rust,no_run

book/src/explanation/game-logic-integration.md

+9-10
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ struct Player;
2727
#[derive(Default, Bundle, LdtkEntity)]
2828
struct PlayerBundle {
2929
player: Player,
30-
#[sprite_bundle]
31-
sprite_bundle: SpriteBundle,
30+
#[sprite]
31+
sprite: Sprite,
3232
}
3333
```
3434

3535
How does `LdtkEntity`/`LdtkIntCell` construct the bundle when derived?
3636
Without any intervention, the bundle's fields are constructed using the bundle's `Default` implementation.
37-
However, various attributes are available to override this behavior, like `#[sprite_bundle]` in the above example.
37+
However, various attributes are available to override this behavior, like `#[sprite]` in the above example.
3838
This attribute gives the entity a sprite using the tileset in its LDtk editor visual.
3939
For documentation about all the available attributes, check out the API reference for these traits:
4040
- [`LdtkEntity`](https://docs.rs/bevy_ecs_ldtk/0.10.0/bevy_ecs_ldtk/app/trait.LdtkEntity.html) <!-- x-release-please-version -->
@@ -74,11 +74,10 @@ fn process_player(
7474
commands
7575
.entity(entity)
7676
.insert(Player)
77-
.insert(SpriteBundle {
78-
texture: assets.load("player.png"),
79-
transform: *transform,
80-
..default()
81-
})
77+
.insert((
78+
Sprite::from_image(assets.load("player.png")),
79+
*transform,
80+
))
8281
.with_children(|commands| {
8382
commands.spawn(PlayerChild);
8483
});
@@ -121,8 +120,8 @@ struct Player;
121120
#[derive(Default, Bundle, LdtkEntity)]
122121
struct PlayerBundle {
123122
player: Player,
124-
#[sprite_bundle]
125-
sprite_bundle: SpriteBundle,
123+
#[sprite]
124+
sprite: Sprite,
126125
}
127126
128127
fn process_player(

book/src/how-to-guides/make-level-selection-follow-player.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Use the transforms of the spawned levels and width/height info from the level's
2525

2626

2727
To access the level asset data, you first need to access the project asset data.
28-
Assuming you only have one project, query for the only `Handle<LdtkProject>` entity and look up its asset data in the `LdtkProject` asset store.
28+
Assuming you only have one project, query for the only `LdtkProjectHandle` entity and look up its asset data in the `LdtkProject` asset store.
2929
Then, get the raw level data for every spawned level using the level entity's `LevelIid` component (there is a provided method for this).
3030

3131
```rust,no_run
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# Migrate from 0.10 to 0.11
2+
3+
## Bevy upgrade
4+
`bevy_ecs_ldtk` has upgraded to Bevy and `bevy_ecs_tilemap` version `0.15`.
5+
A Bevy `0.15` migration guide is available on [Bevy's website](https://bevyengine.org/learn/migration-guides/0-14-to-0-15/).
6+
7+
## `LdtkSpriteSheetBundle` replaced with `Sprite`
8+
Since the `Sprite` struct in Bevy `0.15` can now store `TextureAtlas` information on its own, the use of `LdtkSpriteSheetBundle` has been replaced by a simple use of `Sprite`. The macro has changed as well, and is now named `#[sprite_sheet]`.
9+
```rust,ignore
10+
// 0.10
11+
# use bevy_ecs_ldtk::prelude::*;
12+
# use bevy::prelude::*;
13+
#[derive(Default, Bundle, LdtkEntity)]
14+
struct PlayerBundle {
15+
#[sprite_sheet_bundle]
16+
sprite_bundle: LdtkSpriteSheetBundle,
17+
#[grid_coords]
18+
grid_coords: GridCoords,
19+
}
20+
```
21+
```rust,ignore
22+
// 0.11
23+
# use bevy_ecs_ldtk::prelude::*;
24+
# use bevy::prelude::*;
25+
#[derive(Default, Bundle, LdtkEntity)]
26+
struct PlayerBundle {
27+
#[sprite_sheet]
28+
sprite_sheet: Sprite,
29+
#[grid_coords]
30+
grid_coords: GridCoords,
31+
}
32+
```
33+
34+
## `SpriteBundle` also replaced with `Sprite`
35+
When using a `SpriteBundle` with the `#[sprite_bundle]` macro, use a `Sprite` instead. The macro is now named `#[sprite]`.
36+
```rust,ignore
37+
// 0.10
38+
# use bevy_ecs_ldtk::prelude::*;
39+
# use bevy::prelude::*;
40+
#[derive(Bundle, LdtkEntity, Default)]
41+
pub struct Player {
42+
player: PlayerComponent,
43+
health: Health,
44+
#[sprite_bundle]
45+
sprite_bundle: SpriteBundle,
46+
}
47+
```
48+
```rust,ignore
49+
// 0.11
50+
# use bevy_ecs_ldtk::prelude::*;
51+
# use bevy::prelude::*;
52+
#[derive(Bundle, LdtkEntity, Default)]
53+
pub struct Player {
54+
player: PlayerComponent,
55+
health: Health,
56+
#[sprite]
57+
sprite: Sprite,
58+
}
59+
```
60+
61+
## `Handle<LdtkProject>` replaced with `LdtkProjectHandle`
62+
Handles cannot be used as components in Bevy `0.15` onward. This has two changes.
63+
### Call `.into()` when loading a project
64+
First, you must call `.into()` when loading the world.
65+
```rust,ignore
66+
// 0.10
67+
# use bevy_ecs_ldtk::prelude::*;
68+
# use bevy::prelude::*;
69+
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
70+
commands.spawn(LdtkWorldBundle {
71+
ldtk_handle: asset_server.load("my_project.ldtk"),
72+
..Default::default()
73+
});
74+
}
75+
```
76+
```rust,ignore
77+
// 0.11
78+
# use bevy_ecs_ldtk::prelude::*;
79+
# use bevy::prelude::*;
80+
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
81+
commands.spawn(LdtkWorldBundle {
82+
ldtk_handle: asset_server.load("my_project.ldtk").into(),
83+
..Default::default()
84+
});
85+
}
86+
```
87+
### Replace usages of `Handle<LdtkProject>`
88+
Second, uses of `Handle<LdtkProject>` in queries must be replaced with `LdtkProjectHandle`. It is enough to replace the type in the signature, as the `LdtkProjectHandle` type is a drop-in replacement for the handle.
89+
90+
```rust,ignore
91+
// 0.10
92+
# use bevy_ecs_ldtk::prelude::*;
93+
# use bevy::prelude::*;
94+
fn respawn_world(
95+
mut commands: Commands,
96+
ldtk_projects: Query<Entity, With<Handle<LdtkProject>>>,
97+
input: Res<ButtonInput<KeyCode>>,
98+
) {
99+
if input.just_pressed(KeyCode::KeyR) {
100+
commands.entity(ldtk_projects.single()).insert(Respawn);
101+
}
102+
}
103+
```
104+
```rust,ignore
105+
// 0.11
106+
# use bevy_ecs_ldtk::prelude::*;
107+
# use bevy::prelude::*;
108+
fn respawn_world(
109+
mut commands: Commands,
110+
ldtk_projects: Query<Entity, With<LdtkProjectHandle>>,
111+
input: Res<ButtonInput<KeyCode>>,
112+
) {
113+
if input.just_pressed(KeyCode::KeyR) {
114+
commands.entity(ldtk_projects.single()).insert(Respawn);
115+
}
116+
}
117+
```
118+

book/src/how-to-guides/migration-guides/migrate-from-0.8-to-0.9.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ To update your game to LDtk 1.5.3, you should only need to install the new versi
1212
Fields on an `LdtkEntity`- or `LdtkIntCell`-derived bundle are no longer constructed from the field's `Default` implementation, but the bundle's.
1313

1414
You may observe different behavior in `0.9` if the value for a field in your bundle's `Default` implementation differs from the field type's own `Default` implementation:
15-
```rust,no_run
15+
```rust,ignore
1616
# use bevy::prelude::*;
1717
# use bevy_ecs_ldtk::prelude::*;
1818
#[derive(Component)]
@@ -50,7 +50,7 @@ struct MyBundle {
5050
component: MyComponentThatImplementsDefault,
5151
}
5252
```
53-
```rust,no_run
53+
```rust,ignore
5454
# use bevy_ecs_ldtk::prelude::*;
5555
# use bevy::prelude::*;
5656
# #[derive(Default, Component)]
@@ -80,7 +80,7 @@ fn get_level_of_entity(
8080
}
8181
}
8282
```
83-
```rust,no_run
83+
```rust,ignore
8484
# use bevy_ecs_ldtk::prelude::*;
8585
# use bevy::prelude::*;
8686
// 0.9
@@ -114,7 +114,7 @@ fn do_some_processing_with_ldtk_data(
114114
// do something
115115
}
116116
```
117-
```rust,no_run
117+
```rust,ignore
118118
# use bevy_ecs_ldtk::prelude::*;
119119
# use bevy::prelude::*;
120120
// 0.9
@@ -135,7 +135,7 @@ let tileset_map = ldtk_project.tileset_map;
135135
let int_grid_image_handle = ldtk_project.int_grid_image_handle;
136136
let level_map = ldtk_project.level_map;
137137
```
138-
```rust,no_run
138+
```rust,ignore
139139
# use bevy_ecs_ldtk::prelude::*;
140140
# fn foo(ldtk_project: LdtkProject) {
141141
// 0.9
@@ -157,7 +157,7 @@ ldtk_asset.iter_levels();
157157
158158
ldtk_asset.get_level(&LevelSelection::Uid(24));
159159
```
160-
```rust,no_run
160+
```rust,ignore
161161
# use bevy_ecs_ldtk::{prelude::*, ldtk::LdtkJson};
162162
# fn foo(ldtk_json: LdtkJson, ldtk_project: LdtkProject) {
163163
// 0.9
@@ -215,7 +215,7 @@ fn print_level_entity(levels: Query<Entity, With<Handle<LdtkLevel>>>) {
215215
}
216216
}
217217
```
218-
```rust,no_run
218+
```rust,ignore
219219
# use bevy_ecs_ldtk::prelude::*;
220220
# use bevy::prelude::*;
221221
// 0.9
@@ -238,7 +238,7 @@ fn print_level_uid(levels: Query<Handle<LdtkLevel>>, level_assets: Res<Assets<Ld
238238
}
239239
}
240240
```
241-
```rust,no_run
241+
```rust,ignore
242242
# use bevy_ecs_ldtk::prelude::*;
243243
# use bevy::prelude::*;
244244
// 0.9
@@ -260,7 +260,7 @@ If the level data you need *is* inside the level's `layer_instances`, you may wa
260260
A `Level` might not have complete data - in the case that it's the "raw" level inside an external-levels project's `LdtkProject` asset.
261261
This new `LoadedLevel` type provides type guarantees that the level has complete data.
262262
For internal-levels (aka "standalone") projects, you can retrieve loaded level data with a `LevelIid` and `LdtkProject` alone:
263-
```rust,no_run
263+
```rust,ignore
264264
# use bevy_ecs_ldtk::prelude::*;
265265
# use bevy::prelude::*;
266266
// 0.9, w/ internal_levels enabled
@@ -336,7 +336,7 @@ let level_set = LevelSet {
336336
].into_iter().collect(),
337337
}
338338
```
339-
```rust,no_run
339+
```rust,ignore
340340
# use bevy_ecs_ldtk::prelude::*;
341341
# fn f() {
342342
// 0.9
@@ -364,7 +364,7 @@ fn assert_level_event_type(mut level_events: EventReader<LevelEvent>) {
364364
}
365365
}
366366
```
367-
```rust,no_run
367+
```rust,ignore
368368
# use bevy_ecs_ldtk::prelude::*;
369369
# use bevy::prelude::*;
370370
use std::any::{Any, TypeId};
@@ -387,7 +387,7 @@ fn assert_level_event_type(mut level_events: EventReader<LevelEvent>) {
387387
// 0.8
388388
let level_selection = LevelSelection::Iid("e5eb2d73-60bb-4779-8b33-38a63da8d1db".to_string());
389389
```
390-
```rust,no_run
390+
```rust,ignore
391391
# use bevy_ecs_ldtk::prelude::*;
392392
# fn f() {
393393
// 0.9
@@ -403,7 +403,7 @@ However, you can still construct a `LevelSelection` from a single level index us
403403
// 0.8
404404
let level_selection = LevelSelection::Index(2);
405405
```
406-
```rust,no_run
406+
```rust,ignore
407407
# use bevy_ecs_ldtk::prelude::*;
408408
# fn f() {
409409
// 0.9
@@ -418,7 +418,7 @@ This new method can accept any iterator of strings rather than just one:
418418
// 0.8
419419
let level_set = LevelSet::from_iid("e5eb2d73-60bb-4779-8b33-38a63da8d1db");
420420
```
421-
```rust,no_run
421+
```rust,ignore
422422
# use bevy_ecs_ldtk::prelude::*;
423423
# fn f() {
424424
// 0.9

book/src/how-to-guides/migration-guides/migrate-from-0.9-to-0.10.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct PlayerBundle {
1717
grid_coords: GridCoords,
1818
}
1919
```
20-
```rust,no_run
20+
```rust,ignore
2121
// 0.10
2222
# use bevy_ecs_ldtk::prelude::*;
2323
# use bevy::prelude::*;

book/src/how-to-guides/respawn-levels-and-worlds.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ There is a method on `LdtkProject` to perform this search.
5151
# use bevy::prelude::*;
5252
# use bevy_ecs_ldtk::prelude::*;
5353
{{ #include ../../../examples/collectathon/respawn.rs:13:17 }}
54-
ldtk_projects: Query<&Handle<LdtkProject>>,
54+
ldtk_projects: Query<&LdtkProjectHandle>,
5555
ldtk_project_assets: Res<Assets<LdtkProject>>,
5656
) {
5757
if input.just_pressed(KeyCode::KeyL) {

0 commit comments

Comments
 (0)