支持逐个表配置数组是否为固定长度

This commit is contained in:
2021-01-21 16:40:03 +08:00
parent bb97ff3b1e
commit bb0c84ae3d
2 changed files with 9 additions and 7 deletions

View File

@@ -1,5 +1,7 @@
parser: parser:
first_row_as_field_comment: true first_row_as_field_comment: true
constant_array_length:
- EffectSequence
input: input:
- 配置表.xlsx - 配置表.xlsx
output: output:

View File

@@ -14,8 +14,8 @@ type RawTableData = RawTableCell[][];
export interface ParserConfigs { export interface ParserConfigs {
/** 第一行作为注释 */ /** 第一行作为注释 */
first_row_as_field_comment: boolean; first_row_as_field_comment: boolean;
/** 固定数组长度 */ /** 固定数组长度的表名称 */
constant_array_length: boolean; constant_array_length: string[];
} }
export enum DataType { export enum DataType {
@@ -74,7 +74,7 @@ export class TableParser {
let tables: { [key: string]: TableData } = {}; let tables: { [key: string]: TableData } = {};
for (const name in raw_tables) { for (const name in raw_tables) {
console.log(colors.grey(`\t解析配置表 ${name}`)); console.log(colors.grey(`\t解析配置表 ${name}`));
tables[name] = this.process_table(raw_tables[name]); tables[name] = this.process_table(name, raw_tables[name]);
} }
return tables; return tables;
} }
@@ -104,7 +104,7 @@ export class TableParser {
return xlsl.utils.encode_cell({c: cell.column, r: cell.row}); return xlsl.utils.encode_cell({c: cell.column, r: cell.row});
} }
protected process_table(raw: RawTableData): TableData { protected process_table(sheet_name: string, raw: RawTableData): TableData {
const type_order = [ DataType.string, DataType.float, DataType.int, DataType.bool, DataType.null]; const type_order = [ DataType.string, DataType.float, DataType.int, DataType.bool, DataType.null];
let headers: ColumnDescription[] = []; let headers: ColumnDescription[] = [];
@@ -163,11 +163,11 @@ export class TableParser {
} }
values.push(row); values.push(row);
} }
return this.parse_values(headers, values); return this.parse_values(sheet_name, headers, values);
} }
protected parse_values(raw_headers : ColumnDescription[], raw_values: RawTableData) { protected parse_values(sheet_name: string, raw_headers : ColumnDescription[], raw_values: RawTableData) {
type FiledInfo = { type FiledInfo = {
column: ColumnDescription, column: ColumnDescription,
start: number, start: number,
@@ -207,7 +207,7 @@ export class TableParser {
let arr = []; let arr = [];
for (const idx of filed.indexes) { for (const idx of filed.indexes) {
const cell = raw_row[idx]; const cell = raw_row[idx];
if (cell || this.configs.constant_array_length) { if (cell || (Array.isArray(this.configs.constant_array_length) && this.configs.constant_array_length.includes(sheet_name))) {
arr.push(this.get_cell_value(cell, filed.column.type)); arr.push(this.get_cell_value(cell, filed.column.type));
} }
} }