From e9f7caa9293e65a8c31eb198e50f553b2cbda187 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 28 Jun 2024 16:33:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constants.ts | 43 ++++++++++++++------------ src/editorTable/CSV/CSVimporter.ts | 10 +++--- src/editorTable/EXCEL/excelExporter.ts | 4 +-- src/editorTable/editorTableUtility.ts | 6 ++-- 4 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 90f547b..a492fba 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -76,26 +76,29 @@ export namespace Table { export type NameCN = keyof typeof name.fromCN; } -/** - * 不同类型的CSV文件导入为Json后会放入不同的文件夹 - */ -export const csvTypeToPath = { - "unit": "editorunit", - "sound": "soundall", - "ability": "abilityall", - "model": "editormodel", - "decoration": "editordecoration", - "destructible": "editordestructible", - "effect": "editoreffect", - "icon": "editoricon", - "item": "editoritem", - "physics_object": "editorphysicsobject", - "physics_object_logic": "editorphysicsobjectlogic", - "modifier": "modifierall", - "projectile": "projectileall", - "store": "storeall", - "technology": "technologyall" -} as const; +export namespace CSV { + export const type = { + toPath: { + "unit": "editorunit", + "sound": "soundall", + "ability": "abilityall", + "model": "editormodel", + "decoration": "editordecoration", + "destructible": "editordestructible", + "effect": "editoreffect", + "icon": "editoricon", + "item": "editoritem", + "physics_object": "editorphysicsobject", + "physics_object_logic": "editorphysicsobjectlogic", + "modifier": "modifierall", + "projectile": "projectileall", + "store": "storeall", + "technology": "technologyall" + } as const, + } as const; + + export type Type = keyof typeof type.toPath; +} // 默认情况下各类型物编数据CSV文件的相对路径 (相对于工程项目的script文件) export const defaultTableTypeToCSVfolderPath = { diff --git a/src/editorTable/CSV/CSVimporter.ts b/src/editorTable/CSV/CSVimporter.ts index d51a8f9..875c585 100644 --- a/src/editorTable/CSV/CSVimporter.ts +++ b/src/editorTable/CSV/CSVimporter.ts @@ -6,15 +6,13 @@ import * as vscode from 'vscode'; import * as fs from 'fs'; import { env } from "../../env"; import { isPathValid } from '../../utility'; -import { csvTypeToPath } from "../../constants"; +import { CSV } from "../../constants"; import { saveRowOfCSV } from '../editorTableItemJson'; export class CSVimporter { - private readonly csvTypeToPath: Readonly<{ [key: string]: string }>; public constructor() { - this.csvTypeToPath = csvTypeToPath; } /** @@ -33,7 +31,7 @@ export class CSVimporter vscode.window.showErrorMessage("未找到CSV表格的路径,请从模板中生成"); return false; } - if (!await this.importAllCSVinFolder(csvFolderUri, key)) { + if (!await this.importAllCSVinFolder(csvFolderUri, key as CSV.Type)) { return false; } } @@ -47,12 +45,12 @@ export class CSVimporter * @param tableType * @returns */ - private async importAllCSVinFolder(folder: vscode.Uri, tableType:string): Promise { + private async importAllCSVinFolder(folder: vscode.Uri, tableType: CSV.Type): Promise { if (!env.editorTableUri) { vscode.window.showErrorMessage("物编数据表路径为空"); return false; } - let targetTableFolder = this.csvTypeToPath[tableType]; + let targetTableFolder = CSV.type.toPath[tableType]; let targetEditorTablePath: vscode.Uri = vscode.Uri.joinPath(env.editorTableUri, targetTableFolder); let files = await vscode.workspace.fs.readDirectory(folder); for (const file of files) { diff --git a/src/editorTable/EXCEL/excelExporter.ts b/src/editorTable/EXCEL/excelExporter.ts index d5d4c55..5e30034 100644 --- a/src/editorTable/EXCEL/excelExporter.ts +++ b/src/editorTable/EXCEL/excelExporter.ts @@ -2,7 +2,7 @@ import * as fs from 'fs-extra'; import * as vscode from 'vscode'; import * as path from 'path'; -import { csvTypeToPath, Table } from '../../constants'; +import { CSV, Table } from '../../constants'; import { excel2Json } from './excel2Json'; import { ImportRule } from './importRule'; import { env } from '../../env'; @@ -57,7 +57,7 @@ export class excelExporter { async runRule(rule: ImportRule) { let excelPath = rule.excelRelativePath ? vscode.Uri.joinPath(this.excelPath, rule.excelRelativePath) : undefined; let editorTableType = Table.name.fromCN[rule.editorTableType]; - let targetPath: vscode.Uri = vscode.Uri.joinPath(this.editorTablePath, csvTypeToPath[editorTableType]); + let targetPath: vscode.Uri = vscode.Uri.joinPath(this.editorTablePath, CSV.type.toPath[editorTableType]); //let converter = new excel2Json(rule, excelPath, targetPath); //await converter.convert();//TODO: 把excel数据通过converter转换为目标数据 } diff --git a/src/editorTable/editorTableUtility.ts b/src/editorTable/editorTableUtility.ts index ba061e8..ed55801 100644 --- a/src/editorTable/editorTableUtility.ts +++ b/src/editorTable/editorTableUtility.ts @@ -8,7 +8,7 @@ import * as path from 'path'; import * as fs from 'fs'; import * as vscode from 'vscode'; import { env } from "../env"; -import { Table, csvTypeToPath } from '../constants'; +import { Table, CSV } from '../constants'; import { EditorTableItemInfo } from './types'; import { isFileValid, randomInt, isJson, isCSV, isPathValid, @@ -347,12 +347,12 @@ function getAllEditorTableItemInfoInFolder(editorTableType: Table.NameEN, pathSt return res; } -export function addNewEditorTableItemInProject(editorTableType: Table.NameEN,name:string):boolean { +export function addNewEditorTableItemInProject(editorTableType: Table.NameEN, name:string):boolean { if (!env.editorTableUri) { return false; } let uid: number = allocateNewUIDofEditorTableItem(env.editorTableUri); - let targetPath: vscode.Uri = vscode.Uri.joinPath(env.editorTableUri, csvTypeToPath[editorTableType], String(uid) + '.json'); + let targetPath: vscode.Uri = vscode.Uri.joinPath(env.editorTableUri, CSV.type.toPath[editorTableType], String(uid) + '.json'); try { let templateJsonStr:string = fs.readFileSync(path.join(__dirname, "../../template/json_template/" + editorTableType + ".json"), 'utf8');