forked from Blendman974/faceclaw
Optimize on-glasses animation
This commit is contained in:
1 parent
c8d835176f
commit
08f1b9a2a2
8 files changed
+94
-46
No files matched your search
@@ -1,8 +1,8 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { MenuHighlightMotion } = require('../.test-build/app/ui/menu-highlight-motion.js');
|
||||
const { MenuHighlightMotion, MENU_HIGHLIGHT_DURATION_MS } = require('../.test-build/app/ui/menu-highlight-motion.js');
|
||||
const { GrayImage } = require('../.test-build/app/graphics/image.js');
|
||||
const { encodePresentation, readPresentation } = require('../.test-build/app/graphics/presentation-wire.js');
|
||||
const { encodePresentation, readPresentation, paintPresentation } = require('../.test-build/app/graphics/presentation-wire.js');
|
||||
|
||||
test('highlight animates only navigation that preserves the scroll window', () => {
|
||||
const motion = new MenuHighlightMotion();
|
||||
@@ -11,9 +11,10 @@ test('highlight animates only navigation that preserves the scroll window', () =
|
||||
const moved = motion.paint(1, 0, 10, 40, 100, 20, 100);
|
||||
assert.equal(moved.dx, 0);
|
||||
assert.equal(moved.dy, -20);
|
||||
assert.equal(motion.paint(1, 0, 10, 40, 100, 20, 350).token, moved.token);
|
||||
assert.equal(moved.durationMs, 300);
|
||||
assert.equal(motion.paint(1, 0, 10, 40, 100, 20, 250).token, moved.token);
|
||||
motion.navigate(1, false);
|
||||
const next = motion.paint(2, 0, 10, 60, 100, 20, 350);
|
||||
const next = motion.paint(2, 0, 10, 60, 100, 20, 250);
|
||||
assert.equal(next.dy, -30, 'continue from the halfway position');
|
||||
motion.navigate(2, false);
|
||||
assert.equal(motion.paint(3, 1, 10, 60, 100, 20, 400), undefined, 'scroll snaps');
|
||||
@@ -21,23 +22,45 @@ test('highlight animates only navigation that preserves the scroll window', () =
|
||||
assert.equal(motion.paint(0, 0, 10, 20, 100, 20, 500), undefined, 'wrap snaps');
|
||||
motion.navigate(0, false);
|
||||
motion.paint(1, 0, 10, 40, 100, 20, 600);
|
||||
assert.equal(motion.paint(1, 0, 10, 40, 100, 20, 1100), undefined, 'finished after 500 ms');
|
||||
assert.ok(motion.paint(1, 0, 10, 40, 100, 20, 899));
|
||||
assert.equal(motion.paint(1, 0, 10, 40, 100, 20, 900), undefined, 'finished after 300 ms');
|
||||
assert.equal(motion.paint(2, 0, 10, 60, 100, 20, 1200), undefined, 'programmatic changes snap');
|
||||
});
|
||||
|
||||
test('bridge and fallback preview use the supplied animation duration', () => {
|
||||
const now = Date.now;
|
||||
Date.now = () => 1050;
|
||||
try {
|
||||
const image = new GrayImage(8, 2);
|
||||
image.drawMenuSelection(new GrayImage(2, 2), 5, 0, 0, 255, 0, 0,
|
||||
{ dx: -4, dy: 0, startedAt: 1000, token: 1, durationMs: 100 });
|
||||
const record = readPresentation(encodePresentation(image.draws[0]), 0);
|
||||
assert.equal(record.selection.animation.durationMs, 100);
|
||||
const screen = new Uint8Array(16), output = new Uint8Array(16);
|
||||
paintPresentation(output, screen, 8, 2, record.selection);
|
||||
assert.equal(output[3], 240, 'halfway at 50 ms');
|
||||
assert.equal(output[1], 0);
|
||||
Date.now = () => 1100;
|
||||
output.fill(0);
|
||||
paintPresentation(output, screen, 8, 2, record.selection);
|
||||
assert.equal(output[5], 240, 'complete at 100 ms');
|
||||
assert.equal(output[3], 0);
|
||||
} finally { Date.now = now; }
|
||||
});
|
||||
|
||||
test('animated selection bridge carries relative start, elapsed time and stable token', () => {
|
||||
const now = Date.now;
|
||||
Date.now = () => 1200;
|
||||
try {
|
||||
const image = new GrayImage(8, 4);
|
||||
image.drawMenuSelection(new GrayImage(2, 2, 255), 3, 2, 16, 48, 1, 2,
|
||||
{ dx: -2, dy: -4, startedAt: 1000, token: 42 });
|
||||
{ dx: -2, dy: -4, startedAt: 1000, token: 42, durationMs: MENU_HIGHLIGHT_DURATION_MS });
|
||||
const bytes = encodePresentation(image.draws[0]);
|
||||
assert.equal(bytes[0], 6);
|
||||
assert.equal(bytes.length, 30);
|
||||
assert.equal(bytes.length, 32);
|
||||
const record = readPresentation(bytes, 0);
|
||||
assert.equal(record.end, bytes.length);
|
||||
assert.deepEqual(record.selection.animation, { dx: -2, dy: -4, startedAt: 1000, token: 42 });
|
||||
assert.deepEqual(record.selection.animation, { dx: -2, dy: -4, startedAt: 1000, token: 42, durationMs: MENU_HIGHLIGHT_DURATION_MS });
|
||||
assert.equal(record.selection.x, 3);
|
||||
assert.equal(record.selection.y, 2);
|
||||
} finally { Date.now = now; }
|
||||
|
||||
Reference in new issue
Block a user