Skip to main content

yog_data/found/
mod.rs

1//! What a read met, by what Yog makes of it: content, tags of content,
2//! `.yres` entries. Every one is a reference ([`substrate_data::Read::refs`]);
3//! these split them.
4
5use substrate_data::schema::Found;
6use substrate_data::{Kind, Path, Ref};
7
8use crate::{Meaning, Res, kinds};
9
10/// A tag met: its content's kind (`item`) and its id (`minecraft:planks`).
11#[derive(Debug, Clone, PartialEq, Eq)]
12pub struct TagRef {
13    pub kind: String,
14    pub id: String,
15}
16
17/// The references to content in `refs`: neither tags nor `.yres` entries
18/// nor translation keys nor images.
19pub fn content(refs: &[Found<Ref>]) -> impl Iterator<Item = &Found<Ref>> {
20    let domain = [
21        kinds::Tag::NAME,
22        kinds::Res::NAME,
23        kinds::Lang::NAME,
24        kinds::Image::NAME,
25    ];
26    refs.iter()
27        .filter(move |f| !domain.contains(&f.value.kind.as_str()))
28}
29
30/// The tags in `refs`.
31pub fn tags(refs: &[Found<Ref>]) -> Vec<Found<TagRef>> {
32    meanings(refs)
33        .filter_map(|(m, path)| match m {
34            Meaning::Tag(value) => Some(Found { value, path }),
35            _ => None,
36        })
37        .collect()
38}
39
40/// The `.yres` entries in `refs`.
41pub fn resources(refs: &[Found<Ref>]) -> Vec<Found<Res>> {
42    meanings(refs)
43        .filter_map(|(m, path)| match m {
44            Meaning::Res(value) => Some(Found { value, path }),
45            _ => None,
46        })
47        .collect()
48}
49
50/// What each of `refs` is to Yog, and where.
51fn meanings(refs: &[Found<Ref>]) -> impl Iterator<Item = (Meaning, Path)> + '_ {
52    refs.iter()
53        .filter_map(|f| Some((Meaning::of(f.value.clone())?, f.path.clone())))
54}