Newer
Older
//! Data embedded in the game for the sake of convenience. Future iterations
//! should load this info as assets, to make it easier to customise & reload
use std::collections::HashMap;
use lazy_static::lazy_static;
use crate::world::{CraftSpecialism, TradeGood};
#[derive(Serialize, Deserialize)]
struct RawSpecialisms {
specialism: Vec<CraftSpecialism>,
}
lazy_static! {
pub static ref TRADE_GOODS: HashMap<String, TradeGood> =
toml::from_slice(include_bytes!("../../../raw_assets/trade_goods.toml")).unwrap();
pub static ref SPECIALISMS: Vec<CraftSpecialism> = {
let initial: RawSpecialisms =
toml::from_slice(include_bytes!("../../../raw_assets/specialisms.toml")).unwrap();
initial.specialism
};
}
/// Convert the name of a trade good into its representation.
/// Will panic if the name is incorrect; usually useful in a
/// static context
pub fn get_goods_from_name(name: impl ToString) -> TradeGood {
(*TRADE_GOODS)[&name.to_string()].clone()
}
/// Convert the name of a trade good into its representation.
/// Preferred in a dynamic context where the `Option` can be checked
pub fn get_goods_from_name_checked(name: impl ToString) -> Option<TradeGood> {
(*TRADE_GOODS).get(&name.to_string()).cloned()
}