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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use crate::Attribute;
use arctk::{
err::Error,
img::Gradient,
ord::{Link, Set},
};
use arctk_attr::input;
#[input]
pub enum AttributeLinker {
Opaque(String),
Mirror(String, f64),
Transparent(String, f64),
Refractive(String, f64, [f64; 2]),
Luminous(String, f64),
}
impl<'a> Link<'a, Gradient> for AttributeLinker {
type Inst = Attribute<'a>;
#[inline]
fn requires(&self) -> Vec<String> {
match *self {
Self::Opaque(ref grad)
| Self::Mirror(ref grad, ..)
| Self::Transparent(ref grad, ..)
| Self::Refractive(ref grad, ..)
| Self::Luminous(ref grad, ..) => vec![grad.clone()],
}
}
#[inline]
fn link(self, grads: &'a Set<Gradient>) -> Result<Self::Inst, Error> {
Ok(match self {
Self::Opaque(ref grad) => Attribute::Opaque(
grads
.get(grad)
.unwrap_or_else(|| panic!("Failed to link attribute-gradient key: {}", grad)),
),
Self::Mirror(ref grad, abs_frac) => Attribute::Mirror(
grads
.get(grad)
.unwrap_or_else(|| panic!("Failed to link attribute-gradient key: {}", grad)),
abs_frac,
),
Self::Transparent(ref grad, abs_frac) => Attribute::Transparent(
grads
.get(grad)
.unwrap_or_else(|| panic!("Failed to link attribute-gradient key: {}", grad)),
abs_frac,
),
Self::Refractive(ref grad, abs_frac, ref_indices) => Attribute::Refractive(
grads
.get(grad)
.unwrap_or_else(|| panic!("Failed to link attribute-gradient key: {}", grad)),
abs_frac,
ref_indices,
),
Self::Luminous(ref grad, bright_mult) => Attribute::Luminous(
grads
.get(grad)
.unwrap_or_else(|| panic!("Failed to link attribute-gradient key: {}", grad)),
bright_mult,
),
})
}
}