tiger-lib 1.18.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::context::ScopeContext;
use crate::db::{Db, DbKind};
use crate::everything::Everything;
use crate::game::GameFlags;
use crate::item::{Item, ItemLoader};
use crate::scopes::Scopes;
use crate::token::Token;
use crate::tooltipped::Tooltipped;
use crate::validator::Validator;

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

inventory::submit! {
    ItemLoader::Normal(GameFlags::Vic3, Item::FlagDefinition, FlagDefinition::add)
}

impl FlagDefinition {
    pub fn add(db: &mut Db, key: Token, block: Block) {
        let block = block.condense_tag("list");
        db.add(Item::FlagDefinition, key, block, Box::new(Self {}));
    }
}

impl DbKind for FlagDefinition {
    fn validate(&self, _key: &Token, block: &Block, data: &Everything) {
        let mut vd = Validator::new(block, data);
        vd.field_item("includes", Item::FlagDefinition);
        vd.multi_field_validated_block("flag_definition", validate_flag_definition);
    }
}

fn validate_flag_definition(block: &Block, data: &Everything) {
    let mut vd = Validator::new(block, data);

    for field in &["coa", "coa_with_overlord_canton", "subject_canton", "revolutionary_canton"] {
        if let Some(token) = vd.field_value(field) {
            if let Some((_, list)) = token.split_once('"') {
                data.verify_exists(Item::CoaTemplateList, &list);
            } else {
                data.verify_exists(Item::Coa, token);
            }
        }
    }
    vd.field_bool("allow_overlord_canton");
    vd.field_list_precise_numeric_exactly("overlord_canton_offset", 2);
    vd.field_list_precise_numeric_exactly("overlord_canton_scale", 2);
    vd.field_bool("allow_revolutionary_indicator");

    vd.field_integer("priority");
    vd.field_trigger_builder("trigger", Tooltipped::No, |key| {
        let mut sc = ScopeContext::new(Scopes::CountryDefinition, key);
        sc.define_name("target", Scopes::Country, key);
        sc.define_name("initiator", Scopes::Country, key);
        sc.define_name("actor", Scopes::Country, key);
        sc.define_name("overlord", Scopes::Country, key);
        sc
    });
}