YarnSpinner
YarnSpinner is an interpreter for the Yarn language, written in C#.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
Yarn.YarnSpinnerConsole.ConsoleRunnerImplementation Class Reference
+ Inheritance diagram for Yarn.YarnSpinnerConsole.ConsoleRunnerImplementation:
+ Collaboration diagram for Yarn.YarnSpinnerConsole.ConsoleRunnerImplementation:

Public Member Functions

 ConsoleRunnerImplementation (bool waitForLines=false)
 
void RunLine (Yarn.Line lineText)
 
void RunOptions (Options optionsGroup, OptionChooser optionChooser)
 
void RunCommand (string command)
 
void DialogueComplete ()
 
void HandleErrorMessage (string error)
 
void HandleDebugMessage (string message)
 
virtual void SetNumber (string variableName, float number)
 
virtual float GetNumber (string variableName)
 
virtual void SetValue (string variableName, Value value)
 
virtual Value GetValue (string variableName)
 
void Clear ()
 

Public Attributes

int numberOfExpectedOptions = -1
 
int autoSelectOptionNumber = -1
 
string expectedNextLine = null
 
string expectedNextCommand = null
 
bool autoSelectFirstOption = false
 

Private Attributes

bool waitForLines = false
 
Yarn.MemoryVariableStore variableStore
 

Detailed Description

Definition at line 504 of file Main.cs.

Constructor & Destructor Documentation

Yarn.YarnSpinnerConsole.ConsoleRunnerImplementation.ConsoleRunnerImplementation ( bool  waitForLines = false)

Definition at line 525 of file Main.cs.

References Yarn.YarnSpinnerConsole.ConsoleRunnerImplementation.waitForLines.

526  {
527  this.variableStore = new MemoryVariableStore();
528  this.waitForLines = waitForLines;
529  }

Member Function Documentation

void Yarn.YarnSpinnerConsole.ConsoleRunnerImplementation.Clear ( )

Implements Yarn.VariableStorage.

Definition at line 680 of file Main.cs.

681  {
682  variableStore.Clear();
683  }
void Yarn.YarnSpinnerConsole.ConsoleRunnerImplementation.DialogueComplete ( )

Definition at line 645 of file Main.cs.

646  {
647  // All done
648  }
virtual float Yarn.YarnSpinnerConsole.ConsoleRunnerImplementation.GetNumber ( string  variableName)
virtual

Implements Yarn.VariableStorage.

Definition at line 665 of file Main.cs.

666  {
667  return variableStore.GetValue(variableName).AsNumber;
668  }
virtual Value Yarn.YarnSpinnerConsole.ConsoleRunnerImplementation.GetValue ( string  variableName)
virtual

Implements Yarn.VariableStorage.

Definition at line 675 of file Main.cs.

676  {
677  return variableStore.GetValue(variableName);
678  }
void Yarn.YarnSpinnerConsole.ConsoleRunnerImplementation.HandleDebugMessage ( string  message)

Definition at line 655 of file Main.cs.

References Yarn.YarnSpinnerConsole.Note().

656  {
657  Note(message);
658  }
static void Note(params string[] messages)
Definition: Main.cs:177

+ Here is the call graph for this function:

void Yarn.YarnSpinnerConsole.ConsoleRunnerImplementation.HandleErrorMessage ( string  error)

Definition at line 650 of file Main.cs.

References Yarn.YarnSpinnerConsole.Error().

651  {
652  Error(error);
653  }
static void Error(params string[] messages)
Definition: Main.cs:163

+ Here is the call graph for this function:

void Yarn.YarnSpinnerConsole.ConsoleRunnerImplementation.RunCommand ( string  command)

Definition at line 630 of file Main.cs.

References Yarn.YarnSpinnerConsole.Error(), and Yarn.YarnSpinnerConsole.ConsoleRunnerImplementation.expectedNextCommand.

631  {
632 
633  if (expectedNextCommand != null && expectedNextCommand != command)
634  {
635  // TODO: Output diagnostic info here
636  Error(string.Format(CultureInfo.CurrentCulture, "Unexpected command.\n\tExpected: {0}\n\tReceived: {1}",
637  expectedNextCommand, command));
638  }
639 
640  expectedNextCommand = null;
641 
642  Console.WriteLine("Command: <<" + command + ">>");
643  }
static void Error(params string[] messages)
Definition: Main.cs:163

+ Here is the call graph for this function:

void Yarn.YarnSpinnerConsole.ConsoleRunnerImplementation.RunLine ( Yarn.Line  lineText)

Definition at line 531 of file Main.cs.

References Yarn.YarnSpinnerConsole.Error(), Yarn.YarnSpinnerConsole.ConsoleRunnerImplementation.expectedNextLine, and Yarn.YarnSpinnerConsole.ConsoleRunnerImplementation.waitForLines.

532  {
533 
534  if (expectedNextLine != null && expectedNextLine != lineText.text)
535  {
536  // TODO: Output diagnostic info here
537  Error(string.Format(CultureInfo.CurrentCulture, "Unexpected line.\nExpected: {0}\nReceived: {1}",
538  expectedNextLine, lineText.text));
539 
540  }
541 
542  expectedNextLine = null;
543 
544  Console.WriteLine(lineText.text);
545  if (waitForLines == true)
546  {
547  Console.Read();
548  }
549  }
static void Error(params string[] messages)
Definition: Main.cs:163

+ Here is the call graph for this function:

void Yarn.YarnSpinnerConsole.ConsoleRunnerImplementation.RunOptions ( Options  optionsGroup,
OptionChooser  optionChooser 
)

Definition at line 551 of file Main.cs.

References Yarn.YarnSpinnerConsole.ConsoleRunnerImplementation.autoSelectFirstOption, Yarn.YarnSpinnerConsole.ConsoleRunnerImplementation.autoSelectOptionNumber, Yarn.YarnSpinnerConsole.Error(), Yarn.YarnSpinnerConsole.Note(), Yarn.YarnSpinnerConsole.ConsoleRunnerImplementation.numberOfExpectedOptions, and Yarn.Options.options.

552  {
553 
554  Console.WriteLine("Options:");
555  for (int i = 0; i < optionsGroup.options.Count; i++)
556  {
557  var optionDisplay = string.Format(CultureInfo.CurrentCulture, "{0}. {1}", i + 1, optionsGroup.options[i]);
558  Console.WriteLine(optionDisplay);
559  }
560 
561 
562  // Check to see if the number of expected options
563  // is what we're expecting to see
564  if (numberOfExpectedOptions != -1 &&
565  optionsGroup.options.Count != numberOfExpectedOptions)
566  {
567  // TODO: Output diagnostic info here
568  Error(string.Format(CultureInfo.CurrentCulture, "[ERROR: Expected {0} options, but received {1}]", numberOfExpectedOptions, optionsGroup.options.Count));
569 
570  }
571 
572  // If we were told to automatically select an option, do so
573  if (autoSelectOptionNumber != -1)
574  {
575  Note(string.Format(CultureInfo.CurrentCulture, "[Received {0} options, choosing option {1}]", optionsGroup.options.Count, autoSelectOptionNumber));
576 
577  optionChooser(autoSelectOptionNumber);
578 
580 
581  return;
582 
583  }
584 
585  // Reset the expected options counter
587 
588 
589 
590  if (autoSelectFirstOption == true)
591  {
592  Note("[automatically choosing option 1]");
593  optionChooser(0);
594  return;
595  }
596 
597  do
598  {
599  Console.Write("? ");
600  try
601  {
602  var selectedKey = Console.ReadKey().KeyChar.ToString(CultureInfo.InvariantCulture);
603  int selection;
604 
605  if (int.TryParse(selectedKey, out selection) == true)
606  {
607  Console.WriteLine();
608 
609  // we present the list as 1,2,3, but the API expects
610  // answers as 0,1,2
611  selection -= 1;
612 
613  if (selection > optionsGroup.options.Count)
614  {
615  Console.WriteLine("Invalid option.");
616  }
617  else
618  {
619  optionChooser(selection);
620  break;
621  }
622  }
623 
624  }
625  catch (FormatException) { }
626 
627  } while (true);
628  }
static void Error(params string[] messages)
Definition: Main.cs:163
static void Note(params string[] messages)
Definition: Main.cs:177

+ Here is the call graph for this function:

virtual void Yarn.YarnSpinnerConsole.ConsoleRunnerImplementation.SetNumber ( string  variableName,
float  number 
)
virtual

Implements Yarn.VariableStorage.

Definition at line 660 of file Main.cs.

661  {
662  variableStore.SetValue(variableName, new Value(number));
663  }
virtual void Yarn.YarnSpinnerConsole.ConsoleRunnerImplementation.SetValue ( string  variableName,
Value  value 
)
virtual

Implements Yarn.VariableStorage.

Definition at line 670 of file Main.cs.

671  {
672  variableStore.SetValue(variableName, value);
673  }

Member Data Documentation

bool Yarn.YarnSpinnerConsole.ConsoleRunnerImplementation.autoSelectFirstOption = false
int Yarn.YarnSpinnerConsole.ConsoleRunnerImplementation.autoSelectOptionNumber = -1
string Yarn.YarnSpinnerConsole.ConsoleRunnerImplementation.expectedNextCommand = null
string Yarn.YarnSpinnerConsole.ConsoleRunnerImplementation.expectedNextLine = null
int Yarn.YarnSpinnerConsole.ConsoleRunnerImplementation.numberOfExpectedOptions = -1
Yarn.MemoryVariableStore Yarn.YarnSpinnerConsole.ConsoleRunnerImplementation.variableStore
private

Definition at line 509 of file Main.cs.

bool Yarn.YarnSpinnerConsole.ConsoleRunnerImplementation.waitForLines = false
private

The documentation for this class was generated from the following file: