gw2lib_model/misc/
colors.rs1use either::Either;
2use serde::{Deserialize, Serialize};
3
4use crate::{items::ItemId, BulkEndpoint, Endpoint, EndpointWithId};
5
6pub type RGB = (u8, u8, u8);
7pub type ColorId = u16;
8
9#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
10#[cfg_attr(test, serde(deny_unknown_fields))]
11pub struct MaterialDetails {
12 pub brightness: i8,
13 pub contrast: f32,
14 pub hue: u16,
15 pub saturation: f32,
16 pub lightness: f32,
17 pub rgb: RGB,
18}
19
20#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
21#[cfg_attr(test, serde(deny_unknown_fields))]
22pub enum Hue {
23 Gray,
24 Brown,
25 Red,
26 Orange,
27 Yellow,
28 Green,
29 Blue,
30 Purple,
31}
32
33#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
34#[cfg_attr(test, serde(deny_unknown_fields))]
35pub enum Material {
36 Vibrant,
37 Leather,
38 Metal,
39}
40
41#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
42#[cfg_attr(test, serde(deny_unknown_fields))]
43pub enum Rarity {
44 Starter,
45 Common,
46 Uncommon,
47 Rare,
48 Exclusive,
49}
50
51#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
52#[cfg_attr(test, serde(deny_unknown_fields))]
53pub struct Color {
54 pub id: ColorId,
55 pub name: String,
56 pub base_rgb: RGB,
57 pub cloth: MaterialDetails,
58 pub leather: MaterialDetails,
59 pub metal: MaterialDetails,
60 pub fur: Option<MaterialDetails>,
61 pub item: Option<ItemId>,
63 #[serde(with = "either::serde_untagged")]
65 pub categories: Either<(Hue, Material, Rarity), [(); 0]>,
66}
67
68impl EndpointWithId for Color {
69 type IdType = ColorId;
70}
71impl Endpoint for Color {
72 const AUTHENTICATED: bool = false;
73 const LOCALE: bool = true;
74 const URL: &'static str = "v2/colors";
75 const VERSION: &'static str = "2021-01-11T00:00:00.000Z";
76}
77
78impl BulkEndpoint for Color {
79 const ALL: bool = true;
80
81 fn id(&self) -> &Self::IdType {
82 &self.id
83 }
84}