2020-05-30 19:31:04 +00:00
|
|
|
mod color_material;
|
|
|
|
pub mod entity;
|
2020-06-01 06:39:20 +00:00
|
|
|
mod quad;
|
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-06-07 18:30:04 +00:00
|
|
|
mod dynamic_texture_atlas_builder;
|
2020-05-30 19:31:04 +00:00
|
|
|
|
|
|
|
pub use color_material::*;
|
2020-06-01 06:39:20 +00:00
|
|
|
pub use quad::*;
|
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-06-07 18:30:04 +00:00
|
|
|
pub use dynamic_texture_atlas_builder::*;
|
2020-05-30 19:31:04 +00:00
|
|
|
|
|
|
|
use bevy_app::{stage, AppBuilder, AppPlugin};
|
|
|
|
use bevy_asset::{AddAsset, Assets, Handle};
|
|
|
|
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,
|
|
|
|
shader::asset_shader_def_system,
|
|
|
|
};
|
|
|
|
use glam::Vec2;
|
|
|
|
use legion::prelude::IntoSystem;
|
|
|
|
use sprite::sprite_system;
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
pub struct SpritePlugin;
|
|
|
|
|
|
|
|
pub const QUAD_HANDLE: Handle<Mesh> = Handle::from_u128(142404619811301375266013514540294236421);
|
|
|
|
|
|
|
|
impl AppPlugin for SpritePlugin {
|
|
|
|
fn build(&self, app: &mut AppBuilder) {
|
|
|
|
app.add_asset::<ColorMaterial>()
|
2020-06-06 07:12:38 +00:00
|
|
|
.add_asset::<TextureAtlas>()
|
2020-05-30 19:31:04 +00:00
|
|
|
.add_system_to_stage(stage::POST_UPDATE, sprite_system())
|
|
|
|
.add_system_to_stage(
|
|
|
|
stage::POST_UPDATE,
|
|
|
|
asset_shader_def_system::<ColorMaterial>.system(),
|
|
|
|
);
|
|
|
|
|
|
|
|
let resources = app.resources();
|
|
|
|
let mut render_graph = resources.get_mut::<RenderGraph>().unwrap();
|
|
|
|
render_graph.add_sprite_graph(resources);
|
|
|
|
|
|
|
|
let mut meshes = resources.get_mut::<Assets<Mesh>>().unwrap();
|
|
|
|
meshes.set(
|
|
|
|
QUAD_HANDLE,
|
2020-06-01 06:39:20 +00:00
|
|
|
Mesh::from(shape::Quad {
|
2020-05-30 19:31:04 +00:00
|
|
|
size: Vec2::new(1.0, 1.0),
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut color_materials = resources.get_mut::<Assets<ColorMaterial>>().unwrap();
|
|
|
|
color_materials.add_default(ColorMaterial::default());
|
|
|
|
}
|
|
|
|
}
|