use amethyst::{
animation::{Animation, InterpolationFunction, MaterialChannel, MaterialPrimitive, Sampler},
assets::{AssetStorage, Handle, Loader},
ecs::prelude::*,
renderer::{loaders::load_from_srgba, palette::Srgba, Material},
};
use crate::EffectReturn;
#[derive(Debug)]
pub struct MaterialAnimationFixture;
impl MaterialAnimationFixture {
pub fn effect(world: &mut World) {
let animation_handle = {
let loader = world.read_resource::<Loader>();
let tex_handle = loader.load_from_data(
load_from_srgba(Srgba::new(0.5, 0.5, 0.5, 0.5)).into(),
(),
&world.read_resource(),
);
let texture_sampler = Sampler {
input: vec![0.0],
output: vec![MaterialPrimitive::Texture(tex_handle)],
function: InterpolationFunction::Step,
};
let sprite_offset_sampler = Sampler {
input: vec![0.0],
output: vec![MaterialPrimitive::Offset((0.0, 1.0), (1.0, 0.0))],
function: InterpolationFunction::Step,
};
let texture_animation_handle =
loader.load_from_data(texture_sampler, (), &world.read_resource());
let sampler_animation_handle =
loader.load_from_data(sprite_offset_sampler, (), &world.read_resource());
let animation = Animation::<Material> {
nodes: vec![
(0, MaterialChannel::AlbedoTexture, texture_animation_handle),
(0, MaterialChannel::UvOffset, sampler_animation_handle),
],
};
loader.load_from_data::<Animation<Material>, ()>(animation, (), &world.read_resource())
};
world.insert(EffectReturn(animation_handle));
}
pub fn assertion(world: &mut World) {
let animation_handle = &world
.read_resource::<EffectReturn<Handle<Animation<Material>>>>()
.0;
let store = world.read_resource::<AssetStorage<Animation<Material>>>();
assert!(store.get(animation_handle).is_some());
}
}