Animate bank settlement into holdings and release viewer 2.1.3
This commit is contained in:
parent
a8022adeef
commit
13bbb63b65
4 changed files with 70 additions and 4 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "container-viewer",
|
||||
"version": "2.1.2",
|
||||
"version": "2.1.3",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/boardgamers/container.git",
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ try {
|
|||
window.cargoAnimations.push({
|
||||
id: this.getAttribute('data-piece-id'),
|
||||
frames,
|
||||
holding: this.closest('.bank-holding')?.getAttribute('data-owner'),
|
||||
copies: [...document.querySelectorAll('[data-piece-id]')].filter(
|
||||
(node) =>
|
||||
node.getAttribute('data-piece-id') === this.getAttribute('data-piece-id') &&
|
||||
|
|
@ -558,6 +559,31 @@ try {
|
|||
}, engine.stripSecret(copy(state)));
|
||||
assert.equal(await page.locator('.bank-holding [data-piece-id][role="button"]').count(), 0);
|
||||
assert.equal(await page.locator('.bank-harbor.canClick').count(), 0);
|
||||
// A real pass settles a cash bid for containers and appends an upkeep event.
|
||||
// Both prize pieces must visibly move from their lot into the winner's holding.
|
||||
state = engine.setup(3, { offshoreIsland: true }, 'offshore-browser');
|
||||
const prizeIds = state.offshoreBank.containerLots[0].map((piece) => piece.id);
|
||||
state = engine.move(
|
||||
state,
|
||||
{ name: 'callBank', data: { type: 'containers', lot: 0 }, extraData: { cash: 1 } },
|
||||
player
|
||||
);
|
||||
for (let i = 0; i < 2; i++) state = engine.move(state, { name: 'pass', data: true }, state.currentPlayers[0]);
|
||||
await page.evaluate((player) => host.emit('player', { index: player }), player);
|
||||
await push();
|
||||
await page.waitForFunction(() => document.querySelectorAll('.bank-holding [data-piece-id]').length === 0);
|
||||
const previousAnimations = await page.evaluate(() => window.cargoAnimations.length);
|
||||
const previousLogLength = state.log.length;
|
||||
state = engine.move(state, { name: 'pass', data: true }, state.currentPlayers[0]);
|
||||
assert.ok(state.log.length > previousLogLength + 1, 'settlement includes event and move');
|
||||
await push();
|
||||
await page.waitForFunction(
|
||||
({ ids, owner, start }) =>
|
||||
ids.every((id) =>
|
||||
window.cargoAnimations.slice(start).some((a) => a.id === id && a.holding === String(owner))
|
||||
),
|
||||
{ ids: prizeIds, owner: player, start: previousAnimations }
|
||||
);
|
||||
const cargoAnimations = await page.evaluate(() => window.cargoAnimations);
|
||||
assert.ok(cargoAnimations.length >= 4, 'bank transfers animate physical cargo');
|
||||
assert.ok(
|
||||
|
|
|
|||
|
|
@ -85,14 +85,18 @@ export class OffshoreMotion {
|
|||
const revision = ++this.revision;
|
||||
const previous = this.locations || cargoLocations(before);
|
||||
const next = cargoLocations(after);
|
||||
const logDelta = (after?.log.length ?? 0) - (this.logLength ?? before?.log.length ?? after?.log.length ?? 0);
|
||||
const previousLogLength = this.logLength ?? before?.log.length ?? after?.log.length ?? 0;
|
||||
const logDelta = (after?.log.length ?? 0) - previousLogLength;
|
||||
// One move can also log upkeep/settlement events. Those effects belong to
|
||||
// the same visible transition, not a history jump across multiple moves.
|
||||
const appendedMoves = after?.log.slice(previousLogLength).filter((entry) => entry.type === 'move').length ?? 0;
|
||||
this.locations = next;
|
||||
this.logLength = after?.log.length;
|
||||
const origins = new Map<string, DOMMatrix>();
|
||||
const oldNodes = new Map<string, SVGGraphicsElement>();
|
||||
const reduced = () => !!this.media?.matches;
|
||||
|
||||
if (root && !reduced() && logDelta >= 0 && logDelta <= 1) {
|
||||
if (root && !reduced() && logDelta >= 0 && appendedMoves <= 1) {
|
||||
visibleCargo(root).forEach((node, id) => {
|
||||
const from = previous.get(id);
|
||||
const to = next.get(id);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { cargoLocations, OffshoreMotion } from '@/offshore-motion';
|
||||
import { setup } from 'container-engine';
|
||||
import { move, setup } from 'container-engine';
|
||||
import { MoveName } from 'container-engine/src/move';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
function fixture() {
|
||||
|
|
@ -47,6 +48,41 @@ describe('offshore physical cargo motion', () => {
|
|||
f.motion.destroy();
|
||||
expect(destination.animation.cancel).toHaveBeenCalledOnce();
|
||||
});
|
||||
it('animates a legal bank-lot settlement with its pass and upkeep event', () => {
|
||||
const f = fixture();
|
||||
const game = f.before;
|
||||
const bidder = game.currentPlayers[0];
|
||||
move(game, { name: MoveName.CallBank, data: { type: 'containers', lot: 0 }, extraData: { cash: 1 } }, bidder);
|
||||
const pass = () => move(game, { name: MoveName.Pass, data: true }, game.currentPlayers[0]);
|
||||
pass();
|
||||
pass();
|
||||
const beforeLength = game.log.length;
|
||||
f.motion.transition(f.root, null, game, f.tick);
|
||||
pass(); // Mutates in place, with one move AND a settlement event.
|
||||
expect(game.log.length - beforeLength).toBeGreaterThan(1);
|
||||
expect(game.log.slice(beforeLength).filter((entry) => entry.type === 'move')).toHaveLength(1);
|
||||
expect(game.players[bidder].bankHolding!.map((piece) => piece.id)).toContain(f.piece.id);
|
||||
f.motion.transition(f.root, game, game, f.tick);
|
||||
const destination = f.node();
|
||||
f.callbacks.forEach((fn) => fn());
|
||||
expect(destination.animate).toHaveBeenCalledOnce();
|
||||
f.motion.destroy();
|
||||
});
|
||||
it('still skips backwards history and jumps over multiple moves', () => {
|
||||
for (const backwards of [false, true]) {
|
||||
const f = fixture();
|
||||
const game = JSON.parse(JSON.stringify(f.before));
|
||||
move(game, { name: MoveName.Pass, data: true }, game.currentPlayers[0]);
|
||||
move(game, { name: MoveName.Pass, data: true }, game.currentPlayers[0]);
|
||||
if (backwards) f.before.log = game.log;
|
||||
else f.after.log = game.log;
|
||||
f.motion.transition(f.root, f.before, f.after, f.tick);
|
||||
const destination = f.node();
|
||||
f.callbacks.forEach((fn) => fn());
|
||||
expect(destination.animate).not.toHaveBeenCalled();
|
||||
f.motion.destroy();
|
||||
}
|
||||
});
|
||||
it('does not animate initial render, layout-only changes or pagination', () => {
|
||||
const f = fixture();
|
||||
f.motion.transition(f.root, null, f.before, f.tick);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue