veloren_common/comp/body/
dragon.rs1use crate::{make_case_elim, make_proj_elim};
2use rand::{seq::SliceRandom, thread_rng};
3use serde::{Deserialize, Serialize};
4
5make_proj_elim!(
6 body,
7 #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
8 pub struct Body {
9 pub species: Species,
10 pub body_type: BodyType,
11 }
12);
13
14impl Body {
15 pub fn random() -> Self {
16 let mut rng = thread_rng();
17 let species = *ALL_SPECIES.choose(&mut rng).unwrap();
18 Self::random_with(&mut rng, &species)
19 }
20
21 #[inline]
22 pub fn random_with(rng: &mut impl rand::Rng, &species: &Species) -> Self {
23 let body_type = *ALL_BODY_TYPES.choose(rng).unwrap();
24 Self { species, body_type }
25 }
26}
27
28impl From<Body> for super::Body {
29 fn from(body: Body) -> Self { super::Body::Dragon(body) }
30}
31
32make_case_elim!(
33 species,
34 #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
35 #[repr(u32)]
36 pub enum Species {
37 Reddragon = 0,
38 }
39);
40
41#[derive(Clone, Debug, Deserialize)]
45pub struct AllSpecies<SpeciesMeta> {
46 pub reddragon: SpeciesMeta,
47}
48
49impl<'a, SpeciesMeta> core::ops::Index<&'a Species> for AllSpecies<SpeciesMeta> {
50 type Output = SpeciesMeta;
51
52 #[inline]
53 fn index(&self, &index: &'a Species) -> &Self::Output {
54 match index {
55 Species::Reddragon => &self.reddragon,
56 }
57 }
58}
59
60pub const ALL_SPECIES: [Species; 1] = [Species::Reddragon];
61
62impl<'a, SpeciesMeta: 'a> IntoIterator for &'a AllSpecies<SpeciesMeta> {
63 type IntoIter = std::iter::Copied<std::slice::Iter<'static, Self::Item>>;
64 type Item = Species;
65
66 fn into_iter(self) -> Self::IntoIter { ALL_SPECIES.iter().copied() }
67}
68
69make_case_elim!(
70 body_type,
71 #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
72 #[repr(u32)]
73 pub enum BodyType {
74 Female = 0,
75 Male = 1,
76 }
77);
78
79pub const ALL_BODY_TYPES: [BodyType; 2] = [BodyType::Female, BodyType::Male];