Files
VibemakerSandbox/app/test/arena-presentation.test.js
chenlin fc5ee4f2c6 feat: release v0.2 multi-robot simulator
Add declarative robot packages, shared simulation lifecycle and Microban ONNX/PD walking with independent head control.

Unify comic UI and chase camera; default robot packages to a 4.5m arena with real collision walls. Include regression tests, asset provenance/licenses and verification evidence.
2026-10-28 14:00:26 +08:00

84 lines
2.7 KiB
JavaScript

import test from "node:test";
import assert from "node:assert/strict";
import * as THREE from "three";
import { createArenaFloorPresentation } from "../src/game/worlds/arena/presentation.js";
import { makeInfiniteGrid } from "../src/game/worlds/arena/render.js";
import { validateWorld } from "../src/platform/loader/SchemaValidator.js";
const fixture = () => {
const mesh = new THREE.Mesh();
return {
mesh,
sim: {
model: {
geom(name) {
assert.equal(name, "platform_floor");
return { id: 7 };
},
},
},
rig: { items: [{ id: 7, mesh }] },
};
};
test("arena presentation reuses Microduck grid colours/spacing, but stays flat and replaces only the floor visual", () => {
const { mesh, sim, rig } = fixture(),
view = createArenaFloorPresentation({ sim, rig }),
u = view.grid.material.uniforms;
assert.equal(mesh.visible, false);
assert.equal(u.uCell.value, 0.1);
assert.equal(u.uSection.value, 0.6);
assert.equal(u.uSectionColor.value.getHex(), 0xffb366);
assert.equal(u.uCellColor.value.getHex(), 0x8e8371);
assert.equal(u.uReveal.value, 1);
assert.equal(u.uTopoScale.value, 0);
assert.equal(view.grid.geometry.attributes.position.count, 4);
const p = new THREE.Vector3(12, 0.17, -5);
view.update(p);
assert.equal(view.grid.position.x, 12);
assert.equal(view.grid.position.z, -5);
assert.equal(view.grid.position.y, 0);
assert.ok(u.uFocus.value.equals(p));
let releases = 0;
view.grid.geometry.addEventListener("dispose", () => releases++);
view.grid.material.addEventListener("dispose", () => releases++);
const parent = new THREE.Group();
parent.add(view.root);
view.dispose();
view.dispose();
assert.equal(releases, 2);
assert.equal(mesh.visible, true);
assert.equal(parent.children.length, 0);
});
test("Microduck relief geometry remains unchanged by default; flat presentation explicitly opts out", () => {
const grid = makeInfiniteGrid();
assert.equal(grid.geometry.attributes.position.count, 257 * 257);
assert.equal(grid.material.uniforms.uReveal.value, 0);
grid.geometry.dispose();
grid.material.dispose();
});
test("World presentation style is validated, not a remote script or a physics adapter", () => {
const world = {
schema: 1,
id: "test",
type: "flat",
presentation: "arena-grid",
floor: { rgba: [0.22, 0.27, 0.33, 1], friction: [1, 0.005, 0.0001] },
};
validateWorld(world);
assert.throws(
() =>
validateWorld({ ...world, presentation: "https://untrusted/script.js" }),
/world.json/,
);
assert.throws(
() =>
validateWorld({
schema: 1,
id: "bad",
type: "adapter",
adapter: "arena",
presentation: "arena-grid",
}),
/flat/,
);
});