A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(editor): the batch most worth previewing was the one that showed nothing
esengine17a98414bb76
diff --git a/desktop/src/components/AgentDrawer.tsx b/desktop/src/components/AgentDrawer.tsxindex 5a3a796d3..b0f639d97 100644--- a/desktop/src/components/AgentDrawer.tsx+++ b/desktop/src/components/AgentDrawer.tsx@@ -126,7 +126,26 @@ function PreviewPassage({ entry, onConfirm }: {const [struck, setStruck] = useState<ReadonlySet<number>>(new Set());useEffect(() => { ref.current?.scrollIntoView({ block: 'nearest' }); }, []);- const ops = Array.isArray(entry.input.ops) ? (entry.input.ops as SceneOp[]) : null;+ // A batch big enough to be written to a file is the one most worth reading+ // before it lands, so the file form is loaded rather than waved through. An+ // empty preview beside an Apply button would claim the batch changes nothing.+ const opsPath = typeof entry.input.opsPath === 'string' ? entry.input.opsPath : null;+ const [fromFile, setFromFile] = useState<SceneOp[] | 'unreadable' | null>(null);+ useEffect(() => {+ if (!opsPath) return;+ void (window.estella?.fs?.read(opsPath) ?? Promise.reject())+ .then((text) => {+ const parsed: unknown = JSON.parse(text);+ setFromFile(Array.isArray(parsed) ? (parsed as SceneOp[]) : 'unreadable');+ })+ .catch(() => setFromFile('unreadable'));+ }, [opsPath]);++ const ops = Array.isArray(entry.input.ops)+ ? (entry.input.ops as SceneOp[])+ : (Array.isArray(fromFile) ? fromFile : null);+ const loading = opsPath !== null && fromFile === null;+ const unreadable = fromFile === 'unreadable';const preview = ops ? previewSceneOps(ops, editorScene) : [];// What striking these lines actually costs, dependents included.const dropped = ops ? new Set(withoutDeclined(ops, struck).dropped) : new Set<number>();@@ -142,8 +161,14 @@ function PreviewPassage({ entry, onConfirm }: {return (<div ref={ref} className="ag-ask ag-ask--preview"><span className="ag-ask-g"><Pencil size={16} strokeWidth={1.8} /></span>- <span className="ag-ask-hd">{t('agent.preview.title', { count: preview.length })}</span>- <div className="ag-ask-d">{t('agent.preview.why')}</div>+ <span className="ag-ask-hd">+ {loading ? t('agent.preview.loading')+ : unreadable ? t('agent.preview.unreadable', { path: opsPath ?? '' })+ : t('agent.preview.title', { count: preview.length })}+ </span>+ <div className="ag-ask-d">+ {unreadable ? t('agent.preview.unreadable.why') : t('agent.preview.why')}+ </div><div className="ag-preview">{preview.map((line) => (<buttondiff --git a/desktop/src/i18n/messages/agent.ts b/desktop/src/i18n/messages/agent.tsindex a2ca58b34..07c0630ee 100644--- a/desktop/src/i18n/messages/agent.ts+++ b/desktop/src/i18n/messages/agent.ts@@ -98,6 +98,15 @@ export const agentMessages = defineMessages({en: 'Click a line to strike it out. Striking a new entity also strikes what refers to it.',zh: '点击某一行可划掉它。划掉一个新建实体时,引用它的行会一并划掉。',},+ 'agent.preview.loading': { en: 'Reading the batch…', zh: '正在读取这批改动…' },+ 'agent.preview.unreadable': {+ en: 'This batch comes from {path}, which could not be read',+ zh: '这批改动来自 {path},读取失败',+ },+ 'agent.preview.unreadable.why': {+ en: 'Nothing is previewed below. Applying runs the file as the agent wrote it.',+ zh: '下面没有可预览的内容。应用将按 Agent 写好的文件原样执行。',+ },'agent.preview.apply': { en: 'Apply all', zh: '全部应用' },'agent.preview.applyKept': { en: 'Apply {count}', zh: '应用 {count} 项' },'agent.confirm.allow': { en: 'Run it', zh: '执行' },