tiger-lib 1.17.0

Library used by the tools ck3-tiger, vic3-tiger, and imperator-tiger. This library holds the bulk of the code for them. It can be built either for ck3-tiger with the feature ck3, or for vic3-tiger with the feature vic3, or for imperator-tiger with the feature imperator, but not both at the same time.
Documentation
use crate::block::Block;
use crate::db::{Db, DbKind};
use crate::everything::Everything;
use crate::game::GameFlags;
use crate::item::{Item, ItemLoader, LoadAsFile, Recursive};
use crate::pdxfile::PdxEncoding;
use crate::report::{ErrorKey, Severity, untidy, warn};
use crate::token::Token;
use crate::validator::Validator;

#[derive(Clone, Debug)]
pub struct Font {}

inventory::submit! {
    ItemLoader::Full(GameFlags::jomini(), Item::Font, PdxEncoding::Utf8OptionalBom, ".font", LoadAsFile::No, Recursive::Yes, Font::add)
}

impl Font {
    pub fn add(db: &mut Db, key: Token, block: Block) {
        if key.is("fontfiles") {
            if let Some(name) = block.get_field_value("name") {
                db.add(Item::Fontfiles, name.clone(), block, Box::new(Fontfiles {}));
            } else {
                let msg = "fontfiles entry without name";
                warn(ErrorKey::FieldMissing).msg(msg).loc(key).push();
            }
        } else if key.is("font") {
            if let Some(name) = block.get_field_value("name") {
                db.add(Item::Font, name.clone(), block, Box::new(Self {}));
            } else {
                let msg = "font entry without name";
                warn(ErrorKey::FieldMissing).msg(msg).loc(key).push();
            }
        } else {
            let msg = format!("unknown entry type {key}");
            untidy(ErrorKey::UnknownField).msg(msg).loc(key).push();
        }
    }
}

impl DbKind for Font {
    fn validate(&self, _key: &Token, block: &Block, data: &Everything) {
        let mut vd = Validator::new(block, data);
        vd.set_max_severity(Severity::Warning);
        vd.field_value("name");
        vd.multi_field_validated_block("fontstyle", |block, data| {
            let mut vd = Validator::new(block, data);
            vd.field_validated_value("style", |_, mut vd| {
                for mut vd in vd.split('|') {
                    vd.choice(&[
                        "regular",
                        #[cfg(feature = "eu5")]
                        "semibold",
                        "bold",
                        "extrabold",
                        "italic",
                    ]);
                }
            });
            vd.field_item("fontfiles", Item::Fontfiles);
        });
        vd.multi_field_validated_block("underlineformats", |block, data| {
            let mut vd = Validator::new(block, data);
            vd.unknown_block_fields(|_key, block| {
                // only known key is "default" but there may be others
                let mut vd = Validator::new(block, data);
                vd.field_numeric("thickness");
                vd.field_numeric("offset");
            });
        });
    }
}

#[derive(Clone, Debug)]
pub struct Fontfiles {}

impl DbKind for Fontfiles {
    fn validate(&self, _key: &Token, block: &Block, data: &Everything) {
        let mut vd = Validator::new(block, data);
        vd.set_max_severity(Severity::Warning);
        vd.field_value("name");
        vd.field_bool("always_load");

        vd.multi_field_validated_block("group", |block, data| {
            let mut vd = Validator::new(block, data);
            vd.field_list("languages"); // TODO
            vd.field_list_items("files", Item::File);
        });
    }
}