1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use anim::transition::{SwitchTransition, Transition};
use core::{prefab::Prefab, Ignite, Scalar};
use serde::{Deserialize, Serialize};

pub type ActiveDialogue = Transition<Option<Dialogue>>;

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct Dialogue {
    pub character: String,
    pub text: String,
    #[serde(default)]
    pub options: Vec<DialogueOption>,
}

impl Prefab for Dialogue {}

impl Dialogue {
    pub fn is_dirty(&self) -> bool {
        self.options.iter().any(|option| option.is_dirty())
    }

    pub fn process(&mut self, delta_time: Scalar) {
        for option in &mut self.options {
            option.process(delta_time);
        }
    }
}

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct DialogueOption {
    pub text: String,
    pub action: DialogueAction,
    #[serde(default)]
    pub focused: SwitchTransition,
}

impl Prefab for DialogueOption {}

impl DialogueOption {
    pub fn is_dirty(&self) -> bool {
        self.focused.in_progress()
    }

    pub fn process(&mut self, delta_time: Scalar) {
        self.focused.process(delta_time);
    }
}

#[derive(Ignite, Debug, Clone, Serialize, Deserialize)]
pub enum DialogueAction {
    None,
    JumpToLabel(String),
    JumpToChapter(String),
}

impl Default for DialogueAction {
    fn default() -> Self {
        Self::None
    }
}

impl Prefab for DialogueAction {}