2020-07-10 08:37:06 +00:00
|
|
|
pub mod collide_aabb;
|
2020-07-17 02:34:18 +00:00
|
|
|
pub mod entity;
|
|
|
|
|
2020-05-30 19:31:04 +00:00
|
|
|
mod color_material;
|
2020-06-15 19:47:35 +00:00
|
|
|
mod dynamic_texture_atlas_builder;
|
2020-06-02 02:23:11 +00:00
|
|
|
mod rect;
|
2020-05-30 19:31:04 +00:00
|
|
|
mod render;
|
|
|
|
mod sprite;
|
2020-06-06 07:12:38 +00:00
|
|
|
mod texture_atlas;
|
|
|
|
mod texture_atlas_builder;
|
2020-05-30 19:31:04 +00:00
|
|
|
|
2021-02-18 21:20:37 +00:00
|
|
|
pub mod prelude {
|
|
|
|
pub use crate::{
|
|
|
|
entity::{SpriteBundle, SpriteSheetBundle},
|
|
|
|
ColorMaterial, Sprite, SpriteResizeMode, TextureAtlas, TextureAtlasSprite,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-05-30 19:31:04 +00:00
|
|
|
pub use color_material::*;
|
2020-06-15 19:47:35 +00:00
|
|
|
pub use dynamic_texture_atlas_builder::*;
|
2020-06-02 02:23:11 +00:00
|
|
|
pub use rect::*;
|
2020-05-30 19:31:04 +00:00
|
|
|
pub use render::*;
|
|
|
|
pub use sprite::*;
|
2020-06-06 07:12:38 +00:00
|
|
|
pub use texture_atlas::*;
|
|
|
|
pub use texture_atlas_builder::*;
|
2020-05-30 19:31:04 +00:00
|
|
|
|
2020-07-17 01:47:51 +00:00
|
|
|
use bevy_app::prelude::*;
|
2020-12-03 21:57:36 +00:00
|
|
|
use bevy_asset::{AddAsset, Assets, Handle, HandleUntyped};
|
2021-02-18 21:20:37 +00:00
|
|
|
use bevy_ecs::IntoSystem;
|
2020-07-17 00:23:50 +00:00
|
|
|
use bevy_math::Vec2;
|
2020-11-28 00:39:59 +00:00
|
|
|
use bevy_reflect::{RegisterTypeBuilder, TypeUuid};
|
2020-05-30 19:31:04 +00:00
|
|
|
use bevy_render::{
|
2020-06-01 06:39:20 +00:00
|
|
|
mesh::{shape, Mesh},
|
2020-05-30 19:31:04 +00:00
|
|
|
render_graph::RenderGraph,
|
2020-06-22 00:43:36 +00:00
|
|
|
shader::asset_shader_defs_system,
|
2020-05-30 19:31:04 +00:00
|
|
|
};
|
|
|
|
use sprite::sprite_system;
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
pub struct SpritePlugin;
|
|
|
|
|
2020-12-03 21:57:36 +00:00
|
|
|
pub const QUAD_HANDLE: HandleUntyped =
|
|
|
|
HandleUntyped::weak_from_u64(Mesh::TYPE_UUID, 14240461981130137526);
|
2020-05-30 19:31:04 +00:00
|
|
|
|
2020-08-08 03:22:17 +00:00
|
|
|
impl Plugin for SpritePlugin {
|
2020-05-30 19:31:04 +00:00
|
|
|
fn build(&self, app: &mut AppBuilder) {
|
|
|
|
app.add_asset::<ColorMaterial>()
|
2020-06-06 07:12:38 +00:00
|
|
|
.add_asset::<TextureAtlas>()
|
2020-11-28 00:39:59 +00:00
|
|
|
.register_type::<Sprite>()
|
2021-02-18 21:20:37 +00:00
|
|
|
.add_system_to_stage(CoreStage::PostUpdate, sprite_system.system())
|
2020-05-30 19:31:04 +00:00
|
|
|
.add_system_to_stage(
|
2021-02-18 21:20:37 +00:00
|
|
|
CoreStage::PostUpdate,
|
2020-12-16 05:57:16 +00:00
|
|
|
asset_shader_defs_system::<ColorMaterial>.system(),
|
2020-05-30 19:31:04 +00:00
|
|
|
);
|
|
|
|
|
2020-10-18 20:48:15 +00:00
|
|
|
let resources = app.resources_mut();
|
2020-05-30 19:31:04 +00:00
|
|
|
let mut render_graph = resources.get_mut::<RenderGraph>().unwrap();
|
|
|
|
render_graph.add_sprite_graph(resources);
|
|
|
|
|
|
|
|
let mut meshes = resources.get_mut::<Assets<Mesh>>().unwrap();
|
2020-10-18 20:48:15 +00:00
|
|
|
|
|
|
|
let mut color_materials = resources.get_mut::<Assets<ColorMaterial>>().unwrap();
|
|
|
|
color_materials.set_untracked(Handle::<ColorMaterial>::default(), ColorMaterial::default());
|
|
|
|
meshes.set_untracked(
|
2020-05-30 19:31:04 +00:00
|
|
|
QUAD_HANDLE,
|
2020-07-10 08:37:06 +00:00
|
|
|
// Use a flipped quad because the camera is facing "forward" but quads should face backward
|
2020-07-20 08:33:30 +00:00
|
|
|
Mesh::from(shape::Quad::new(Vec2::new(1.0, 1.0))),
|
2020-10-18 20:48:15 +00:00
|
|
|
)
|
2020-05-30 19:31:04 +00:00
|
|
|
}
|
|
|
|
}
|