From 56c35273efc431d09176bc93db04cb6d35a221ad Mon Sep 17 00:00:00 2001 From: min Date: Tue, 9 Jun 2026 20:59:30 +0300 Subject: [PATCH] =?UTF-8?q?fix(g20):=20=5FnpcCmd=20=D0=B6=D0=B4=D1=91?= =?UTF-8?q?=D1=82=20npc=5Flua=5F=20=D0=BF=D1=80=D0=B5=D1=84=D0=B8=D0=BA?= =?UTF-8?q?=D1=81=20+=20sb.api.setNpcLocalRef?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _npcCmd проверял только индекс 'npc:_local_' (для JS-воркера), ref от Lua-shim 'npc_lua_0' пропускался — отложенные setLabel/damage терялись. Также: проверка sb.api?._localToRealNpc была false после рефакторинга (перенёс в local closure). Замена на sb.api?.setNpcLocalRef — публичный метод. Убрал debug-логи. --- src/editor/engine/GameRuntime.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/editor/engine/GameRuntime.js b/src/editor/engine/GameRuntime.js index 7138dec..400a1b9 100644 --- a/src/editor/engine/GameRuntime.js +++ b/src/editor/engine/GameRuntime.js @@ -326,10 +326,6 @@ export class GameRuntime { } } catch (_) {} } else { - if (cmd === 'npc.spawn' || cmd === 'npc.damage' || cmd === 'scene.setLabel' || cmd === 'scene.clearLabel') { - // eslint-disable-next-line no-console - console.warn('[Lua onCommand]', cmd, JSON.stringify(payload).slice(0, 200)); - } this._handleCommand(null, cmd, payload); } }); @@ -1497,7 +1493,8 @@ export class GameRuntime { const nid = this._resolveNpcId(ref); if (nid != null) { fn(nid); return; } // ещё не резолвится — откладываем (только для локальных ref NPC) - if (typeof ref === 'string' && ref.indexOf('npc:_local_') === 0) { + if (typeof ref === 'string' + && (ref.indexOf('npc:_local_') === 0 || ref.startsWith('npc_lua_'))) { if (!this._pendingNpcCmds) this._pendingNpcCmds = new Map(); if (!this._pendingNpcCmds.has(ref)) this._pendingNpcCmds.set(ref, []); this._pendingNpcCmds.get(ref).push(fn); @@ -2156,8 +2153,8 @@ export class GameRuntime { // Также сообщаем Lua-sandbox-ам маппинг, чтобы // npc.onDeath по локальному ref находил npcId. for (const sb of this.sandboxes) { - if (sb.api?._localToRealNpc) { - try { sb.api.setNpcLocalRef?.(payload.ref, 'npc:' + npcId); } catch (_) {} + if (sb.api?.setNpcLocalRef) { + try { sb.api.setNpcLocalRef(payload.ref, 'npc:' + npcId); } catch (_) {} } } }