-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from MrGVSV/bevy-0.6
Add Support for Bevy 0.6
- Loading branch information
Showing
6 changed files
with
134 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[package] | ||
name = "bevy_tile_atlas" | ||
version = "0.1.4" | ||
edition = "2018" | ||
version = "0.2.0" | ||
edition = "2021" | ||
authors = ["Gino Valente <[email protected]>"] | ||
description = "A TextureAtlas builder for ordered tilesets" | ||
repository = "https://github.com/MrGVSV/bevy_tile_atlas" | ||
|
@@ -10,14 +10,23 @@ keywords = ["bevy", "tile", "tileset", "texture", "ordered"] | |
readme = "README.md" | ||
exclude = ["assets/**/*", ".github/**/*"] | ||
|
||
[badges] | ||
maintenance = { status = "as-is" } | ||
|
||
|
||
[dependencies] | ||
bevy = "0.5" | ||
bevy_asset = { version = "0.6", default-features = false } | ||
bevy_ecs = { version = "0.6", default-features = false } | ||
bevy_log = { version = "0.6", default-features = false, optional = true } | ||
bevy_math = { version = "0.6", default-features = false } | ||
bevy_render = { version = "0.6", default-features = false } | ||
bevy_sprite = { version = "0.6", default-features = false } | ||
thiserror = "1.0.30" | ||
|
||
[dev-dependencies] | ||
bevy = "0.6" | ||
|
||
[features] | ||
default = ["debug"] | ||
# Enables logging (specifically for warnings, errors, or automatic texture format conversions) | ||
debug = ["bevy_log"] | ||
|
||
[[example]] | ||
name = "atlas" | ||
path = "examples/atlas.rs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,38 @@ | ||
use bevy::asset::{Assets, Handle, HandleId}; | ||
use bevy::ecs::component::Component; | ||
use bevy::prelude::{ResMut, Texture}; | ||
//! Defines the `TextureStore` trait which is used by `TileAtlasBuilder` to manage its textures | ||
use bevy_asset::{Assets, Handle, HandleId}; | ||
use bevy_ecs::system::{ResMut, Resource}; | ||
use bevy_render::texture::Image; | ||
use std::ops::{Deref, DerefMut}; | ||
|
||
/// Trait used in the [`TileAtlasBuilder::finish`](crate::TileAtlasBuilder::finish) method to get and | ||
/// add textures. | ||
/// | ||
/// The reason for such a trait and not simply using `Assets<Image>` is to allow the builder to be used | ||
/// in places where `Assets<Image>` might not be available (such as within a custom `AssetLoader`). | ||
pub trait TextureStore { | ||
fn add(&mut self, asset: Texture) -> Handle<Texture>; | ||
fn get<H: Into<HandleId>>(&self, handle: H) -> Option<&Texture>; | ||
/// Add a texture to the store | ||
fn add(&mut self, asset: Image) -> Handle<Image>; | ||
/// Get a texture from the store | ||
fn get<H: Into<HandleId>>(&self, handle: H) -> Option<&Image>; | ||
} | ||
|
||
impl TextureStore for Assets<Texture> { | ||
fn add(&mut self, asset: Texture) -> Handle<Texture> { | ||
impl TextureStore for Assets<Image> { | ||
fn add(&mut self, asset: Image) -> Handle<Image> { | ||
self.add(asset) | ||
} | ||
|
||
fn get<H: Into<HandleId>>(&self, handle: H) -> Option<&Texture> { | ||
fn get<H: Into<HandleId>>(&self, handle: H) -> Option<&Image> { | ||
self.get(handle) | ||
} | ||
} | ||
|
||
impl<'w, T: TextureStore + Component> TextureStore for ResMut<'w, T> { | ||
fn add(&mut self, asset: Texture) -> Handle<Texture> { | ||
impl<'w, T: TextureStore + Resource> TextureStore for ResMut<'w, T> { | ||
fn add(&mut self, asset: Image) -> Handle<Image> { | ||
self.deref_mut().add(asset) | ||
} | ||
|
||
fn get<H: Into<HandleId>>(&self, handle: H) -> Option<&Texture> { | ||
fn get<H: Into<HandleId>>(&self, handle: H) -> Option<&Image> { | ||
self.deref().get(handle) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters