public TagYarnDialogSelector(Yarn.VariableStorage variableStorage) { VariableStorage = variableStorage; Dialogue = new Yarn.Dialogue(VariableStorage) { LogDebugMessage = delegate(string message) { DebugLog.Log(message); }, LogErrorMessage = delegate(string message) { DebugLog.Err(message); } }; }
public void Init() { if (System.IO.Path.GetFileName(Environment.CurrentDirectory) != "Tests") { if (TestContext.CurrentContext.TestDirectory == Environment.CurrentDirectory) { // Hop up to the folder that contains the Tests folder var topLevelPath = System.IO.Path.Combine(Environment.CurrentDirectory, "..", "..", ".."); Environment.CurrentDirectory = topLevelPath; } var newWorkingDir = System.IO.Path.Combine(Environment.CurrentDirectory, "Tests"); Environment.CurrentDirectory = newWorkingDir; } dialogue = new Yarn.Dialogue(storage); dialogue.LogDebugMessage = delegate(string message) { Console.WriteLine(message); }; dialogue.LogErrorMessage = delegate(string message) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("ERROR: " + message); Console.ResetColor(); if (errorsCauseFailures == true) { Assert.Fail(); } }; dialogue.library.RegisterFunction("assert", 1, delegate(Yarn.Value[] parameters) { if (parameters[0].AsBool == false) { Assert.Fail("Assertion failed"); } }); dialogue.library.RegisterFunction("prepare_for_options", 2, delegate(Yarn.Value[] parameters) { nextExpectedOptionCount = (int)parameters[0].AsNumber; nextOptionToSelect = (int)parameters[1].AsNumber; }); dialogue.library.RegisterFunction("expect_line", -1, delegate(Yarn.Value[] parameters) { nextExpectedLine = parameters[0].AsString; }); dialogue.library.RegisterFunction("expect_command", -1, delegate(Yarn.Value[] parameters) { nextExpectedCommand = parameters[0].AsString; }); }
public YarnDialogSelector() { variableStorage = new Yarn.MemoryVariableStore(); dialogue = new Yarn.Dialogue(variableStorage) { LogDebugMessage = delegate(string message) { DebugLog.Log(message); }, LogErrorMessage = delegate(string message) { DebugLog.Err(message); } }; }
private void InitIfNeeded() { // create the main Dialogue runner, and pass our variableStorage to it varStorage = new MerinoVariableStorage(); dialogue = new Yarn.Dialogue(varStorage); // setup the logging system. dialogue.LogDebugMessage = message => MerinoDebug.Log(LoggingLevel.Verbose, message); dialogue.LogErrorMessage = PlaytestErrorLog; // icons if (errorIcon == null) { errorIcon = EditorGUIUtility.Load("icons/d_console.erroricon.sml.png") as Texture; } }
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(); }
// UTILITY protected static void DebugNodes(Yarn.Dialogue dialogue) { List <string> startNodes = dialogue.allNodes.ToList(); string debugLog = "Start Nodes\n"; foreach (string node in startNodes) { debugLog += '\t' + node + '\n'; IEnumerable <string> tags = dialogue.GetTagsForNode(node); foreach (var tag in tags) { debugLog += "\t\t" + tag + '\n'; } } DebugLog.Log(debugLog); }
void Start() { // Ensure that we have our Implementation object if (dialogueUI == null) { Debug.LogError ("Implementation was not set! Can't run the dialogue!"); return; } // And that we have our variable storage object if (variableStorage == null) { Debug.LogError ("Variable storage was not set! Can't run the dialogue!"); return; } // Ensure that the variable storage has the right stuff in it variableStorage.ResetToDefaults (); // Create the main Dialogue runner, and pass our variableStorage to it dialogue = new Yarn.Dialogue (variableStorage); // Set up the logging system. dialogue.LogDebugMessage = Debug.Log; dialogue.LogErrorMessage = Debug.LogError; // Load all JSON foreach (var source in sourceText) { dialogue.LoadString (source.text); } if (startAutomatically) { StartDialogue(); } }