diff --git a/viewer/README.md b/viewer/README.md index 92b6501..3fb0264 100644 --- a/viewer/README.md +++ b/viewer/README.md @@ -59,9 +59,12 @@ sidecars together (do not upload only the entry bundle). ## Tutorials on BGS Upload the same JS, CSS and locale sidecars as the ordinary viewer. The `container` global exposes -both `launch` and `launchTutorial`. Chapter metadata is exported as `chapterCards` -from `src/tutorial/lessons.ts`; enter these IDs, versions, titles and descriptions -in the BGS version's Tutorial settings. +both `launch` and `launchTutorial`. Complete BGS metadata is exported as `tutorialCatalog` +from `src/tutorial/lessons.ts` (`chapterSections` and `chapterCards` are also exported). +Save that payload in the BGS version's Tutorial settings, including the `sections` +array and each chapter's `section`. The six original chapters belong to **Base game**; +the three bank chapters belong to **Offshore Island**. Preserve chapter IDs and +versions when changing grouping so existing progress stays associated with its lesson. Lessons run the real engine locally with deterministic opponents and private player views. The extra lesson controls make drag actions accessible on mobile. diff --git a/viewer/scripts/offshore-smoke.mjs b/viewer/scripts/offshore-smoke.mjs index 8b8a69f..37a2ec4 100644 --- a/viewer/scripts/offshore-smoke.mjs +++ b/viewer/scripts/offshore-smoke.mjs @@ -42,6 +42,24 @@ const browser = await chromium.launch({ executablePath: process.env.CHROMIUM_EXE try { for (const width of [390, 1400]) { const page = await browser.newPage({ viewport: { width, height: 900 } }); + await page.addInitScript(() => { + window.cargoAnimations = []; + const animate = Element.prototype.animate; + Element.prototype.animate = function (frames, options) { + if (options?.duration === 320 && this.hasAttribute('data-piece-id')) { + window.cargoAnimations.push({ + id: this.getAttribute('data-piece-id'), + frames, + copies: [...document.querySelectorAll('[data-piece-id]')].filter( + (node) => + node.getAttribute('data-piece-id') === this.getAttribute('data-piece-id') && + !node.closest('.bank-lot-draft') + ).length, + }); + } + return animate.call(this, frames, options); + }; + }); const errors = []; page.on('pageerror', (e) => errors.push(e.message)); page.on('console', (msg) => { @@ -303,7 +321,8 @@ try { ); await page.evaluate((player) => host.emit('player', { index: player }), player); await push(); - await page.getByRole('button', { name: 'Return at $3', exact: true }).click(); + await page.locator('.bank-choice [data-piece-id]').click(); + await page.getByRole('button', { name: 'Return to factory store at $3', exact: true }).click(); const repricing = await page.evaluate(() => moves.at(-1)); assert.equal(repricing.length, 1, 'interruption is not appended to the previous bid buffer'); state = engine.move(state, repricing[0], player); @@ -539,6 +558,18 @@ 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); + const cargoAnimations = await page.evaluate(() => window.cargoAnimations); + assert.ok(cargoAnimations.length >= 4, 'bank transfers animate physical cargo'); + assert.ok( + cargoAnimations.every((animation) => animation.copies === 1), + 'no duplicate animated cargo' + ); + assert.ok( + cargoAnimations.every((animation) => + animation.frames.every((frame) => !/NaN|Infinity/.test(frame.transform)) + ), + 'SVG motion matrices remain finite' + ); assert.deepEqual(errors, []); await page.close(); console.log( diff --git a/viewer/scripts/tutorial-smoke.mjs b/viewer/scripts/tutorial-smoke.mjs index ca1dba6..43283fa 100644 --- a/viewer/scripts/tutorial-smoke.mjs +++ b/viewer/scripts/tutorial-smoke.mjs @@ -96,8 +96,10 @@ async function playOnBoard(page, move) { } return; } - if (move.name === 'returnBankContainer') - return page.getByRole('button', { name: `Return at $${move.extraData.price}`, exact: true }).click(); + if (move.name === 'returnBankContainer') { + await page.locator(`.bank-choice [data-piece-id="${move.data.id}"]`).click(); + return page.locator(`.bank-return-destination[data-price="${move.extraData.price}"]`).click(); + } if (move.name === 'distributeBankContainer') return page.locator(`.bank-choice [data-piece-id="${move.data.id}"]`).click(); if (move.name === 'loadBankContainer') diff --git a/viewer/src/components/Game.vue b/viewer/src/components/Game.vue index 243dae7..5b36938 100644 --- a/viewer/src/components/Game.vue +++ b/viewer/src/components/Game.vue @@ -212,6 +212,8 @@ + + + {{ 'Return to ' + bankReturnCargo.district + ' store at $' + price }} + + + item.type === 'move' && isEqual(item.move, this.turnMoves[i])); } + private offshoreMotion = new OffshoreMotion(); + + beforeDestroy() { + this.offshoreMotion.destroy(); + } + replaceState(state: GameState) { + this.offshoreMotion.transition(this.$el, this.G, state, (callback) => this.$nextTick(callback)); this.ui.selected = null; this.G = JSON.parse(JSON.stringify(state)); @@ -1606,10 +1641,48 @@ export default class Game extends Vue { @Watch('player') @Watch('interactionDisabled') resetBankDraft() { + this.selectedBankReturn = null; this.bankDraft = null; this.offshoreContainers = new Set(); this.bankBidError = false; } + selectedBankReturn: string | null = null; + get bankReturnCargo() { + const decision = this.G?.offshoreBank?.decision; + if (!this.canMove || decision?.kind !== 'return') return undefined; + return decision.containers.find( + (c) => + c.container.piece.id === this.selectedBankReturn && + this.getCurrentPlayerMoves()[MoveName.ReturnBankContainer]?.some( + (piece) => piece.id === c.container.piece.id + ) + ); + } + get bankReturnPrices() { + const cargo = this.bankReturnCargo; + if (!cargo) return []; + return [1, 2, 3, 4, 5, 6].filter((price) => + legalBankAction(this.G!, this.player, { + name: MoveName.ReturnBankContainer, + data: cargo.container.piece, + extraData: { price }, + }) + ); + } + selectBankReturn(id: string) { + this.selectedBankReturn = id; + if (this.bankReturnCargo) { + this.viewPlayerBoard(this.player!); + this.$nextTick(() => (this.$el.querySelector('.bank-return-destination') as SVGElement)?.focus?.()); + } + } + returnBankContainer(price: number) { + const cargo = this.bankReturnCargo; + if (!cargo || !this.bankReturnPrices.includes(price)) return; + this.sendBankMove({ name: MoveName.ReturnBankContainer, data: cargo.container.piece, extraData: { price } }); + this.selectedBankReturn = null; + this.viewBank(); + } bankDraft: { type: 'cash' | 'containers'; lot: number } | null = null; bankBidError = false; offshoreContainers = new Set(); @@ -2788,3 +2861,15 @@ text { } } + + diff --git a/viewer/src/components/OffshoreBank.vue b/viewer/src/components/OffshoreBank.vue index 7bbee0a..b73d96c 100644 --- a/viewer/src/components/OffshoreBank.vue +++ b/viewer/src/components/OffshoreBank.vue @@ -190,9 +190,9 @@ - {{ decisionTitle }} + {{ decisionTitle }} -