From 3ab473fd789c0734ae688e0c43c1ffdd858e4712 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 28 Mar 2024 15:24:09 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9D=9E=E5=BF=85=E8=A6=81=E4=B8=8D=E8=AF=A2?= =?UTF-8?q?=E9=97=AE=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/env.ts | 28 +++++++++++++++++++--------- src/extension.ts | 22 ++++++++++------------ src/launchGame.ts | 2 +- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/env.ts b/src/env.ts index aabee6b..417fac4 100644 --- a/src/env.ts +++ b/src/env.ts @@ -52,7 +52,7 @@ export class Env { return false; } - private async searchEditorUri(): Promise { + private async searchEditorUri(askUser = false): Promise { // 先看看设置里有没有 let editorPath: string|undefined = vscode.workspace.getConfiguration('Y3-Helper').get('EditorPath'); if (editorPath && await this.isValidEditorPath(editorPath)) { @@ -66,7 +66,7 @@ export class Env { } // 如果没有,则询问用户 - while (true) { + while (askUser) { let selectedFiles = await vscode.window.showOpenDialog({ canSelectFiles: true, openLabel: '选择Y3编辑器路径', @@ -132,7 +132,7 @@ export class Env { return mapFolder; } - private async searchProjectPath(): Promise { + private async searchProjectPath(askUser = false): Promise { // 先直接搜索打开的工作目录 if (vscode.workspace.workspaceFolders) { for (const folder of vscode.workspace.workspaceFolders) { @@ -143,6 +143,10 @@ export class Env { } } + if (!askUser) { + return undefined; + } + // 如果没有,则询问用户 let selectedFolders = await vscode.window.showOpenDialog({ canSelectFiles: true, @@ -300,15 +304,15 @@ export class Env { } - private async init() { + private async init(askUser = false) { await Promise.allSettled([ (async () => { - this.editorUri = await this.searchEditorUri(); + this.editorUri = await this.searchEditorUri(askUser); this.editorVersion = await this.getEditorVersion(); this.editorExeUri = this.getEditorExeUri(); })(), (async () => { - this.mapUri = await this.searchProjectPath(); + this.mapUri = await this.searchProjectPath(askUser); if (this.mapUri) { this.projectUri = vscode.Uri.joinPath(this.mapUri, '../..'); this.scriptUri = vscode.Uri.joinPath(this.mapUri, 'script'); @@ -329,9 +333,15 @@ export class Env { tools.log.info(`editorTableUri: ${this.editorTableUri?.fsPath}`); } - public async waitReady() { + // 如果找不到路径,是否弹框询问用户? + public async waitReady(askUser = false) { if (this.status === 'ready') { - return; + if (!askUser) { + return; + } + if (this.mapUri) { + return; + } } if (this.status === 'initing') { // 自旋 @@ -341,7 +351,7 @@ export class Env { return; } this.status = 'initing'; - await this.init(); + await this.init(askUser); this.status = 'ready'; } diff --git a/src/extension.ts b/src/extension.ts index 2e114d3..c3f3ab5 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -25,11 +25,9 @@ class Helper { this.mainMenu = new MainMenu(this.env); } - private async reload(waitReady = false) { + private async reload() { this.env = new Env(); - if (waitReady) { - await this.env.waitReady(); - } + await this.env.waitReady(); this.mainMenu.reload(this.env); } @@ -44,7 +42,7 @@ class Helper { private registerCommonCommands() { vscode.commands.registerCommand('y3-helper.reloadEnv', async () => { - await this.reload(true); + await this.reload(); }); vscode.commands.registerCommand('y3-helper.shell', async (...args: any[]) => { runShell("执行命令", args[0], args.slice(1)); @@ -62,7 +60,7 @@ class Helper { location: vscode.ProgressLocation.Notification, title: '正在初始化Y3项目...', }, async (progress, token) => { - await this.env.waitReady(); + await this.env.waitReady(true); if (!this.env.scriptUri) { vscode.window.showErrorMessage('未找到Y3地图路径,请先用编辑器创建地图或重新指定!'); return; @@ -200,7 +198,7 @@ class Helper { return; } - await this.env.waitReady(); + await this.env.waitReady(true); await vscode.debug.startDebugging(vscode.workspace.workspaceFolders?.[0], "💡附加"); }); }); @@ -213,7 +211,7 @@ class Helper { */ private registerCommandOfImportObjectDataFromAllCSVbyConfig() { vscode.commands.registerCommand('y3-helper.importObjectDataFromAllCSV', async () => { - await this.env.waitReady(); + await this.env.waitReady(true); let projectUri = this.env.projectUri; let editorExeUri = this.env.editorExeUri; let scriptUri= this.env.scriptUri; @@ -247,7 +245,7 @@ class Helper { // 在CSV表格中添加物编项目的命令 let addNewDataInCSVcommand = vscode.commands.registerCommand('y3-helper.addNewDataInCSV', async () => { - await this.env.waitReady(); + await this.env.waitReady(true); const editorTableTypes: vscode.QuickPickItem[] = [ { label: '单位', description: 'unit' }, { label: '装饰物', description: 'decoration' }, @@ -290,7 +288,7 @@ class Helper { // 把Y3工程项目中已有的物编数据的UID和名称添加到CSV表格以便填写和导入的命令 let addUIDandNameToCSVfromProjectCommand = vscode.commands.registerCommand("y3-helper.addUIDandNameToCSVfromProject", async () => { - await this.env.waitReady(); + await this.env.waitReady(true); const inputOptions: vscode.InputBoxOptions = { prompt: 'UID或名称', placeHolder: 'UID或名称', @@ -327,7 +325,7 @@ class Helper { private registerCommandOfGenerateAllTemplateCSV() { vscode.commands.registerCommand('y3-helper.generateAllTemplateCSV', async () => { console.log("y3-helper.generateTemplateCSV"); - await this.env.waitReady(); + await this.env.waitReady(true); let projectUri = this.env.projectUri; let editorExeUri = this.env.editorExeUri; if (!projectUri) { @@ -352,7 +350,7 @@ class Helper { private registerCommandOfDownloadPresetUI() { vscode.commands.registerCommand('y3-helper.downloadPresetUI', async () => { - await this.env.waitReady(); + await this.env.waitReady(true); if (!this.env.mapUri) { vscode.window.showErrorMessage("未找到地图路径!"); return false; diff --git a/src/launchGame.ts b/src/launchGame.ts index 4c385f9..4c6698c 100644 --- a/src/launchGame.ts +++ b/src/launchGame.ts @@ -11,7 +11,7 @@ export class GameLauncher { } public async launch(luaArgs?: {[key: string]: string|number|boolean}): Promise { - await this.env.waitReady(); + await this.env.waitReady(true); let projectUri = this.env.projectUri; let editorExeUri = this.env.editorExeUri; if (!projectUri) {