Ejemplo n.º 1
0
 /// <summary>
 /// 语法解析,获得每个文本
 /// </summary>
 private static void GetInfos()
 {
     s_TranslationInfos = new List <TranslationInfo>();
     foreach (string line in s_TableTranslation)
     {
         string[] contents = line.Split(',');
         // 逐句检测,一旦发现未定义bank号的句子,就停止解析
         if (contents.Length != 6)
         {
             return;
         }
         TranslationInfo info = new TranslationInfo();
         info.group      = int.Parse(contents[0]);
         info.addrLo     = int.Parse(contents[1], System.Globalization.NumberStyles.AllowHexSpecifier);
         info.addrHi     = int.Parse(contents[2], System.Globalization.NumberStyles.AllowHexSpecifier);
         info.addr       = int.Parse(contents[3], System.Globalization.NumberStyles.AllowHexSpecifier);
         info.textBlocks = new List <TextBlockInfo>();
         // 以[NEXT]为分割符进行分割
         List <string> subContents = SplitContent(contents[5]);
         foreach (string str in subContents)
         {
             TextBlockInfo ti = new TextBlockInfo();
             ti.bankNo            = findBankNo(str);
             ti.isFullDigitalMode = contents[4].Equals("D");
             ti.str  = str;
             ti.data = new List <Byte>();
             info.textBlocks.Add(ti);
         }
         s_TranslationInfos.Add(info);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 文本处理
        /// </summary>
        private static void ProcessInfos()
        {
            s_DicUniqueChars = new Dictionary <int, string>();
            s_DicUniqueASCII = new Dictionary <int, string>();
            int nextAddr = 0;

            for (int i = 0; i < s_TranslationInfos.Count; ++i)
            {
                TranslationInfo info = s_TranslationInfos[i];
                if (nextAddr == 0)
                {
                    nextAddr = info.addr;
                }
                info.addr = nextAddr;

                for (int j = 0; j < info.textBlocks.Count; ++j)
                {
                    TextBlockInfo ti = info.textBlocks[j];

                    // 如果bankNo为0,说明使用了默认bank。一般来说这是有问题的!不过也不排除某种极端情况。安全起见给出个警告吧!
                    if (ti.bankNo > 0)
                    {
                        if (!s_DicUniqueChars.ContainsKey(ti.bankNo))
                        {
                            s_DicUniqueChars.Add(ti.bankNo, string.Empty);
                        }
                        if (!s_DicUniqueASCII.ContainsKey(ti.bankNo))
                        {
                            s_DicUniqueASCII.Add(ti.bankNo, string.Empty);
                        }
                        // 首先处理fullDigitalMode
                        if (ti.isFullDigitalMode)
                        {
                            s_DicUniqueASCII[ti.bankNo] = "0123456789";
                        }
                        s_DicUniqueChars[ti.bankNo] = GetUniqueChars(s_DicUniqueChars[ti.bankNo] + ti.str);
                        s_DicUniqueASCII[ti.bankNo] = GetUniqueASCII(s_DicUniqueASCII[ti.bankNo] + ti.str);
                        if (s_DicUniqueChars[ti.bankNo].Length > MAX_UNIQUE_CHAR_COUNT)
                        {
                            Console.WriteLine("FATAL ERROR! Too many characters in bank " + ti.bankNo);
                            Console.WriteLine(s_DicUniqueChars[ti.bankNo]);
                        }
                    }
                    else
                    {
                        Console.WriteLine("WARNING! bankNo == 0!");
                    }

                    char[] chars = ti.str.ToArray();
                    int    start = -1;
                    for (int k = 0; k < chars.Length; ++k)
                    {
                        char c = chars[k];
                        switch (c)
                        {
                        case '[':
                        {
                            start = k;
                            break;
                        }

                        case ']':
                        {
                            string control = ti.str.Substring(start, k - start + 1);
                            start = -1;
                            Byte v = 0xFF;
                            if (s_Ctrl2Code.ContainsKey(control))
                            {
                                v = s_Ctrl2Code[control];
                            }
                            ti.data.Add(v);
                            break;
                        }

                        case '<':
                        {
                            start = k;
                            break;
                        }

                        case '>':
                        {
                            string value = ti.str.Substring(start + 1, k - start - 1);
                            start = -1;
                            Byte v = (Byte)int.Parse(value, System.Globalization.NumberStyles.AllowHexSpecifier);
                            ti.data.Add(v);
                            break;
                        }

                        case '{':
                        {
                            start = k;
                            break;
                        }

                        case '}':
                        {
                            string value = ti.str.Substring(start + 1, k - start - 1);
                            start = -1;
                            Byte bankNo = (Byte)int.Parse(value, System.Globalization.NumberStyles.AllowHexSpecifier);
                            ti.data.Add((Byte)(bankNo + 0x20));
                            break;
                        }

                        default:
                        {
                            if (start < 0)
                            {
                                if (c <= 0x7F)
                                {
                                    if (c == ' ')
                                    {
                                        ti.data.Add(0xFE);
                                    }
                                    else
                                    {
                                        int offset = s_DicUniqueASCII[ti.bankNo].IndexOf(c);
                                        ti.data.Add((Byte)(offset + 0x80));
                                    }
                                }
                                else
                                {
                                    int offset = s_DicUniqueChars[ti.bankNo].IndexOf(c);
                                    ti.data.Add((Byte)(offset + 0x60));
                                }
                            }
                            break;
                        }
                        }
                    }
                    nextAddr += ti.data.Count;
                }
                s_TranslationInfos[i] = info;
            }
        }