Exemplo n.º 1
0
        /// <summary>
        /// Formats the messages with the generated font by replacing the text with shift-jis characters.
        /// </summary>
        /// <param name="save"></param>
        public void Format(bool save = true)
        {
            foreach (ScriptDocument script in Scripts)
            {
                if (script.BaseFile.GetType() != typeof(LZBFile))
                {
                    continue;
                }
                List <IScriptElement> elements = ScriptParser.Parse(script);
                foreach (IScriptElement element in elements)
                {
                    if (element.GetType() == typeof(ScriptMessage))
                    {
                        ScriptMessage message = (ScriptMessage)element;
                        message.Format(this);
                    }
                    else if (element.GetType() == typeof(ScriptGmap))
                    {
                        ScriptGmap gmap = (ScriptGmap)element;
                        gmap.Format(this);
                    }
                }
                ScriptParser.Parse(script, elements);
                if (save)
                {
                    script.WriteToOriginalFile();
                }
            }

            foreach (HardCodedText text in HardCodedTexts)
            {
                text.Format(this);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Generates the font characters for the current script file.
        /// </summary>
        public void GenerateFont()
        {
            StringBuilder stringBuilder = new StringBuilder();

            foreach (ScriptDocument script in Scripts)
            {
                List <IScriptElement> elements = ScriptParser.Parse(script);
                foreach (IScriptElement element in elements)
                {
                    if (element.GetType() == typeof(ScriptMessage))
                    {
                        ScriptMessage message = (ScriptMessage)element;
                        stringBuilder.AppendLine(message.ContentText);
                    }
                    else if (element.GetType() == typeof(ScriptGmap))
                    {
                        ScriptGmap gmap = (ScriptGmap)element;
                        stringBuilder.AppendLine(gmap.ContentText);
                    }
                }
            }
            foreach (HardCodedText text in HardCodedTexts)
            {
                if (text.NewString == null)
                {
                    stringBuilder.AppendLine(text.Translation);
                }
                else
                {
                    stringBuilder.AppendLine(text.NewString);
                }
            }

            HashSet <string> dictionary = CreateDictionary(ScriptParser.TextToLines(stringBuilder.ToString()));

            //DEBUG OUTPUT START
            Console.WriteLine("Dictionary Size: {0} Symbols", dictionary.Count);
            if (dictionary.Count > 3302)
            {
                Console.WriteLine("Dictionary size is exceeding the 3302 limit!");
                MessageBox.Show("Dictionary size is exceeding the 3302 limit!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            //DEBUG OUTPUT END

            GenerateFont(dictionary, Font);
        }
Exemplo n.º 3
0
        public static List <IScriptElement> Parse(ScriptDocument script)
        {
            List <IScriptElement> result = new List <IScriptElement>();

            //add linebreak to text property to keep content linebreak free
            //last line linebreak only works with scripttext for now

            bool          isMessage = false;
            bool          isGmap    = false;
            ScriptMessage message   = null;
            ScriptGmap    gmap      = null;

            string[] lines;
            if (script.TextBuffer.Contains("\r"))
            {
                lines = TextToLines(script.TextBuffer);
            }
            else
            {
                lines = script.TextBuffer.Split('\n'); //fix for XML serialization f*****g up CR LF
            }

            for (int i = 0; i < lines.Length; i++)
            {
                bool   eof  = (i == lines.Length - 1);
                string line = lines[i];

                if (String.IsNullOrEmpty(line))
                {
                    isGmap    = false;
                    isMessage = false;
                    message   = null;

                    result.Add(new ScriptText(line, !eof));
                    continue;
                }

                //fixing weird html special tags in script for gamelogic ScriptCommands
                if (line.Contains("&gt;"))
                {
                    line = line.Replace("&gt;", ">");
                }
                if (line.Contains("&lt;"))
                {
                    line = line.Replace("&lt;", "<");
                }
                // "==" is ok as it is!

                if (isMessage)
                {
                    if (line.EndsWith("%ME:") || line.EndsWith("%END:"))
                    {
                        message.Content += line;
                        isMessage        = false;
                        message          = null;
                    }
                    else
                    {
                        message.Content += line + "\r\n";
                    }
                    continue;
                }

                if (isGmap)
                {
                    gmap.Content += line + "\r\n";
                    continue;
                }

                Match matchCommand = _regexCommand.Match(line);
                if (matchCommand.Success)
                {
                    if (matchCommand.Index != 0)
                    {
                        result.Add(new ScriptText(line.Substring(0, matchCommand.Index)));
                        //add flag to command for not doing line break
                    }

                    if (matchCommand.Groups[1].Value == "MESSAGE")
                    {
                        isMessage = true;
                        message   = new ScriptMessage(matchCommand, i);
                        result.Add(message);
                        continue;
                    }

                    if (matchCommand.Groups[1].Value == "END" && matchCommand.Groups[2].Value == "GLOBALSET")
                    {
                        isGmap = true;
                        gmap   = new ScriptGmap(matchCommand, i);
                        result.Add(gmap);
                        continue;
                    }

                    if (matchCommand.Index + matchCommand.Length != line.Length)
                    {
                        result.Add(new ScriptCommand(matchCommand, i, false));
                        int index = matchCommand.Index + matchCommand.Length;
                        result.Add(new ScriptText(line.Substring(index, line.Length - index), !eof));
                    }
                    else
                    {
                        result.Add(new ScriptCommand(matchCommand, i));
                    }
                }
                else
                {
                    result.Add(new ScriptText(line, !eof));
                }
            }

            //Script cleanup
            for (int i = result.Count - 1; i >= 0; i--)
            {
                //remove all japanese dev comments (free ups ps1 ram, mitigates crashes...)
                if (result[i].Text.StartsWith("."))
                {
                    result.RemoveAt(i);
                }

                //remove all double empty lines in script that appeared after comment remove
                if (i >= 1)
                {
                    if (result[i].Text == "\r\n" && result[i - 1].Text == "\r\n")
                    {
                        result.RemoveAt(i);
                    }
                }
            }

            return(result);
        }