Skip to content

Commit

Permalink
Merge pull request #574 from rparrett/bevy-0.15
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherBiscardi authored Dec 14, 2024
2 parents 93a01d7 + 86235d6 commit 0f67a1f
Show file tree
Hide file tree
Showing 44 changed files with 426 additions and 430 deletions.
11 changes: 7 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,26 @@ render = []
serde = ["dep:serde"]

[dependencies]
bevy = { version = "0.14.0", default-features = false, features = [
bevy = { version = "0.15", default-features = false, features = [
"bevy_core_pipeline",
"bevy_render",
"bevy_asset",
"bevy_sprite",
] }
# See Bevy#16563
bevy_internal = { version = "0.15", features = ["bevy_image"] }
log = "0.4"
serde = { version = "1", features = ["derive"], optional = true }

[dev-dependencies]
ldtk_rust = { version = "0.6" }
rand = "0.8"
env_logger = "0.10"
serde_json = { version = "1.0" }
tiled = { version = "0.11.0", default-features = false }
thiserror = { version = "1.0" }

[dev-dependencies.bevy]
version = "0.14.0"
version = "0.15"
default-features = false
features = [
"bevy_core_pipeline",
Expand All @@ -43,6 +44,7 @@ features = [
"png",
"ktx2",
"bevy_winit",
"bevy_window",
"bevy_text",
"bevy_sprite",
#"file_watcher",
Expand All @@ -51,7 +53,7 @@ features = [
]

[target.'cfg(unix)'.dev-dependencies.bevy]
version = "0.14.0"
version = "0.15"
default-features = false
features = [
"bevy_core_pipeline",
Expand All @@ -60,6 +62,7 @@ features = [
"png",
"ktx2",
"bevy_winit",
"bevy_window",
"wayland",
"x11",
"bevy_text",
Expand Down
4 changes: 2 additions & 2 deletions examples/3d_iso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use bevy_ecs_tilemap::prelude::*;
mod helpers;

fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);

let map_handle: Handle<helpers::tiled::TiledMap> = asset_server.load("iso_map.tmx");
let map_handle = helpers::tiled::TiledMapHandle(asset_server.load("iso_map.tmx"));

commands.spawn(helpers::tiled::TiledMapBundle {
tiled_map: map_handle,
Expand Down
4 changes: 2 additions & 2 deletions examples/accessing_tiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct CurrentColor(u16);
struct LastUpdate(f64);

fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);

let texture_handle: Handle<Image> = asset_server.load("tiles.png");

Expand Down Expand Up @@ -109,7 +109,7 @@ fn update_map(
)>,
mut tile_query: Query<&mut TileTextureIndex>,
) {
let current_time = time.elapsed_seconds_f64();
let current_time = time.elapsed_secs_f64();
for (mut current_color, mut last_update, tile_storage, map_size) in tilemap_query.iter_mut() {
if current_time - last_update.0 > 0.1 {
current_color.0 += 1;
Expand Down
2 changes: 1 addition & 1 deletion examples/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fn create_animated_flowers(mut commands: Commands, asset_server: Res<AssetServer
}

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

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn startup(
ArrayTextureLoader,
>,
) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);

let texture_handle: Handle<Image> = asset_server.load("tiles.png");

Expand Down
4 changes: 3 additions & 1 deletion examples/bench.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use bevy::{
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
prelude::*,
window::PresentMode,
};
use bevy_ecs_tilemap::prelude::*;

mod helpers;

fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);

let texture_handle: Handle<Image> = asset_server.load("tiles.png");

Expand Down Expand Up @@ -50,6 +51,7 @@ fn main() {
.set(WindowPlugin {
primary_window: Some(Window {
title: String::from("Benchmark Example"),
present_mode: PresentMode::AutoNoVsync,
..Default::default()
}),
..default()
Expand Down
4 changes: 2 additions & 2 deletions examples/chunking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bevy::{math::Vec3Swizzles, prelude::*, utils::HashSet};
use bevy_ecs_tilemap::prelude::*;
mod helpers;

/// Press WASD to move the camera around, and watch as chunks spawn/despawn in response.
// Press WASD to move the camera around, and watch as chunks spawn/despawn in response.

const TILE_SIZE: TilemapTileSize = TilemapTileSize { x: 16.0, y: 16.0 };
// For this example, don't choose too large a chunk size.
Expand Down Expand Up @@ -54,7 +54,7 @@ fn spawn_chunk(commands: &mut Commands, asset_server: &AssetServer, chunk_pos: I
}

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

fn camera_pos_to_chunk_pos(camera_pos: &Vec2) -> IVec2 {
Expand Down
2 changes: 1 addition & 1 deletion examples/colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod helpers;
const QUADRANT_SIDE_LENGTH: u32 = 64;

fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);

let texture_handle: Handle<Image> = asset_server.load("tiles.png");

Expand Down
6 changes: 3 additions & 3 deletions examples/custom_shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ fn startup(
asset_server: Res<AssetServer>,
mut materials: ResMut<Assets<MyMaterial>>,
) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);

let my_material_handle = materials.add(MyMaterial {
let my_material_handle = MaterialTilemapHandle::from(materials.add(MyMaterial {
brightness: 0.5,
..default()
});
}));

let texture_handle: Handle<Image> = asset_server.load("tiles.png");

Expand Down
24 changes: 10 additions & 14 deletions examples/frustum_cull_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl FromWorld for FontHandle {

// Generates the initial tilemap, which is a square grid.
fn spawn_tilemap(mut commands: Commands, tile_handle_square: Res<TileHandleSquare>) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);

let map_size = TilemapSize {
// Render chunks are of size 64, so let's create two render chunks
Expand Down Expand Up @@ -122,13 +122,6 @@ fn spawn_map_type_label(
windows: Query<&Window>,
map_type_q: Query<&TilemapType>,
) {
let text_style = TextStyle {
font: font_handle.clone(),
font_size: 20.0,
color: Color::BLACK,
};
let text_justify = JustifyText::Center;

for window in windows.iter() {
for map_type in map_type_q.iter() {
// Place the map type label somewhere in the top left side of the screen
Expand All @@ -138,12 +131,15 @@ fn spawn_map_type_label(
..Default::default()
};
commands.spawn((
Text2dBundle {
text: Text::from_section(format!("{map_type:?}"), text_style.clone())
.with_justify(text_justify),
transform,
Text2d::new(format!("{map_type:?}")),
TextFont {
font: font_handle.clone(),
font_size: 20.0,
..default()
},
TextColor(Color::BLACK),
TextLayout::new_with_justify(JustifyText::Center),
transform,
MapTypeLabel,
));
}
Expand All @@ -160,7 +156,7 @@ fn swap_map_type(
&mut TilemapTileSize,
)>,
keyboard_input: Res<ButtonInput<KeyCode>>,
mut map_type_label_q: Query<&mut Text, With<MapTypeLabel>>,
mut map_type_label_q: Query<&mut Text2d, With<MapTypeLabel>>,
tile_handle_square: Res<TileHandleSquare>,
tile_handle_hex_row: Res<TileHandleHexRow>,
tile_handle_hex_col: Res<TileHandleHexCol>,
Expand Down Expand Up @@ -216,7 +212,7 @@ fn swap_map_type(
}

for mut label_text in map_type_label_q.iter_mut() {
label_text.sections[0].value = format!("{:?}", map_type.as_ref());
label_text.0 = format!("{:?}", map_type.as_ref());
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/game_of_life.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use bevy_ecs_tilemap::prelude::*;
mod helpers;

fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);

let texture_handle: Handle<Image> = asset_server.load("tiles.png");

Expand Down Expand Up @@ -58,7 +58,7 @@ fn update(
mut tile_storage_query: Query<(&TileStorage, &TilemapSize, &mut LastUpdate)>,
tile_query: Query<(Entity, &TilePos, &TileVisible)>,
) {
let current_time = time.elapsed_seconds_f64();
let current_time = time.elapsed_secs_f64();
let (tile_storage, map_size, mut last_update) = tile_storage_query.single_mut();
if current_time - last_update.0 > 0.1 {
for (entity, position, visibility) in tile_query.iter() {
Expand Down
2 changes: 1 addition & 1 deletion examples/helpers/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,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
30 changes: 15 additions & 15 deletions examples/helpers/ldtk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ use bevy_ecs_tilemap::{
use std::{collections::HashMap, io::ErrorKind};
use thiserror::Error;

use bevy::{
asset::{io::Reader, AsyncReadExt},
reflect::TypePath,
};
use bevy::{asset::io::Reader, reflect::TypePath};
use bevy::{
asset::{AssetLoader, AssetPath, LoadContext},
prelude::*,
Expand Down Expand Up @@ -39,9 +36,12 @@ pub struct LdtkMapConfig {
pub selected_level: usize,
}

#[derive(Default, Component)]
pub struct LdtkMapHandle(pub Handle<LdtkMap>);

#[derive(Default, Bundle)]
pub struct LdtkMapBundle {
pub ldtk_map: Handle<LdtkMap>,
pub ldtk_map: LdtkMapHandle,
pub ldtk_map_config: LdtkMapConfig,
pub transform: Transform,
pub global_transform: GlobalTransform,
Expand All @@ -61,11 +61,11 @@ impl AssetLoader for LdtkLoader {
type Settings = ();
type Error = LdtkAssetLoaderError;

async fn load<'a>(
&'a self,
reader: &'a mut Reader<'_>,
_settings: &'a Self::Settings,
load_context: &'a mut LoadContext<'_>,
async fn load(
&self,
reader: &mut dyn Reader,
_settings: &Self::Settings,
load_context: &mut LoadContext<'_>,
) -> Result<Self::Asset, Self::Error> {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
Expand Down Expand Up @@ -110,8 +110,8 @@ pub fn process_loaded_tile_maps(
mut commands: Commands,
mut map_events: EventReader<AssetEvent<LdtkMap>>,
maps: Res<Assets<LdtkMap>>,
mut query: Query<(Entity, &Handle<LdtkMap>, &LdtkMapConfig)>,
new_maps: Query<&Handle<LdtkMap>, Added<Handle<LdtkMap>>>,
mut query: Query<(Entity, &LdtkMapHandle, &LdtkMapConfig)>,
new_maps: Query<&LdtkMapHandle, Added<LdtkMapHandle>>,
) {
let mut changed_maps = Vec::<AssetId<LdtkMap>>::default();
for event in map_events.read() {
Expand All @@ -136,16 +136,16 @@ pub fn process_loaded_tile_maps(

// If we have new map entities, add them to the changed_maps list
for new_map_handle in new_maps.iter() {
changed_maps.push(new_map_handle.id());
changed_maps.push(new_map_handle.0.id());
}

for changed_map in changed_maps.iter() {
for (entity, map_handle, map_config) in query.iter_mut() {
// only deal with currently changed map
if map_handle.id() != *changed_map {
if map_handle.0.id() != *changed_map {
continue;
}
if let Some(ldtk_map) = maps.get(map_handle) {
if let Some(ldtk_map) = maps.get(&map_handle.0) {
// Despawn all existing tilemaps for this LdtkMap
commands.entity(entity).despawn_descendants();

Expand Down
Loading

0 comments on commit 0f67a1f

Please sign in to comment.