Exemplo n.º 1
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);
        }
    }
Exemplo n.º 2
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());
    }
Exemplo n.º 3
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());
    }
Exemplo n.º 4
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());
    }