예제 #1
0
        internal TableMeta ParseTableMeta(string filename, DataTable dt, string cmp)
        {
            TableMeta meta = new TableMeta();

            meta.TableName = filename;
            //第0行注释 第一行name 第二行type
            for (int i = 0; i < dt.Columns.Count; i++)
            {
                if (!IsExportField(cmp, dt, i))
                {
                    continue;
                }
                TableField field = new TableField();
                field.fieldName = dt.Rows[1].ItemArray[i].ToString();
                field.typeName  = dt.Rows[2].ItemArray[i].ToString();
                if (field.typeName == "int")
                {
                    field.fieldType = TableFieldType.IntField;
                }
                else if (field.typeName == "float")
                {
                    field.fieldType = TableFieldType.FloatField;
                }
                else if (field.typeName == "string")
                {
                    field.fieldType = TableFieldType.StringField;
                }
                else if (field.typeName == "int+")
                {
                    field.fieldType = TableFieldType.IntList;
                }
                else if (field.typeName == "float+")
                {
                    field.fieldType = TableFieldType.FloatList;
                }
                else if (field.typeName == "string+")
                {
                    field.fieldType = TableFieldType.StringList;
                }
                else if (field.typeName[field.typeName.Length - 1] == '+')
                {
                    field.fieldType = TableFieldType.StructList;
                }
                else
                {
                    field.fieldType = TableFieldType.StructField;
                }
                meta.Fields.Add(field);
            }
            return(meta);
        }
예제 #2
0
        public bool ImportTableStruct(string filepath)
        {
            m_metaList.Clear();
            string[] lines = File.ReadAllLines(filepath);
            for (int i = 0; i < lines.Count(); i++)
            {
                if (Regex.IsMatch(lines[i], @"^\s*//.*$"))
                {
                    continue;
                }                                                       //注释
                if (Regex.IsMatch(lines[i], @"^\s*$"))
                {
                    continue;
                }                                                //空行
                if (Regex.IsMatch(lines[i], @"^\s*\w+\s+{\s*$")) //结构体开始
                {
                    if (m_parseState != ParseState.EndStruct)
                    {
                        Console.WriteLine("tbs文件错误:第{0}行", i);
                        return(false);
                    }
                    m_parseState = ParseState.BeginStruct;
                    Match match = Regex.Match(lines[i], @"^\s*(\w+)\s+{\s*$");
                    m_tableMeta           = new TableMeta();
                    m_tableMeta.TableName = match.Groups[1].Value;
                    continue;
                }
                if (Regex.IsMatch(lines[i], @"^\s*}\s*$"))//结构体结束
                {
                    if (m_parseState != ParseState.BeginStruct)
                    {
                        Console.WriteLine("tbs文件错误:第{0}行", i);
                        return(false);
                    }
                    m_parseState = ParseState.EndStruct;
                    m_metaList.Add(m_tableMeta);
                    continue;
                }
                if (m_parseState == ParseState.BeginStruct)
                {
                    Match m = Regex.Match(lines[i], @"\s*(\w+)\s+(\w+)\s*$");//var type
                    if (m.Success == false)
                    {
                        Console.WriteLine("tbs文件错误:第{0}行", i);
                        return(false);
                    }

                    TableField field = new TableField();
                    field.fieldName = m.Groups[1].Value;
                    field.typeName  = m.Groups[2].Value;
                    switch (field.typeName)
                    {
                    case "int": { field.fieldType = TableFieldType.IntField; break; }

                    case "float": { field.fieldType = TableFieldType.FloatField; break; }

                    case "string": { field.fieldType = TableFieldType.StringField; break; }

                    case "int+": { field.fieldType = TableFieldType.IntList; break; }

                    case "float+": { field.fieldType = TableFieldType.FloatList; break; }

                    case "string+": { field.fieldType = TableFieldType.StringList; break; }

                    default:
                        Console.WriteLine("tbs文件错误:第{0}行", i);
                        return(false);
                    }
                    m_tableMeta.Fields.Add(field);
                    continue;
                }

                Console.WriteLine("tbs文件错误:第{0}行", i);
                return(false);
            }
            return(true);
        }