A shader so far worked only on its own wearer. Effects over the whole game picture, such as a vignette, grey, scanlines or a red flash on a hit, had no place to live. A camera now wears one, drawn the way a field shader of a particle source is (#170). - The camera gets a Shader row and, while one is picked, a Shader resolution row. The shader's properties follow as camera rows. They load, animate and appear in a Properties node under Type Camera. - Every view keeps masks and objects in one container. CameraShade renders it into the camera's picture, cleared to the background, and draws the shader over the frame. Game tab and play.html take the container off the stage while the picture stands in for it. - Screen pixels gives the picture as many pixels as it covers on screen. Camera pixels uses View width x View height and scales up without smoothing. - A pixel counts as a camera pixel in both (the user's choice). The uniform uPixelScale makes Texture size read View width x View height, so a Blur keeps its reach at any game scale. - Each camera wears its own shader, overlay cameras included. A red flash on the game camera leaves the HUD of an overlay camera alone. - The scene view's eye has a Shader switch on the Camera row, off by default. With it on, the main camera's shader lies over its frame, below symbols and gizmos, and the world around it stays drawn. - New tool tools/perf-camera-shader.mjs measures the cost. Measured on stein2 (HD 630, Game tab at Fit 1310x679): a camera shader that hands the picture through stays inside the scene's own spread of 3 to 5 fps between runs. A Blur of 4 cost 4 to 8 fps. Tests: - Gate on melektaus-atx: 227 files, 3497 tests (3487 + 10). - e2e 63 alone: 11 checks (6 + 5), e2e sum 1725 counted. - 63e-63i: pass-through is byte-equal and upright at 100%, flat red reaches the corners while the overlay keeps its green, Texture size reads 640 x 360 in both resolutions at Fit, no shader draws as before, and the scene view shows it only with the switch on. - Counter-checks: a camera left out of the shader wearers fails 1 unit test. Counting screen pixels fails 63g with #ab6000. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
183 lines
8.1 KiB
TypeScript
183 lines
8.1 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
||
import { ASSET_TYPES } from '../../src/core/model/AssetTypes';
|
||
import { DECLARED_PORT_KINDS, FIELD_KINDS, kindMark, VARIABLE_KINDS } from '../../src/core/properties/kinds';
|
||
import {
|
||
ASSET_ICON_SVG,
|
||
GAME_ICON_SVG,
|
||
GROUP_ICON_SVG,
|
||
LIST_ICON_SVG,
|
||
PLUGINS_ICON_SVG,
|
||
USERS_ICON_SVG,
|
||
} from '../../src/editor/panels/assetIcons';
|
||
import { HEADER_ICON_SVG } from '../../src/editor/panels/headerIcons';
|
||
import { ARROW_ICON_SVG, KIND_ICON_SVG, ROW_ACTION_ICON_SVG } from '../../src/editor/panels/markIcons';
|
||
import { TOOLBAR_ICON_SVG, VISIBILITY_ICON_SVG } from '../../src/editor/panels/toolbarIcons';
|
||
import { UI_ICON_SVG } from '../../src/ui/icons';
|
||
import { tintSvg } from '../../src/ui/svg';
|
||
import { SYMBOL_SVG } from '../../src/viewport/symbolIcons';
|
||
|
||
/** Opening tags as name + attributes; the files are flat, so no real XML parser is needed. */
|
||
function tags(svg: string): { name: string; attrs: Record<string, string> }[] {
|
||
return [...svg.matchAll(/<([a-z]+)([^>]*?)\/?>/g)].map(([, name, rest]) => ({
|
||
name: name!,
|
||
attrs: Object.fromEntries([...rest!.matchAll(/([a-zA-Z-]+)="([^"]*)"/g)].map(([, k, v]) => [k!, v!])),
|
||
}));
|
||
}
|
||
|
||
describe('icon files', () => {
|
||
it('has a scene view symbol for every symbol (#175)', () => {
|
||
expect(Object.keys(SYMBOL_SVG).sort()).toEqual([
|
||
'behavior',
|
||
'camera',
|
||
'collider',
|
||
'container',
|
||
'joint',
|
||
'particles',
|
||
'rigidbody',
|
||
]);
|
||
});
|
||
|
||
it('has an asset panel icon for every asset type, each its own picture (#176)', () => {
|
||
expect(Object.keys(ASSET_ICON_SVG).sort()).toEqual([...ASSET_TYPES].sort());
|
||
expect(new Set(Object.values(ASSET_ICON_SVG)).size).toBe(ASSET_TYPES.length);
|
||
});
|
||
|
||
const icons = [
|
||
...Object.entries(SYMBOL_SVG).map(([name, svg]) => [`symbol ${name}`, svg]),
|
||
...Object.entries(ASSET_ICON_SVG).map(([name, svg]) => [`asset ${name}`, svg]),
|
||
['list tab', LIST_ICON_SVG],
|
||
['game tab', GAME_ICON_SVG],
|
||
['hierarchy group', GROUP_ICON_SVG],
|
||
['plugins tab', PLUGINS_ICON_SVG],
|
||
['user management tab', USERS_ICON_SVG],
|
||
...Object.entries(TOOLBAR_ICON_SVG).map(([name, svg]) => [`toolbar ${name}`, svg]),
|
||
...Object.entries(VISIBILITY_ICON_SVG).map(([name, svg]) => [`visibility ${name}`, svg]),
|
||
...Object.entries(HEADER_ICON_SVG).map(([name, svg]) => [`header ${name}`, svg]),
|
||
...Object.entries(UI_ICON_SVG).map(([name, svg]) => [`ui ${name}`, svg]),
|
||
...Object.entries(KIND_ICON_SVG).map(([name, svg]) => [`kind ${name}`, svg]),
|
||
...Object.entries(ROW_ACTION_ICON_SVG).map(([name, svg]) => [`row action ${name}`, svg]),
|
||
...Object.entries(ARROW_ICON_SVG).map(([name, svg]) => [`arrow ${name}`, svg]),
|
||
];
|
||
|
||
// The symbols that were characters until #214: the font the editor ships has no such glyphs.
|
||
it('marks every kind a user can pick once – by a picture, or by letters where it has none (#214)', () => {
|
||
const picked = [...new Set([...VARIABLE_KINDS, ...FIELD_KINDS, ...DECLARED_PORT_KINDS])];
|
||
const marks = picked.map((kind) => {
|
||
const icon = KIND_ICON_SVG[kind];
|
||
const letters = kindMark(kind);
|
||
expect(Boolean(icon) !== Boolean(letters), `${kind}: a picture or letters, not both`).toBe(true);
|
||
return icon ?? letters;
|
||
});
|
||
expect(new Set(marks).size).toBe(picked.length);
|
||
});
|
||
|
||
// A test finds a picture by the id of its file (`locateIcon`), so every id names one file.
|
||
it('names each picture a test looks for after its own file (#214)', () => {
|
||
const named = icons.map(([, svg]) => tags(svg!)[0]!.attrs.id).filter((id) => id !== undefined);
|
||
expect(new Set(named).size).toBe(named.length);
|
||
for (const svg of [
|
||
...Object.values(UI_ICON_SVG),
|
||
...Object.values(KIND_ICON_SVG),
|
||
...Object.values(ROW_ACTION_ICON_SVG),
|
||
...Object.values(ARROW_ICON_SVG),
|
||
])
|
||
expect(tags(svg)[0]!.attrs.id).toBeDefined();
|
||
});
|
||
|
||
// The magnet stands alone in the header, without the "Snap" it replaced (#194): a picture another
|
||
// button already wears would say that button's thing.
|
||
it('draws the snap switch as a magnet of its own, bent without arcs (#194)', () => {
|
||
const others = [
|
||
...Object.values(ASSET_ICON_SVG),
|
||
...Object.values(TOOLBAR_ICON_SVG),
|
||
LIST_ICON_SVG,
|
||
GAME_ICON_SVG,
|
||
PLUGINS_ICON_SVG,
|
||
];
|
||
expect(others).not.toContain(HEADER_ICON_SVG.snap);
|
||
expect(HEADER_ICON_SVG.snap).toContain('C');
|
||
for (const { attrs } of tags(HEADER_ICON_SVG.snap).slice(1)) expect(attrs.d ?? '').not.toMatch(/[Aa]/);
|
||
});
|
||
|
||
it('has one icon per button of the top bar, each its own picture (#183)', () => {
|
||
expect(Object.keys(TOOLBAR_ICON_SVG).sort()).toEqual([
|
||
'eye',
|
||
'menu',
|
||
'pause',
|
||
'play',
|
||
'redo',
|
||
'stop',
|
||
'undo',
|
||
]);
|
||
expect(new Set(Object.values(TOOLBAR_ICON_SVG)).size).toBe(7);
|
||
});
|
||
|
||
it('has one picture per switch behind the eye', () => {
|
||
expect(Object.keys(VISIBILITY_ICON_SVG).sort()).toEqual(['label', 'shader', 'shape', 'symbol']);
|
||
expect(new Set(Object.values(VISIBILITY_ICON_SVG)).size).toBe(4);
|
||
});
|
||
|
||
// The bar carries no captions any more, so a picture shared with a tab or an asset type would be
|
||
// the only thing left telling the two apart – and it would not.
|
||
it('draws the top bar in pictures of its own, none of them an asset icon (#183)', () => {
|
||
const others = [...Object.values(ASSET_ICON_SVG), LIST_ICON_SVG, GAME_ICON_SVG, PLUGINS_ICON_SVG];
|
||
for (const svg of Object.values(TOOLBAR_ICON_SVG)) expect(others).not.toContain(svg);
|
||
});
|
||
|
||
// Pixi's parser draws an A in the middle of a path as a spike (the puzzle piece of #119); undo
|
||
// and redo are the arcs of this set, so they are the ones that have to keep clear of it.
|
||
it('bends the top bar arrows with cubic curves rather than arcs (#183)', () => {
|
||
for (const svg of [TOOLBAR_ICON_SVG.undo, TOOLBAR_ICON_SVG.redo]) {
|
||
expect(svg).toContain('C');
|
||
for (const { attrs } of tags(svg).slice(1)) expect(attrs.d ?? '').not.toMatch(/[Aa]/);
|
||
}
|
||
});
|
||
|
||
// Pixi draws the file's coordinates as they are and ignores the viewBox, so the viewBox only
|
||
// shows the file right elsewhere – centred on the origin, it matches what the editor draws.
|
||
it.each(icons)('%s is centred on its origin', (_, svg) => {
|
||
const root = tags(svg)[0]!;
|
||
expect(root.name).toBe('svg');
|
||
const [x, y, w, h] = root.attrs.viewBox!.split(' ').map(Number);
|
||
expect([x, y]).toEqual([-w! / 2, -h! / 2]);
|
||
expect([Number(root.attrs.width), Number(root.attrs.height)]).toEqual([w, h]);
|
||
});
|
||
|
||
it('draws the asset icons in the 16 units a list row and a button reserve', () => {
|
||
for (const svg of [
|
||
...Object.values(ASSET_ICON_SVG),
|
||
LIST_ICON_SVG,
|
||
GAME_ICON_SVG,
|
||
PLUGINS_ICON_SVG,
|
||
USERS_ICON_SVG,
|
||
])
|
||
expect(tags(svg)[0]!.attrs.viewBox).toBe('-8 -8 16 16');
|
||
});
|
||
|
||
it('gives the List, Game, Plugins and User management tabs a picture no asset type has (#176, #119, #179)', () => {
|
||
const tabs = [LIST_ICON_SVG, GAME_ICON_SVG, PLUGINS_ICON_SVG, USERS_ICON_SVG];
|
||
for (const svg of tabs) expect(Object.values(ASSET_ICON_SVG)).not.toContain(svg);
|
||
expect(new Set(tabs).size).toBe(tabs.length);
|
||
});
|
||
|
||
it.each(icons)('%s uses only what the Pixi parser draws like a browser', (_, svg) => {
|
||
for (const { name, attrs } of tags(svg).slice(1)) {
|
||
// polygon and polyline read their points as whole numbers; groups would carry transforms,
|
||
// which the parser ignores.
|
||
expect(['path', 'circle', 'rect', 'ellipse', 'line']).toContain(name);
|
||
expect(attrs.transform).toBeUndefined();
|
||
// Without a fill a browser fills black, Pixi does not fill at all once there is a stroke.
|
||
expect(attrs.fill, `${name} states its fill`).toBeDefined();
|
||
for (const paint of [attrs.fill, attrs.stroke].filter((p) => p !== undefined))
|
||
expect(paint).toMatch(/^(none|currentColor|#[0-9a-f]{6})$/);
|
||
}
|
||
});
|
||
|
||
it('puts the theme colour where the file says currentColor', () => {
|
||
expect(tintSvg('<path fill="currentColor" stroke="currentColor"/>', 0x0000ff)).toBe(
|
||
'<path fill="#0000ff" stroke="#0000ff"/>',
|
||
);
|
||
for (const [, svg] of icons) expect(tintSvg(svg!, 0xb066ff)).not.toContain('currentColor');
|
||
});
|
||
});
|