From a05981e675820a1f78cf41d473a3afd858d2410a Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Sat, 19 Oct 2024 21:18:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A4=A7=E5=9C=B0=E5=9B=BE=E4=BC=9A?= =?UTF-8?q?=E4=B8=80=E6=AC=A1=E6=80=A7=E6=8A=8A=E6=89=80=E6=9C=89=E4=BC=A4?= =?UTF-8?q?=E5=AE=B3=E6=B8=B2=E6=9F=93=E5=AE=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/libs/events.js | 3 +-- src/core/render/preset/damage.ts | 40 +++++++++++++++----------------- src/game/state/hero.ts | 22 +++++++++--------- src/plugin/fx/itemDetail.ts | 9 ++++--- src/plugin/game/skillTree.ts | 3 +-- 5 files changed, 36 insertions(+), 41 deletions(-) diff --git a/public/libs/events.js b/public/libs/events.js index 7f3a5cc..a4f29af 100644 --- a/public/libs/events.js +++ b/public/libs/events.js @@ -431,8 +431,7 @@ events.prototype.trigger = function (x, y, callback) { if ( trigger == 'changeFloor' && !noPass && - this._trigger_ignoreChangeFloor(block) && - !loop + this._trigger_ignoreChangeFloor(block) ) return _executeCallback(); // @ts-ignore diff --git a/src/core/render/preset/damage.ts b/src/core/render/preset/damage.ts index 6ead4cd..ee65ca2 100644 --- a/src/core/render/preset/damage.ts +++ b/src/core/render/preset/damage.ts @@ -156,10 +156,8 @@ export class Damage extends Sprite { /** 默认描边宽度 */ strokeWidth: number = 2; - /** 单个点的懒更新 */ - private needUpdateBlock: boolean = false; /** 要懒更新的所有分块 */ - private needUpdateBlocks: Set = new Set(); + private dirtyBlocks: Set = new Set(); constructor() { super('absolute', false, true); @@ -203,6 +201,7 @@ export class Damage extends Sprite { for (let i = 0; i < num; i++) { this.blockData.set(i, new Map()); this.renderable.set(i, new Set()); + this.dirtyBlocks.add(i); } this.emit('setMapSize', width, height); @@ -221,13 +220,19 @@ export class Damage extends Sprite { this.blockData.forEach(v => v.clear()); this.renderable.forEach(v => v.clear()); this.block.clearAllCache(); + const w = this.block.blockData.width; + const h = this.block.blockData.height; + const num = w * h; + for (let i = 0; i < num; i++) { + this.dirtyBlocks.add(i); + } enemy.list.forEach(v => { if (isNil(v.x) || isNil(v.y)) return; const index = this.block.getIndexByLoc(v.x, v.y); this.blockData.get(index)?.set(v.y * this.mapWidth + v.x, v); }); - this.updateBlocks(); + // this.updateBlocks(); this.update(this); } @@ -248,13 +253,14 @@ export class Damage extends Sprite { * @param blocks 要更新的分块集合 * @param map 是否更新地图伤害 */ - updateBlocks(blocks?: Set, map: boolean = true) { + updateBlocks(blocks?: Set) { if (blocks) { - blocks.forEach(v => this.updateBlock(v, map)); + blocks.forEach(v => this.dirtyBlocks.add(v)); this.emit('updateBlocks', blocks); } else { - this.blockData.forEach((_, k) => this.updateBlock(k, false)); - if (map) this.extractAllMapDamage(); + this.blockData.forEach((v, i) => { + this.dirtyBlocks.add(i); + }); this.emit('updateBlocks', new Set(this.blockData.keys())); } this.update(this); @@ -278,18 +284,7 @@ export class Damage extends Sprite { this.update(this); // 渲染懒更新,优化性能表现 - if (!this.needUpdateBlock) { - this.needUpdateBlocks.add(block); - this.requestBeforeFrame(() => { - this.needUpdateBlock = false; - this.updateBlocks(this.needUpdateBlocks, false); - this.needUpdateBlocks.clear(); - // this.needUpdateBlocks.forEach(v => this.updateBlock(v, false)); - // todo: 阻击夹域等地图伤害检测是否必要更新,例如不包含阻击夹域的怪就不必要更新这个怪物信息 - // this.extractAllMapDamage(); - }); - this.needUpdateBlock = true; - } + this.dirtyBlocks.add(block); } /** @@ -487,6 +482,7 @@ export class Damage extends Sprite { const size = cell * block.blockSize; this.emit('beforeDamageRender', render, transform); + render.forEach(v => { const [x, y] = block.getBlockXYByIndex(v); const bx = x * block.blockSize; @@ -502,7 +498,9 @@ export class Damage extends Sprite { return; } - this.updateBlock(v, true); + if (this.dirtyBlocks.has(v)) { + this.updateBlock(v, true); + } this.emit('dirtyUpdate', v); // 否则依次渲染并写入缓存 diff --git a/src/game/state/hero.ts b/src/game/state/hero.ts index 47c1475..918fb32 100644 --- a/src/game/state/hero.ts +++ b/src/game/state/hero.ts @@ -62,19 +62,19 @@ function getRealStatus( ): any { const { getSkillLevel } = Mota.Plugin.require('skillTree_g'); if (name instanceof Array) { - return Object.fromEntries( - name.map(v => [v, getRealStatus(status, v, floorId)]) - ); + const res: any = {}; + name.forEach(v => { + res[v] = getRealStatus(status, v, floorId); + }); + return res; } if (name === 'all') { - return Object.fromEntries( - Object.keys(core.status.hero).map(v => [ - v, - v !== 'all' && - getRealStatus(status, v as keyof HeroStatus, floorId) - ]) - ); + const res: any = {}; + Object.keys(core.status.hero).forEach(v => { + res[v] = getRealStatus(status, v as keyof HeroStatus, floorId); + }); + return res; } let s = (status?.[name] ?? core.status.hero[name]) as number; @@ -109,7 +109,7 @@ function getRealStatus( // buff if (typeof s === 'number') { - s *= core.getBuff(name as keyof NumbericHeroStatus); + s *= flags[`__${name}_buff__`] ?? 1; s = Math.floor(s); } diff --git a/src/plugin/fx/itemDetail.ts b/src/plugin/fx/itemDetail.ts index 98044c6..e24178f 100644 --- a/src/plugin/fx/itemDetail.ts +++ b/src/plugin/fx/itemDetail.ts @@ -66,8 +66,8 @@ export class FloorItemDetail implements ILayerGroupRenderExtends { if (!mainSetting.getValue('screen.itemDetail')) return; if (this.dirtyBlock.has(block)) { this.sprite.block.clearCache(block, 1); - this.render(block); } + this.render(block); }; private onUpdateMapSize = (width: number, height: number) => { @@ -216,14 +216,13 @@ export class FloorItemDetail implements ILayerGroupRenderExtends { * @param block 需要渲染的格子 */ render(block: number) { - this.calAllItems(new Set([block])); + if (this.dirtyBlock.has(block)) { + this.calAllItems(new Set([block])); + } const data = this.detailData; - - if (!this.dirtyBlock.has(block)) return; this.dirtyBlock.delete(block); const info = data.get(block); if (!info) return; - info.forEach(({ x, y, diff }) => { let n = 0; for (const [key, value] of Object.entries(diff)) { diff --git a/src/plugin/game/skillTree.ts b/src/plugin/game/skillTree.ts index 45aff28..c60c953 100644 --- a/src/plugin/game/skillTree.ts +++ b/src/plugin/game/skillTree.ts @@ -217,10 +217,9 @@ export function getSkillFromIndex(index: number) { /** * 获取技能等级 - * @param {number} skill */ export function getSkillLevel(skill: number) { - return (levels[skill] ??= 0); + return levels[skill] ?? 0; } export function getSkillConsume(skill: number) {