예제 #1
0
        private string ProcessDialogScript(string script)
        {
            StringBuilder sb = new StringBuilder(script.Length);
            StreamReader  sr = new StreamReader(new MemoryStream(Encoding.Default.GetBytes(script), false), Encoding.Default);
            string        thisLine;
            string        originalLine;

            while ((thisLine = sr.ReadLine()) != null)
            {
                originalLine = thisLine;
                thisLine     = thisLine.Trim();

                if (DialogScriptConverter.IsRealScriptLineInDialog(originalLine))
                {
                    originalLine = ProcessScript(originalLine);
                }
                else if (thisLine.IndexOf("//") >= 0)
                {
                    thisLine = thisLine.Substring(0, thisLine.IndexOf("//"));
                }
                else if (thisLine.IndexOf(":") > 0)
                {
                    int characterNameLength = 0;
                    while (Char.IsLetterOrDigit(thisLine[characterNameLength]))
                    {
                        characterNameLength++;
                    }
                    string characterName = thisLine.Substring(0, characterNameLength);
                    int    charID        = FindCharacterIDForCharacter(characterName);
                    if (charID >= 0)
                    {
                        string lineText = thisLine.Substring(thisLine.IndexOf(":") + 1).Trim();
                        originalLine = string.Format("{0}: {1}", characterName, CreateSpeechLine(charID, lineText));
                    }
                }

                sb.AppendLine(originalLine);
            }
            sr.Close();
            return(sb.ToString());
        }
예제 #2
0
 private Script CompileDialogs(CompileMessages errors, bool rebuildAll)
 {
     DialogScriptConverter dialogConverter = new DialogScriptConverter();
     string dialogScriptsText = dialogConverter.ConvertGameDialogScripts(_game, errors, rebuildAll);
     Script dialogScripts = new Script(Script.DIALOG_SCRIPTS_FILE_NAME, dialogScriptsText, false);
     Script globalScript = _game.Scripts.GetScriptByFilename(Script.GLOBAL_SCRIPT_FILE_NAME);
     if (!System.Text.RegularExpressions.Regex.IsMatch(globalScript.Text, @"function\s+dialog_request\s*\("))
     {
         // A dialog_request must exist in the global script, otherwise
         // the dialogs script fails to load at run-time
         globalScript.Text += Environment.NewLine + "function dialog_request(int param) {" + Environment.NewLine + "}";
     }
     return dialogScripts;
 }