From c505efeb6644f685752acb1deb241a4cc553ab30 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Wed, 26 Feb 2025 23:04:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20render=20=E4=B8=AD=E9=80=92=E5=BD=92?= =?UTF-8?q?=E8=B0=83=E7=94=A8=20update=20=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/render/item.ts | 14 ++++++++++++++ src/data/logger.json | 1 + 2 files changed, 15 insertions(+) diff --git a/src/core/render/item.ts b/src/core/render/item.ts index 308fe60..2869be5 100644 --- a/src/core/render/item.ts +++ b/src/core/render/item.ts @@ -351,6 +351,13 @@ export abstract class RenderItem //#endregion + //#region debug + + /** 是否需要禁用更新,如果出现更新,那么发出警告并停止更新操作 */ + private forbidUpdate: boolean = false; + + //#endregion + constructor( type: RenderItemPosition, enableCache: boolean = true, @@ -392,6 +399,7 @@ export abstract class RenderItem */ renderContent(canvas: MotaOffscreenCanvas2D, transform: Transform) { if (this.hidden) return; + this.forbidUpdate = true; this.emit('beforeRender', transform); if (this.transformFallThrough) { this.fallTransform = transform; @@ -425,6 +433,7 @@ export abstract class RenderItem } ctx.restore(); this.emit('afterRender', transform); + this.forbidUpdate = false; } /** @@ -601,6 +610,11 @@ export abstract class RenderItem } update(item: RenderItem = this): void { + if (import.meta.env.DEV) { + if (this.forbidUpdate) { + logger.warn(61, this.constructor.name); + } + } if (this._parent) { if (this.cacheDirty && this._parent.cacheDirty) return; this.cacheDirty = true; diff --git a/src/data/logger.json b/src/data/logger.json index 2dff98f..3ea6a95 100644 --- a/src/data/logger.json +++ b/src/data/logger.json @@ -92,6 +92,7 @@ "58": "Fail to set ellipse round rect, since length of 'ellipse' property should only be 2, 4, 6 or 8. delivered: $1", "59": "Unknown icon '$1' in parsing text content.", "60": "Repeated Tip id: '$1'.", + "61": "Unexpected recursive call of $1.update in render function. Please ensure you must do this, if you do, ignore this warn.", "1001": "Item-detail extension needs 'floor-binder' and 'floor-damage' extension as dependency.", "1101": "Cannot add new effect to point effect instance, for there's no more reserve space for it. Please increase the max count of the instance." }