tiger_lib/vic3/data/
messages.rs

1//! Notifications that are triggered with the `post_notification` effect.
2
3use crate::block::Block;
4use crate::db::{Db, DbKind};
5use crate::everything::Everything;
6use crate::game::GameFlags;
7use crate::item::{Item, ItemLoader};
8use crate::token::Token;
9use crate::validator::Validator;
10
11#[derive(Clone, Debug)]
12pub struct Message {}
13
14inventory::submit! {
15    ItemLoader::Normal(GameFlags::Vic3, Item::Message, Message::add)
16}
17
18impl Message {
19    pub fn add(db: &mut Db, key: Token, block: Block) {
20        db.add(Item::Message, key, block, Box::new(Self {}));
21    }
22}
23
24impl DbKind for Message {
25    fn validate(&self, key: &Token, block: &Block, data: &Everything) {
26        let mut vd = Validator::new(block, data);
27
28        let loca = format!("notification_{key}_name");
29        data.verify_exists_implied(Item::Localization, &loca, key);
30        let loca = format!("notification_{key}_tooltip");
31        data.verify_exists_implied(Item::Localization, &loca, key);
32        let loca = format!("notification_{key}_desc");
33        data.verify_exists_implied(Item::Localization, &loca, key);
34
35        vd.req_field("type");
36        vd.req_field("texture");
37        vd.req_field("notification_type");
38
39        vd.field_value("type"); // TODO: find out what is allowed here
40        vd.field_item("group", Item::Localization);
41        vd.field_item("texture", Item::File);
42        vd.field_choice("notification_type", &["none", "feed", "toast", "popup"]);
43
44        vd.field_integer("days");
45
46        // Notification type can be changed in settings, so this field is useful for all types.
47        // The value refers to one of the notification_popup widgets in gui/popups.gui
48        vd.field_item("popup_name", Item::WidgetName);
49
50        vd.field_item("on_created_soundeffect", Item::Sound);
51        vd.field_choice("color", &["bad", "neutral", "good"]);
52    }
53}