public bool RequiresStop(string arg) { thes = DialogueManager.thes; string funcName = arg.Substring(0, arg.IndexOf("(")); return(thes.IsSynonym("random", funcName) || thes.IsSynonym("comparevar", funcName) || thes.IsSynonym("goto", funcName) || thes.IsSynonym("loadfile", funcName) || thes.IsSynonym("wait", funcName)); }
public IEnumerator ReadDialogue(Choice subChoice, float time = 0) { //uiManager.dialogueText.text = string.Empty; while (uiManager.isDisplayingText) { yield return(new WaitForEndOfFrame()); } yield return(new WaitForSeconds(time)); currentlyActiveChoice = subChoice; string func; for (int i = dialogueLine[dialogueLine.Count - 1]; i < subChoice.choiceText.Count; i++) { string line = subChoice.choiceText[i]; dialogueLine[dialogueLine.Count - 1] = i; switch (subChoice.choiceText[i].First()) { default: text += (varManager.EvaluateFormula("charVisible") == 1 ? (charManager.currentChar + ": ") : "") + subChoice.choiceText[i]; if (text.Contains("\\n")) { text = text.Replace(" \\n", "\n").Replace("\\n", "\n"); } else { StartCoroutine(uiManager.DisplayText(text)); yield return(new WaitForSeconds(.6f)); canPressButton = true; while (canPressButton) { yield return(new WaitForEndOfFrame()); } text = string.Empty; } break; case '-': //$SwitchCharacter() --- OR --- $SetCast() Quick notation line = line.Replace("-", "").Replace("(", "").Replace(")", ""); string[] args = parser.ParseParameters(line); if (args.Length == 1) { charManager.SetCurrentChar(args[0]); } else { charManager.SetCharacterCast(args); } break; case '*': //$DisplayChoice() Quick notation SaveLine(i + 1); uiManager.DisplayChoices(line.Replace("*", "")); yield break; case '[': //$SetVar() Quick notation line = line.Replace("[", "").Replace("]", "").Replace(" ", ""); func = "setvar(" + line + ")"; functionManager.InterpretFunction(func); break; case '<': //$SetPersistentVar() Quick notations line = line.Replace("<", "").Replace(">", "").Replace(" ", ""); func = "setpersistentvar(" + line + ")"; functionManager.InterpretFunction(func); break; case '|': //$GetVar() Quick notation --OR-- $CompareVar() Quick notation line = line.Replace("|", "").Replace(" ", ""); if (!(line.Contains(">") || line.Contains("<") || line.Contains("="))) { Debug.Log(varManager.EvaluateFormula(line)); break; } else { SaveLine(i + 1); func = "comparevar(" + line + ")"; functionManager.InterpretFunction(func); yield break; } case '%': //$ChanceDialogue() Quick Notation line = line.Replace(" ", "").Replace("%", "").Replace("(", "").Replace(")", ""); SaveLine(i + 1); func = "random(" + line + ")"; functionManager.InterpretFunction(func); yield break; case '$': //Special function func = line.Substring(1, line.IndexOf("(") - 1).ToLower(); if (thes.IsSynonym("wait", func)) { StartCoroutine(uiManager.DisplayText(text, true)); text = string.Empty; } if (functionManager.RequiresStop(line.ToLower().Replace("$", ""))) { SaveLine(i + 1); functionManager.InterpretFunction(line.Replace("$", "")); yield break; } else { functionManager.InterpretFunction(line.Replace("$", "")); break; } } } if (subChoice.parentChoice != subChoice) { FallThrough(); } else { Debug.LogWarning("[Snow# 4] End of File."); } }
public void InterpretFunction(string line) { string arg = line.Substring(line.IndexOf("(")).Replace("(", "").Replace(")", ""); line = line.ToLower(); string funcName = line.Substring(0, line.IndexOf("(")); thes = DialogueManager.thes; if (thes.IsSynonym("opentheme", funcName)) { DialogueManager.uiManager = themeConstructor.ConstructTheme(arg); } else if (thes.IsSynonym("savetheme", funcName)) { themeSaver.CreateTheme(arg); DialogueManager.uiManager.ResetUI(); DialogueManager.uiManager = themeConstructor.ConstructTheme(arg); } else if (thes.IsSynonym("setpersistentvar", funcName)) { arg = arg.Replace(" ", ""); varManager.SetVar(parser.ParseParameters(arg), true); } else if (thes.IsSynonym("setvar", funcName)) { arg = arg.Replace(" ", ""); varManager.SetVar(parser.ParseParameters(arg)); } else if (thes.IsSynonym("resetvar", funcName)) { arg = arg.Replace(" ", ""); varManager.ResetVar(); } else if (thes.IsSynonym("comparevar", funcName)) { string[] statements = parser.ParseParameters(arg); bool hasElse = statements[statements.Length - 1] == "else"; DialogueManager.uiManager.choices = new string[statements.Length]; int index = varManager.CompareVar(statements) - 1; if (index >= 0) { DialogueManager.uiManager.ChooseChoice(index); } else if (hasElse) { DialogueManager.uiManager.ChooseChoice(DialogueManager.uiManager.choices.Length - 1); } else { dialogue.FallThrough(); DialogueManager.currentlyActiveChoice.choicesPassed += DialogueManager.uiManager.choices.Length; } } else if (thes.IsSynonym("setcast", funcName)) { charManager.SetCharacterCast(parser.ParseParameters(arg)); } else if (thes.IsSynonym("setchar", funcName)) { charManager.SetCurrentChar(arg); } else if (thes.IsSynonym("random", funcName)) { arg = arg.Replace(" ", ""); Random(parser.ParseParameters(arg)); } else if (thes.IsSynonym("goto", funcName)) { arg = arg.Replace(" ", ""); GotoKey(arg); } else if (thes.IsSynonym("setkey", funcName)) { arg = arg.Replace(" ", ""); varManager.SetKey(arg); } else if (thes.IsSynonym("loadthes", funcName)) { arg = arg.Replace(" ", ""); DialogueManager.thes = new Thesaurus(arg); } else if (thes.IsSynonym("requirechar", funcName)) { string val = (arg.ToLower() == "false" ? "0" : "1"); varManager.SetVar(new string[] { "charVisible=" + val }); } else if (thes.IsSynonym("setspeed", funcName)) { if (arg == "d" || arg == "default") { arg = dialogue.startingTextSpeed + ""; } varManager.SetVar(new string[] { "typeRate=" + arg }); } else if (thes.IsSynonym("loadfile", funcName)) { string[] args = parser.ParseParameters(arg); DialogueManager.parser.MakeTree(args[1].Replace(" ", ""), args[0]); DialogueManager.dialogueLine = new List <int>(1) { 0 }; dialogue.StartReading(DialogueManager.parser.dialogue); } else if (thes.IsSynonym("wait", funcName)) { if (float.TryParse(arg, out float t)) { dialogue.FallThrough(t); } else { throw new Exception("Snow# 4: Argument of the '$Wait' function must be a numerical value. Value found was: [" + arg + "]"); } } else if (thes.IsSynonym("quit", funcName)) { Application.Quit(); } }