51 lines
974 B
Rust
51 lines
974 B
Rust
use std::fmt::Display;
|
|
|
|
use serde::Deserialize;
|
|
|
|
#[derive(Debug, Deserialize, PartialEq, Eq)]
|
|
pub struct Recipes {
|
|
pub starters: Vec<Recipe>,
|
|
pub soups: Vec<Recipe>,
|
|
pub fish: Vec<Recipe>,
|
|
pub meat: Vec<Recipe>,
|
|
pub deserts: Vec<Recipe>,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, PartialEq, Eq)]
|
|
pub struct Recipe {
|
|
pub name: String,
|
|
pub is_special: bool,
|
|
pub ingredients: Vec<String>,
|
|
pub normal: FoodStats,
|
|
pub plus: FoodStats,
|
|
}
|
|
|
|
impl Recipe {
|
|
pub fn stats(&self, is_plus: bool) -> &FoodStats {
|
|
if is_plus { &self.plus } else { &self.normal }
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, PartialEq, Eq)]
|
|
pub struct FoodStats {
|
|
pub str: u8,
|
|
pub mag: u8,
|
|
pub def: u8,
|
|
pub hp: u8,
|
|
pub mp: u8,
|
|
}
|
|
|
|
impl Display for FoodStats {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
let val = serde_json::json!({
|
|
"str": self.str,
|
|
"mag": self.mag,
|
|
"def": self.def,
|
|
"hp": self.hp,
|
|
"mp": self.mp
|
|
});
|
|
f.write_str(&val.to_string())?;
|
|
Ok(())
|
|
}
|
|
}
|