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()"; } 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; } if (head.Name == ConstDefine.StrHeadId) { 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({id}, {content.ToString()}));"); allLines.Add(sb.ToString()); } return(allLines.ToArray()); }
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}"); } }