Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port over to bevy v0.15 #45

Merged
merged 14 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

## [unreleased]

**BREAKING CHANGES**
This version brings breaking changes.
A [migration guide](https://adrien-bon.github.io/bevy_ecs_tiled/migrations/v0_5.html) is available to help adapt to these.

### Features

- Update to Bevy 0.15

### Changed

- Remove `map_initial_transform` and `map_initial_visibility` from `TiledMapSettings`, use required components instead
- Simplify map reload mechanisms and update corresponding example

## v0.4.2

### Changed
Expand Down
20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ default = ["render", "png"]
png = ["bevy/png"]
bmp = ["bevy/bmp"]
jpeg = ["bevy/jpeg"]
#gif = ["bevy/gif"]
gif = ["bevy/gif"]

# Expose features of the bevy_ecs_tilemap crate.
atlas = ["bevy_ecs_tilemap/atlas"]
Expand All @@ -46,18 +46,18 @@ user_properties = ["dep:serde", "dep:serde_json"]

[dependencies]
# Main dependencies
bevy = { version = "0.14", default-features = false }
bevy_ecs_tilemap = { version = "0.14", default-features = false }
bevy = { version = "0.15", default-features = false }
bevy_ecs_tilemap = { git = "https://github.com/rparrett/bevy_ecs_tilemap.git", rev = "86235d6f9f4f05cd4e3f6af9d3392b08a590a48f", default-features = false }
tiled = "0.13"

# Utilities
futures-lite = "2.4"
futures-lite = "2.5"
log = "0.4"
thiserror = "2.0"
thiserror = "1.0"

# Optional dependencies, enabled via features.
bevy_rapier2d = { version = "0.27", optional = true }
avian2d = { version = "0.1", optional = true }
bevy_rapier2d = { version = "0.28", optional = true }
avian2d = { git = "https://github.com/Jondolf/avian.git", rev = "5cd89f141cc97d37e6ad2575184158372d1f1f6c", optional = true }
serde = { version = "1.0", optional = true, features = ["derive"] }
serde_json = { version = "1.0", optional = true }

Expand All @@ -70,11 +70,11 @@ features = ["debug","user_properties","physics","avian","rapier"]
# only check 3 features at once
max_combination_size = 3
# do not check bevy images features since we don't directly use them
denylist = ["png", "bmp", "jpeg"]
denylist = ["png", "bmp", "jpeg", "gif"]

[dev-dependencies]
bevy = { version = "0.14", features = ["file_watcher"] }
bevy-inspector-egui = "0.27"
bevy = { version = "0.15", features = ["file_watcher"] }
bevy-inspector-egui = "0.28"

[[example]]
name = "basic"
Expand Down
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ Add dependencies to your `Cargo.toml` file:

```toml
[dependencies]
bevy = "0.14"
bevy = "0.15"
bevy_ecs_tiled = "0.4"
bevy_ecs_tilemap = "0.14"
bevy_ecs_tilemap = "0.15"
```

Then add the plugin to your app and spawn a map:
Expand All @@ -77,7 +77,7 @@ fn main() {

fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
// Spawn a 2D camera
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);

// Load the map: ensure any tile / tileset paths are relative to assets/ folder
let map_handle: Handle<TiledMap> = asset_server.load("map.tmx");
Expand All @@ -87,16 +87,23 @@ fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
}
```

Please note that you should have the `map.tmx` file in your local `assets/` folder, as well as required dependencies (for instance, associated tilesets).
Basically, all you have to do is to spawn a [`TiledMapHandle`](https://docs.rs/bevy_ecs_tiled/latest/bevy_ecs_tiled/struct.TiledMapHandle.html) with the map asset you want to load (the `map.tmx` file).
Note that this map asset should be in your local `assets/` folder, as well as required dependencies (for instance, associated tilesets).

You can customize various settings about how to load the map by inserting the [`TiledMapSettings`](https://docs.rs/bevy_ecs_tiled/latest/bevy_ecs_tiled/components/struct.TiledMapSettings.html) component on the map entity.
You can tweak how to load the map by adding various components on the map entity, notably:

Also, you can browse the [examples](https://github.com/adrien-bon/bevy_ecs_tiled/tree/main/examples/README.md) for more advanced use cases.
- [`TiledMapSettings`](https://docs.rs/bevy_ecs_tiled/latest/bevy_ecs_tiled/components/struct.TiledMapSettings.html)
- [`TilemapRenderSettings`](https://docs.rs/bevy_ecs_tilemap/latest/bevy_ecs_tilemap/map/struct.TilemapRenderSettings.html)
- [`Transform`](https://docs.rs/bevy/latest/bevy/transform/components/struct.Transform.html)
- [`Visibility`](https://docs.rs/bevy/latest/bevy/render/view/visibility/enum.Visibility.html)

You can browse the [examples](https://github.com/adrien-bon/bevy_ecs_tiled/tree/main/examples/README.md) for more advanced use cases.

## Bevy Compatibility

|bevy|bevy_ecs_tilemap|bevy_ecs_tiled|
|---|---|---|
|0.15|0.15|0.5|
|0.14|0.14|0.3 - 0.4|
|0.13|main@e4f3cc6|branch 0.2|
|0.12|0.12|0.1|
Expand Down
1 change: 1 addition & 0 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

# Migration guides

- [From v0.4.X to v0.5.X](migrations/v0_5.md)
- [From v0.3.X to v0.4.X](migrations/v0_4.md)

# Miscellaneous
Expand Down
18 changes: 12 additions & 6 deletions book/src/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Add dependencies to your `Cargo.toml` file:

```toml
[dependencies]
bevy = "0.14"
bevy = "0.15"
bevy_ecs_tiled = "0.4"
bevy_ecs_tilemap = "0.14"
bevy_ecs_tilemap = "0.15"
```

Then add the plugin to your app and spawn a map:
Expand All @@ -30,7 +30,7 @@ fn main() {

fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
// Spawn a 2D camera
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);

// Load the map: ensure any tile / tileset paths are relative to assets/ folder
let map_handle: Handle<TiledMap> = asset_server.load("map.tmx");
Expand All @@ -40,8 +40,14 @@ fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
}
```

Please note that you should have the `map.tmx` file in your local `assets/` folder, as well as required dependencies (for instance, associated tilesets).
Basically, all you have to do is to spawn a [`TiledMapHandle`](https://docs.rs/bevy_ecs_tiled/latest/bevy_ecs_tiled/struct.TiledMapHandle.html) with the map asset you want to load (the `map.tmx` file).
Note that this map asset should be in your local `assets/` folder, as well as required dependencies (for instance, associated tilesets).

You can customize various settings about how to load the map by inserting the [`TiledMapSettings`](https://docs.rs/bevy_ecs_tiled/latest/bevy_ecs_tiled/components/struct.TiledMapSettings.html) component on the map entity.
You can tweak how to load the map by adding various components on the map entity, notably:

Also, you can browse the [examples](https://github.com/adrien-bon/bevy_ecs_tiled/tree/main/examples/README.md) for more advanced use cases.
- [`TiledMapSettings`](https://docs.rs/bevy_ecs_tiled/latest/bevy_ecs_tiled/components/struct.TiledMapSettings.html)
- [`TilemapRenderSettings`](https://docs.rs/bevy_ecs_tilemap/latest/bevy_ecs_tilemap/map/struct.TilemapRenderSettings.html)
- [`Transform`](https://docs.rs/bevy/latest/bevy/transform/components/struct.Transform.html)
- [`Visibility`](https://docs.rs/bevy/latest/bevy/render/view/visibility/enum.Visibility.html)

You can browse the [examples](https://github.com/adrien-bon/bevy_ecs_tiled/tree/main/examples/README.md) for more advanced use cases.
1 change: 0 additions & 1 deletion book/src/guides/map_events.md

This file was deleted.

4 changes: 2 additions & 2 deletions book/src/guides/physics.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn main() {

// Just load the map as usual
fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
commands.spawn(TiledMapHandle(asset_server.load("finite.tmx")));
}
```
Expand All @@ -62,7 +62,7 @@ use bevy_ecs_tiled::prelude::*;

// Load the map with custom physics settings (and an Avian backend)
fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
commands.spawn((
TiledMapHandle(asset_server.load("finite.tmx")),
// With this configuration, we will restrict the spawn of collider
Expand Down
11 changes: 7 additions & 4 deletions book/src/guides/spawn_reload.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ pub fn despawn_map(

All child entities, like layers and tiles, will automatically be despawned.

## Reload a map
## Respawn / reload a map

If you want to reload a map, you can of course despawn it then spawn it again.
If you want to reload or respawn a map, you can of course despawn it then spawn it again.
It's tedious, but it works.

However, there is an easier way.
Instead, you can insert the `RespawnTiledMap` component:
You can instead insert the `RespawnTiledMap` component to the map entity:

```rust,no_run
fn respawn_map(
Expand All @@ -62,12 +62,13 @@ fn respawn_map(
}
```

This will reload the exact same map but using new entities.
This will load the exact same map but using new entities for layers or tiles (map entity will be preserved).
It means that if you updated some components (for instance, a tile color or an object position) they will be back as they were when you first loaded the map.
It's useful to implement a level respawn for instance.

Another use case is to load a new map over an existing one.
An easy way to do that is to just spawn a new `TiledMapHandle` over an existing map.
Note you can also reload the exact same map, which is equivalent to using the `RespawnTiledMap` component.

```rust,no_run
fn handle_reload(
Expand All @@ -83,3 +84,5 @@ fn handle_reload(
}
}
```

In both cases, note that map additional components such as `TiledMapSettings` or `TilemapRenderSettings` will be preserved.
44 changes: 44 additions & 0 deletions book/src/migrations/v0_5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# From v0.4.X to v0.5.X

## Overview

Version 0.5 updates the crate for Bevy v0.15.

It also takes advantage of the new `required_component` feature to simplify the crate API.

## Bevy v0.15 update

[Bevy official migration guide](https://bevyengine.org/learn/migration-guides/0-14-to-0-15/)

## Misc changes

### `TiledMapSettings` update

`map_initial_transform` and `map_initial_visibility` have been removed from `TiledMapSettings`.

If you want to tweak your map positioning or visibility, you should instead directly insert corresponding `Transform` or `Visibility` components on the map entity.

Before:

```rust,no_run
let map_handle: Handle<TiledMap> = asset_server.load("map.tmx");
commands.spawn((
TiledMapHandle(map_handle),
TiledMapSettings {
map_initial_transform: Transform::from_xyz(150., 100., 0.),
map_initial_visibility: Visibility::Hidden,
..Default::default()
},
));
```

After:

```rust,no_run
let map_handle: Handle<TiledMap> = asset_server.load("map.tmx");
commands.spawn((
TiledMapHandle(map_handle),
Transform::from_xyz(150., 100., 0.),
Visibility::Hidden,
));
```
2 changes: 1 addition & 1 deletion examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn main() {

fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
// Spawn a 2D camera (required by Bevy)
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);

// Load the map ...
let map_handle: Handle<TiledMap> = asset_server.load("finite.tmx");
Expand Down
43 changes: 16 additions & 27 deletions examples/helper/assets.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use bevy::{ecs::system::EntityCommands, prelude::*};
use bevy_ecs_tiled::prelude::*;
use bevy_ecs_tilemap::map::TilemapRenderSettings;

pub type MapInfosCallback = fn(&mut EntityCommands);

Expand Down Expand Up @@ -42,9 +41,7 @@ impl AssetsManager {
Self {
map_assets: Vec::new(),
map_entity: None,
text_entity: commands
.spawn(TextBundle::from(AssetsManager::BASE_TEXT))
.id(),
text_entity: commands.spawn(Text::from(AssetsManager::BASE_TEXT)).id(),
map_index: 0,
}
}
Expand All @@ -60,33 +57,25 @@ impl AssetsManager {
);

// Update displayed text
commands
.entity(self.text_entity)
.insert(TextBundle::from(format!(
"{}\nmap name = {}\n{}",
AssetsManager::BASE_TEXT,
self.map_assets[self.map_index].path,
self.map_assets[self.map_index].description
)));
commands.entity(self.text_entity).insert(Text::from(format!(
"{}\nmap name = {}\n{}",
AssetsManager::BASE_TEXT,
self.map_assets[self.map_index].path,
self.map_assets[self.map_index].description
)));

// Handle map update: spawn the map if it does not exist yet
// or just update the map handle if already spawned
// Handle map update: despawn the map if it already exists
if let Some(entity) = self.map_entity {
let mut entity_commands = commands.entity(entity);
entity_commands.insert(TiledMapHandle(
self.map_assets[self.map_index].asset.to_owned(),
));
entity_commands.remove::<TiledMapSettings>();
entity_commands.remove::<TilemapRenderSettings>();
(self.map_assets[self.map_index].callback)(&mut entity_commands);
} else {
let mut entity_commands = commands.spawn(TiledMapHandle(
self.map_assets[self.map_index].asset.to_owned(),
));
(self.map_assets[self.map_index].callback)(&mut entity_commands);
self.map_entity = Some(entity_commands.id());
commands.entity(entity).despawn_recursive();
}

// Then spawn the new map
let mut entity_commands = commands.spawn(TiledMapHandle(
self.map_assets[self.map_index].asset.to_owned(),
));
(self.map_assets[self.map_index].callback)(&mut entity_commands);
self.map_entity = Some(entity_commands.id());

// Update the map index
self.map_index += 1;
if self.map_index >= self.map_assets.len() {
Expand Down
6 changes: 1 addition & 5 deletions examples/helper/avian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ pub fn spawn_player(commands: &mut Commands, radius: f32, spawn_position: Vec2)
.insert(Name::new("PlayerControlledObject (Avian2D physics)"))
.insert(Collider::circle(radius))
.insert(GravityScale(GRAVITY_SCALE))
.insert(TransformBundle::from(Transform::from_xyz(
spawn_position.x,
spawn_position.y,
0.0,
)));
.insert(Transform::from_xyz(spawn_position.x, spawn_position.y, 0.0));
}

pub fn move_player(
Expand Down
2 changes: 1 addition & 1 deletion examples/helper/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub fn movement(
}

let z = transform.translation.z;
transform.translation += time.delta_seconds() * direction * 500.;
transform.translation += time.delta_secs() * direction * 500.;
// Important! We need to restore the Z values when moving the camera around.
// Bevy has a specific camera setup and this can mess with how our layers are shown.
transform.translation.z = z;
Expand Down
4 changes: 2 additions & 2 deletions examples/helper/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ pub fn rotate(
) {
for (_, mut transform) in tilemap.iter_mut() {
if keyboard_input.pressed(KeyCode::KeyQ) {
transform.rotate_z(f32::to_radians(ROTATION_SPEED * time.delta_seconds()));
transform.rotate_z(f32::to_radians(ROTATION_SPEED * time.delta_secs()));
}

if keyboard_input.pressed(KeyCode::KeyE) {
transform.rotate_z(f32::to_radians(ROTATION_SPEED * time.delta_seconds() * -1.));
transform.rotate_z(f32::to_radians(ROTATION_SPEED * time.delta_secs() * -1.));
}
}
}
6 changes: 1 addition & 5 deletions examples/helper/rapier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ pub fn spawn_player(commands: &mut Commands, radius: f32, spawn_position: Vec2)
.insert(Collider::ball(radius))
.insert(Velocity::zero())
.insert(GravityScale(GRAVITY_SCALE))
.insert(TransformBundle::from(Transform::from_xyz(
spawn_position.x,
spawn_position.y,
0.0,
)));
.insert(Transform::from_xyz(spawn_position.x, spawn_position.y, 0.0));
}

pub fn move_player(
Expand Down
Loading
Loading