2024-07-20 12:13:04 +00:00
|
|
|
use paste::paste;
|
|
|
|
use std::sync::OnceLock;
|
|
|
|
|
|
|
|
use super::DataLoadError;
|
|
|
|
|
|
|
|
macro_rules! template_tables {
|
|
|
|
($($template_type:ident;)*) => {
|
|
|
|
$(paste! {
|
|
|
|
mod [<$template_type:snake>];
|
|
|
|
pub use [<$template_type:snake>]::$template_type;
|
|
|
|
})*
|
|
|
|
|
|
|
|
$(paste! {
|
|
|
|
static [<$template_type:snake:upper _TB>]: OnceLock<Vec<$template_type>> = OnceLock::new();
|
|
|
|
})*
|
|
|
|
|
|
|
|
pub(crate) fn load_tables(filecfg_path: &str) -> Result<(), DataLoadError> {
|
|
|
|
$(paste! {
|
|
|
|
let file_name = concat!(stringify!($template_type), "Tb.json");
|
|
|
|
let path = format!("{filecfg_path}/{file_name}");
|
|
|
|
|
|
|
|
let data = std::fs::read_to_string(path)?;
|
|
|
|
[<$template_type:snake:upper _TB>].set(serde_json::from_str(&data).map_err(|err| DataLoadError::FromJsonError(String::from(stringify!($template_type)), err))?).unwrap();
|
|
|
|
})*
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
$(paste! {
|
|
|
|
pub mod [<$template_type:snake _tb>] {
|
|
|
|
pub fn iter() -> ::std::slice::Iter<'static, super::$template_type> {
|
|
|
|
super::[<$template_type:snake:upper _TB>].get().unwrap().iter()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})*
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
template_tables! {
|
|
|
|
AvatarBaseTemplate;
|
|
|
|
UnlockConfigTemplate;
|
|
|
|
SectionConfigTemplate;
|
|
|
|
ProcedureConfigTemplate;
|
|
|
|
PostGirlConfigTemplate;
|
|
|
|
TrainingQuestTemplate;
|
2024-07-24 18:36:02 +00:00
|
|
|
WeaponTemplate;
|
2024-07-20 12:13:04 +00:00
|
|
|
}
|