Esempio n. 1
0
    private void WriteTabClassMember(StreamWriter sw, string createLogo)
    {
        string ttChar        = "\t\t";
        string protectedChar = " { protected set; get; }";

        for (int i = 0; i < _sheet.Heads.Count; i++)
        {
            HeadWrapper head = _sheet.Heads[i];

            if (head.IsNotes || head.Logo.Contains(createLogo) == false)
            {
                continue;
            }

            // 跳过ID
            if (head.Name == ConstDefine.StrHeadId)
            {
                continue;
            }

            // 变量名称首字母大写
            string headName = StringHelper.ToUpperFirstChar(head.Name);

            if (head.Type == "int" || head.Type == "List<int>" ||
                head.Type == "long" || head.Type == "List<long>" ||
                head.Type == "float" || head.Type == "List<float>" ||
                head.Type == "double" || head.Type == "List<double>" ||
                head.Type == "string" || head.Type == "List<string>" ||
                head.Type == "bool")
            {
                sw.WriteLine(ttChar + $"public {head.Type} " + headName + protectedChar);
            }
            else if (head.Type == "language")
            {
                sw.WriteLine(ttChar + $"public string " + headName + protectedChar);
            }
            else if (head.Type == "List<language>")
            {
                sw.WriteLine(ttChar + $"public List<string> " + headName + protectedChar);
            }
            else if (head.Type.Contains("enum") || head.Type.Contains("class"))
            {
                string extendType = StringHelper.GetExtendType(head.Type);
                sw.WriteLine(ttChar + $"public {extendType} " + headName + protectedChar);
            }
            else
            {
                throw new Exception($"Not support head type {head.Type}");
            }
        }
    }
Esempio n. 2
0
    public override void ExportFile(string path, string createLogo)
    {
        ByteBuffer fileBuffer  = new ByteBuffer(ConfigDefine.CfgStreamMaxLen);
        ByteBuffer tableBuffer = new ByteBuffer(ConfigDefine.TabStreamMaxLen);

        for (int i = 0; i < _sheet.Tables.Count; i++)
        {
            TableWrapper table = _sheet.Tables[i];

            // 写入行标记
            fileBuffer.WriteShort(ConfigDefine.TabStreamHead);

            // 清空缓存
            tableBuffer.Clear();

            // 写入数据
            for (int j = 0; j < _sheet.Heads.Count; j++)
            {
                HeadWrapper head  = _sheet.Heads[j];
                string      value = table.GetCellValue(head.CellNum);
                WriteCell(tableBuffer, head, value, createLogo);
            }

            // 检测数据大小有效性
            int tabSize = tableBuffer.ReadableBytes;
            if (tabSize == 0)
            {
                throw new Exception($"{_sheet.FileName} tableBuffer readable bytes is zero.");
            }

            // 写入到总缓存
            fileBuffer.WriteInt(tabSize);
            fileBuffer.WriteBytes(tableBuffer.ReadBytes(tabSize));
        }

        // 创建文件
        string filePath = StringHelper.MakeSaveFullPath(path, $"{_sheet.FileName}.bytes");

        using (FileStream fs = new FileStream(filePath, FileMode.Create))
        {
            byte[] data   = fileBuffer.GetBuffer();
            int    length = fileBuffer.ReadableBytes;
            fs.Write(data, 0, length);
        }
    }
Esempio n. 3
0
    public void CreateCfgBytesFile(string path)
    {
        MoByteBuffer byteBuffer  = new MoByteBuffer(ResDefine.CfgStreamMaxLen);
        MoByteBuffer tableBuffer = new MoByteBuffer(ResDefine.TabStreamMaxLen);

        for (int i = 0; i < _tables.Count; i++)
        {
            //写入行标记
            byteBuffer.WriteShort(ResDefine.TabStreamHead);
            //清空缓存
            tableBuffer.Clear();

            //写入数据
            IRow row = _tables[i].Row;
            for (int cellNum = row.FirstCellNum; cellNum < row.LastCellNum; cellNum++)
            {
                ICell       cell  = row.GetCell(cellNum);
                string      value = GetTableCellValue(cell);
                HeadWrapper head  = GetHead(cellNum);
                WriteCell(tableBuffer, head, value);
            }

            //检测数据大小有效性
            int tabSize = tableBuffer.ReadableBytes();
            if (tabSize == 0)
            {
                throw new Exception("Table size is zero.");
            }

            //写入到总缓存
            byteBuffer.WriteInt(tabSize);
            byteBuffer.WriteBytes(tableBuffer.ReadBytes(tabSize));
        }

        //创建文件
        string filePath = GetSaveFileFullPath(path, ".bytes");

        using (FileStream fs = new FileStream(filePath, FileMode.Create))
        {
            byte[] data   = byteBuffer.Buf;
            int    length = byteBuffer.ReadableBytes();
            fs.Write(data, 0, length);
        }
    }
Esempio n. 4
0
    private void WriteTabClassMember(StreamWriter sw)
    {
        string tChar         = "\t";
        string protectedChar = " { protected set; get; }";

        for (int i = 0; i < _heads.Count; i++)
        {
            HeadWrapper head = _heads[i];

            if (head.IsEmpty || head.Logo.Contains(CreateLogo) == false)
            {
                continue;
            }

            //跳过ID
            if (head.Name == StrHeadId)
            {
                continue;
            }

            //变量名称首字母大写
            string headName = ToUpperFirstChar(head.Name);

            if (head.Type == "int" || head.Type == "long" || head.Type == "float" || head.Type == "double" ||
                head.Type == "List<int>" || head.Type == "List<long>" || head.Type == "List<float>" || head.Type == "List<double>" ||
                head.Type == "bool" || head.Type == "string")
            {
                sw.WriteLine(tChar + $"public {head.Type} " + headName + protectedChar);
            }
            else if (head.Type == "enumIndex" || head.Type == "enumName" || head.Type == "wrapper")
            {
                sw.WriteLine(tChar + $"public {head.TypeEx} " + headName + protectedChar);
            }
            else if (head.Type == "List<wrapper>")
            {
                sw.WriteLine(tChar + $"public List<{head.TypeEx}> " + headName + protectedChar);
            }
            else
            {
                throw new Exception($"Not support head type {head.Type}");
            }
        }
    }
Esempio n. 5
0
    /// <summary>
    /// 获取ID的列号
    /// </summary>
    private int GetIDCellNum(string createLogo)
    {
        for (int i = 0; i < _sheet.Heads.Count; i++)
        {
            HeadWrapper head = _sheet.Heads[i];
            if (head.IsNotes)
            {
                continue;
            }
            if (head.Logo.Contains(createLogo))
            {
                if (head.Name == ConstDefine.StrHeadId)
                {
                    return(head.CellNum);
                }
            }
        }

        throw new Exception($"id列的导出标记需要增加 {createLogo} ");
    }
Esempio n. 6
0
    /// <summary>
    /// 缓存单元格数据
    /// </summary>
    public void CacheAllCellValue(SheetData sheet)
    {
        for (int i = 0; i < sheet.Heads.Count; i++)
        {
            HeadWrapper head = sheet.Heads[i];

            // 如果是备注列
            if (head.IsNotes)
            {
                _cellValues.Add(head.CellNum, string.Empty);
                continue;
            }

            // 获取单元格字符串
            ICell  cell  = Row.GetCell(head.CellNum);
            string value = sheet.GetCellValue(cell);

            // 检测数值单元格是否为空值
            if (string.IsNullOrEmpty(value))
            {
                if (head.Type == "int" || head.Type == "long" || head.Type == "float" || head.Type == "double" ||
                    head.Type == "enum" || head.Type == "bool")
                {
                    // 如果开启了自动补全功能
                    if (SettingConfig.Instance.EnableAutoCompleteCell)
                    {
                        value = SettingConfig.Instance.AutoCompleteCellContent;
                    }
                    else
                    {
                        throw new Exception($"数值单元格不能为空,请检查{head.Name}列");
                    }
                }
            }

            _cellValues.Add(head.CellNum, value);
        }
    }
Esempio n. 7
0
    private string GetLuaKeys(string createLogo)
    {
        StringBuilder sb = new StringBuilder();

        sb.Append("local keys = {");

        for (int i = 0; i < _sheet.Heads.Count; i++)
        {
            HeadWrapper head = _sheet.Heads[i];
            if (head.IsNotes)
            {
                continue;
            }
            if (head.Logo.Contains(createLogo))
            {
                string name = $"\"{head.Name}\"";
                sb.Append(name);
                sb.Append(",");
            }
        }

        sb.Append("}");
        return(sb.ToString());
    }
Esempio n. 8
0
    private void WriteTabClassMember(StreamWriter sw, string createLogo)
    {
        string tTwoChar      = "\t\t";
        string tThreeChar    = "\t\t\t";
        string protectedChar = " { protected set; get; }";

        List <string> headTypeList = new List <string>();

        headTypeList.Add("int");

        List <string> headNameList = new List <string>();

        headNameList.Add("Id");

        for (int i = 0; i < _sheet.Heads.Count; i++)
        {
            HeadWrapper head = _sheet.Heads[i];

            if (head.IsNotes || head.Logo.Contains(createLogo) == false)
            {
                continue;
            }

            // 跳过ID
            if (head.Name == ConstDefine.StrHeadId)
            {
                continue;
            }

            // 变量名称首字母大写
            string headName = StringHelper.ToUpperFirstChar(head.Name);
            headNameList.Add(headName);

            if (head.Type == "int" || head.Type == "List<int>" ||
                head.Type == "long" || head.Type == "List<long>" ||
                head.Type == "float" || head.Type == "List<float>" ||
                head.Type == "double" || head.Type == "List<double>" ||
                head.Type == "string" || head.Type == "List<string>" ||
                head.Type == "bool")
            {
                sw.WriteLine(tTwoChar + $"public {head.Type} {headName}" + protectedChar);
                headTypeList.Add(head.Type);
            }
            else if (head.Type == "language")
            {
                sw.WriteLine(tTwoChar + $"public string {headName}" + protectedChar);
                headTypeList.Add("string");
            }
            else if (head.Type == "List<language>")
            {
                sw.WriteLine(tTwoChar + $"public List<string> {headName}" + protectedChar);
                headTypeList.Add("List<string>");
            }
            else if (head.Type.Contains("enum") || head.Type.Contains("class"))
            {
                string extendType = StringHelper.GetExtendType(head.Type);
                sw.WriteLine(tTwoChar + $"public {extendType} {headName}" + protectedChar);
                headTypeList.Add(extendType);
            }
            else
            {
                throw new Exception($"Not support head type {head.Type}");
            }
        }

        // 构造函数
        sw.WriteLine();
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < headNameList.Count; i++)
        {
            sb.Append($"{headTypeList[i]} {StringHelper.ToLowerFirstChar(headNameList[i])}");
            if (i < headNameList.Count - 1)
            {
                sb.Append(", ");
            }
        }
        sw.WriteLine(tTwoChar + $"public Cfg{_sheet.FileName}Tab({sb.ToString()})");
        sw.WriteLine(tTwoChar + "{");
        for (int i = 0; i < headNameList.Count; i++)
        {
            string name = headNameList[i];
            sw.WriteLine(tThreeChar + $"{StringHelper.ToUpperFirstChar(name)} = {StringHelper.ToLowerFirstChar(name)};");
        }
        sw.WriteLine(tTwoChar + "}");
    }
Esempio n. 9
0
    private void WriteTabClassFunction(StreamWriter sw, string createLogo)
    {
        string ttChar  = "\t\t";
        string tttChar = "\t\t\t";

        sw.WriteLine(ttChar + "public override void ReadByte(ByteBuffer byteBuf)");
        sw.WriteLine(ttChar + "{");

        for (int i = 0; i < _sheet.Heads.Count; i++)
        {
            HeadWrapper head = _sheet.Heads[i];

            if (head.IsNotes || head.Logo.Contains(createLogo) == false)
            {
                continue;
            }

            // 变量名称首字母大写
            string headName = StringHelper.ToUpperFirstChar(head.Name);

            // HashCode
            if (head.Name == ConstDefine.StrHeadId && head.Type == "string")
            {
                sw.WriteLine(tttChar + $"{headName} = byteBuf.ReadUTF().GetHashCode();");
                continue;
            }

            if (head.Type == "bool")
            {
                sw.WriteLine(tttChar + $"{headName} = byteBuf.ReadBool();");
            }
            else if (head.Type == "int")
            {
                sw.WriteLine(tttChar + $"{headName} = byteBuf.ReadInt();");
            }
            else if (head.Type == "long")
            {
                sw.WriteLine(tttChar + $"{headName} = byteBuf.ReadLong();");
            }
            else if (head.Type == "float")
            {
                sw.WriteLine(tttChar + $"{headName} = byteBuf.ReadFloat();");
            }
            else if (head.Type == "double")
            {
                sw.WriteLine(tttChar + $"{headName} = byteBuf.ReadDouble();");
            }

            else if (head.Type == "List<int>")
            {
                sw.WriteLine(tttChar + $"{headName} = byteBuf.ReadListInt();");
            }
            else if (head.Type == "List<long>")
            {
                sw.WriteLine(tttChar + $"{headName} = byteBuf.ReadListLong();");
            }
            else if (head.Type == "List<float>")
            {
                sw.WriteLine(tttChar + $"{headName} = byteBuf.ReadListFloat();");
            }
            else if (head.Type == "List<double>")
            {
                sw.WriteLine(tttChar + $"{headName} = byteBuf.ReadListDouble();");
            }

            else if (head.Type == "string")
            {
                sw.WriteLine(tttChar + $"{headName} = byteBuf.ReadUTF();");
            }
            else if (head.Type == "List<string>")
            {
                sw.WriteLine(tttChar + $"{headName} = byteBuf.ReadListUTF();");
            }

            // NOTE:多语言在字节流会是哈希值
            else if (head.Type == "language")
            {
                sw.WriteLine(tttChar + $"{headName} = LANG.Convert(byteBuf.ReadInt());");
            }
            else if (head.Type == "List<language>")
            {
                sw.WriteLine(tttChar + $"{headName} = LANG.Convert(byteBuf.ReadListInt());");
            }

            else if (head.Type.Contains("enum"))
            {
                string extendType = StringHelper.GetExtendType(head.Type);
                sw.WriteLine(tttChar + $"{headName} = StringConvert.IndexToEnum<{extendType}>(byteBuf.ReadInt());");
            }
            else if (head.Type.Contains("class"))
            {
                string extendType = StringHelper.GetExtendType(head.Type);
                sw.WriteLine(tttChar + $"{headName} = {extendType}.Parse(byteBuf);");
            }
            else
            {
                throw new Exception($"Not support head type {head.Type}");
            }
        }

        sw.WriteLine(ttChar + "}");
    }
Esempio n. 10
0
    private string[] GetAllLines(string createLogo)
    {
        List <string> allLines = new List <string>();
        StringBuilder sb       = new StringBuilder();

        // 写入表头类型
        sb.Clear();
        for (int i = 0; i < _sheet.Heads.Count; i++)
        {
            HeadWrapper head = _sheet.Heads[i];
            if (head.IsNotes)
            {
                continue;
            }
            if (head.Logo.Contains(createLogo))
            {
                string content;
                if (head.Type == "int")
                {
                    content = "int";
                }
                else if (head.Type == "long")
                {
                    content = "long";
                }
                else if (head.Type == "float")
                {
                    content = "float";
                }
                else if (head.Type == "double")
                {
                    content = "double";
                }
                else if (head.Type == "string")
                {
                    content = "string";
                }
                else if (head.Type == "bool")
                {
                    content = "bool";
                }
                else if (head.Type == "language")
                {
                    content = "string";
                }
                else if (head.Type.Contains("enum"))
                {
                    content = "int";
                }
                else if (head.Type.Contains("class"))
                {
                    content = "string";
                }
                else if (head.Type.Contains("List"))
                {
                    content = "string";                     //注意:列表直接导出为字符串
                }
                else
                {
                    throw new Exception($"Not support head type {head.Type}");
                }

                sb.Append(content);
                sb.Append("\t");
            }
        }
        sb.Remove(sb.Length - 1, 1);         //移除最后一个的换行符
        allLines.Add(sb.ToString());

        // 写入表头名称
        sb.Clear();
        for (int i = 0; i < _sheet.Heads.Count; i++)
        {
            HeadWrapper head = _sheet.Heads[i];
            if (head.IsNotes)
            {
                continue;
            }
            if (head.Logo.Contains(createLogo))
            {
                sb.Append(head.Name);
                sb.Append("\t");
            }
        }
        sb.Remove(sb.Length - 1, 1);         //移除最后一个的换行符
        allLines.Add(sb.ToString());

        // 写入数据
        for (int i = 0; i < _sheet.Tables.Count; i++)
        {
            sb.Clear();
            TableWrapper table = _sheet.Tables[i];
            for (int j = 0; j < _sheet.Heads.Count; j++)
            {
                HeadWrapper head = _sheet.Heads[j];
                if (head.IsNotes)
                {
                    continue;
                }
                if (head.Logo.Contains(createLogo))
                {
                    string cellValue = table.GetCellValue(head.CellNum);
                    sb.Append(cellValue);
                    sb.Append("\t");
                }
            }
            sb.Remove(sb.Length - 1, 1);             //移除最后一个的换行符
            allLines.Add(sb.ToString());
        }

        return(allLines.ToArray());
    }
Esempio n. 11
0
    /// <summary>
    /// 加载页签
    /// </summary>
    public void Load(IWorkbook workbook, ISheet sheet)
    {
        _workbook = workbook;
        _sheet    = sheet;

        // 公式计算器
        _evaluator = new XSSFFormulaEvaluator(_workbook);

        int firstRowNum = sheet.FirstRowNum;

        // 数据头一共三行
        IRow row1 = sheet.GetRow(firstRowNum);         //类型
        IRow row2 = sheet.GetRow(++firstRowNum);       //名称
        IRow row3 = sheet.GetRow(++firstRowNum);       //CBS

        // 检测策划备注行
        while (true)
        {
            int checkRow = firstRowNum + 1;
            if (checkRow > sheet.LastRowNum)
            {
                break;
            }
            IRow row = sheet.GetRow(checkRow);
            if (IsNotesRow(row))
            {
                ++firstRowNum;
            }
            else
            {
                break;
            }
        }

        // 组织头部数据
        for (int cellNum = row1.FirstCellNum; cellNum < row1.LastCellNum; cellNum++)
        {
            ICell row1cell = row1.GetCell(cellNum);
            ICell row2cell = row2.GetCell(cellNum);
            ICell row3cell = row3.GetCell(cellNum);

            // 检测重复的列
            string headName   = GetCellValue(row1cell);
            bool   isNotesRow = headName.Contains(ConstDefine.StrNotesRow);
            if (isNotesRow == false)
            {
                if (IsContainsHead(headName))
                {
                    throw new Exception($"检测到重复列 : {headName}");
                }
            }

            // 创建Wrapper
            string      type    = GetCellValue(row1cell);
            string      name    = GetCellValue(row2cell);
            string      logo    = GetCellValue(row3cell);
            HeadWrapper wrapper = new HeadWrapper(cellNum, name, type, logo);
            Heads.Add(wrapper);
        }

        // 如果没有ID列
        if (IsContainsHead(ConstDefine.StrHeadId) == false)
        {
            throw new Exception("表格必须设立一个 'id' 列.");
        }

        // 所有数据行
        int tableBeginRowNum = ++firstRowNum;         //Table初始行

        for (int rowNum = tableBeginRowNum; rowNum <= sheet.LastRowNum; rowNum++)
        {
            IRow row = sheet.GetRow(rowNum);

            // 如果是结尾行
            if (IsEndRow(row))
            {
                break;
            }

            TableWrapper wrapper = new TableWrapper(rowNum, row);
            wrapper.CacheAllCellValue(this);
            Tables.Add(wrapper);
        }

        // 创建所有注册的导出器
        for (int i = 0; i < ExportHandler.ExportTypes.Count; i++)
        {
            Type         type     = ExportHandler.ExportTypes[i];
            BaseExporter exporter = (BaseExporter)Activator.CreateInstance(type, this);
            _exporters.Add(exporter);
        }
    }
Esempio n. 12
0
    private void WriteCell(ByteBuffer buffer, HeadWrapper head, string value, string createLogo)
    {
        if (head.IsNotes || head.Logo.Contains(createLogo) == false)
        {
            return;
        }

        if (head.Type == "int")
        {
            buffer.WriteInt(StringConvert.StringToValue <int>(value));
        }
        else if (head.Type == "long")
        {
            buffer.WriteLong(StringConvert.StringToValue <long>(value));
        }
        else if (head.Type == "float")
        {
            buffer.WriteFloat(StringConvert.StringToValue <float>(value));
        }
        else if (head.Type == "double")
        {
            buffer.WriteDouble(StringConvert.StringToValue <double>(value));
        }

        else if (head.Type == "List<int>")
        {
            buffer.WriteListInt(StringConvert.StringToValueList <int>(value, ConstDefine.StrSplitChar));
        }
        else if (head.Type == "List<long>")
        {
            buffer.WriteListLong(StringConvert.StringToValueList <long>(value, ConstDefine.StrSplitChar));
        }
        else if (head.Type == "List<float>")
        {
            buffer.WriteListFloat(StringConvert.StringToValueList <float>(value, ConstDefine.StrSplitChar));
        }
        else if (head.Type == "List<double>")
        {
            buffer.WriteListDouble(StringConvert.StringToValueList <double>(value, ConstDefine.StrSplitChar));
        }

        // bool
        else if (head.Type == "bool")
        {
            buffer.WriteBool(StringConvert.StringToBool(value));
        }

        // string
        else if (head.Type == "string")
        {
            buffer.WriteUTF(value);
        }
        else if (head.Type == "List<string>")
        {
            buffer.WriteListUTF(StringConvert.StringToStringList(value, ConstDefine.StrSplitChar));
        }

        // NOTE:多语言在字节流会是哈希值
        else if (head.Type == "language")
        {
            buffer.WriteInt(value.GetHashCode());
        }
        else if (head.Type == "List<language>")
        {
            List <string> langList = StringConvert.StringToStringList(value, ConstDefine.StrSplitChar);
            List <int>    hashList = new List <int>();
            for (int i = 0; i < langList.Count; i++)
            {
                hashList.Add(langList[i].GetHashCode());
            }
            buffer.WriteListInt(hashList);
        }

        // wrapper
        else if (head.Type.Contains("class"))
        {
            buffer.WriteUTF(value);
        }

        // enum
        else if (head.Type.Contains("enum"))
        {
            buffer.WriteInt(StringConvert.StringToValue <int>(value));
        }

        else
        {
            throw new Exception($"Not support head type {head.Type}");
        }
    }
Esempio n. 13
0
    private string[] GetDataLines(string createLogo)
    {
        List <string> allLines = new List <string>();
        StringBuilder sb       = new StringBuilder();
        string        tChar    = "\t";

        bool isStringID = IsStringID(createLogo);

        for (int i = 0; i < _sheet.Tables.Count; i++)
        {
            TableWrapper table = _sheet.Tables[i];

            sb.Clear();
            sb.Append(tChar);

            int    idCellNum = GetIDCellNum(createLogo);
            string id        = table.GetCellValue(idCellNum);
            if (isStringID)
            {
                sb.Append($"{id} = ");
            }
            else
            {
                sb.Append($"[{id}] = ");
            }

            sb.Append("{");

            for (int j = 0; j < _sheet.Heads.Count; j++)
            {
                HeadWrapper head = _sheet.Heads[j];
                if (head.IsNotes)
                {
                    continue;
                }
                if (head.Logo.Contains(createLogo))
                {
                    string cellValue = table.GetCellValue(head.CellNum);

                    if (head.Type == "bool")
                    {
                        cellValue = StringConvert.StringToBool(cellValue).ToString().ToLower();
                    }

                    if (head.Type == "string")
                    {
                        cellValue = $"\"{cellValue}\"";
                    }

                    if (head.Type == "language")
                    {
                        int hashCode = cellValue.GetHashCode();
                        cellValue = $"L({hashCode})";
                    }

                    if (head.Type.Contains("class"))
                    {
                        cellValue = $"\"{cellValue}\"";
                    }

                    if (head.Type.Contains("List"))
                    {
                        List <string> splitValues = StringConvert.StringToStringList(cellValue, ConstDefine.StrSplitChar);
                        if (splitValues.Count == 0)
                        {
                            cellValue = "nil";
                        }
                        else
                        {
                            // 多语言LIST
                            bool isLanguageList = head.Type.Contains("language");
                            if (isLanguageList)
                            {
                                cellValue = "{";
                                for (int k = 0; k < splitValues.Count; k++)
                                {
                                    int hashCode = splitValues[k].GetHashCode();
                                    cellValue += $"L({hashCode})";
                                    cellValue += ",";
                                }
                                cellValue += "}";
                            }

                            // 字符串LIST
                            bool isStringList = head.Type.Contains("string");
                            if (isStringList)
                            {
                                cellValue = "{";
                                for (int k = 0; k < splitValues.Count; k++)
                                {
                                    cellValue += "\"";
                                    cellValue += splitValues[k];
                                    cellValue += "\"";
                                    cellValue += ",";
                                }
                                cellValue += "}";
                            }

                            // 其它List
                            if (isLanguageList == false && isStringList == false)
                            {
                                cellValue = "{";
                                for (int k = 0; k < splitValues.Count; k++)
                                {
                                    cellValue += splitValues[k];
                                    cellValue += ",";
                                }
                                cellValue += "}";
                            }
                        }
                    }

                    sb.Append(cellValue);
                    sb.Append(",");
                }
            }

            sb.Append("},");
            allLines.Add(sb.ToString());
        }

        return(allLines.ToArray());
    }
Esempio n. 14
0
    private void WriteTabClassFunction(StreamWriter sw)
    {
        string tChar    = "\t";
        string tTwoChar = "\t\t";

        sw.WriteLine(tChar + "public override void ReadByte(MoByteBuffer byteBuf)");
        sw.WriteLine(tChar + "{");

        for (int i = 0; i < _heads.Count; i++)
        {
            HeadWrapper head = _heads[i];

            if (head.IsEmpty || head.Logo.Contains(CreateLogo) == false)
            {
                continue;
            }

            //HashCode
            if (head.Name == StrHeadId && head.Type == "string")
            {
                sw.WriteLine(tTwoChar + $"{ToUpperFirstChar(head.Name)} = byteBuf.ReadUTF().GetHashCode();");
                continue;
            }

            //变量名称首字母大写
            string headName = ToUpperFirstChar(head.Name);

            if (head.Type == "int")
            {
                sw.WriteLine(tTwoChar + $"{headName} = byteBuf.ReadInt();");
            }
            else if (head.Type == "long")
            {
                sw.WriteLine(tTwoChar + $"{headName} = byteBuf.ReadLong();");
            }
            else if (head.Type == "float")
            {
                sw.WriteLine(tTwoChar + $"{headName} = byteBuf.ReadFloat();");
            }
            else if (head.Type == "double")
            {
                sw.WriteLine(tTwoChar + $"{headName} = byteBuf.ReadDouble();");
            }
            else if (head.Type == "List<int>")
            {
                sw.WriteLine(tTwoChar + $"{headName} = byteBuf.ReadListInt();");
            }
            else if (head.Type == "List<long>")
            {
                sw.WriteLine(tTwoChar + $"{headName} = byteBuf.ReadListLong();");
            }
            else if (head.Type == "List<float>")
            {
                sw.WriteLine(tTwoChar + $"{headName} = byteBuf.ReadListFloat();");
            }
            else if (head.Type == "List<double>")
            {
                sw.WriteLine(tTwoChar + $"{headName} = byteBuf.ReadListDouble();");
            }
            else if (head.Type == "bool")
            {
                sw.WriteLine(tTwoChar + $"{headName} = byteBuf.ReadBool();");
            }
            else if (head.Type == "string")
            {
                sw.WriteLine(tTwoChar + $"{headName} = byteBuf.ReadUTF();");
            }
            else if (head.Type == "enumIndex")
            {
                sw.WriteLine(tTwoChar + $"{headName} = MoStringConvert.IndexToEnum<{head.TypeEx}>(byteBuf.ReadInt());");
            }
            else if (head.Type == "enumName")
            {
                sw.WriteLine(tTwoChar + $"{headName} = MoStringConvert.NameToEnum<{head.TypeEx}>(byteBuf.ReadUTF());");
            }
            else if (head.Type == "wrapper")
            {
                sw.WriteLine(tTwoChar + $"{headName} = {head.TypeEx}.Parse(byteBuf);");
            }
            else if (head.Type == "List<wrapper>")
            {
                sw.WriteLine(tTwoChar + $"{headName} = {head.TypeEx}.ParseList(byteBuf);");
            }
            else
            {
                throw new Exception($"Not support head type {head.Type}");
            }
        }

        sw.WriteLine(tChar + "}");
    }
Esempio n. 15
0
    private string[] GetTextLines()
    {
        List <string> allLines = new List <string>();

        StringBuilder sb = new StringBuilder();

        //写入表头
        sb.Clear();
        for (int i = 0; i < _heads.Count; i++)
        {
            HeadWrapper head = _heads[i];
            if (head.IsEmpty)
            {
                continue;
            }
            if (head.Logo.Contains(CreateLogo))
            {
                sb.Append(head.Name);
                sb.Append("\t");
            }
        }
        allLines.Add(sb.ToString());

        //写入表头
        sb.Clear();
        for (int i = 0; i < _heads.Count; i++)
        {
            HeadWrapper head = _heads[i];
            if (head.IsEmpty)
            {
                continue;
            }
            if (head.Logo.Contains(CreateLogo))
            {
                sb.Append(head.Type);
                sb.Append("\t");
            }
        }
        allLines.Add(sb.ToString());

        //写入数据
        for (int i = 0; i < _tables.Count; i++)
        {
            sb.Clear();
            TableWrapper table = _tables[i];
            for (int j = 0; j < _heads.Count; j++)
            {
                HeadWrapper head = _heads[j];
                if (head.IsEmpty)
                {
                    continue;
                }
                if (head.Logo.Contains(CreateLogo))
                {
                    ICell cell = table.Row.GetCell(head.CellNum);
                    sb.Append(GetTableCellValue(cell));
                    sb.Append("\t");
                }
            }
            allLines.Add(sb.ToString());
        }

        return(allLines.ToArray());
    }
Esempio n. 16
0
    private void WriteCell(MoByteBuffer buffer, HeadWrapper head, string value)
    {
        if (head.IsEmpty || head.Logo.Contains(CreateLogo) == false)
        {
            return;
        }

        //int
        if (head.Type == "int")
        {
            buffer.WriteInt(MoStringConvert.StringToValue <int>(value));
        }
        else if (head.Type == "List<int>")
        {
            buffer.WriteListInt(MoStringConvert.StringToValueList <int>(value, '_'));
        }

        //long
        else if (head.Type == "long")
        {
            buffer.WriteLong(MoStringConvert.StringToValue <long>(value));
        }
        else if (head.Type == "List<long>")
        {
            buffer.WriteListLong(MoStringConvert.StringToValueList <long>(value, '_'));
        }

        //float
        else if (head.Type == "float")
        {
            buffer.WriteFloat(MoStringConvert.StringToValue <float>(value));
        }
        else if (head.Type == "List<float>")
        {
            buffer.WriteListFloat(MoStringConvert.StringToValueList <float>(value, '_'));
        }

        //double
        else if (head.Type == "double")
        {
            buffer.WriteDouble(MoStringConvert.StringToValue <double>(value));
        }
        else if (head.Type == "List<double>")
        {
            buffer.WriteListDouble(MoStringConvert.StringToValueList <double>(value, '_'));
        }

        //bool
        else if (head.Type == "bool")
        {
            buffer.WriteBool(MoStringConvert.StringToBool(value));
        }

        //string
        else if (head.Type == "string")
        {
            buffer.WriteUTF(value);
        }

        //enum
        else if (head.Type == "enumIndex")
        {
            buffer.WriteInt(MoStringConvert.StringToValue <int>(value));
        }
        else if (head.Type == "enumName")
        {
            buffer.WriteUTF(value);
        }

        //wrapper
        else if (head.Type == "wrapper")
        {
            buffer.WriteUTF(value);
        }
        else if (head.Type == "List<wrapper>")
        {
            buffer.WriteUTF(value);
        }

        else
        {
            throw new Exception($"Not support head type {head.Type}");
        }
    }
Esempio n. 17
0
    private string[] GetDataLines(string createLogo)
    {
        List <string> allLines = new List <string>();
        StringBuilder sb       = new StringBuilder();
        StringBuilder content  = new StringBuilder();

        bool isStringID = IsStringID(createLogo);

        for (int i = 0; i < _sheet.Tables.Count; i++)
        {
            TableWrapper table = _sheet.Tables[i];

            int    idCellNum = GetIDCellNum(createLogo);
            string id        = table.GetCellValue(idCellNum);
            if (isStringID)
            {
                id = id.GetHashCode().ToString();
            }

            sb.Clear();
            content.Clear();

            for (int j = 0; j < _sheet.Heads.Count; j++)
            {
                HeadWrapper head = _sheet.Heads[j];
                if (head.IsNotes || head.Logo.Contains(createLogo) == false)
                {
                    continue;
                }

                string cellValue = table.GetCellValue(head.CellNum);

                if (head.Type == "float")
                {
                    cellValue = $"{cellValue}f";
                }

                if (head.Type == "bool")
                {
                    cellValue = StringConvert.StringToBool(cellValue).ToString().ToLower();
                }

                if (head.Type == "string")
                {
                    cellValue = $"\"{cellValue}\"";
                }

                if (head.Type == "language")
                {
                    int hashCode = cellValue.GetHashCode();
                    cellValue = $"LANG.Convert({hashCode})";
                }

                if (head.Type.Contains("enum"))
                {
                    string extendType = StringHelper.GetExtendType(head.Type);
                    cellValue = $"({extendType}){cellValue}";                     //TODO 因为是热更层,这里对枚举进行强转
                }

                if (head.Type.Contains("class"))
                {
                    string extendType = StringHelper.GetExtendType(head.Type);
                    cellValue = $"{extendType}.Parse(\"{cellValue}\")";
                }

                if (head.Type.Contains("List"))
                {
                    List <string> splitValues = StringConvert.StringToStringList(cellValue, ConstDefine.StrSplitChar);
                    if (splitValues.Count == 0)
                    {
                        if (head.Type.Contains("language"))
                        {
                            cellValue = $"new List<string>()";
                        }
                        else
                        {
                            cellValue = $"new {head.Type}()";
                        }
                    }
                    else
                    {
                        // 多语言LIST
                        bool isLanguageList = head.Type.Contains("language");
                        if (isLanguageList)
                        {
                            cellValue  = "new List<string>()";
                            cellValue += "{";
                            for (int k = 0; k < splitValues.Count; k++)
                            {
                                int hashCode = splitValues[k].GetHashCode();
                                cellValue += $"LANG.Convert({hashCode})";
                                if (k < splitValues.Count - 1)
                                {
                                    cellValue += ",";
                                }
                            }
                            cellValue += "}";
                        }

                        // 字符串LIST
                        bool isStringList = head.Type.Contains("string");
                        if (isStringList)
                        {
                            cellValue  = $"new {head.Type}()";
                            cellValue += "{";
                            for (int k = 0; k < splitValues.Count; k++)
                            {
                                cellValue += "\"";
                                cellValue += splitValues[k];
                                cellValue += "\"";
                                if (k < splitValues.Count - 1)
                                {
                                    cellValue += ",";
                                }
                            }
                            cellValue += "}";
                        }

                        // 浮点数LIST
                        bool isFloatList = head.Type.Contains("float");
                        if (isFloatList)
                        {
                            cellValue  = $"new {head.Type}()";
                            cellValue += "{";
                            for (int k = 0; k < splitValues.Count; k++)
                            {
                                cellValue += splitValues[k];
                                cellValue += "f";
                                if (k < splitValues.Count - 1)
                                {
                                    cellValue += ",";
                                }
                            }
                            cellValue += "}";
                        }

                        // 其它List
                        if (isLanguageList == false && isStringList == false && isFloatList == false)
                        {
                            cellValue  = $"new {head.Type}()";
                            cellValue += "{";
                            for (int k = 0; k < splitValues.Count; k++)
                            {
                                cellValue += splitValues[k];
                                if (k < splitValues.Count - 1)
                                {
                                    cellValue += ",";
                                }
                            }
                            cellValue += "}";
                        }
                    }
                }

                content.Append(cellValue);
                if (j < _sheet.Heads.Count - 1)
                {
                    content.Append(", ");
                }
            }

            sb.Append($"AddElement({id}, new Cfg{_sheet.FileName}Tab({content.ToString()}));");
            allLines.Add(sb.ToString());
        }

        return(allLines.ToArray());
    }
Esempio n. 18
0
    /// <summary>
    /// 解析
    /// </summary>
    /// <param name="sheet"></param>
    public void Parase(ISheet sheet)
    {
        int firstRowNum = sheet.FirstRowNum;

        //数据头一共6行
        IRow row1 = sheet.GetRow(firstRowNum);
        IRow row2 = sheet.GetRow(++firstRowNum);
        IRow row3 = sheet.GetRow(++firstRowNum);
        IRow row4 = sheet.GetRow(++firstRowNum);

        ++firstRowNum;         //无用行
        ++firstRowNum;         //无用行

        for (int cellNum = row1.FirstCellNum; cellNum < row1.LastCellNum; cellNum++)
        {
            ICell row1cell = row1.GetCell(cellNum);
            ICell row2cell = row2.GetCell(cellNum);
            ICell row3cell = row3.GetCell(cellNum);
            ICell row4cell = row4.GetCell(cellNum);

            //检测重复的列
            string headName = row1cell.StringCellValue;
            if (string.IsNullOrEmpty(headName) == false)
            {
                if (IsContainsHead(headName))
                {
                    throw new Exception($"Have same head name : {headName}");
                }
            }

            //创建Wrapper
            string      name    = row1cell.StringCellValue;
            string      type    = row2cell.StringCellValue;
            string      typeEx  = row3cell.StringCellValue;
            string      logo    = row4cell.StringCellValue;
            HeadWrapper wrapper = new HeadWrapper(cellNum, name, type, typeEx, logo);
            _heads.Add(wrapper);
        }

        //如果没有ID列
        if (IsContainsHead(StrHeadId) == false)
        {
            throw new Exception("Not found 'id' cell.");
        }

        int tableBeginRowNum = ++firstRowNum;         //Table初始行

        for (int rowNum = tableBeginRowNum; rowNum <= sheet.LastRowNum; rowNum++)
        {
            IRow row = sheet.GetRow(rowNum);

            //检测结尾行
            if (IsEndRow(row))
            {
                break;
            }

            //创建Wrapper
            TableWrapper wrapper = new TableWrapper(rowNum, row);
            _tables.Add(wrapper);
        }
    }