Files
feuerwerk/tests/editor/scene-visibility.test.ts
T
adminandClaude Opus 5.5 7dd3ae1131
game-maker / gate (push) Successful in 3m19s
game-maker / suite (push) Failing after 11m41s
Tie two objects with a hinge, a spring, a rope or for good (#154)
Two bodies could not be connected: no door on a hinge, no lamp on
a rope, no wheel on an axle. This is the first step of the issue,
the four joints without a motor. The slider and the motors follow
in a second step under the same issue.

- Joint is a new asset type, placed as a child of the object it
  holds, like a collider or a rigidbody. "Add joint…" in the
  object menu makes one or places one the project has. An object
  takes as many as it needs.
- Where the joint sits is the point it holds its object at. A
  hinge and a fixed joint have that one point only. A spring and a
  rope end at a connected anchor on the other object, counted in
  that object's own units, or in the scene's without one.
- The rows follow the type: length, stiffness and damping for a
  spring, length for a rope, an angle limit for a hinge. Length 0
  takes the distance the two ends were placed at. The limit counts
  from how the two were placed.
- The connected object is an object reference in the schema of the
  type. Pasting, containers and removing treat it as they treat
  every reference since #258.
- shownFor is a new schema option: a row is shown while an enum of
  the same bag holds one of the named values.
- The object needs a rigidbody, its own or one further up. Without
  one the joint holds nothing and the console says so once.
- A connected object without a rigidbody is a moving anchor: the
  joint has a kinematic body of its own that follows it.
- A connected object destroyed while playing makes the joint let go
  with a hint. Removed in the editor the reference empties, so the
  joint holds on to the scene. The issue asked for "inactive" there.
- "Add joint" ties two objects while the game runs, from a joint
  asset as the template. Destroy on the joint lets go, there is no
  Break joint node. Destroy with keep children takes the joints
  along with the object.
- The scene view draws a line from each joint to what it holds on
  to and rings the held point. A selected spring or rope has a
  round handle on its far end, and dragging it is one undo step.
- Joints hold in Play only. The editor run simulates nothing
  (#148), and the inspector of a placed joint says so.
- Rapier counts a revolute joint's limits absolutely, not from the
  start, so the placed angle is added. Measured with a probe.
- The + menu has 25 types now and no longer fits under its button
  on a canvas 800 high. It scrolls there, and e2e 04 scrolls to
  the last entry instead of expecting it in view.

Tests:
- Gate on melektaus-atx for this state: 218 files, 3390 tests
  (3336 + 54), exit 0.
- e2e 1-16,24,39-46,51,52,57,58 on melektaus-atx: 831 checks, all
  pass. Module 41 alone: 25 checks (21 + 4).
- 54 new unit tests: 40 in joints.test.ts (rope, spring, pendulum,
  limit, fixed, the other end, the node, containers, paste), 6 for
  the line the scene view draws, 4 catalog cases of the node. The
  remaining 4 come from tests that make a case per asset type.
- Four new e2e checks in module 41: Add joint from the menu, the
  rope to the hook with its line and handle, dragging the handle
  with one undo, the bob hanging in Play next to one that falls.
- e2e 04, 40 and 46 count the new type in their lists.
- 21 of 22 unit counter-probes fail their tests. The other one is
  equivalent: Rapier ignores removing a joint that left with its
  body, the guard stays.
- Three browser counter-probes fail their checks (2, 1 and 2).
- One screenshot looked at: icon, line, handle and the rope rows.
- The e2e sum of 1691 is counted (1687 + 4, 1687 measured by CI
  on e066613). The full suite and the smokes did not run.
- Not seen in the browser: spring, hinge with limit and fixed
  joint, the node Add joint, a connected object that moves, joints
  inside a container, the released game. Unit tests cover them
  but the last. Limits under a mirrored parent are not handled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-02 21:43:12 +02:00

111 lines
4.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* What the scene view shows of each placeable type – symbol, name, a collider's outline. It lives
* in the project like the game scale: saved, but never an undo step.
*/
import { describe, expect, it } from 'vitest';
import { createEmptyProject } from '../../src/core/model/Project';
import {
defaultSceneVisibility,
sceneVisibilityOf,
shows,
VISIBILITY_TYPES,
visibilityParts,
} from '../../src/core/model/sceneVisibility';
import { deserializeProject, serializeProject } from '../../src/core/store/serialize';
import { EditorState } from '../../src/editor/state';
function loaded() {
const state = new EditorState();
state.loadProject(createEmptyProject('p', 'P'), 1);
return state;
}
describe('scene visibility', () => {
it('lists every placeable type, Behavior to Tilemap', () => {
expect(VISIBILITY_TYPES).toEqual([
'behavior',
'camera',
'clip',
'collider',
'container',
'joint',
'particles',
'rigidbody',
'sprite',
'text',
'tilemap',
]);
});
it('gives a symbol switch only to types with a symbol, and an outline switch to what collides', () => {
expect(visibilityParts('behavior')).toEqual(['symbol', 'label']);
expect(visibilityParts('collider')).toEqual(['symbol', 'label', 'shape']);
expect(visibilityParts('sprite')).toEqual(['label']);
expect(visibilityParts('tilemap')).toEqual(['label', 'shape']);
});
it('shows what it always showed in a new project and in one written before there was any', () => {
for (const visibility of [
createEmptyProject('p', 'P').sceneVisibility,
deserializeProject({ id: 'p', name: 'P', assets: [] }).sceneVisibility,
]) {
expect(shows(visibility, 'behavior', 'symbol')).toBe(true);
expect(shows(visibility, 'behavior', 'label')).toBe(true);
expect(shows(visibility, 'collider', 'shape')).toBe(true);
expect(shows(visibility, 'tilemap', 'shape')).toBe(true);
expect(shows(visibility, 'sprite', 'label')).toBe(false);
expect(shows(visibility, 'sprite', 'shape')).toBe(true);
}
});
it('survives a save and a load', () => {
const project = createEmptyProject('p', 'P');
project.sceneVisibility.collider.shape = false;
project.sceneVisibility.tilemap.shape = false;
project.sceneVisibility.rigidbody.label = false;
project.sceneVisibility.sprite.label = true;
const back = deserializeProject(JSON.parse(JSON.stringify(serializeProject(project)))).sceneVisibility;
expect(back.collider.shape).toBe(false);
expect(back.tilemap.shape).toBe(false);
expect(back.rigidbody.label).toBe(false);
expect(back.sprite.label).toBe(true);
expect(back.behavior).toEqual(defaultSceneVisibility().behavior);
});
it('reads untrusted JSON part by part, the rest as the defaults', () => {
const read = sceneVisibilityOf({
sceneVisibility: { camera: { symbol: false, label: 'no' }, texture: { label: true }, text: 3 },
});
expect(read.camera).toEqual({ symbol: false, label: true, shape: true });
expect(read.text).toEqual(defaultSceneVisibility().text);
expect('texture' in read).toBe(false);
expect(sceneVisibilityOf(null)).toEqual(defaultSceneVisibility());
});
it('never hides what a type does not have to hide', () => {
const visibility = defaultSceneVisibility();
visibility.sprite.symbol = false;
visibility.sprite.shape = false;
expect(shows(visibility, 'sprite', 'shape')).toBe(true);
visibility.behavior.shape = false;
expect(shows(visibility, 'behavior', 'shape')).toBe(true);
});
it('saves a switch without an undo step', () => {
const state = loaded();
state.setSceneVisibility('collider', 'shape', false);
expect(state.project.sceneVisibility.collider.shape).toBe(false);
expect(state.saveStatus).toBe('dirty');
expect(state.commands.canUndo).toBe(false);
});
it('keeps a switch flipped while playing after Stop', () => {
const state = loaded();
state.enterPlay();
state.setSceneVisibility('behavior', 'label', false);
expect(state.project.sceneVisibility.behavior.label).toBe(false);
state.exitPlay();
expect(state.project.sceneVisibility.behavior.label).toBe(false);
});
});