mod block_item;
mod body;
mod book;
mod compile;
mod ctx;
mod datapack;
mod defs;
mod entry;
mod file;
mod files;
mod import;
pub(crate) use import::font_copy_path;
mod looks;
pub(crate) mod material;
mod model;
mod outputs;
mod recipe;
pub(crate) mod refs;
mod source;
mod table;
mod textures;
mod vocab;
pub use compile::compile;
pub use import::{Imported, import_command};
pub use outputs::{OutputSet, TAGS_FILE, TagLists, merge_outputs, read_tags};
pub use source::{GENERATED_PARTS_DIR, Source, write_source};
pub use vocab::TEMPLATES;
use serde_json::Value;
use std::collections::{BTreeMap, BTreeSet};
use std::path::{Path, PathBuf};
use yog_ids::Format;
pub const CONTENT_DIR: &str = yog_ids::project::CONTENT;
pub const GENERATED_FILE: &str = ".yog-build/generated/yog-content.g.rs";
pub type Output = (String, Vec<u8>);
const CONTENT: [Format; 9] = [
Format::Block,
Format::Item,
Format::Recipe,
Format::Book,
Format::Def,
Format::Model,
Format::Anim,
Format::Entity,
Format::Font,
];
fn content_format(path: &Path) -> Option<Format> {
Format::of_path(path).filter(|f| CONTENT.contains(f))
}
#[derive(Debug, Default)]
pub struct Compiled {
pub outputs: Vec<Output>,
lang: Lang,
lang_aliases: Vec<(String, String)>,
tags: BTreeMap<String, defs::data::TagEntries>,
pub source: Option<Source>,
pub data_files: Vec<(String, Vec<u8>)>,
pub warnings: Vec<String>,
pub registrations: String,
pub packed: BTreeSet<String>,
pub blocks: usize,
pub items: usize,
pub recipes: usize,
pub books: usize,
}
pub use yog_ids::{valid_id, valid_namespace, valid_path};
pub fn find(root: &Path) -> Vec<PathBuf> {
crate::files::under(&root.join(CONTENT_DIR), &|p| content_format(p).is_some())
}
fn pretty(v: &Value) -> Vec<u8> {
let mut s = serde_json::to_string_pretty(v).unwrap_or_default();
s.push('\n');
s.into_bytes()
}
type Lang = BTreeMap<(String, String), BTreeMap<String, String>>;
#[cfg(test)]
mod tests;
const WHOLE_BELOW: f64 = 1e15;
pub fn num_value(n: f64) -> serde_json::Value {
if n.fract() == 0.0 && n.abs() < WHOLE_BELOW {
serde_json::Value::from(n as i64)
} else {
serde_json::Number::from_f64(n)
.map(serde_json::Value::Number)
.unwrap_or(serde_json::Value::Null)
}
}