public void TestCommands() { var path = System.IO.Path.Combine("TestCases", "Commands.node"); dialogue.LoadFile(path); dialogue.Compile(); foreach (var result in dialogue.Run()) { HandleResult(result); } }
IEnumerator RunDialogue(string startNode = "Start") { // Get lines, options and commands from the Dialogue object, one at a time. foreach (Yarn.Dialogue.RunnerResult step in dialogue.Run(startNode)) { CurrentNode = dialogue.currentNode; if (step is Yarn.Dialogue.LineResult) { // Wait for line to finish displaying var lineResult = step as Yarn.Dialogue.LineResult; yield return(this.StartCoroutine(RunLine(lineResult.line))); } else if (step is Yarn.Dialogue.OptionSetResult) { // Wait for user to finish picking an option var optionSetResult = step as Yarn.Dialogue.OptionSetResult; RunOptions(optionSetResult.options, optionSetResult.setSelectedOptionDelegate); yield return(new WaitWhile(() => inputOption < 0)); } else if (step is Yarn.Dialogue.CommandResult) { // Wait for command to finish running var commandResult = step as Yarn.Dialogue.CommandResult; yield return(this.StartCoroutine(RunCommand(commandResult.command))); } } MerinoDebug.Log(LoggingLevel.Info, "Reached the end of the dialogue."); CurrentNode = null; // No more results! The dialogue is done. yield return(new WaitUntil(() => MerinoPrefs.stopOnDialogueEnd)); StopPlaytest_Internal(); }
public YarnEngine( String ConversationFile, String StartNode, Yarn.MemoryVariableStore Memory, IYarnPlayerInterface PlayerInterface) { this.PlayerInterface = PlayerInterface; this.Memory = Memory; CommandGrammar = new YarnCommandGrammar(); foreach (var method in AssetManager.EnumerateModHooks(typeof(YarnCommandAttribute), typeof(void), new Type[] { typeof(YarnEngine), typeof(List <Ancora.AstNode>), typeof(Yarn.MemoryVariableStore) })) { var attribute = method.GetCustomAttributes(false).FirstOrDefault(a => a is YarnCommandAttribute) as YarnCommandAttribute; if (attribute == null) { continue; } CommandHandlers[attribute.CommandName] = new CommandHandler { Action = (state, args, mem) => method.Invoke(null, new Object[] { state, args, mem }), Settings = attribute }; } Dialogue = new Yarn.Dialogue(Memory); Dialogue.LogDebugMessage = delegate(string message) { Console.WriteLine(message); }; Dialogue.LogErrorMessage = delegate(string message) { Console.WriteLine("Yarn Error: " + message); }; //try { Dialogue.LoadFile(AssetManager.ResolveContentPath(ConversationFile), false, false, null); } //catch (Exception e) { // Console.Error.WriteLine(e.ToString()); } Runner = Dialogue.Run(StartNode).GetEnumerator(); }