【优化】LubanAssistant 支持自由组织##field的位置

main
walon 2021-10-28 10:48:10 +08:00
parent e7c03419a5
commit c8cd68af61
2 changed files with 24 additions and 15 deletions

View File

@ -298,16 +298,6 @@ namespace Luban.Job.Cfg.DataSources.Excel
return TryParseMeta(metaStr, out orientRow, out tableName); return TryParseMeta(metaStr, out orientRow, out tableName);
} }
private static bool IsSubFieldRow(List<Cell> row)
{
if (row.Count == 0)
{
return false;
}
var s = row[0].Value?.ToString()?.Trim();
return s == "##field";
}
private static bool IsTypeRow(List<Cell> row) private static bool IsTypeRow(List<Cell> row)
{ {
if (row.Count == 0) if (row.Count == 0)

View File

@ -90,11 +90,30 @@ namespace LubanAssistant
return rootTile; return rootTile;
} }
private static bool IsSubFieldRow(Range cell) private static bool TryParseNextSubFieldRowIndex(Range sheetCells, int startRowIndex, out int rowIndex)
{ {
var s = cell.Value?.ToString()?.Trim(); for (int i = startRowIndex; ; i++)
return s == "##field"; {
string rowTag = sheetCells[i, 1].Value?.ToString() ?? "";
if (rowTag.StartsWith("##field"))
{
rowIndex = i;
return true;
} }
else if (!rowTag.StartsWith("##"))
{
break;
}
}
rowIndex = 0;
return false;
}
//private static bool IsSubFieldRow(Range cell)
//{
// var s = cell.Value?.ToString()?.Trim();
// return s == "##field";
//}
private static bool IsTypeRow(Range cell) private static bool IsTypeRow(Range cell)
{ {
@ -140,11 +159,11 @@ namespace LubanAssistant
} }
title.AddSubTitle(newSubTitle); title.AddSubTitle(newSubTitle);
} }
if (rowIndex < sheet.UsedRange.Rows.Count && IsSubFieldRow(sheet.Cells[rowIndex + 1, 1])) if (rowIndex < sheet.UsedRange.Rows.Count && TryParseNextSubFieldRowIndex(sheet.Cells, rowIndex + 1, out int nextRowIndex))
{ {
foreach (var subTitle in title.SubTitleList) foreach (var subTitle in title.SubTitleList)
{ {
ParseSubTitle(sheet, rowIndex + 1, subTitle); ParseSubTitle(sheet, nextRowIndex, subTitle);
} }
} }
} }