Skip to content

Upgrade to bevy 0.7 #5

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

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
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
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ bevy = "0.7"
# asefile = "0.3.2"
asefile = { git = "https://github.com/B-Reif/asefile", branch = "fix-tileset-inner" }
anyhow = "1.0"
benimator = { version = "2.0", optional = true }
bevy_ecs_tilemap = { version = "0.5", optional = true }
benimator = { version = "3.0", optional = true }
bevy_ecs_tilemap = { version = "0.6", optional = true }

[profile.dev.package."*"]
opt-level = 2
Expand All @@ -23,4 +23,4 @@ required-features = ["benimator"]

[[example]]
name = "tilemap"
required-features = ["bevy_ecs_tilemap"]
required-features = ["bevy_ecs_tilemap"]
8 changes: 4 additions & 4 deletions examples/animated/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ fn main() {
.add_plugins(DefaultPlugins)
.add_plugin(loader::AseLoaderDefaultPlugin)
.add_plugin(benimator::AnimationPlugin::default())
.add_system(exit_on_esc_system.system())
.add_system(exit_on_esc_system)
.add_state(AppState::Loading)
.add_system_set(SystemSet::on_enter(AppState::Loading).with_system(load_sprites.system()))
.add_system_set(SystemSet::on_enter(AppState::Loading).with_system(load_sprites))
.add_system_set(
SystemSet::on_update(AppState::Loading).with_system(check_loading_sprites.system()),
SystemSet::on_update(AppState::Loading).with_system(check_loading_sprites),
)
.add_system_set(SystemSet::on_enter(AppState::Game).with_system(spawn_sprites.system()))
.add_system_set(SystemSet::on_enter(AppState::Game).with_system(spawn_sprites))
.run()
}

Expand Down
18 changes: 9 additions & 9 deletions examples/tilemap/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ fn main() {
.add_plugins(DefaultPlugins)
.add_plugin(TilemapPlugin)
.add_plugin(loader::AseLoaderDefaultPlugin)
.add_system(exit_on_esc_system.system())
.add_system(exit_on_esc_system)
.add_state(AppState::Loading)
.add_system_set(SystemSet::on_enter(AppState::Loading).with_system(load_sprites.system()))
.add_system_set(SystemSet::on_enter(AppState::Loading).with_system(load_sprites))
.add_system_set(
SystemSet::on_update(AppState::Loading).with_system(check_loading_sprites.system()),
SystemSet::on_update(AppState::Loading).with_system(check_loading_sprites),
)
.add_system_set(SystemSet::on_enter(AppState::Game).with_system(spawn_camera.system()))
.add_system_set(SystemSet::on_enter(AppState::Game).with_system(spawn_tiles.system()))
.add_system_set(SystemSet::on_enter(AppState::Game).with_system(spawn_camera))
.add_system_set(SystemSet::on_enter(AppState::Game).with_system(spawn_tiles))
.run()
}

Expand Down Expand Up @@ -64,7 +64,7 @@ fn set_tiles(layer_builder: &mut LayerBuilder<TileBundle>) {
..Tile::default()
};
let tile_pos = UVec2::new(x as u32, y as u32);
layer_builder.set_tile(tile_pos, tile.into()).unwrap();
layer_builder.set_tile(tile_pos.into(), tile.into()).unwrap();
}
}
}
Expand All @@ -77,16 +77,16 @@ fn spawn_tiles(
) {
for (_, tileset) in tilesets.iter() {
let texture_handle = tileset.texture.clone();
let material_handle = materials.add(ColorMaterial::texture(texture_handle));
//let material_handle = materials.add(ColorMaterial::from(texture_handle));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't mean to leave these comments in.

// The layer_settings method of Tileset is implemented in the "bevy_ecs_tilemap" feature.
let settings = tileset.layer_settings(UVec2::new(3, 3), UVec2::new(3, 3));
let settings = tileset.layer_settings(MapSize(3, 3), ChunkSize(3, 3));

let (mut layer_builder, layer_entity) =
LayerBuilder::<TileBundle>::new(&mut commands, settings, 0u16, 0u16);

set_tiles(&mut layer_builder);

map_query.build_layer(&mut commands, layer_builder, material_handle);
map_query.build_layer(&mut commands, layer_builder, texture_handle);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed these because build_layer doesn't accept ColorMaterial. I made this change quickly without understanding what the example is trying to do, I'll fix it soon


let map_entity = commands.spawn().id();
let mut map = Map::new(0u16, map_entity);
Expand Down
2 changes: 1 addition & 1 deletion src/asset/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub(crate) struct SpriteData<T> {
}
impl SpriteData<Image> {
pub(crate) fn new(ase: &AsepriteFile, frame: u32) -> Self {
let img = ase.frame(frame).image();
let img = &ase.frame(frame).image();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why I did this, I'll look into that

let size = Extent3d {
width: ase.width() as u32,
height: ase.height() as u32,
Expand Down
16 changes: 8 additions & 8 deletions src/bevy_ecs_tilemap.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::asset::{TileSize, Tileset};
use bevy::math::{UVec2, Vec2};
use bevy::prelude::Vec2;
use bevy_ecs_tilemap::prelude::*;

impl From<TileSize> for Vec2 {
Expand All @@ -16,22 +16,22 @@ impl Tileset {
/// ```
/// #[cfg(feature = "bevy_ecs_tilemap")]
/// use bevy_ase::asset::Tileset;
/// use bevy_ecs_tilemap::LayerSettings;
/// use bevy::math::UVec2;
/// use bevy_ecs_tilemap::{MapSize, ChunkSize, LayerSettings};
///
/// // Create new layer settings from a tileset, with specified map size and chunk size.
/// fn my_layer_settings(tileset: &Tileset) -> LayerSettings {
/// let map_size = UVec2::new(30, 30);
/// let chunk_size = UVec2::new(15, 15);
/// let map_size = MapSize(30, 30);
/// let chunk_size = ChunkSize(15, 15);
/// tileset.layer_settings(map_size, chunk_size)
/// }
/// ```
pub fn layer_settings(&self, map_size: UVec2, chunk_size: UVec2) -> LayerSettings {
pub fn layer_settings(&self, map_size: MapSize, chunk_size: ChunkSize) -> LayerSettings {
let texture_size = self.texture_size();
LayerSettings::new(
map_size,
chunk_size,
Vec2::new(self.tile_size.width as f32, self.tile_size.height as f32),
self.texture_size(),
TileSize(self.tile_size.width as f32, self.tile_size.height as f32),
TextureSize(texture_size.x, texture_size.y),
)
}
}
2 changes: 1 addition & 1 deletion src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ pub(crate) type AseAssetResources<'a> = (
/// // Creates a Bevy app and adds the ase_importer system.
/// // This system is already added by default in AseLoaderPlugin.
/// fn app() {
/// App::new().add_system(ase_importer.system());
/// App::new().add_system(ase_importer);
/// }
/// ```
pub fn ase_importer(
Expand Down