示例#1
0
        public bool Save(FOCommon.Dialog.Dialog dialog, String fileName)
        {
            var lines = new List <string>();

            lines.Add("[comment]");
            lines.Add(dialog.Comment);
            lines.Add("");
            lines.Add("[data]");
            lines.Add("lang=" + String.Join(" ", dialog.LanguageTrees.ToArray()));
            lines.Add("");
            lines.Add("[dialog]");
            lines.Add("&");
            int nodeNum = 0;

            foreach (FOCommon.Dialog.Node node in dialog.Nodes)
            {
                nodeNum = WriteNode(lines, nodeNum, node);
            }
            lines[lines.Count - 1] = lines[lines.Count - 1].Replace('#', '&');
            lines[lines.Count - 1] = lines[lines.Count - 1].Replace('@', '&');

            lines.Add("");
            foreach (String lang in dialog.LanguageTrees)
            {
                WriteDialogStrings(dialog, lines, lang);
            }

            // Add editor metadata here

            File.WriteAllLines(fileName, lines.ToArray(), Encoding.GetEncoding("Windows-1251"));

            return(true);
        }
示例#2
0
        public bool Parse()
        {
            if (!File.Exists(_fileName))
            {
                Utils.Log(_fileName + " doesn't exist. Can't parse data.");
                return(false);
            }

            _lines.Clear();
            _lines.AddRange(File.ReadAllLines(_fileName, Encoding.GetEncoding("Windows-1251")));

            bool parseMode = false;
            bool isNode    = true;

            Node node      = null;
            var  languages = new List <string>();

            _textStrings.Parse();
            var langEndLine = new Regex("^\\[.*\\]");

            int answerNum = 0;
            int nodeNum   = 0;

            _dialog = new Dialog.Dialog();

            int parseLine = 0;

            foreach (string line in _lines)
            {
                parseLine++;
                if (line == "[dialog]")
                {
                    parseMode = true;
                    continue;
                }

                if (parseLine == 2)
                {
                    _dialog.Comment = line;
                }

                if (line.Contains("lang="))
                {
                    string langStr = line.Substring(5, line.Length - 5);
                    languages.AddRange(langStr.Split(' '));
                    _dialog.LanguageTrees = languages;

                    foreach (String lang in languages)
                    {
                        ParseLanguageStrings(langEndLine, lang);
                    }
                }

                if (!parseMode)
                {
                    continue;
                }
                if (String.IsNullOrEmpty(line))
                {
                    break;
                }

                if (line == "&")
                {
                    continue;
                }
                String[] parts = line.Split(' ');
                if (isNode)
                {
                    node = ParseNode(langEndLine, languages, parts, ref nodeNum);
                }
                else // It's an answer
                {
                    var ans = ParseAnswer(answerNum, langEndLine, parts, languages, nodeNum);
                    node.Answers.Add(ans);
                }
                if (IsLastTok(parts, '@'))
                {
                    _dialog.Nodes.Add(node);
                    isNode    = true;
                    answerNum = 0;
                }
                else
                {
                    answerNum++;
                    isNode = false;
                }

                if (IsLastTok(parts, '&'))
                {
                    _dialog.Nodes.Add(node);
                    parseMode = false;
                }
            }
            return(true);
        }
示例#3
0
        public bool Parse()
        {
            if (!File.Exists(_fileName))
            {
                Utils.Log(_fileName + " doesn't exist. Can't parse data.");
                return false;
            }

            _lines.Clear();
            _lines.AddRange(File.ReadAllLines(_fileName, Encoding.GetEncoding("Windows-1251")));

            bool parseMode=false;
            bool isNode = true;

            Node node = null;
            var languages = new List<string>();

            _textStrings.Parse();
            var langEndLine = new Regex("^\\[.*\\]");

            int answerNum=0;
            int nodeNum = 0;
            _dialog = new Dialog.Dialog();

            int parseLine=0;
            foreach (string line in _lines)
            {
                parseLine++;
                if (line == "[dialog]")
                {
                    parseMode = true;
                    continue;
                }

                if (parseLine == 2)
                    _dialog.Comment = line;

                if (line.Contains("lang="))
                {
                    string langStr = line.Substring(5, line.Length - 5);
                    languages.AddRange(langStr.Split(' '));
                    _dialog.LanguageTrees = languages;

                    foreach (String lang in languages)
                    {
                        ParseLanguageStrings(langEndLine, lang);
                    }
                }

                if (!parseMode)
                    continue;
                if (String.IsNullOrEmpty(line))
                    break;

                if (line == "&")
                {
                    continue;
                }
                String[] parts = line.Split(' ');
                if (isNode)
                {
                    node = ParseNode(langEndLine, languages, parts, ref nodeNum);
                }
                else // It's an answer
                {
                    var ans = ParseAnswer(answerNum, langEndLine, parts, languages, nodeNum);
                    node.Answers.Add(ans);
                }
                if (IsLastTok(parts, '@'))
                {
                    _dialog.Nodes.Add(node);
                    isNode = true;
                    answerNum = 0;
                }
                else
                {
                    answerNum++;
                    isNode = false;
                }

                if (IsLastTok(parts, '&'))
                {
                    _dialog.Nodes.Add(node);
                    parseMode = false;
                }
            }
            return true;
        }
示例#4
0
        private void WriteDialogStrings(Dialog.Dialog dialog, List<string> lines, string lang)
        {
            lines.Add("[" + lang + "]");
            lines.Add(MSGFormat(100, dialog.NpcName[lang]));
            if (dialog.DescriptionAlive[lang] != null)
                foreach (String str in dialog.DescriptionAlive[lang]) lines.Add(MSGFormat(200, str));
            if (dialog.DescriptionAliveFull[lang] != null)
                foreach (String str in dialog.DescriptionAliveFull[lang]) lines.Add(MSGFormat(210, str));
            if (dialog.DescriptionKnocked[lang] != null)
                foreach (String str in dialog.DescriptionKnocked[lang]) lines.Add(MSGFormat(220, str));
            if (dialog.DescriptionKnockedFull[lang] != null)
                foreach (String str in dialog.DescriptionKnockedFull[lang]) lines.Add(MSGFormat(230, str));
            if (dialog.DescriptionDead[lang] != null)
                foreach (String str in dialog.DescriptionDead[lang]) lines.Add(MSGFormat(240, str));
            if (dialog.DescriptionDeadFull[lang] != null)
                foreach (String str in dialog.DescriptionDeadFull[lang]) lines.Add(MSGFormat(250, str));
            if (dialog.DescriptionCriticalDead[lang] != null)
                foreach (String str in dialog.DescriptionCriticalDead[lang]) lines.Add(MSGFormat(260, str));
            if (dialog.DescriptionCriticalDeadFull[lang] != null)
                foreach (String str in dialog.DescriptionCriticalDeadFull[lang]) lines.Add(MSGFormat(270, str));
            int nodeNum = 0;
            foreach (FOCommon.Dialog.Node node in dialog.Nodes)
            {
                int ansNum = 0;
                lines.Add(MSGFormat(++nodeNum*1000, node.Text[lang]));
                foreach (FOCommon.Dialog.Answer answer in node.Answers)
                {
                    lines.Add(MSGFormat(nodeNum*1000 + (++ansNum*10), answer.Text[lang]));
                }
            }

            foreach (KeyValuePair<int, List<String>> kvp in dialog.UserStrings[lang])
            {
                foreach (String line in kvp.Value)
                    lines.Add(MSGFormat(100000000 + kvp.Key, line));
            }
            lines.Add("");
        }