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
GeneratingAlternatives
ViewingAlternatives
EditingCharacters
TheJournal
LoadingFromJournal
SrdReference
SrdReferenceLists
RollingDice
DeletingThings
AdvancingTime
CheckingTheTime
Conclusion
Cancel
Resume
Restart
Implementations§
Source§impl TutorialCommand
impl TutorialCommand
Sourcefn output(
&self,
command_output: Option<Result<String, String>>,
app_meta: &mut AppMeta,
) -> Result<String, String>
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.
Sourcefn is_correct_command(&self, command: Option<&CommandType>) -> bool
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
impl Autocomplete for TutorialCommand
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
impl Clone for TutorialCommand
Source§fn clone(&self) -> TutorialCommand
fn clone(&self) -> TutorialCommand
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more