Added flower and grass items

This commit is contained in:
Joshua Barretto 2019-09-25 23:04:18 +01:00
parent 7f4e587215
commit a2758b091c
2 changed files with 53 additions and 4 deletions

View File

@ -94,6 +94,21 @@ impl Consumable {
}
}
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum Ingredient {
Flower,
Grass,
}
impl Ingredient {
pub fn name(&self) -> &'static str {
match self {
Ingredient::Flower => "flower",
Ingredient::Grass => "grass",
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum Debug {
Boost,
@ -114,7 +129,9 @@ pub enum Item {
kind: Consumable,
effect: Effect,
},
Ingredient,
Ingredient {
kind: Ingredient,
},
Debug(Debug),
}
@ -123,8 +140,8 @@ impl Item {
match self {
Item::Tool { kind, .. } => kind.name(),
Item::Armor { kind, .. } => kind.name(),
Item::Consumable { .. } => "<consumable>",
Item::Ingredient => "<ingredient>",
Item::Consumable { kind, .. } => kind.name(),
Item::Ingredient { kind } => kind.name(),
Item::Debug(_) => "Debugging item",
}
}
@ -134,7 +151,7 @@ impl Item {
Item::Tool { .. } => "tool",
Item::Armor { .. } => "armour",
Item::Consumable { .. } => "consumable",
Item::Ingredient => "ingredient",
Item::Ingredient { .. } => "ingredient",
Item::Debug(_) => "debug",
}
}
@ -148,6 +165,16 @@ impl Item {
BlockKind::Apple => Some(Self::apple()),
BlockKind::Mushroom => Some(Self::mushroom()),
BlockKind::Velorite => Some(Self::velorite()),
BlockKind::BlueFlower => Some(Self::flower()),
BlockKind::PinkFlower => Some(Self::flower()),
BlockKind::PurpleFlower => Some(Self::flower()),
BlockKind::RedFlower => Some(Self::flower()),
BlockKind::WhiteFlower => Some(Self::flower()),
BlockKind::YellowFlower => Some(Self::flower()),
BlockKind::Sunflower => Some(Self::flower()),
BlockKind::LongGrass => Some(Self::grass()),
BlockKind::MediumGrass => Some(Self::grass()),
BlockKind::ShortGrass => Some(Self::grass()),
_ => None,
}
}
@ -174,6 +201,18 @@ impl Item {
effect: Effect::Xp(250),
}
}
pub fn flower() -> Self {
Item::Ingredient {
kind: Ingredient::Flower,
}
}
pub fn grass() -> Self {
Item::Ingredient {
kind: Ingredient::Grass,
}
}
}
impl Default for Item {

View File

@ -131,6 +131,16 @@ impl BlockKind {
pub fn is_collectible(&self) -> bool {
match self {
BlockKind::BlueFlower => true,
BlockKind::PinkFlower => true,
BlockKind::PurpleFlower => true,
BlockKind::RedFlower => true,
BlockKind::WhiteFlower => true,
BlockKind::YellowFlower => true,
BlockKind::Sunflower => true,
BlockKind::LongGrass => true,
BlockKind::MediumGrass => true,
BlockKind::ShortGrass => true,
BlockKind::Apple => true,
BlockKind::Mushroom => true,
BlockKind::Velorite => true,