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
//! Endings.
//!
//! An ending is the final state of a run. The engine evaluates endings after
//! every turn (when none is already active) and picks the highest-priority
//! ending whose `trigger` condition holds. Endings can also be forced
//! explicitly via `Effect::TriggerEnding`.
use crate::interactive_fiction::data::condition::Condition;
use crate::interactive_fiction::data::text::Text;
use serde::{Deserialize, Serialize};
use std::collections::BTreeSet;
/// A terminal conclusion for a run.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Ending {
/// Short title shown on the game-over screen.
pub title: String,
/// Paragraph shown as the immediate outcome.
pub description: Text,
/// Epilogue shown after the description.
pub epilogue: Text,
/// Condition that causes the ending to fire when evaluated in-line.
/// When the ending is forced via `Effect::TriggerEnding`, this is ignored.
pub trigger: Condition,
/// Higher priority endings override lower ones when multiple trigger the same turn.
pub priority: i32,
/// Free-form tags used when listing unlocked endings.
pub tags: BTreeSet<String>,
}
impl Ending {
pub fn new(
title: impl Into<String>,
description: Text,
epilogue: Text,
trigger: Condition,
) -> Self {
Self {
title: title.into(),
description,
epilogue,
trigger,
priority: 0,
tags: BTreeSet::new(),
}
}
pub fn with_priority(mut self, priority: i32) -> Self {
self.priority = priority;
self
}
pub fn with_tag(mut self, tag: impl Into<String>) -> Self {
self.tags.insert(tag.into());
self
}
}