tiger_lib/ck3/data/
suggestions.rs1use crate::block::Block;
2use crate::context::ScopeContext;
3use crate::db::{Db, DbKind};
4use crate::everything::Everything;
5use crate::game::GameFlags;
6use crate::item::{Item, ItemLoader};
7use crate::scopes::Scopes;
8use crate::token::Token;
9use crate::tooltipped::Tooltipped;
10use crate::validate::validate_modifiers_with_base;
11use crate::validator::Validator;
12
13#[derive(Clone, Debug)]
14pub struct Suggestion {}
15
16inventory::submit! {
17 ItemLoader::Normal(GameFlags::Ck3, Item::Suggestion, Suggestion::add)
18}
19
20impl Suggestion {
21 pub fn add(db: &mut Db, key: Token, block: Block) {
22 db.add(Item::Suggestion, key, block, Box::new(Self {}));
23 }
24}
25
26impl DbKind for Suggestion {
27 fn validate(&self, key: &Token, block: &Block, data: &Everything) {
28 let mut vd = Validator::new(block, data);
29
30 data.verify_exists(Item::Localization, key);
31 let loca = format!("{key}_label");
32 data.mark_used(Item::Localization, &loca); let loca = format!("{key}_desc");
34 data.verify_exists_implied(Item::Localization, &loca, key);
35 let loca = format!("{key}_click");
36 data.verify_exists_implied(Item::Localization, &loca, key);
37
38 let mut sc = ScopeContext::new(Scopes::Character, key);
39 vd.field_effect_rooted("check_create_suggestion", Tooltipped::No, Scopes::Character);
41
42 vd.field_effect_builder("effect", Tooltipped::No, |key| {
44 let mut sc = ScopeContext::new(Scopes::Character, key);
45 sc.set_strict_scopes(false);
47 sc
48 });
49
50 vd.field_item("soundeffect", Item::Sound);
51
52 vd.field_validated_block_sc("weight", &mut sc, validate_modifiers_with_base);
53
54 let mut sc = ScopeContext::new(Scopes::Character, key);
56 sc.set_strict_scopes(false);
57 vd.field_validated_block_sc("score", &mut sc, validate_modifiers_with_base);
58
59 vd.field_trigger_builder("is_valid", Tooltipped::No, |key| {
60 let mut sc = ScopeContext::new(Scopes::Character, key);
61 sc.set_strict_scopes(false); sc
63 });
64 }
65}