Merge branch 'make_crustaceans_tameable' into 'master'

make_crustaceans_tameable

See merge request veloren/veloren!4219
This commit is contained in:
Samuel Keiffer 2023-12-26 19:55:21 +00:00
commit c3db45541c
4 changed files with 67 additions and 17 deletions

View File

@ -1,11 +1,16 @@
use crate::{make_case_elim, make_proj_elim};
use rand::{seq::SliceRandom, thread_rng};
use serde::{Deserialize, Serialize};
use strum::{Display, EnumString};
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct Body {
pub species: Species,
pub body_type: BodyType,
}
make_proj_elim!(
body,
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct Body {
pub species: Species,
pub body_type: BodyType,
}
);
impl Body {
pub fn random() -> Self {
@ -25,11 +30,29 @@ impl From<Body> for super::Body {
fn from(body: Body) -> Self { super::Body::Crustacean(body) }
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[repr(u32)]
pub enum Species {
Crab = 0,
}
// Renaming any enum entries here (re-ordering is fine) will require a
// database migration to ensure pets correctly de-serialize on player login.
make_case_elim!(
species,
#[derive(
Copy,
Clone,
Debug,
Display,
EnumString,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
Serialize,
Deserialize,
)]
#[repr(u32)]
pub enum Species {
Crab = 0,
}
);
/// Data representing per-species generic data.
#[derive(Clone, Debug, Serialize, Deserialize)]
@ -57,10 +80,26 @@ impl<'a, SpeciesMeta: 'a> IntoIterator for &'a AllSpecies<SpeciesMeta> {
fn into_iter(self) -> Self::IntoIter { ALL_SPECIES.iter().copied() }
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[repr(u32)]
pub enum BodyType {
Female = 0,
Male = 1,
}
make_case_elim!(
body_type,
#[derive(
Copy,
Clone,
Debug,
Display,
EnumString,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
Serialize,
Deserialize,
)]
#[repr(u32)]
pub enum BodyType {
Female = 0,
Male = 1,
}
);
pub const ALL_BODY_TYPES: [BodyType; 2] = [BodyType::Female, BodyType::Male];

View File

@ -52,7 +52,10 @@ pub fn is_tameable(body: &Body) -> bool {
| quadruped_medium::Species::Hirdrasil
)
},
Body::QuadrupedLow(_) | Body::QuadrupedSmall(_) | Body::BirdMedium(_) => true,
Body::QuadrupedLow(_)
| Body::QuadrupedSmall(_)
| Body::BirdMedium(_)
| Body::Crustacean(_) => true,
_ => false,
}
}

View File

@ -220,6 +220,10 @@ pub fn convert_body_to_database_json(
"bird_medium",
serde_json::to_string(&GenericBody::from(body))?,
),
Body::Crustacean(body) => (
"crustacean",
serde_json::to_string(&GenericBody::from(body))?,
),
_ => {
return Err(PersistenceError::ConversionError(format!(
"Unsupported body type for persistence: {:?}",
@ -597,6 +601,9 @@ pub fn convert_body_from_database(
"bird_medium" => {
deserialize_body!(body_data, BirdMedium, bird_medium)
},
"crustacean" => {
deserialize_body!(body_data, Crustacean, crustacean)
},
_ => {
return Err(PersistenceError::ConversionError(format!(
"{} is not a supported body type for deserialization",

View File

@ -60,6 +60,7 @@ generic_body_from_impl!(comp::quadruped_low::Body);
generic_body_from_impl!(comp::quadruped_medium::Body);
generic_body_from_impl!(comp::quadruped_small::Body);
generic_body_from_impl!(comp::bird_medium::Body);
generic_body_from_impl!(comp::crustacean::Body);
#[derive(Serialize, Deserialize)]
pub struct CharacterPosition {