From 372e431b90b38639d59e7aa5fc1a046dccda7c14 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, 26 Dec 2024 15:57:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=80=BB=E6=98=AF=E7=94=9F=E6=88=90=E6=89=80?= =?UTF-8?q?=E6=9C=89=E7=9A=84=E7=B1=B3=E5=A1=94=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/metaBuilder/baseBuilder.ts | 36 +++++----------------------------- src/metaBuilder/initBuilder.ts | 9 ++++----- 2 files changed, 9 insertions(+), 36 deletions(-) diff --git a/src/metaBuilder/baseBuilder.ts b/src/metaBuilder/baseBuilder.ts index 8edc1ef..73d4749 100644 --- a/src/metaBuilder/baseBuilder.ts +++ b/src/metaBuilder/baseBuilder.ts @@ -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(); - - 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); } } diff --git a/src/metaBuilder/initBuilder.ts b/src/metaBuilder/initBuilder.ts index 38f3ea6..4bef669 100644 --- a/src/metaBuilder/initBuilder.ts +++ b/src/metaBuilder/initBuilder.ts @@ -24,7 +24,6 @@ class InitBuilder extends BaseBuilder { return; } let codes = this.builders - .filter((builder) => builder.exists) .map((builder) => { // 将正斜杠和反斜杠替换为点号 let name = builder.path @@ -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(); - }); - } } @@ -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'); }