yarnspinner_runtime 0.8.0

Runtime / VM for Yarn Spinner for Rust, the friendly tool for writing game dialogue
Documentation
//! Adapted from <https://github.com/YarnSpinnerTool/YarnSpinner/blob/da39c7195107d8211f21c263e4084f773b84eaff/YarnSpinner/Dialogue.cs>, which we split off into multiple files

use crate::prelude::*;
use core::fmt::Display;

/// An option to be presented to the user.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "bevy", derive(Reflect))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy", reflect(Debug, PartialEq))]
#[cfg_attr(
    all(feature = "bevy", feature = "serde"),
    reflect(Serialize, Deserialize)
)]
pub struct DialogueOption {
    /// The [`Line`] that should be presented to the user for this option.
    pub line: Line,

    /// The identifying number for this option.
    ///
    /// When the user selects this option, this value should be used as the parameter for [`Dialogue::set_selected_option`].
    pub id: OptionId,

    /// The name of the node that will be run if this option is selected.
    ///
    /// The value of this property not be valid if this is a shortcut option.
    pub destination_node: String,

    /// Gets a value indicating whether the player should be permitted to select this option.
    ///
    /// If this value is `false`, this option had a line condition on it that failed.
    /// The option will still be delivered to the game, but, depending on the needs of the game,
    /// the game may decide to not allow the player to select it, or not offer it to the player at all.
    ///
    /// This is intended for situations where games wish to show options that the player _could_ have taken,
    /// if some other condition had been met (e.g. having enough "charisma" points).
    pub is_available: bool,
}

/// The identifying number for an option. You should not need to create these yourself, since you get them from [`DialogueOption`]s.
///
/// Since the IDs are just zero-based indices, you can also derive them yourself. Note that the index numeration includes options which
/// have [`DialogueOption::is_available`] set to `false`, so the index of an option may not be as it appears in the list of options presented to the user.11
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "bevy", derive(Reflect))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy", reflect(Debug, PartialEq, Hash))]
#[cfg_attr(
    all(feature = "bevy", feature = "serde"),
    reflect(Serialize, Deserialize)
)]
pub struct OptionId(pub usize);

impl Display for OptionId {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.0)
    }
}