コード例 #1
0
    private static void ParseListLanguageToCache(Dictionary <int, LanguageWrapper> cacheLanguages, SheetData sheet, int cellNum)
    {
        foreach (var table in sheet.Tables)
        {
            // 获取格子内容
            string cellValue = table.GetCellValue(cellNum);

            List <string> splitValues = StringConvert.StringToStringList(cellValue, ConstDefine.StrSplitChar);
            for (int i = 0; i < splitValues.Count; i++)
            {
                string splitValue = splitValues[i];
                int    hashCode   = splitValue.GetHashCode();
                if (cacheLanguages.ContainsKey(hashCode) == false)
                {
                    LanguageWrapper wrapper = new LanguageWrapper();
                    wrapper.Source  = sheet.FileName;
                    wrapper.Content = splitValue;
                    cacheLanguages.Add(hashCode, wrapper);
                }
            }
        }
    }
コード例 #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());
    }
コード例 #3
0
ファイル: BytesExporter.cs プロジェクト: moto2002/FlashExcel
    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}");
        }
    }
コード例 #4
0
 /// <summary>
 /// 获取内置标记列表
 /// </summary>
 public List <string> GetBuildinTags()
 {
     return(StringConvert.StringToStringList(BuildinTags, ';'));
 }
コード例 #5
0
 /// <summary>
 /// 获取资源标记列表
 /// </summary>
 public List <string> GetAssetTags()
 {
     return(StringConvert.StringToStringList(AssetTags, ';'));
 }
コード例 #6
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());
    }
コード例 #7
0
 /// <summary>
 /// 获取内置标记列表
 /// </summary>
 public string[] GetBuildinTags()
 {
     return(StringConvert.StringToStringList(BuildinTags, ';').ToArray());
 }