Files
feuerwerk/tests/editor/animation-strip.test.ts
T
rootandClaude Opus 5 1135bf4562 Play sprite animations from an animation asset worn through texture
An animation asset is a list of pictures (whole textures or frames) with
frames per second and Loop/Once/Ping-pong playback. A sprite wears it
through its texture property, so the picker, instance overrides and the
Properties node work unchanged; there is no dedicated play node.

A different animation starts from its first frame, the same one set again
runs on, so a graph may choose Run or Idle every frame. The clock lives on
the entity, not in props, which the world writes back as overrides. The
AnimationSystem ticks before behaviors, and On animation finished fires
once when a Once animation reaches its end.

The Animation tab plays a preview above a frame strip: reorder by dragging,
Delete, duplicate, + Frames, pause/resume, and wheel zoom about the pointer
with pan and Fit. Scene and Container tabs show the first frame; edit mode
has no clock. Right-clicking a texture creates an animation from its frames.

Button now measures its label with the bold font it draws in, which cut
the Animation tab and red dialog buttons short.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-11 23:52:34 +02:00

39 lines
1.3 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import {
gapAt,
maxScroll,
moveTarget,
STRIP_PAD,
TILE,
TILE_GAP,
tileIndexAt,
} from '../../src/editor/animation/strip';
const STEP = TILE + TILE_GAP;
describe('the frame strip', () => {
it('finds the tile under the pointer, and none in the gaps or past the last', () => {
const at = (x: number) => tileIndexAt(x, 3, 0);
expect([at(STRIP_PAD), at(STRIP_PAD + TILE), at(STRIP_PAD + STEP + 1)]).toEqual([0, 0, 1]);
expect([at(STRIP_PAD - 1), at(STRIP_PAD + TILE + 2), at(STRIP_PAD + 3 * STEP + 1)]).toEqual([-1, -1, -1]);
expect(tileIndexAt(STRIP_PAD + 1, 3, STEP)).toBe(1);
});
it('drops into the gap nearest to the pointer', () => {
const gap = (x: number) => gapAt(x, 3, 0);
expect([gap(0), gap(STRIP_PAD + TILE / 2 - 1), gap(STRIP_PAD + TILE / 2 + 1), gap(9999)]).toEqual([
0, 0, 1, 3,
]);
});
it('turns a gap into the index the frame ends up at, and a drop beside itself into nothing', () => {
expect([moveTarget(0, 0), moveTarget(0, 1)]).toEqual([null, null]);
expect([moveTarget(0, 3), moveTarget(2, 0), moveTarget(1, 3)]).toEqual([2, 0, 2]);
});
it('scrolls only as far as the last tile needs', () => {
expect(maxScroll(2, 500)).toBe(0);
expect(maxScroll(10, 300)).toBe(STRIP_PAD * 2 + 10 * TILE + 9 * TILE_GAP - 300);
});
});