Skip to content

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.

feat(agent): the brief says how a look is made

yhh9b5cacdd5c95
diff --git a/desktop/electron/agent/prompt.ts b/desktop/electron/agent/prompt.ts
index 4a55bd254..a5f4b158c 100644
--- a/desktop/electron/agent/prompt.ts
+++ b/desktop/electron/agent/prompt.ts
@@ -34,6 +34,8 @@ Working style:
- Prefer one apply_scene_ops over many small calls when building something: it is one undo step for the user and one round trip for you, and it is the ONE write the user sees BEFORE it lands — they get a line-by-line preview and can strike parts of it out. A dozen set_field calls give them no such chance, so build with a batch and save the single writes for genuinely single changes.
- Units are the editor's: 1 world unit = 1 design pixel. Y is up in the world, and UI is laid out top-down.
- Game content lives in the WORLD: a board, its pieces, a character are Sprite / ShapeRenderer entities you place with Transform.position. A Canvas and its UINodes are for HUD and menus, and their placement is the layout's OUTPUT — a Transform.position written on a UI node is overwritten at the next relayout, which looks like nothing happened. Move those with layout inputs instead (UINode.position = Absolute, then left/top), or let the flow place them.
+- A LOOK is a material, not a script. Sprite and Mesh2D have a \`material\` field taking a \`.esmaterial\`: a small JSON that names a shader — either \`builtin:<id>\` (sprite-unlit, sprite-lit, sprite-hit-flash, sprite-outline, sprite-dissolve, sprite-pixelate, sprite-uv-scroll — a stock effect is shared by reference, no file is spawned) or a project-relative \`.esshader\` — plus a \`properties\` map of its parameter values. create_asset writes either kind. An \`.esshader\` for the 2D domains is fragment-only (\`#pragma domain Unlit2D\` or \`Lit2D\`; the batch vertex stage is injected) and the injected names carry no prefix: \`u_time\`, \`u_viewport\`, \`applyLighting2D\`, \`noise2d\`. Nothing type-checks a shader the way check_scripts checks a system — a broken one is a black or missing sprite at run time — so play it and read get_logs before calling it done. Drive a parameter from a system with \`Material.setUniform(sprite.material, 'u_amount', v)\`: at run time that field IS the handle. The visual Material Graph (\`.esmatgraph\`) is the same shader through a node editor — open_asset it, read and write it with get_asset_document / edit_asset_document, and save_asset_document to write it AND recompile the \`.esshader\` its materials read. Writing the shader text is fewer moving parts when you already know the effect you want.
+- Mesh2D geometry is not a component field. Vertices go up through \`Res(Meshes2D)\` — \`meshes.setGeometry(entity, { positions, indices })\` from a system, positions as x,y pairs in local space — so a custom mesh is authored in code and the editor viewport shows it only in Play. set_field cannot reach it.
- Behaviour is a system and data is a component, both declared through the front door: \`defineSystem([Query(Mut(Transform)), Res(Time)], (q, t) => {...})\` and \`defineComponent('Name', { speed: 100 })\`, registered with \`addSystemToSchedule\`. create_script writes either one already wired into the entry that loads it. The underscore-prefixed fields you can see on those objects (\`_params\`, \`_fn\`, \`_id\`) are the scheduler's, not an authoring surface: assembling one by hand happens to run and leaves a project nobody else's tools understand.
- A game reads input from the ENGINE, never from the DOM. In a system, ask for \`Res(Input)\` and \`Res(CameraView)\`: \`input.isMouseButtonPressed(0)\` (0 = left, 1 = right, 2 = middle — plain numbers; \`MouseButton\` is the InputMap BINDING builder, \`MouseButton(0)\`, and has no \`.Left\`), \`input.mouseX/mouseY\` (SCREEN pixels, canvas-relative, y down), and \`camera.getWorldMousePosition()\` / \`camera.screenToWorld(x, y)\` for where that is in the world — both return \`null\` when there is no camera, so check before using it. \`document.querySelector('canvas')\` plus a click listener works in a browser and nowhere else the project ships to — a mini-game runtime and a native build have no DOM — and it makes the game redo screen-to-world arithmetic the camera already knows, which is wrong for every window that is not the design aspect.
- Ask the compiler, do not guess and do not page the .d.ts. \`lookup_symbol\` gives a name's real signature, its doc and where it is declared, in one call; \`search_project_files\` finds where something is written. Writing a .ts file REPORTS ITS TYPE ERRORS in the reply, and \`check_scripts\` asks for them at any time. A game whose script does not compile does not run at all, so an error there is the first thing to fix — not something to discover after the screen comes up black.
diff --git a/desktop/tests/agent-brief-compiles.test.ts b/desktop/tests/agent-brief-compiles.test.ts
index 21c02820f..548f0bde6 100644
--- a/desktop/tests/agent-brief-compiles.test.ts
+++ b/desktop/tests/agent-brief-compiles.test.ts
@@ -63,6 +63,9 @@ describe("the agent's brief", () => {
'addSystemToSchedule',
'lookup_symbol',
'check_scripts',
+ "Material.setUniform(sprite.material, 'u_amount', v)",
+ 'Res(Meshes2D)',
+ 'meshes.setGeometry(entity, { positions, indices })',
]) {
expect([taught, SYSTEM_PROMPT.includes(taught)]).toEqual([taught, true]);
}
diff --git a/desktop/tests/fixtures/agent-brief-usage.ts b/desktop/tests/fixtures/agent-brief-usage.ts
index eeb238b89..009b6576d 100644
--- a/desktop/tests/fixtures/agent-brief-usage.ts
+++ b/desktop/tests/fixtures/agent-brief-usage.ts
@@ -17,11 +17,15 @@ import {
CameraView,
Commands,
Input,
+ Material,
+ Mesh2D,
+ Meshes2D,
MouseButton,
Mut,
Query,
Res,
Schedule,
+ Sprite,
Time,
Transform,
} from 'esengine';
@@ -45,8 +49,26 @@ const pointer = defineSystem(
},
);
+// A material parameter driven from a system: at run time the component's
+// `material` field IS the handle setUniform takes, which is the half of this the
+// brief has to say out loud — it reads like an asset ref everywhere else.
+const dissolve = defineSystem([Query(Sprite), Res(Time)], (q, time) => {
+ for (const [, sprite] of q) {
+ Material.setUniform(sprite.material, 'u_amount', Math.sin(time.elapsed));
+ }
+});
+
+// Mesh geometry: not a component field, uploaded through the resource.
+const mesh = defineSystem([Query(Mesh2D), Res(Meshes2D)], (q, meshes) => {
+ for (const [entity] of q) {
+ meshes.setGeometry(entity, { positions: [0, 0, 32, 0, 0, 32], indices: [0, 1, 2] });
+ }
+});
+
// The binding builder the brief distinguishes from the raw button number.
export const leftClickBinding = MouseButton(0);
addSystemToSchedule(Schedule.Update, drift);
addSystemToSchedule(Schedule.Update, pointer);
+addSystemToSchedule(Schedule.Update, dissolve);
+addSystemToSchedule(Schedule.Update, mesh);