diff --git a/package.json b/package.json index 58be1e4..f80dd51 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,18 @@ { "command": "y3-helper.downloadPresetUI", "title": "Y3:下载预设资源(UI)" + }, + { + "command": "y3-helper.addNewDataInCSV", + "title": "Y3:在CSV表格中添加新物编数据" + }, + { + "command": "y3-helper.modifyUIDandNameInCSV", + "title": "Y3:修改CSV表格中的物编数据UID和名称" + }, + { + "command": "y3-helper.", + "title": "Y3:修改CSV表格中的物编数据UID和名称" } ], "configuration": { diff --git a/src/constants.ts b/src/constants.ts new file mode 100644 index 0000000..1817b05 --- /dev/null +++ b/src/constants.ts @@ -0,0 +1,63 @@ + + +export const enum EditorTableType { + Unit = "unit", + Decoration = "decoration", + Item = "item", + Ability = "ability", + Modifier = "modifier", + Projectile = "projectile", + Technology = "technology", + Destructible = "destructible", + Sound = "sound" +} + + +export const englishPathToChinese: Readonly<{ [key: string]: string } >= { + "editorunit": "单位", + "soundall": "声音", + "abilityall": "技能", + "editordecoration": "装饰物", + "editordestructible": "可破坏物", + "editoritem": "物品", + "modifierall": "魔法效果", + "projectileall": "投射物", + "technologyall": "科技" +}; +export const englishToChinese: Readonly<{ [key: string]: string } >= { + "unit": "单位", + "decoration": "装饰物", + "item": "物品", + "ability": "技能", + "modifier": "魔法效果", + "projectile": "投射物", + "technology": "科技", + "destructible": "可破坏物", + "sound": "声音" +}; +export const chineseToEnglish:Readonly< { [key: string]: string } >= { + "单位": "unit", + "装饰物": "decoration", + "物品": "item", + "技能": "ability", + "魔法效果": "modifier", + "投射物": "projectile", + "科技": "technology", + "可破坏物": "destructible", + "声音": "sound" +}; + +/** + * 物编数据类型与其在Y3项目中存放的文件夹名的对应关系 + */ +export const editorTableTypeToFolderName: Readonly<{ [key: string]: string }> = { + "unit": "editorunit", + "decoration": "editordecoration", + "item": "editoritem", + "ability": "abilityall", + "modifier": "modifierall", + "projectile": "projectileall", + "technology": "technologyall", + "destructible": "editordestructible", + "sound":"soundall" +}; \ No newline at end of file diff --git a/src/CSVeditor.ts b/src/editorTable/CSVeditor.ts similarity index 65% rename from src/CSVeditor.ts rename to src/editorTable/CSVeditor.ts index 7a94114..1b39c15 100644 --- a/src/CSVeditor.ts +++ b/src/editorTable/CSVeditor.ts @@ -1,5 +1,5 @@ -import { Env } from "./env"; - +import { Env } from "../env"; +import csvParser from 'csv-parser'; /** * 物编数据CSV表格的编辑器 */ diff --git a/src/CSVimporter.ts b/src/editorTable/CSVimporter.ts similarity index 99% rename from src/CSVimporter.ts rename to src/editorTable/CSVimporter.ts index 2bf2aa4..28a0426 100644 --- a/src/CSVimporter.ts +++ b/src/editorTable/CSVimporter.ts @@ -6,8 +6,8 @@ import * as vscode from 'vscode'; import csvParser from 'csv-parser'; import * as fs from 'fs'; -import { Env } from "./env"; -import { isInDirectory, isFileValid, isPathValid, removeSpacesAndNewlines, toUnicodeIgnoreASCII, getFileNameByVscodeUri, hash } from './utility'; +import { Env } from "../env"; +import { isInDirectory, isFileValid, isPathValid, removeSpacesAndNewlines, toUnicodeIgnoreASCII, getFileNameByVscodeUri, hash } from '../utility'; import * as path from 'path'; import { v4 as uuidv4 } from 'uuid'; diff --git a/src/editorTable.ts b/src/editorTable/editorTable.ts similarity index 95% rename from src/editorTable.ts rename to src/editorTable/editorTable.ts index 758ba95..7d6bc3c 100644 --- a/src/editorTable.ts +++ b/src/editorTable/editorTable.ts @@ -1,13 +1,13 @@ import * as vscode from 'vscode'; import * as path from 'path'; import * as fs from 'fs'; -import { Env } from './env'; -import { isPathValid, isJson, getFileNameByVscodeUri } from './utility'; +import { Env } from '../env'; +import { isPathValid, isJson, getFileNameByVscodeUri } from '../utility'; import { encode } from 'punycode'; +import { englishPathToChinese } from '../constants'; - -export class Y3HelperDataProvider implements vscode.TreeDataProvider { +export class EditorTableDataProvider implements vscode.TreeDataProvider { private _onDidChangeTreeData: vscode.EventEmitter = new vscode.EventEmitter(); readonly onDidChangeTreeData: vscode.Event = this._onDidChangeTreeData.event; public readonly englishPathToChinese: { [key: string]: string }; @@ -15,7 +15,7 @@ export class Y3HelperDataProvider implements vscode.TreeDataProvider { private zhlanguageJson: any = undefined; constructor(private env: Env) { - this.englishPathToChinese = this.env.englishPathToChinese; + this.englishPathToChinese = englishPathToChinese; if (!vscode.workspace.workspaceFolders) { vscode.window.showErrorMessage("当前未打开工作目录"); return; @@ -79,7 +79,7 @@ export class Y3HelperDataProvider implements vscode.TreeDataProvider { } else if (stat.isDirectory()) { if (label in this.englishPathToChinese) { - label = this.englishPathToChinese[label]; + label = this.englishPathToChinese[label] + '(' + label + ')'; } else { return Promise.resolve(fileNodes); @@ -211,7 +211,7 @@ export class GoEditorTableSymbolProvider implements vscode.WorkspaceSymbolProvid export class GoEditorTableDocumentSymbolProvider implements vscode.DocumentSymbolProvider { private englishKeyToChineseKey: any; constructor(private zhlanguageJson: any = undefined ) { - let englishKeyToChineseKeyJsonPath = path.join(__dirname, "../config/englishKeyToChineseKey.json"); + let englishKeyToChineseKeyJsonPath = path.join(__dirname, "../../config/englishKeyToChineseKey.json"); if (isPathValid(englishKeyToChineseKeyJsonPath)) { try { this.englishKeyToChineseKey = JSON.parse(fs.readFileSync(englishKeyToChineseKeyJsonPath, 'utf8')); @@ -220,6 +220,9 @@ export class GoEditorTableDocumentSymbolProvider implements vscode.DocumentSymbo vscode.window.showErrorMessage("读取和解析" + englishKeyToChineseKeyJsonPath + "时失败,错误为:" + error); } } + else { + vscode.window.showErrorMessage("在以下路径找不到englishKeyToChineseKey.json:\n"+englishKeyToChineseKeyJsonPath); + } } public provideDocumentSymbols( document: vscode.TextDocument, token: vscode.CancellationToken): @@ -313,4 +316,4 @@ function getChineseName(editorTableJsonName:string,editorTableJson: any, zhlangu res = name + "(" + editorTableJsonName.substring(0, editorTableJsonName.length - 5) + ")";//显示为"这是一个单位(134219828)"的格式 } return res; -} +} \ No newline at end of file diff --git a/src/templateGenerator.ts b/src/editorTable/templateGenerator.ts similarity index 68% rename from src/templateGenerator.ts rename to src/editorTable/templateGenerator.ts index d6060e3..4d1cc1a 100644 --- a/src/templateGenerator.ts +++ b/src/editorTable/templateGenerator.ts @@ -1,16 +1,17 @@ import * as vscode from 'vscode'; import * as fs from 'fs-extra'; -import { Env } from './env'; +import { Env } from '../env'; import * as path from 'path'; -import { isInDirectory, isFileValid, isPathValid, removeSpacesAndNewlines, toUnicodeIgnoreASCII } from './utility'; +import { isInDirectory, isFileValid, isPathValid, removeSpacesAndNewlines, toUnicodeIgnoreASCII } from '../utility'; +import { chineseToEnglish,englishToChinese } from '../constants'; export class TemplateGenerator{ private env: Env; private readonly englishToChinese; private readonly chineseToEnglish; public constructor(env: Env) { this.env = env; - this.chineseToEnglish = this.env.chineseToEnglish; - this.englishToChinese = this.env.englishToChinese; + this.chineseToEnglish = chineseToEnglish; + this.englishToChinese = englishToChinese; } @@ -22,7 +23,7 @@ export class TemplateGenerator{ */ public generateTemplateCSVToTargetPath(templateType: string, targetPath: vscode.Uri): boolean{ try { - fs.copy(path.join(path.join(__dirname, "../template/csv_template"), templateType), targetPath.fsPath,{ overwrite: false }); + fs.copy(path.join(path.join(__dirname, "../../template/csv_template"), templateType), targetPath.fsPath,{ overwrite: false }); } catch (error) { vscode.window.showErrorMessage("模板生成异常:"+error); @@ -35,7 +36,7 @@ export class TemplateGenerator{ try { await this.renameTemplateCSVtoChinese(); - await fs.copySync(path.join(__dirname, "../template/csv_template"), targetPath.fsPath, { overwrite: false }); + await fs.copySync(path.join(__dirname, "../../template/csv_template"), targetPath.fsPath, { overwrite: false }); await this.renameTemplateCSVtoEnglish(); } catch (error) { @@ -53,8 +54,8 @@ export class TemplateGenerator{ for (let key in this.englishToChinese) { let oldFileName: string = key; let newFileName: string = this.englishToChinese[key]; - oldFileName = path.join(__dirname, "../template/csv_template/" + oldFileName); - newFileName = path.join(__dirname, "../template/csv_template/" + newFileName); + oldFileName = path.join(__dirname, "../../template/csv_template/" + oldFileName); + newFileName = path.join(__dirname, "../../template/csv_template/" + newFileName); await fs.renameSync(oldFileName, newFileName); } } @@ -63,8 +64,8 @@ export class TemplateGenerator{ for (let key in this.chineseToEnglish) { let oldFileName: string = key; let newFileName: string = this.chineseToEnglish[key]; - oldFileName = path.join(__dirname, "../template/csv_template/" + oldFileName); - newFileName = path.join(__dirname, "../template/csv_template/" + newFileName); + oldFileName = path.join(__dirname, "../../template/csv_template/" + oldFileName); + newFileName = path.join(__dirname, "../../template/csv_template/" + newFileName); await fs.renameSync(oldFileName, newFileName); } } diff --git a/src/env.ts b/src/env.ts index 05ef137..6253fdd 100644 --- a/src/env.ts +++ b/src/env.ts @@ -5,13 +5,14 @@ import path from 'path'; import * as tools from './tools'; import { isPathValid } from './utility'; import * as fs from 'fs'; +import { EditorTableType } from './constants'; type EditorVersion = '1.0' | '2.0' | 'unknown'; export class Env { constructor() { - this.updateTableTypeToCSVfolderPath();// 初始化时从插件配置更新物编数据对应存放文件夹路径的关系 + this.initTableTypeToCSVfolderPath();// 初始化时从插件配置更新物编数据对应存放文件夹路径的关系 } private async searchEditorUriByReg(): Promise { @@ -186,9 +187,10 @@ export class Env { public y3Uri?: vscode.Uri; public projectUri?: vscode.Uri; public editorTableUri?: vscode.Uri;// 物编数据 + public csvTableUri?: vscode.Uri;// CSV表格路径 // 默认情况下各类型物编数据CSV文件的相对路径 (相对于工程项目的script文件) - public defaultTableTypeToCSVfolderPath: Readonly<{ [key: string]: string }> = { + private readonly defaultTableTypeToCSVfolderPath: Readonly<{ [key: string]: string }> = { unit: "./resource/editor_table/单位", decoration: "./resource/editor_table/装饰物", item: "./resource/editor_table/物品", @@ -201,7 +203,7 @@ export class Env { }; // 实际情况下各类型物编数据CSV文件的相对路径 (相对于工程项目的script文件) - public tableTypeToCSVfolderPath: { [key: string]: string } = { + public readonly tableTypeToCSVfolderPath: { [key: string]: string } = { unit: "./resource/editor_table/单位", decoration: "./resource/editor_table/装饰物", item: "./resource/editor_table/物品", @@ -212,39 +214,7 @@ export class Env { destructible: "./resource/editor_table/可破坏物", sound: "./resource/editor_table/声音" }; - public readonly englishPathToChinese: { [key: string]: string } = { - "editorunit": "单位", - "soundall": "声音", - "abilityall": "技能", - "editordecoration": "装饰物", - "editordestructible": "可破坏物", - "editoritem": "物品", - "modifierall": "魔法效果", - "projectileall": "投射物", - "technologyall": "科技" - }; - public readonly englishToChinese: { [key: string]: string } = { - "unit": "单位", - "decoration": "装饰物", - "item": "物品", - "ability": "技能", - "modifier": "魔法效果", - "projectile": "投射物", - "technology": "科技", - "destructible": "可破坏物", - "sound": "声音" - }; - public readonly chineseToEnglish: { [key: string]: string } = { - "单位": "unit", - "装饰物": "decoration", - "物品": "item", - "技能": "ability", - "魔法效果": "modifier", - "投射物": "projectile", - "科技": "technology", - "可破坏物": "destructible", - "声音": "sound" - }; + private _zhlanguageJson: any = undefined; public get zhlanguageJson(): any { @@ -291,7 +261,7 @@ export class Env { /** * 从插件配置中更新物编数据类型对应的CSV文件保存地址 */ - public updateTableTypeToCSVfolderPath(): void { + public initTableTypeToCSVfolderPath(): void { let csvPathConfig: any = vscode.workspace.getConfiguration('Y3-Helper.CSVPath'); //console.log(vscode.workspace.getConfiguration('Y3-Helper.CSVPath').unit); for (const key in this.defaultTableTypeToCSVfolderPath) { @@ -322,6 +292,7 @@ export class Env { this.scriptUri = vscode.Uri.joinPath(this.mapUri, 'script'); this.y3Uri = vscode.Uri.joinPath(this.scriptUri, 'y3'); this.editorTableUri = vscode.Uri.joinPath(this.mapUri, "editor_table"); + this.csvTableUri = vscode.Uri.joinPath(this.scriptUri, "./resource/editor_table/"); } })(), ]); @@ -351,4 +322,13 @@ export class Env { await this.init(); this.status = 'ready'; } + + public allocateEditorTableObjectUID(editorTableType:EditorTableType): number{ + let res: number = 0; + // todo:分配物编对象数据的UID + + return res; + } } + + diff --git a/src/extension.ts b/src/extension.ts index c7f3409..b147a27 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -3,13 +3,13 @@ import { runShell } from './runShell'; import { LuaDocMaker } from './makeLuaDoc'; import { Env } from './env'; import { GameLauncher } from './launchGame'; -import { CSVimporter } from './CSVimporter'; +import { CSVimporter } from './editorTable/CSVimporter'; import * as utility from './utility'; -import { TemplateGenerator } from './templateGenerator'; -import { Y3HelperDataProvider, GoEditorTableSymbolProvider, GoEditorTableDocumentSymbolProvider } from './editorTable'; +import { TemplateGenerator } from './editorTable/templateGenerator'; +import { EditorTableDataProvider, GoEditorTableSymbolProvider, GoEditorTableDocumentSymbolProvider } from './editorTable/editorTable'; import * as tools from "./tools"; import * as preset from './preset'; - +import { englishPathToChinese } from './constants'; class Helper { private context: vscode.ExtensionContext; private env: Env; @@ -301,8 +301,8 @@ class Helper { * 注册CSVeditor相关的命令 */ private registerCommandOfCSVeditor() { - vscode.commands.registerCommand('y3-helper.addNewDataInCSV', async () => { - const items: vscode.QuickPickItem[] = [ + let disposable = vscode.commands.registerCommand('y3-helper.addNewDataInCSV', async () => { + const editorTableTypes: vscode.QuickPickItem[] = [ { label: '单位', description: 'unit' }, { label: '装饰物', description: 'decoration' }, { label: '物品', description: 'item' }, @@ -313,15 +313,27 @@ class Helper { { label: '可破坏物', description: 'destructible' }, { label: '声音', description: 'sound' } ]; - vscode.window.showQuickPick(items, { + vscode.window.showQuickPick(editorTableTypes, { placeHolder: '选择你要添加的物编数据类型(CSV)' }).then(selection => { if (selection) { vscode.window.showInformationMessage(`你选择了: ${selection.label}`); } - vscode.window.showInputBox(); + + const inputOptions: vscode.InputBoxOptions = { + prompt: '请输入物编数据的名称或UID', + placeHolder: '数字', + validateInput: (text: string) => { + if (text.length === 0) { + return "输入的内容为空"; + } + return null; + } + }; + vscode.window.showInputBox(inputOptions); }); }); + this.context.subscriptions.push(disposable); } private registerCommandOfGenerateAllTemplateCSV() { @@ -338,14 +350,14 @@ class Helper { vscode.window.showErrorMessage("未找到编辑器!"); return false; } - if (!this.env.scriptUri) { - vscode.window.showErrorMessage("未找到script文件夹"); + if (!this.env.csvTableUri) { + vscode.window.showErrorMessage("未找到合适的位置生成CSV"); return false; } // 生成csv模板 let templateGenerator = new TemplateGenerator(this.env); - let targetUri: vscode.Uri = vscode.Uri.joinPath(this.env.scriptUri,"./resource/editor_table/"); + let targetUri: vscode.Uri = this.env.csvTableUri; await templateGenerator.generateAllTemplateCSVtoTargetPath(targetUri); }); } @@ -381,22 +393,22 @@ class Helper { } private registerEditorTableView() { - const y3HelperDataProvider=new Y3HelperDataProvider(this.env); + const editorTableDataProvider=new EditorTableDataProvider(this.env); vscode.window.registerTreeDataProvider( 'y3-helper.editorTableView', - y3HelperDataProvider + editorTableDataProvider ); vscode.commands.registerCommand('y3-helper.refreshTableViewer', () => { - y3HelperDataProvider.refresh(); + editorTableDataProvider.refresh(); }); - vscode.commands.registerCommand('y3-helper.editorTableView.refresh', () => y3HelperDataProvider.refresh()); + vscode.commands.registerCommand('y3-helper.editorTableView.refresh', () => editorTableDataProvider.refresh()); const goEditorTableSymbolProvider = new GoEditorTableSymbolProvider( this.env.editorTablePath, this.env.zhlanguageJson, - this.env.englishPathToChinese + englishPathToChinese ); this.context.subscriptions.push(vscode.languages.registerWorkspaceSymbolProvider(goEditorTableSymbolProvider)); diff --git a/src/test/suite/extension.test.ts b/src/test/suite/extension.test.ts index 8441988..17e7035 100644 --- a/src/test/suite/extension.test.ts +++ b/src/test/suite/extension.test.ts @@ -4,7 +4,7 @@ import * as assert from 'assert'; // as well as import your extension to test it import * as vscode from 'vscode'; // import * as myExtension from '../../extension'; -import '../../CSVimporter'; +import '../../editorTable/CSVimporter'; suite('Extension Test Suite', () => { diff --git a/template/csv_template/modifier/custom_key.csv b/template/csv_template/modifier/custom_key.csv index 3ba9724..508b43d 100644 --- a/template/csv_template/modifier/custom_key.csv +++ b/template/csv_template/modifier/custom_key.csv @@ -1,3 +1,3 @@ key,uid,name,attach_model_list,get_effect_list,lose_effect_list,material_alpha,material_change,material_color,material_color_intensity,modifier_icon,show_on_ui ID,UID,名称,最大持续时间,最大持续时间,最大持续时间,不透明度,材质变化,基础材质变色,材质变色强度,图标,显示图标 -134240918,134240918,这是一个modifier,(),,(),0,0,"(255, 255, 255)",0,106533,True +134240918,134240918,这是一个魔法效果,(),,(),0,0,"(255, 255, 255)",0,106533,True diff --git a/template/csv_template/modifier/display.csv b/template/csv_template/modifier/display.csv index 031227c..0d4873d 100644 --- a/template/csv_template/modifier/display.csv +++ b/template/csv_template/modifier/display.csv @@ -1,3 +1,3 @@ key,uid,name,attach_model_list,get_effect_list,lose_effect_list,material_alpha,material_change,material_color,material_color_intensity,modifier_icon,show_on_ui ID,UID,名称,最大持续时间,最大持续时间,最大持续时间,不透明度,材质变化,基础材质变色,材质变色强度,图标,显示图标 -134240918,134240918,这是一个modifier,(),,(),0,0,"(255, 255, 255)",0,106534,True +134240918,134240918,这是一个魔法效果,(),,(),0,0,"(255, 255, 255)",0,106534,True diff --git a/template/csv_template/modifier/sound_event.csv b/template/csv_template/modifier/sound_event.csv index 538b7d7..13c52e5 100644 --- a/template/csv_template/modifier/sound_event.csv +++ b/template/csv_template/modifier/sound_event.csv @@ -1,3 +1,3 @@ key,uid,name,sound_event_list ID,UID,名称,声音事件列表 -134240918,134240918,这是一个modifier,() +134240918,134240918,这是一个魔法效果,()