tiger_lib/vic3/data/
geographic_regions.rs

1use crate::block::Block;
2use crate::db::{Db, DbKind};
3use crate::everything::Everything;
4use crate::game::GameFlags;
5use crate::item::{Item, ItemLoader};
6use crate::token::Token;
7use crate::validator::Validator;
8
9#[derive(Clone, Debug)]
10pub struct GeographicRegion {}
11
12inventory::submit! {
13    ItemLoader::Normal(GameFlags::Vic3, Item::GeographicRegion, GeographicRegion::add)
14}
15
16impl GeographicRegion {
17    pub fn add(db: &mut Db, key: Token, block: Block) {
18        db.add(Item::GeographicRegion, key, block, Box::new(Self {}));
19    }
20}
21
22impl DbKind for GeographicRegion {
23    fn add_subitems(&self, _key: &Token, block: &Block, db: &mut Db) {
24        if let Some(key) = block.get_field_value("short_key") {
25            db.add_flag(Item::GeographicRegionShortKey, key.clone());
26        }
27    }
28
29    fn validate(&self, key: &Token, block: &Block, data: &Everything) {
30        let mut vd = Validator::new(block, data);
31
32        data.verify_exists(Item::Localization, key);
33
34        vd.req_field("short_key");
35        vd.field_identifier("short_key", "geographic region short key");
36
37        // TODO: validate this list of scopes (sr:some_strategic_region)
38        vd.field_list("strategic_regions");
39
40        vd.field_list_items("state_regions", Item::StateRegion);
41    }
42}