use yog_data::field;
use yog_formats::recipe::{COOK_TIME, Cooking, Shaped, Shapeless};
use crate::content::formats::recipe::registration::RecipeKind;
const EMPTY: char = ' ';
pub(super) fn shaped(s: Shaped) -> RecipeKind {
let key = s
.key
.0
.iter()
.filter_map(|(k, ing)| {
let ch = k.chars().next().filter(|c| *c != EMPTY)?;
Some((ch, yog_formats::recipe::ids(ing)))
})
.collect();
RecipeKind::Shaped {
pattern: s.pattern,
key,
}
}
pub(super) fn shapeless(s: &Shapeless) -> RecipeKind {
RecipeKind::Shapeless(s.ingredients.iter().map(yog_formats::recipe::ids).collect())
}
pub(super) fn cooking(ty: &str, k: Cooking) -> Option<RecipeKind> {
let kind = yog_registry::recipe_kinds::game_kind(ty)?;
let method = yog_registry::Cooking::of_kind(ty)?;
let default_time = kind
.default_of(field!(Cooking, cook_time))
.map_or(*COOK_TIME.start(), |t| t as u32);
Some(RecipeKind::Cooking {
method,
input: yog_formats::recipe::ids(&k.ingredient),
experience: k.experience,
cook_time: k.cook_time.unwrap_or(default_time),
})
}