Files
feuerwerk/tests/core/project-files.test.ts
T
adminandClaude Opus 5.5 7e829f737e
game-maker / gate (push) Successful in 3m26s
game-maker / suite (push) Failing after 9m6s
Load every picture of a project ahead so animated tiles don't flicker
A texture was fetched only when it was drawn for the first time. Until
the file arrived, the tilemap skipped the cell for that frame. An
animated tile whose next step sat in another picture therefore blinked
away once on its first cycle, and sprite animations did the same.

- FileLibrary gets preload(files). It requests every file that is not
  held, loading or known to have failed. Each library reports what it
  holds through holds().
- src/core/model/projectFiles.ts lists the files a project names per
  library: uploaded textures, fonts and pixel art cels.
- App.ts runs the preload on every project event. That covers opening
  a project, new assets and edits from a collaborator.
- A new test hook __gm.heldPictures() reports which textures of the
  project are in memory.

Not done on purpose:
- The tilemap keeps no fallback frame while a step is still loading.
- Sounds still load on first play.

Not checked: the flicker itself was not reproduced in the browser, the
e2e check measures "held in memory". Modules 42, 44 and 47 read
textures from the project and were not run locally.

Tests:
- ./check.sh: 174 files, 2518 tests, CHECK EXIT 0
- e2e 39 + 40: ALL PASSED, 96 checks
- 3 new unit tests for preload and the project file list
- New e2e check 40k-ii: an unplaced picture is held after a reload
- Counter-probe: without the preload 40k-ii fails with
  "Autotiles: held false, unworn: held false"

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 23:50:49 +02:00

72 lines
2.2 KiB
TypeScript

/**
* What the editor loads ahead of the first draw: every stored file a project's assets name, so an
* animation or an animated tile does not blink out the first time it reaches a frame of its own.
*/
import { describe, expect, it } from 'vitest';
import type { Asset } from '../../src/core/model/Asset';
import { createEmptyProject } from '../../src/core/model/Project';
import { projectFiles } from '../../src/core/model/projectFiles';
const PNG_A = `${'a'.repeat(64)}.png`;
const PNG_B = `${'b'.repeat(64)}.webp`;
const FONT = `${'c'.repeat(64)}.woff2`;
const CEL_A = `${'d'.repeat(64)}.cel`;
const CEL_B = `${'e'.repeat(64)}.cel`;
function projectWith(assets: unknown[]) {
const project = createEmptyProject('p', 'P');
project.assets.push(...(assets as Asset[]));
return project;
}
describe('the files a project names', () => {
it('lists every texture, font and cel, drawn somewhere or not', () => {
const project = projectWith([
{
id: 't1',
type: 'texture',
name: 'Water 1',
props: {},
file: PNG_A,
width: 16,
height: 16,
frames: [],
},
{
id: 't2',
type: 'texture',
name: 'Water 2',
props: {},
file: PNG_B,
width: 16,
height: 16,
frames: [],
},
{ id: 'f', type: 'font', name: 'Font', props: {}, file: FONT },
{
id: 'px',
type: 'pixelart',
name: 'Px',
props: {},
width: 8,
height: 8,
layers: [{ id: 'l', name: 'L', opacity: 1 }],
frames: [
{ id: 'f1', cels: { l: CEL_A } },
{ id: 'f2', cels: { l: CEL_B } },
{ id: 'f3', cels: { l: CEL_A } },
],
},
]);
expect(projectFiles(project)).toEqual({ textures: [PNG_A, PNG_B], fonts: [FONT], cels: [CEL_A, CEL_B] });
});
it('leaves out a name that is no stored file', () => {
const project = projectWith([
{ id: 't', type: 'texture', name: 'Failed', props: {}, file: '', width: 0, height: 0, frames: [] },
{ id: 'f', type: 'font', name: 'Failed', props: {}, file: 'x.woff2' },
]);
expect(projectFiles(project)).toEqual({ textures: [], fonts: [], cels: [] });
});
});