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::modif::{ModifKinds as _, validate_modifs};
use crate::token::Token;
use crate::validator::Validator;
use crate::vic3::modif::ModifKinds;
use crate::vic3::tables::modifs::modif_scope_kind;

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

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

impl Modifier {
    pub fn add(db: &mut Db, key: Token, block: Block) {
        db.add_exact_dup_ok(Item::Modifier, key, block, Box::new(Self {}));
    }
}

impl DbKind for Modifier {
    fn validate(&self, key: &Token, block: &Block, data: &Everything) {
        let mut vd = Validator::new(block, data);

        // The dynamic defines for cultures are required but don't need localizations
        if !key.as_str().ends_with("_standard_of_living_modifier_positive")
            && !key.as_str().ends_with("_standard_of_living_modifier_negative")
            && !key.as_str().ends_with("_cultural_acceptance_modifier_positive")
            && !key.as_str().ends_with("_cultural_acceptance_modifier_negative")
            && !key.as_str().ends_with("_fervor_target_modifier_positive")
            && !key.as_str().ends_with("_fervor_target_modifier_negative")
        {
            data.verify_exists(Item::Localization, key);
        }
        vd.field_item("icon", Item::File);

        validate_modifs(block, data, ModifKinds::all(), vd);
    }

    fn validate_call(
        &self,
        _key: &Token,
        block: &Block,
        from: &Token,
        _from_block: &Block,
        data: &Everything,
        sc: &mut ScopeContext,
    ) {
        let mut vd = Validator::new(block, data);

        // Mark as known field
        vd.field("icon");

        // Ensure contained modifs are valid at this location
        let (scopes, scope_reason) = sc.scopes_reason(data);
        let scope_kinds = modif_scope_kind(scopes);
        vd.unknown_fields(|key, _| {
            if let Some(kind) = ModifKinds::lookup_modif(key, data, None) {
                scope_kinds.require_from(
                    kind,
                    key,
                    Some((from, scopes, scope_reason)),
                    crate::Severity::Warning,
                );
            }
        });
    }
}