veloren/common/src/comp/body/bird_small.rs
Joshua Yanovski 3fa21b3dc7 Per-speces NPC names!
Is also able to refactor some of the uglier code and introduces a
framework that (suitably extended) could be useful in removing
boilerplate elsewhere.
2020-01-29 04:41:32 +01:00

49 lines
1.2 KiB
Rust

use rand::{seq::SliceRandom, thread_rng};
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Body {
pub head: Head,
pub torso: Torso,
pub wing_l: WingL,
pub wing_r: WingR,
}
impl Body {
pub fn random() -> Self {
let mut rng = thread_rng();
Self {
head: *(&ALL_HEADS).choose(&mut rng).unwrap(),
torso: *(&ALL_TORSOS).choose(&mut rng).unwrap(),
wing_l: *(&ALL_WING_LS).choose(&mut rng).unwrap(),
wing_r: *(&ALL_WING_RS).choose(&mut rng).unwrap(),
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[repr(u32)]
pub enum Head {
Default,
}
const ALL_HEADS: [Head; 1] = [Head::Default];
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[repr(u32)]
pub enum Torso {
Default,
}
const ALL_TORSOS: [Torso; 1] = [Torso::Default];
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[repr(u32)]
pub enum WingL {
Default,
}
const ALL_WING_LS: [WingL; 1] = [WingL::Default];
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[repr(u32)]
pub enum WingR {
Default,
}
const ALL_WING_RS: [WingR; 1] = [WingR::Default];