tiger_lib/ck3/data/
culture_history.rs1use crate::block::Block;
2use crate::date::Date;
3use crate::db::{Db, DbKind};
4use crate::everything::Everything;
5use crate::game::GameFlags;
6use crate::item::{Item, ItemLoader, LoadAsFile, Recursive};
7use crate::pdxfile::PdxEncoding;
8use crate::token::Token;
9use crate::validator::Validator;
10
11#[derive(Clone, Debug)]
12pub struct CultureHistory {}
13
14inventory::submit! {
15 ItemLoader::Full(GameFlags::Ck3, Item::CultureHistory, PdxEncoding::Detect, ".txt", LoadAsFile::Yes, Recursive::No, CultureHistory::add)
16}
17
18impl CultureHistory {
19 pub fn add(db: &mut Db, key: Token, block: Block) {
20 db.add(Item::CultureHistory, key, block, Box::new(Self {}));
21 }
22}
23
24impl DbKind for CultureHistory {
25 fn validate(&self, key: &Token, block: &Block, data: &Everything) {
26 if key.starts_with("heritage_") {
27 data.verify_exists(Item::CultureHeritage, key);
28 } else {
29 data.verify_exists(Item::Culture, key);
30 }
31
32 let mut vd = Validator::new(block, data);
33 vd.validate_history_blocks(validate_history);
34 }
35}
36
37fn validate_history(_date: Date, _key: &Token, block: &Block, data: &Everything) {
38 let mut vd = Validator::new(block, data);
39
40 vd.multi_field_item("discover_innovation", Item::Innovation);
41 vd.multi_field_validated_block("add_innovation_progress", |block, data| {
42 let mut vd = Validator::new(block, data);
43 vd.field_item("culture_innovation", Item::Innovation);
44 vd.field_numeric_range("progress", 0.0..=100.0);
45 });
46 vd.field_item("join_era", Item::CultureEra);
47 vd.field_numeric_range("progress_era", 0.0..=100.0);
48}