1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use amethyst_assets::PrefabData;
use amethyst_core::ecs::{Component, DenseVecStorage, Entity, Write};
use amethyst_error::Error;
#[derive(Clone, Debug, Default, serde::Serialize, serde::Deserialize)]
pub struct AmbientColor(#[serde(with = "crate::serde_shim::srgba")] pub palette::Srgba);
impl AsRef<palette::Srgba> for AmbientColor {
fn as_ref(&self) -> &palette::Srgba {
&self.0
}
}
impl<'a> PrefabData<'a> for AmbientColor {
type SystemData = Write<'a, AmbientColor>;
type Result = ();
fn add_to_entity(
&self,
_: Entity,
ambient: &mut Self::SystemData,
_: &[Entity],
_: &[Entity],
) -> Result<(), Error> {
ambient.0 = self.0;
Ok(())
}
}
#[derive(Clone, Debug, Default, serde::Serialize, serde::Deserialize)]
pub struct Tint(#[serde(with = "crate::serde_shim::srgba")] pub palette::Srgba);
impl Component for Tint {
type Storage = DenseVecStorage<Self>;
}
impl Into<[f32; 4]> for Tint {
fn into(self) -> [f32; 4] {
let (r, g, b, a) = self.0.into_components();
[r, g, b, a]
}
}