Пример #1
0
 public static void writeSPTFile(BinaryWriter w, SPTBlock block)
 {
     for (int i = 0; i < block.Elements.Count; ++i)
     {
         if (block.Elements[i] is SPTBlock)
         {
             writeSPTFile(w, (SPTBlock)block.Elements[i]);
         }
         else if (block.Elements[i] is SPTCommand)
         {
             SPTCommand c = ((SPTCommand)block.Elements[i]);
             if (c.GetArg(0)[0] == '{')
             {
                 w.Write(Font10Converter.SHIFT_JIS.GetBytes("{" + (block.LineNumber + block.Size - 2) + "\0\r"));
             }
             else if (c.GetArg(0)[0] == '}')
             {
                 w.Write(Font10Converter.SHIFT_JIS.GetBytes("}" + (block.LineNumber - 1) + "\0\r"));
             }
             else
             {
                 byte[] ba = c.ToByteArray();
                 //byte[] wr = Encoding.Convert(Encoding.Unicode, Encoding.GetEncoding(1252), Encoding.Unicode.GetBytes(ws));
                 w.Write(ba);
             }
         }
     }
 }
Пример #2
0
        public static SPTCommand FromStream(BinaryReader r, int id, SPTBlock b)
        {
            string     arg = "";
            SPTCommand ret = null;

            while (r.BaseStream.Position + 1 < r.BaseStream.Length)
            {
                if (ret == null)
                {
                    ret = new SPTCommand(id, b);
                }

                char c = r.ReadChar();
                if (c == 0)
                {
                    ret.args.Add(arg);
                    arg = "";
                }
                else if (c == 0x0D)
                {
                    break;
                }
                else
                {
                    arg += c;
                }
            }
            return(ret);
        }
Пример #3
0
 // Make a duplicate SPTBlock... just the blocks are duplicated
 public SPTBlock(SPTBlock orig) : base(orig.LineNumber)
 {
     Elements = new List <SPTElement>();
     for (int i = 0; i < orig.Elements.Count; ++i)
     {
         if (orig.Elements[i] is SPTBlock)
         {
             Elements.Add(new SPTBlock(((SPTBlock)orig.Elements[i])));
         }
         else
         {
             Elements.Add(orig.Elements[i]);
         }
     }
 }
Пример #4
0
        private static int UpdateLineNumbers(SPTBlock block, int start = 0)
        {
            int i = 0;

            if (start == 0)
            {
                block.Elements[0] = new SPTCommand(0, block);
                ((SPTCommand)block.Elements[0]).PushArg((block.Size - 1).ToString());
                ++i;
            }
            for (; i < block.Elements.Count; ++i)
            {
                block.Elements[i].LineNumber = ++start;
                if (block.Elements[i] is SPTBlock)
                {
                    start = UpdateLineNumbers((SPTBlock)block.Elements[i], --start);
                }
            }
            return(start);
        }
Пример #5
0
 public SPTCommand(SPTBlock b)
     : base(-1)
 {
     args  = new List <string>(10);
     Block = b;
 }
Пример #6
0
 public SPTCommand(int lineNum, SPTBlock block) : base(lineNum)
 {
     args  = new List <string>(10);
     Block = block;
 }
Пример #7
0
        private void loadSPT()
        {
            if (sptReader == null)
            {
                return;
            }
            panel1.Controls.Clear();
            lastElement = null;
            Edited      = false;

            // data structure set up
            int id = 0;

            root           = new SPTBlock(0);
            blockHierarchy = new Stack <SPTBlock>();
            blockHierarchy.Push(root);
            SPTCommand c;

            // case-specific flags
            bool needNewBlock      = true;
            bool checkNameWinClose = false;

            while ((c = SPTCommand.FromStream(sptReader, id++, blockHierarchy.Peek())) != null)
            {
                // pre loop logic
                if (c.GetArg(0)[0] == '{')
                {
                    SPTBlock b = new SPTBlock(id);
                    b.Elements.Add(c);
                    blockHierarchy.Peek().Elements.Add(b);
                    blockHierarchy.Push(b);
                    continue;
                }
                else if (c.GetArg(0)[0] == '}')
                {
                    blockHierarchy.Pop().Elements.Add(c);
                    continue;
                }
                blockHierarchy.Peek().Elements.Add(c);
                if (!(c.GetArg(0).Equals("message") || c.GetArg(0).Equals("message0")))
                {
                    needNewBlock = true;
                }
                ////

                if (c.GetArg(0).Equals("message") || c.GetArg(0).Equals("message0"))                 // start of message set
                {
                    if (needNewBlock)
                    {
                        if (c.GetArg(1) != "mbox0")
                        {
                            addTranslatable(new Note("Found non-mbox0 message box, tell me about this", id));
                        }
                        addTranslatable(new MessageBlock());
                        needNewBlock = false;
                    }
                    for (int i = 2; i < c.ArgCount; ++i)
                    {
                        string msg = c.GetArg(i);
                        if (i + 1 < c.ArgCount)
                        {
                            msg += "§";
                        }
                        lastElement.JapText += msg;
                    }
                    lastElement.JapText += "¶\r\n";
                    lastElement.commands.Add(c);
                }
                else if (c.GetArg(0).Equals("nameset0"))                 // setting talker name
                {
                    if (c.GetArg(1).Equals("N0"))
                    {
                        addTranslatable(new Nameplate());
                        lastElement.JapText = c.GetArg(2);
                        lastElement.commands.Add(c);
                    }
                }
                else if (c.GetArg(0).Equals("nameset"))                 // check for azuma talking
                {
                    if (c.GetArg(1).Equals("N0") && c.GetArg(2).StartsWith("00_"))
                    {
                        if (lastElement != null && lastElement.JapText.Equals("NO NAME:"))                         //it removes nameplate for azuma, have to ignore for this
                        {
                            panel1.Controls.Remove(lastElement);
                        }
                        lastElement = ((panel1.Controls.Count - 1 >= 0) ? (Translatable)panel1.Controls[panel1.Controls.Count - 1] : null);
                        addTranslatable(new Note("AZUMA:"));
                    }
                }
                else if (c.GetArg(0).Equals("actortext0") && c.GetArg(1).Equals("name_win"))                 // check if name window being hidden
                {
                    checkNameWinClose = true;
                    continue;
                }
                else if (c.GetArg(0).Equals("actordisp0") && c.GetArg(1).Equals("name_win") && c.GetArg(2).Equals("false") && checkNameWinClose)
                {
                    addTranslatable(new Note("NO NAME:"));
                }
                else if (c.GetArg(0).Equals("scriptcall0") && c.GetArg(1).Equals("select"))
                {
                    int nopts = Convert.ToInt32(c.GetArg(2));
                    addTranslatable(new Note("SELECTION (" + nopts + "):"));
                    GenericTranslatable t = new GenericTranslatable(c);
                    for (int i = 0; i < nopts + 1; ++i)
                    {
                        t.AddArg(new GenericTArgOpts(3 + i, (i > 0)));
                    }
                    addTranslatable(t);
                }
                else if (c.GetArg(0).Equals("scriptcall"))
                {
                    addTranslatable(new Note("Note: This script calls \"" + c.GetArg(1) + ".spt\"."));
                }
                else if (c.GetArg(0).StartsWith("ifselect") || (c.ArgCount > 1 && c.GetArg(1).StartsWith("ifselect")))
                {
                    addTranslatable(new Note("IF-SELECT:"));
                    GenericTranslatable t = new GenericTranslatable(c);
                    t.AddArg(new GenericTArgOpts(c.GetArg(0).StartsWith("ifselect") ? 1 : 2, true));
                    addTranslatable(t);
                }
                else
                {
                    // some non-known command. try finding japanese text.
                    // arg 0 is always english command - it won't have japanese text.
                    bool done = false;
                    if (c.ArgCount > 1)
                    {
                        for (int i = 1; i < c.ArgCount && !done; ++i)
                        {
                            string arg = c.GetArg(i);
                            // check if one of the first 3 characters is japanese
                            for (int j = 0; j < Math.Min(3, arg.Length); ++j)
                            {
                                if (Font10Converter.IsJapanese(arg[j]))
                                {
                                    addTranslatable(new Note("Unidentified Japanese text detected, tell me about this. Full command shown.", id));
                                    GenericTranslatable t = new GenericTranslatable(c);
                                    for (int k = 0; k < c.ArgCount; ++k)
                                    {
                                        t.AddArg((GenericTArgOpts)k);
                                    }
                                    addTranslatable(t);
                                    done = true;
                                    break;
                                }
                            }
                        }
                    }
                }

                ////
                checkNameWinClose = false;
                // post loop logic
            }
            panel1.Focus();             // so the scroll bar works more intuitively
            UpdateFromMemory();
            status("Loaded \"" + txtSPTPath.Text.Substring(txtSPTPath.Text.LastIndexOf('\\') + 1) + "\"");
        }