Skip to content

Commit

Permalink
编辑器状态等待编辑器路径
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Mar 28, 2024
1 parent 5a3d8ff commit e973b01
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 26 deletions.
37 changes: 26 additions & 11 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let defaultTableTypeToCSVfolderPath: Readonly<{ [key: string]: string }> = {
sound: "./resource/editor_table/声音"
};

function reReady(method: Function, context: ClassMethodDecoratorContext) {
function rePrepare(method: Function, context: ClassMethodDecoratorContext) {
let running = false;
return async function (this: any, ...args: any[]) {
if (running) {
Expand Down Expand Up @@ -208,8 +208,7 @@ class EnvPath {
return editorExeUri;
}

public status: 'not ready' | 'initing' | 'ready' = 'not ready';
public editorVersion?: EditorVersion;
public editorVersion: EditorVersion = 'unknown';
public editorUri?: vscode.Uri;
public editorExeUri?: vscode.Uri;
public mapUri?: vscode.Uri;
Expand Down Expand Up @@ -257,25 +256,34 @@ class EnvPath {
}
}

@reReady
public async editorReady(askUser = false) {
if (this.editorUri) {
@rePrepare
public async updateEditor(askUser = false) {
let editorUri = await this.searchEditorUri(askUser);
if (!editorUri) {
return;
}
this.editorUri = await this.searchEditorUri(askUser);
this.editorUri = editorUri;
this.editorVersion = await this.getEditorVersion();
this.editorExeUri = this.getEditorExeUri();
tools.log.info(`editorUri: ${this.editorUri?.fsPath}`);
tools.log.info(`editorExeUri: ${this.editorExeUri?.fsPath}`);
tools.log.info(`editorVersion: ${this.editorVersion}`);
}

@reReady
public async mapReady(askUser = false) {
if (this.mapUri) {
public async editorReady(askUser = false) {
if (this.editorUri) {
return;
}
await this.updateEditor(askUser);
}

@rePrepare
public async updateMap(askUser = false) {
let mapUri = await this.searchProjectPath(askUser);
if (!mapUri) {
return;
}
this.mapUri = await this.searchProjectPath(askUser);
this.mapUri = mapUri;
if (this.mapUri) {
this.projectUri = vscode.Uri.joinPath(this.mapUri, '../..');
this.scriptUri = vscode.Uri.joinPath(this.mapUri, 'script');
Expand All @@ -290,6 +298,13 @@ class EnvPath {
tools.log.info(`y3Uri: ${this.y3Uri?.fsPath}`);
tools.log.info(`editorTableUri: ${this.editorTableUri?.fsPath}`);
}

public async mapReady(askUser = false) {
if (this.mapUri) {
return;
}
await this.updateMap(askUser);
}
}

class Env extends EnvPath {
Expand Down
23 changes: 8 additions & 15 deletions src/mainMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ let nodeEnv = new TreeNode('环境', {
iconPath: new vscode.ThemeIcon('server-environment'),
childs: [
new TreeNode('编辑器', {
update: (node) => {
update: async (node) => {
await env.editorReady(true);
node.tooltip = env.editorUri?.fsPath;
node.iconPath = env.editorUri ? new vscode.ThemeIcon('settings') : new vscode.ThemeIcon('error');
node.description = env.editorUri ? env.editorUri.fsPath : '未找到编辑器';
Expand All @@ -155,7 +156,8 @@ let nodeEnv = new TreeNode('环境', {
},
}),
new TreeNode('Lua脚本', {
update: (node) => {
update: async (node) => {
await env.mapReady(true);
node.tooltip = env.scriptUri?.fsPath;
node.iconPath = env.scriptUri ? new vscode.ThemeIcon('book') : new vscode.ThemeIcon('error');
node.description = env.scriptUri ? env.scriptUri.fsPath : '未找到Lua脚本';
Expand All @@ -173,9 +175,6 @@ class TreeProvider implements vscode.TreeDataProvider<TreeNode> {
public refresh = new vscode.EventEmitter<TreeNode | undefined>();
onDidChangeTreeData = this.refresh.event;

constructor() {
}

async getChildren(node?: TreeNode): Promise<TreeNode[] | undefined> {
if (!node) {
await env.mapReady();
Expand Down Expand Up @@ -211,19 +210,13 @@ class MainMenu {
});
this.view.onDidChangeVisibility(async (e) => {
if (e.visible) {
if (this.state !== 'not init') {
return;
}
this.state = 'initing';
this.view.message = '正在初始化...';
await env.mapReady();
this.state = 'inited';
this.refresh();
}
});
}

private refresh() {
private async refresh() {
await env.mapReady();
if (env.scriptUri) {
this.view.message = undefined;
} else {
Expand All @@ -232,8 +225,8 @@ class MainMenu {
this.tree.refresh.fire(undefined);
}

reload() {
this.refresh();
async reload() {
await this.refresh();
}
}

Expand Down

0 comments on commit e973b01

Please sign in to comment.