Skip to content

Commit

Permalink
Merge pull request #310 from StarArawn/bevy-track
Browse files Browse the repository at this point in the history
Track bevy main
  • Loading branch information
StarArawn committed Nov 13, 2022
2 parents 0c9a2cd + 691bdf5 commit 21a783c
Show file tree
Hide file tree
Showing 41 changed files with 864 additions and 744 deletions.
39 changes: 33 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "bevy_ecs_tilemap"
description = "A tilemap rendering plugin for bevy which is more ECS friendly by having an entity per tile."
version = "0.8.0"
version = "0.9.0"
authors = ["John Mitchell"]
homepage = "https://github.com/StarArawn/bevy_ecs_tilemap"
repository = "https://github.com/StarArawn/bevy_ecs_tilemap"
Expand All @@ -15,7 +15,12 @@ atlas = []
render = []

[dependencies]
bevy = { version = "0.8", default-features = false, features=["bevy_core_pipeline", "bevy_render", "bevy_asset", "bevy_sprite"] }
bevy = { git = "https://github.com/bevyengine/bevy", version = "0.9", default-features = false, features = [
"bevy_core_pipeline",
"bevy_render",
"bevy_asset",
"bevy_sprite",
] }
log = "0.4"
regex = "1.5.4"

Expand All @@ -28,14 +33,36 @@ serde_json = { version = "1.0" }
tiled = { version = "0.9", default-features = false }

[dev-dependencies.bevy]
version = "0.8"
git = "https://github.com/bevyengine/bevy"
version = "0.9"
default-features = false
features=["bevy_core_pipeline", "bevy_render", "bevy_asset", "png", "ktx2", "bevy_winit", "bevy_text", "bevy_sprite", "filesystem_watcher"]
features = [
"bevy_core_pipeline",
"bevy_render",
"bevy_asset",
"png",
"ktx2",
"bevy_winit",
"bevy_text",
"bevy_sprite",
"filesystem_watcher",
]

[target.'cfg(unix)'.dev-dependencies.bevy]
version = "0.8"
git = "https://github.com/bevyengine/bevy"
version = "0.9"
default-features = false
features=["bevy_core_pipeline", "bevy_render", "bevy_asset", "png", "ktx2", "bevy_winit", "x11", "bevy_text", "bevy_sprite"]
features = [
"bevy_core_pipeline",
"bevy_render",
"bevy_asset",
"png",
"ktx2",
"bevy_winit",
"x11",
"bevy_text",
"bevy_sprite",
]

[target.wasm32-unknown-unknown]
runner = "wasm-server-runner"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ wasm-server-runner .\target\wasm32-unknown-unknown\release\examples\animation.wa
|bevy|bevy_ecs_tilemap|
|---|---|
|`main`|`bevy-track`|
|0.9|0.9|
|0.8|0.8|
|0.8|0.7|
|0.7|0.6|
Expand Down
34 changes: 19 additions & 15 deletions examples/accessing_tiles.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy::{prelude::*, render::texture::ImageSettings};
use bevy::prelude::*;
use bevy_ecs_tilemap::helpers::square_grid::neighbors::Neighbors;
use bevy_ecs_tilemap::prelude::*;

Expand All @@ -11,7 +11,7 @@ struct CurrentColor(u16);
struct LastUpdate(f64);

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

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

Expand All @@ -30,16 +30,15 @@ fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
// Create a tilemap entity a little early
// We want this entity early because we need to tell each tile which tilemap entity
// it is associated with. This is done with the TilemapId component on each tile.
let tilemap_entity = commands.spawn().id();
let tilemap_entity = commands.spawn_empty().id();

// Spawn a 32 by 32 tilemap.
// Alternatively, you can use helpers::fill_tilemap.
for x in 0..map_size.x {
for y in 0..map_size.y {
let tile_pos = TilePos { x, y };
let tile_entity = commands
.spawn()
.insert_bundle(TileBundle {
.spawn(TileBundle {
position: tile_pos,
tilemap_id: TilemapId(tilemap_entity),
..Default::default()
Expand Down Expand Up @@ -85,7 +84,7 @@ fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
// Once the tile storage is inserted onto the tilemap entity it can no longer be accessed.
commands
.entity(tilemap_entity)
.insert_bundle(TilemapBundle {
.insert(TilemapBundle {
grid_size,
size: map_size,
storage: tile_storage,
Expand All @@ -110,7 +109,7 @@ fn update_map(
)>,
mut tile_query: Query<&mut TileTextureIndex>,
) {
let current_time = time.seconds_since_startup();
let current_time = time.elapsed_seconds_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 Expand Up @@ -150,14 +149,19 @@ fn update_map(

fn main() {
App::new()
.insert_resource(WindowDescriptor {
width: 1270.0,
height: 720.0,
title: String::from("Basic Example"),
..Default::default()
})
.insert_resource(ImageSettings::default_nearest())
.add_plugins(DefaultPlugins)
.add_plugins(
DefaultPlugins
.set(WindowPlugin {
window: WindowDescriptor {
width: 1270.0,
height: 720.0,
title: String::from("Accessing Tiles Example"),
..Default::default()
},
..default()
})
.set(ImagePlugin::default_nearest()),
)
.add_plugin(TilemapPlugin)
.add_startup_system(startup)
.add_system(helpers::camera::movement)
Expand Down
76 changes: 38 additions & 38 deletions examples/animation.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use bevy::{
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
prelude::*,
render::texture::ImageSettings,
};
use bevy_ecs_tilemap::prelude::*;
use bevy_ecs_tilemap::tiles::{AnimatedTile, TileBundle, TilePos, TileStorage, TileTextureIndex};
Expand Down Expand Up @@ -34,7 +33,7 @@ const FLOWERS_METADATA: TilemapMetadata = TilemapMetadata {
fn create_background(mut commands: Commands, asset_server: Res<AssetServer>) {
let texture_handle: Handle<Image> = asset_server.load(BACKGROUND);

let tilemap_entity = commands.spawn().id();
let tilemap_entity = commands.spawn_empty().id();

let TilemapMetadata {
size,
Expand All @@ -54,18 +53,16 @@ fn create_background(mut commands: Commands, asset_server: Res<AssetServer>) {

let map_type = TilemapType::default();

commands
.entity(tilemap_entity)
.insert_bundle(TilemapBundle {
size,
grid_size,
map_type,
tile_size,
storage: tile_storage,
texture: TilemapTexture::Single(texture_handle),
transform: get_tilemap_center_transform(&size, &grid_size, &map_type, 0.0),
..Default::default()
});
commands.entity(tilemap_entity).insert(TilemapBundle {
size,
grid_size,
map_type,
tile_size,
storage: tile_storage,
texture: TilemapTexture::Single(texture_handle),
transform: get_tilemap_center_transform(&size, &grid_size, &map_type, 0.0),
..Default::default()
});
}

fn create_animated_flowers(mut commands: Commands, asset_server: Res<AssetServer>) {
Expand All @@ -79,7 +76,7 @@ fn create_animated_flowers(mut commands: Commands, asset_server: Res<AssetServer

let mut tile_storage = TileStorage::empty(size);

let tilemap_entity = commands.spawn().id();
let tilemap_entity = commands.spawn_empty().id();

// Choose 10 random tiles to contain flowers.
let mut rng = thread_rng();
Expand All @@ -92,8 +89,8 @@ fn create_animated_flowers(mut commands: Commands, asset_server: Res<AssetServer
for (x, y) in indices.into_iter().choose_multiple(&mut rng, 10) {
let tile_pos = TilePos { x, y };
let tile_entity = commands
.spawn()
.insert_bundle(TileBundle {
.spawn_empty()
.insert(TileBundle {
position: tile_pos,
tilemap_id: TilemapId(tilemap_entity),
texture_index: TileTextureIndex(0),
Expand All @@ -112,34 +109,37 @@ fn create_animated_flowers(mut commands: Commands, asset_server: Res<AssetServer
}
let map_type = TilemapType::Square;

commands
.entity(tilemap_entity)
.insert_bundle(TilemapBundle {
size,
grid_size,
map_type,
tile_size,
storage: tile_storage,
texture: TilemapTexture::Single(texture_handle),
transform: get_tilemap_center_transform(&size, &grid_size, &map_type, 1.0),
..Default::default()
});
commands.entity(tilemap_entity).insert(TilemapBundle {
size,
grid_size,
map_type,
tile_size,
storage: tile_storage,
texture: TilemapTexture::Single(texture_handle),
transform: get_tilemap_center_transform(&size, &grid_size, &map_type, 1.0),
..Default::default()
});
}

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

fn main() {
App::new()
.insert_resource(WindowDescriptor {
width: 1270.0,
height: 720.0,
title: String::from("Animated Map Example"),
..Default::default()
})
.insert_resource(ImageSettings::default_nearest())
.add_plugins(DefaultPlugins)
.add_plugins(
DefaultPlugins
.set(WindowPlugin {
window: WindowDescriptor {
width: 1270.0,
height: 720.0,
title: String::from("Animated Map Example"),
..Default::default()
},
..default()
})
.set(ImagePlugin::default_nearest()),
)
.add_plugin(LogDiagnosticsPlugin::default())
.add_plugin(FrameTimeDiagnosticsPlugin::default())
.add_plugin(TilemapPlugin)
Expand Down
55 changes: 25 additions & 30 deletions examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use bevy::{
prelude::*,
render::texture::{BevyDefault, ImageSettings},
};
use bevy::{prelude::*, render::texture::BevyDefault};
use bevy_ecs_tilemap::prelude::*;

mod helpers;
Expand All @@ -11,7 +8,7 @@ fn startup(
asset_server: Res<AssetServer>,
#[cfg(not(feature = "atlas"))] array_texture_loader: Res<ArrayTextureLoader>,
) {
commands.spawn_bundle(Camera2dBundle::default());
commands.spawn(Camera2dBundle::default());

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

Expand All @@ -22,7 +19,7 @@ fn startup(
// it is associated with. This is done with the TilemapId component on each tile.
// Eventually, we will insert the `TilemapBundle` bundle on the entity, which
// will contain various necessary components, such as `TileStorage`.
let tilemap_entity = commands.spawn().id();
let tilemap_entity = commands.spawn_empty().id();

// To begin creating the map we will need a `TileStorage` component.
// This component is a grid of tile entities and is used to help keep track of individual
Expand All @@ -36,8 +33,7 @@ fn startup(
for y in 0..tilemap_size.y {
let tile_pos = TilePos { x, y };
let tile_entity = commands
.spawn()
.insert_bundle(TileBundle {
.spawn(TileBundle {
position: tile_pos,
tilemap_id: TilemapId(tilemap_entity),
..Default::default()
Expand All @@ -51,18 +47,16 @@ fn startup(
let grid_size = tile_size.into();
let map_type = TilemapType::default();

commands
.entity(tilemap_entity)
.insert_bundle(TilemapBundle {
grid_size,
map_type,
size: tilemap_size,
storage: tile_storage,
texture: TilemapTexture::Single(texture_handle),
tile_size,
transform: get_tilemap_center_transform(&tilemap_size, &grid_size, &map_type, 0.0),
..Default::default()
});
commands.entity(tilemap_entity).insert(TilemapBundle {
grid_size,
map_type,
size: tilemap_size,
storage: tile_storage,
texture: TilemapTexture::Single(texture_handle),
tile_size,
transform: get_tilemap_center_transform(&tilemap_size, &grid_size, &map_type, 0.0),
..Default::default()
});

// Add atlas to array texture loader so it's preprocessed before we need to use it.
// Only used when the atlas feature is off and we are using array textures.
Expand Down Expand Up @@ -107,16 +101,17 @@ fn swap_texture_or_hide(

fn main() {
App::new()
.insert_resource(WindowDescriptor {
width: 1270.0,
height: 720.0,
title: String::from(
"Basic Example - Press Space to change Texture and H to show/hide tilemap.",
),
..Default::default()
})
.insert_resource(ImageSettings::default_nearest())
.add_plugins(DefaultPlugins)
.add_plugins(DefaultPlugins.set(WindowPlugin{
window: WindowDescriptor {
width: 1270.0,
height: 720.0,
title: String::from(
"Basic Example - Press Space to change Texture and H to show/hide tilemap.",
),
..Default::default()
},
..default()
}).set(ImagePlugin::default_nearest()))
.add_plugin(TilemapPlugin)
.add_startup_system(startup)
.add_system(helpers::camera::movement)
Expand Down
Loading

0 comments on commit 21a783c

Please sign in to comment.