Skip to content

Commit

Permalink
总是生成所有的米塔文件
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Dec 26, 2024
1 parent 7d0c94a commit 372e431
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 36 deletions.
36 changes: 5 additions & 31 deletions src/metaBuilder/baseBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,19 @@
import * as vscode from 'vscode';
import { env } from '../env';
import * as tools from '../tools';
import { throttle } from '../utility/decorators';

export abstract class BaseBuilder {
constructor(public path: string) {
}
protected _onDidChange = new vscode.EventEmitter<void>();

public onDidChange = this._onDidChange.event;

public exists = false;
constructor(public path: string) { }

private debounceTimer?: NodeJS.Timeout;
public update() {
if (this.debounceTimer) {
clearTimeout(this.debounceTimer);
}
this.debounceTimer = setTimeout(() => {
this.debounceTimer = undefined;
this.didUpdate();
}, 1000);
}

private async didUpdate() {
@throttle(500)
public async update() {
if (!env.scriptUri) {
this.updateExists(false);
return;
}
let code = await this.make();
if (code) {
this.updateExists(await tools.fs.writeFile(env.scriptUri, this.path, code));
} else {
tools.fs.removeFile(env.scriptUri, this.path);
this.updateExists(false);
}
}

private updateExists(exists: boolean) {
if (exists !== this.exists) {
this.exists = exists;
this._onDidChange.fire();
await tools.fs.writeFile(env.scriptUri, this.path, code);
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/metaBuilder/initBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class InitBuilder extends BaseBuilder {
return;
}
let codes = this.builders
.filter((builder) => builder.exists)
.map((builder) => {
// 将正斜杠和反斜杠替换为点号
let name = builder.path
Expand All @@ -41,10 +40,6 @@ class InitBuilder extends BaseBuilder {
public addChild(builder: any, fileName: string) {
let instance = new builder(luaPath + '/' + fileName);
this.addFile(instance);
instance.onDidChange(() => {
this.update();
});

}
}

Expand All @@ -60,5 +55,9 @@ export function init() {
initBuilder.addChild(Font, 'font.lua');
//initBuilder.addChild(Objects, 'objects.lua');

env.onDidChange(() => {
initBuilder.update();
});

new TS(tsPath + '/map-declare.d.ts');
}

0 comments on commit 372e431

Please sign in to comment.