Enum initiative_core::app::command::tutorial::TutorialCommand

source ·
pub enum TutorialCommand {
Show 19 variants Introduction, GeneratingLocations, SavingLocations, GeneratingCharacters { inn: ThingRef, }, GeneratingAlternatives { inn: ThingRef, }, ViewingAlternatives { inn: ThingRef, npc_name: String, }, EditingCharacters { inn: ThingRef, npc: ThingRef, }, TheJournal { inn: ThingRef, npc: ThingRef, }, LoadingFromJournal { inn: ThingRef, npc: ThingRef, }, SrdReference { inn: ThingRef, npc: ThingRef, }, SrdReferenceLists { inn: ThingRef, npc: ThingRef, }, RollingDice { inn: ThingRef, npc: ThingRef, }, DeletingThings { inn: ThingRef, npc: ThingRef, }, AdvancingTime { inn: ThingRef, npc: ThingRef, }, CheckingTheTime { inn: ThingRef, npc: ThingRef, }, Conclusion { inn: ThingRef, npc: ThingRef, }, Cancel { inn: Option<ThingRef>, npc: Option<ThingRef>, }, Resume, Restart { inn: Option<ThingRef>, npc: Option<ThingRef>, },
}
Expand description

An enum representing each possible state of the tutorial. The Introduction variant is mapped to the tutorial command, while each other variant is registered as a CommandAlias upon completion of the previous step.

What’s up with the data fields? There is some dynamically generated content that gets carried along from one tutorial step to the next. In order for the “Deleting Things” step to drop the name of the randomly generated inn, it needs to be persisted through the entire process.

While the tutorial is active, every user input is interpreted as a TutorialCommand by registering a CommandAlias::StrictWildcard. TutorialCommand::run then re-parses the user input, displaying the result in all cases. If the input parsed to the correct command, it advances the tutorial to the next step and appends its own output to the end of the command output. If the user did something different, the command takes effect anyway, and a brief note about the tutorial still being active is appended to the output.

Variants§

§

Introduction

§

GeneratingLocations

§

SavingLocations

§

GeneratingCharacters

Fields

§

GeneratingAlternatives

Fields

§

ViewingAlternatives

Fields

§npc_name: String
§

EditingCharacters

Fields

§

TheJournal

Fields

§

LoadingFromJournal

Fields

§

SrdReference

Fields

§

SrdReferenceLists

Fields

§

RollingDice

Fields

§

DeletingThings

Fields

§

AdvancingTime

Fields

§

CheckingTheTime

Fields

§

Conclusion

Fields

§

Cancel

§

Resume

§

Restart

Implementations§

source§

impl TutorialCommand

source

fn output( &self, command_output: Option<Result<String, String>>, app_meta: &mut AppMeta, ) -> Result<String, String>

Generate the output to be displayed to the user when invoking TutorialCommand::run. This is done in a separate method because it can be invoked in two ways: by satisfying a tutorial step and advancing to the next step, and by running the resume command to get a reminder prompt indicating what the user is supposed to do.

Very counterintuitively, there is an off-by-one state going on here. The resume command doesn’t have access to the current step, only the next step, which is registered as an alias and monitoring the app state until its prompt is satisfied. Self::Resume, then, runs on that registered alias, while the various registered variants work around this limitation by running the output method of the alias after registration.

That was the reasoning, anyhow. Whether or not it was a good decision is left to the judgement of the reader.

source

fn inn(&self) -> Option<ThingRef>

Extract the inn reference from the enum variant, if present.

source

fn npc(&self) -> Option<ThingRef>

Extract the NPC reference from the enum variant, if present.

source

fn is_correct_command(&self, command: Option<&CommandType>) -> bool

Is this the command that is required to advance to the next step of the tutorial? This is determined not by a string match but by validating the parsed result, eg. time and now are equally recognized for the CheckingTheTime step because they both parse to CommandType::Time(TimeCommand::Now).

Trait Implementations§

source§

impl Autocomplete for TutorialCommand

source§

fn autocomplete<'life0, 'life1, 'async_trait>( input: &'life0 str, _app_meta: &'life1 AppMeta, ) -> Pin<Box<dyn Future<Output = Vec<AutocompleteSuggestion>> + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait,

source§

impl Clone for TutorialCommand

source§

fn clone(&self) -> TutorialCommand

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl ContextAwareParse for TutorialCommand

source§

fn parse_input<'life0, 'life1, 'async_trait>( input: &'life0 str, _app_meta: &'life1 AppMeta, ) -> Pin<Box<dyn Future<Output = CommandMatches<Self>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

source§

impl Debug for TutorialCommand

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for TutorialCommand

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl From<TutorialCommand> for CommandType

source§

fn from(c: TutorialCommand) -> CommandType

Converts to this type from the input type.
source§

impl PartialEq for TutorialCommand

source§

fn eq(&self, other: &TutorialCommand) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Runnable for TutorialCommand

source§

fn run<'life0, 'life1, 'async_trait>( self, input: &'life0 str, app_meta: &'life1 mut AppMeta, ) -> Pin<Box<dyn Future<Output = Result<String, String>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

source§

impl Eq for TutorialCommand

source§

impl StructuralPartialEq for TutorialCommand

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V