2020-06-22 19:14:40 +00:00
|
|
|
use crate::ColorMaterial;
|
2020-05-13 23:42:27 +00:00
|
|
|
use bevy_asset::{Assets, Handle};
|
2020-07-17 01:26:21 +00:00
|
|
|
use bevy_core::Byteable;
|
2020-07-10 08:37:06 +00:00
|
|
|
use bevy_ecs::{Query, Res};
|
2020-07-17 00:23:50 +00:00
|
|
|
use bevy_math::Vec2;
|
2020-06-22 19:14:40 +00:00
|
|
|
use bevy_render::{
|
2020-07-17 01:26:21 +00:00
|
|
|
renderer::{RenderResource, RenderResources},
|
2020-06-22 19:14:40 +00:00
|
|
|
texture::Texture,
|
|
|
|
};
|
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
#[derive(Default, RenderResources, RenderResource)]
|
|
|
|
#[render_resources(from_self)]
|
2020-05-04 08:22:25 +00:00
|
|
|
pub struct Sprite {
|
2020-06-27 04:40:09 +00:00
|
|
|
pub size: Vec2,
|
2020-05-04 08:22:25 +00:00
|
|
|
}
|
|
|
|
|
2020-06-22 19:14:40 +00:00
|
|
|
// SAFE: sprite is repr(C) and only consists of byteables
|
|
|
|
unsafe impl Byteable for Sprite {}
|
2020-05-04 08:22:25 +00:00
|
|
|
|
2020-07-10 04:18:35 +00:00
|
|
|
pub fn sprite_system(
|
|
|
|
materials: Res<Assets<ColorMaterial>>,
|
|
|
|
textures: Res<Assets<Texture>>,
|
|
|
|
mut query: Query<(&mut Sprite, &Handle<ColorMaterial>)>,
|
|
|
|
) {
|
2020-07-22 03:12:15 +00:00
|
|
|
for (mut sprite, handle) in &mut query.iter() {
|
2020-07-10 04:18:35 +00:00
|
|
|
let material = materials.get(&handle).unwrap();
|
|
|
|
if let Some(texture_handle) = material.texture {
|
|
|
|
if let Some(texture) = textures.get(&texture_handle) {
|
|
|
|
sprite.size = texture.size;
|
2020-05-04 08:22:25 +00:00
|
|
|
}
|
2020-07-10 04:18:35 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-04 08:22:25 +00:00
|
|
|
}
|