mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
6f3d5da6f3
This enables us to automatically create configuration formats from enums or structs. For enums, we create a structure with a field for each case, representing a pattern match; the configuration format can then enter a different expression for each case. For structs, we create an enum with a variant for each field, representing projecting by that field; the configuration format selects the field to project from, and then can write a further expression on that field (for instance, it can perform another pattern match). So far we don't actually have anything that *uses* this functionality; I decided to finish it for the purpose of specifying a default lantern offset, only to discover that we already return a lantern offset from the animation crate. So I fixed it there instead.
45 lines
991 B
Rust
45 lines
991 B
Rust
use crate::{make_case_elim, make_proj_elim};
|
|
use rand::{seq::SliceRandom, thread_rng};
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
make_proj_elim!(
|
|
body,
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
pub struct Body {
|
|
pub torso: Torso,
|
|
pub tail: Tail,
|
|
}
|
|
);
|
|
|
|
impl Body {
|
|
pub fn random() -> Self {
|
|
let mut rng = thread_rng();
|
|
Self {
|
|
torso: *(&ALL_TORSOS).choose(&mut rng).unwrap(),
|
|
tail: *(&ALL_TAILS).choose(&mut rng).unwrap(),
|
|
}
|
|
}
|
|
}
|
|
|
|
make_case_elim!(
|
|
torso,
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
#[repr(u32)]
|
|
pub enum Torso {
|
|
Default = 0,
|
|
}
|
|
);
|
|
|
|
const ALL_TORSOS: [Torso; 1] = [Torso::Default];
|
|
|
|
make_case_elim!(
|
|
tail,
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
#[repr(u32)]
|
|
pub enum Tail {
|
|
Default = 0,
|
|
}
|
|
);
|
|
|
|
const ALL_TAILS: [Tail; 1] = [Tail::Default];
|