Use board destinations for bank returns, animate cargo and group lessons
This commit is contained in:
parent
46b44cdc7b
commit
283bea6170
27 changed files with 509 additions and 53 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -212,6 +212,8 @@
|
|||
<g v-if="G && G.options.offshoreIsland">
|
||||
<OffshoreBank
|
||||
:selectedOffer="bankDraft"
|
||||
:selected-return="bankReturnCargo?.container.piece.id"
|
||||
@select-return="selectBankReturn"
|
||||
:draft-cargo="
|
||||
bankCashOffer ? bankBidCargo.filter((c) => offshoreContainers.has(c.id)) : null
|
||||
"
|
||||
|
|
@ -439,6 +441,31 @@
|
|||
/>
|
||||
</template>
|
||||
|
||||
<g v-if="bankReturnCargo" class="bank-return-destinations">
|
||||
<rect
|
||||
v-for="price in bankReturnPrices"
|
||||
:key="price"
|
||||
class="bank-return-destination"
|
||||
:data-price="price"
|
||||
:data-district="bankReturnCargo.district"
|
||||
:x="player * 250 + 8 + (price - (bankReturnCargo.district === 'factory' ? 1 : 2)) * 48"
|
||||
:y="bankReturnCargo.district === 'factory' ? 160 : 250"
|
||||
width="40"
|
||||
height="40"
|
||||
fill="#1b6c8722"
|
||||
stroke="blue"
|
||||
stroke-width="2"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
:aria-label="'Return to ' + bankReturnCargo.district + ' store at $' + price"
|
||||
@click.stop="returnBankContainer(price)"
|
||||
@keydown.enter.prevent.stop="returnBankContainer(price)"
|
||||
@keydown.space.prevent.stop="returnBankContainer(price)"
|
||||
>
|
||||
<title>{{ 'Return to ' + bankReturnCargo.district + ' store at $' + price }}</title>
|
||||
</rect>
|
||||
</g>
|
||||
|
||||
<rect
|
||||
v-for="zone in bankBidZones"
|
||||
:key="'bank-bid-' + zone.district"
|
||||
|
|
@ -826,6 +853,7 @@
|
|||
import InlineLog from './InlineLog.vue';
|
||||
import OffshoreBank from './OffshoreBank.vue';
|
||||
import { legalBankAction } from '../offshore-actions';
|
||||
import { OffshoreMotion } from '../offshore-motion';
|
||||
import { islandValue } from '../island-value';
|
||||
import ColorBlindButton from './buttons/ColorBlindButton.vue';
|
||||
import { colorBadgeHtml } from '../color-blind';
|
||||
|
|
@ -1008,7 +1036,14 @@ export default class Game extends Vue {
|
|||
.every((item, i) => 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<string>();
|
||||
|
|
@ -2788,3 +2861,15 @@ text {
|
|||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<style scoped>
|
||||
.bank-return-destination {
|
||||
cursor: pointer;
|
||||
}
|
||||
.bank-return-destination:hover,
|
||||
.bank-return-destination:focus-visible {
|
||||
fill: #1b6c8755;
|
||||
stroke-width: 3;
|
||||
outline: none;
|
||||
}
|
||||
</style>
|
||||
|
|
|
|||
|
|
@ -190,9 +190,9 @@
|
|||
<g
|
||||
v-if="bank.decision"
|
||||
class="bank-decision"
|
||||
:transform="bank.decision.kind === 'distribute' ? 'translate(20 950)' : 'translate(520 680)'"
|
||||
:transform="bank.decision.kind !== 'seize' ? 'translate(20 950)' : 'translate(520 680)'"
|
||||
>
|
||||
<text v-if="decisionTitle" x="0" y="0" font-size="14">{{ decisionTitle }}</text>
|
||||
<text v-if="decisionTitle" x="0" y="-12" font-size="14">{{ decisionTitle }}</text>
|
||||
<g
|
||||
v-if="bank.decision.kind === 'distribute'"
|
||||
class="bank-payment-route"
|
||||
|
|
@ -226,7 +226,7 @@
|
|||
:key="choice.data.id"
|
||||
class="bank-choice"
|
||||
:transform="
|
||||
bank.decision.kind === 'distribute'
|
||||
bank.decision.kind !== 'seize'
|
||||
? `translate(${index * 70} 0)`
|
||||
: `translate(0 ${40 + index * 35})`
|
||||
"
|
||||
|
|
@ -240,43 +240,30 @@
|
|||
/>
|
||||
<OffshoreCargo
|
||||
:pieces="[choice.data]"
|
||||
:transform="choice.name === names.ReturnBankContainer ? undefined : 'translate(10 0) scale(2)'"
|
||||
:selectable="choice.name === names.ReturnBankContainer ? [] : [choice.data.id]"
|
||||
transform="translate(10 0) scale(2)"
|
||||
:selectable="[choice.data.id]"
|
||||
:selected="
|
||||
choice.name === names.ReturnBankContainer && selectedReturn === choice.data.id
|
||||
? [choice.data.id]
|
||||
: []
|
||||
"
|
||||
:action-label="
|
||||
choice.name === names.SeizeBankContainer
|
||||
choice.name === names.ReturnBankContainer
|
||||
? 'Choose return destination'
|
||||
: choice.name === names.SeizeBankContainer
|
||||
? 'Select for loan default'
|
||||
: 'Pay into container lot ' + (distributionLot + 1)
|
||||
"
|
||||
@select="emitMove(choice)"
|
||||
@select="
|
||||
choice.name === names.ReturnBankContainer
|
||||
? $emit('select-return', choice.data.id)
|
||||
: emitMove(choice)
|
||||
"
|
||||
/>
|
||||
<template v-if="choice.name === names.ReturnBankContainer">
|
||||
<g
|
||||
v-for="price in returnPrices(choice)"
|
||||
:key="price"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
:aria-label="'Return at $' + price"
|
||||
@click.stop="emitMove({ ...choice, extraData: { price } })"
|
||||
@keydown.enter.prevent.stop="emitMove({ ...choice, extraData: { price } })"
|
||||
@keydown.space.prevent.stop="emitMove({ ...choice, extraData: { price } })"
|
||||
>
|
||||
<rect
|
||||
:x="29 + (price - 1) * 30"
|
||||
y="-3"
|
||||
width="27"
|
||||
height="24"
|
||||
fill="#c6c6b8"
|
||||
stroke="#899997"
|
||||
/>
|
||||
<text :x="42 + (price - 1) * 30" y="12" text-anchor="middle" font-size="16">{{
|
||||
price
|
||||
}}</text>
|
||||
</g>
|
||||
</template>
|
||||
</g>
|
||||
<Button
|
||||
v-if="decisionPages > 1"
|
||||
:transform="bank.decision.kind === 'distribute' ? 'translate(0 40)' : 'translate(0 190)'"
|
||||
:transform="bank.decision.kind !== 'seize' ? 'translate(0 40)' : 'translate(0 190)'"
|
||||
:width="100"
|
||||
:text="'More ' + (decisionPage + 1) + '/' + decisionPages"
|
||||
@click="decisionPage = (decisionPage + 1) % decisionPages"
|
||||
|
|
@ -300,6 +287,7 @@ import PlayerToken from './PlayerToken.vue';
|
|||
export default class OffshoreBank extends Vue {
|
||||
@Prop({ required: true }) state!: GameState;
|
||||
@Prop() player?: number;
|
||||
@Prop() selectedReturn?: string;
|
||||
@Prop() selectedOffer?: { type: BankAuctionType; lot: number };
|
||||
@Prop({ default: () => ({}) }) availableMoves!: AvailableMoves;
|
||||
@Prop({ default: () => playerColors }) playerColors!: string[];
|
||||
|
|
@ -360,16 +348,11 @@ export default class OffshoreBank extends Vue {
|
|||
}
|
||||
get decisionTitle() {
|
||||
return this.bank?.decision?.kind === 'return'
|
||||
? 'Outbid'
|
||||
? 'Outbid containers'
|
||||
: this.bank?.decision?.kind === 'seize'
|
||||
? 'Loan default'
|
||||
: '';
|
||||
}
|
||||
returnPrices(choice: Moves.MoveBankContainer) {
|
||||
return [1, 2, 3, 4, 5, 6].filter((price) =>
|
||||
legalBankAction(this.state, this.player, { ...choice, extraData: { price } })
|
||||
);
|
||||
}
|
||||
get distributionLot() {
|
||||
const lots = [0, 1, 2].filter((i) => !this.bank?.auctions.some((a) => a.type === 'containers' && a.lot === i));
|
||||
return lots[(this.bank?.decision?.cursor || 0) % lots.length];
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
{
|
||||
"Choose return destination": "Vælg destination for returnering",
|
||||
"Return to factory store at ${p0}": "Returnér til fabrikslageret til ${p0}",
|
||||
"Return to warehouse store at ${p0}": "Returnér til lagerbeholdningen til ${p0}",
|
||||
"$10 with all five colours; otherwise $5": "$10 med alle fem farver; ellers $5",
|
||||
"$30 in containers minus the $6 payment.": "$30 i containere minus betalingen på $6.",
|
||||
"$5 or $10": "$5 eller $10",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
{
|
||||
"Choose return destination": "Rückgabeziel wählen",
|
||||
"Return to factory store at ${p0}": "Für ${p0} in den Fabrikbestand zurücklegen",
|
||||
"Return to warehouse store at ${p0}": "Für ${p0} in den Lagerhausbestand zurücklegen",
|
||||
"$10 with all five colours; otherwise $5": "$10 mit allen fünf Farben; sonst $5",
|
||||
"$30 in containers minus the $6 payment.": "30 $ in Containern abzüglich der Zahlung von 6 $.",
|
||||
"$5 or $10": "5 $ oder 10 $",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
{
|
||||
"Choose return destination": "Επιλέξτε προορισμό επιστροφής",
|
||||
"Return to factory store at ${p0}": "Επιστροφή στην αποθήκη εργοστασίου με τιμή ${p0}",
|
||||
"Return to warehouse store at ${p0}": "Επιστροφή στην αποθήκη λιμανιού με τιμή ${p0}",
|
||||
"$10 with all five colours; otherwise $5": "$10 με και τα πέντε χρώματα· αλλιώς $5",
|
||||
"$30 in containers minus the $6 payment.": "$30 σε κοντέινερ μείον την πληρωμή $6.",
|
||||
"$5 or $10": "$5 ή $10",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
{
|
||||
"Choose return destination": "Choose return destination",
|
||||
"Return to factory store at ${p0}": "Return to factory store at ${p0}",
|
||||
"Return to warehouse store at ${p0}": "Return to warehouse store at ${p0}",
|
||||
"$10 with all five colours; otherwise $5": "$10 with all five colours; otherwise $5",
|
||||
"$30 in containers minus the $6 payment.": "$30 in containers minus the $6 payment.",
|
||||
"$5 or $10": "$5 or $10",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
{
|
||||
"Choose return destination": "مقصد بازگشت را انتخاب کنید",
|
||||
"Return to factory store at ${p0}": "بازگرداندن به موجودی کارخانه با قیمت ${p0}",
|
||||
"Return to warehouse store at ${p0}": "بازگرداندن به موجودی انبار با قیمت ${p0}",
|
||||
"$10 with all five colours; otherwise $5": "با هر پنج رنگ: ۱۰ دلار؛ در غیر این صورت: ۵ دلار",
|
||||
"$30 in containers minus the $6 payment.": "۳۰ دلار ارزش کانتینرها منهای پرداخت ۶ دلار.",
|
||||
"$5 or $10": "۵ یا ۱۰ دلار",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
{
|
||||
"Choose return destination": "Choisissez la destination de retour",
|
||||
"Return to factory store at ${p0}": "Remettre au magasin d’usine au prix de {p0} $",
|
||||
"Return to warehouse store at ${p0}": "Remettre au magasin d’entrepôt au prix de {p0} $",
|
||||
"$10 with all five colours; otherwise $5": "10 $ avec les cinq couleurs ; sinon 5 $",
|
||||
"$30 in containers minus the $6 payment.": "30 $ de conteneurs moins le paiement de 6 $.",
|
||||
"$5 or $10": "5 $ ou 10 $",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
{
|
||||
"Choose return destination": "वापसी का स्थान चुनें",
|
||||
"Return to factory store at ${p0}": "${p0} की कीमत पर कारखाना भंडार में लौटाएँ",
|
||||
"Return to warehouse store at ${p0}": "${p0} की कीमत पर गोदाम भंडार में लौटाएँ",
|
||||
"$10 with all five colours; otherwise $5": "सभी पाँच रंगों के साथ $10; अन्यथा $5",
|
||||
"$30 in containers minus the $6 payment.": "कंटेनरों में $30 घटाकर $6 भुगतान।",
|
||||
"$5 or $10": "$5 या $10",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
{
|
||||
"Choose return destination": "Scegli la destinazione del reso",
|
||||
"Return to factory store at ${p0}": "Rimetti nel deposito della fabbrica al prezzo di ${p0}",
|
||||
"Return to warehouse store at ${p0}": "Rimetti nel deposito del magazzino al prezzo di ${p0}",
|
||||
"$10 with all five colours; otherwise $5": "$10 con tutti e cinque i colori; altrimenti $5",
|
||||
"$30 in containers minus the $6 payment.": "$30 in container meno il pagamento di $6.",
|
||||
"$5 or $10": "$5 o $10",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
{
|
||||
"Choose return destination": "반환 위치 선택",
|
||||
"Return to factory store at ${p0}": "공장 재고에 ${p0} 가격으로 반환",
|
||||
"Return to warehouse store at ${p0}": "창고 재고에 ${p0} 가격으로 반환",
|
||||
"$10 with all five colours; otherwise $5": "다섯 색상이 모두 있으면 $10, 아니면 $5",
|
||||
"$30 in containers minus the $6 payment.": "컨테이너 $30에서 $6 지불을 뺀 금액.",
|
||||
"$5 or $10": "$5 또는 $10",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
{
|
||||
"Choose return destination": "Kies de terugplaatslocatie",
|
||||
"Return to factory store at ${p0}": "Terugplaatsen in de fabrieksvoorraad voor ${p0}",
|
||||
"Return to warehouse store at ${p0}": "Terugplaatsen in de pakhuisvoorraad voor ${p0}",
|
||||
"$10 with all five colours; otherwise $5": "$10 met alle vijf kleuren; anders $5",
|
||||
"$30 in containers minus the $6 payment.": "$30 aan containers minus de betaling van $6.",
|
||||
"$5 or $10": "$5 of $10",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
{
|
||||
"Choose return destination": "Wybierz miejsce zwrotu",
|
||||
"Return to factory store at ${p0}": "Zwróć do zapasów fabrycznych z ceną ${p0}",
|
||||
"Return to warehouse store at ${p0}": "Zwróć do zapasów magazynowych z ceną ${p0}",
|
||||
"$10 with all five colours; otherwise $5": "10 $ przy wszystkich pięciu kolorach; w przeciwnym razie 5 $",
|
||||
"$30 in containers minus the $6 payment.": "30 $ w kontenerach minus opłata 6 $.",
|
||||
"$5 or $10": "5 $ lub 10 $",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
{
|
||||
"Choose return destination": "Escolha o destino da devolução",
|
||||
"Return to factory store at ${p0}": "Devolver ao estoque da fábrica pelo preço de ${p0}",
|
||||
"Return to warehouse store at ${p0}": "Devolver ao estoque do armazém pelo preço de ${p0}",
|
||||
"$10 with all five colours; otherwise $5": "$10 com as cinco cores; caso contrário, $5",
|
||||
"$30 in containers minus the $6 payment.": "$30 em contêineres menos o pagamento de $6.",
|
||||
"$5 or $10": "$5 ou $10",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
{
|
||||
"Choose return destination": "Alege destinația returnării",
|
||||
"Return to factory store at ${p0}": "Returnează în stocul fabricii la prețul de ${p0}",
|
||||
"Return to warehouse store at ${p0}": "Returnează în stocul depozitului la prețul de ${p0}",
|
||||
"$10 with all five colours; otherwise $5": "$10 cu toate cele cinci culori; altfel $5",
|
||||
"$30 in containers minus the $6 payment.": "30 $ în containere minus plata de 6 $.",
|
||||
"$5 or $10": "5 $ sau 10 $",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
{
|
||||
"Choose return destination": "Выберите место возврата",
|
||||
"Return to factory store at ${p0}": "Вернуть на склад фабрики по цене ${p0}",
|
||||
"Return to warehouse store at ${p0}": "Вернуть на склад гавани по цене ${p0}",
|
||||
"$10 with all five colours; otherwise $5": "$10 при наличии всех пяти цветов; иначе $5",
|
||||
"$30 in containers minus the $6 payment.": "$30 в контейнерах минус выплата $6.",
|
||||
"$5 or $10": "$5 или $10",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
{
|
||||
"Choose return destination": "Chọn nơi trả hàng",
|
||||
"Return to factory store at ${p0}": "Trả về khu bán hàng của nhà máy với giá ${p0}",
|
||||
"Return to warehouse store at ${p0}": "Trả về khu bán hàng của nhà kho với giá ${p0}",
|
||||
"$10 with all five colours; otherwise $5": "$10 nếu có đủ năm màu; nếu không thì $5",
|
||||
"$30 in containers minus the $6 payment.": "$30 trong container trừ đi khoản thanh toán $6.",
|
||||
"$5 or $10": "$5 hoặc $10",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
{
|
||||
"Choose return destination": "选择退回位置",
|
||||
"Return to factory store at ${p0}": "以 ${p0} 的价格退回工厂销售区",
|
||||
"Return to warehouse store at ${p0}": "以 ${p0} 的价格退回仓库销售区",
|
||||
"$10 with all five colours; otherwise $5": "集齐五色时每个 $10,否则 $5",
|
||||
"$30 in containers minus the $6 payment.": "集装箱价值 $30,减去支付的 $6。",
|
||||
"$5 or $10": "$5 或 $10",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
{
|
||||
"Choose return destination": "選擇退回位置",
|
||||
"Return to factory store at ${p0}": "以 ${p0} 的價格退回工廠庫存",
|
||||
"Return to warehouse store at ${p0}": "以 ${p0} 的價格退回倉庫庫存",
|
||||
"$10 with all five colours; otherwise $5": "五種顏色齊全時每個$10;否則每個$5",
|
||||
"$30 in containers minus the $6 payment.": "貨櫃價值$30減去$6付款。",
|
||||
"$5 or $10": "$5或$10",
|
||||
|
|
|
|||
151
viewer/src/offshore-motion.ts
Normal file
151
viewer/src/offshore-motion.ts
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
import { ContainerPiece, GameState } from 'container-engine/src/gamestate';
|
||||
|
||||
/** Logical ownership, not screen position: pagination and layout changes are not moves. */
|
||||
export function cargoLocations(state?: GameState | null): Map<string, string> {
|
||||
const result = new Map<string, string>();
|
||||
if (!state?.options.offshoreIsland) return result;
|
||||
const add = (pieces: ContainerPiece[], location: string) =>
|
||||
pieces.forEach((piece) => result.set(piece.id, location));
|
||||
state.players.forEach((player, i) => {
|
||||
add(
|
||||
player.containersOnFactoryStore.map((c) => c.piece),
|
||||
`factory:${i}`
|
||||
);
|
||||
add(
|
||||
player.containersOnWarehouseStore.map((c) => c.piece),
|
||||
`warehouse:${i}`
|
||||
);
|
||||
add(player.ship.containers, `ship:${i}`);
|
||||
add(player.containersOnIsland, `island:${i}`);
|
||||
add(player.bankHolding || [], `bank:holding:${i}`);
|
||||
});
|
||||
const bank = state.offshoreBank;
|
||||
bank?.containerLots.forEach((pieces, i) => add(pieces, `bank:lot:${i}`));
|
||||
bank?.auctions.forEach((auction) =>
|
||||
add(
|
||||
auction.containers.map((c) => c.container.piece),
|
||||
`bank:escrow:${auction.type}:${auction.lot}`
|
||||
)
|
||||
);
|
||||
// Seizure choices still belong to their original store until actually seized.
|
||||
if (bank?.decision && bank.decision.kind !== 'seize') {
|
||||
add(
|
||||
bank.decision.containers.map((c) => c.container.piece),
|
||||
`bank:${bank.decision.kind}`
|
||||
);
|
||||
add(bank.decision.payment, 'bank:payment');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function visibleCargo(root: Element): Map<string, SVGGraphicsElement> {
|
||||
const nodes = new Map<string, SVGGraphicsElement>();
|
||||
const duplicates = new Set<string>();
|
||||
root.querySelectorAll<SVGGraphicsElement>('[data-piece-id]').forEach((node) => {
|
||||
const id = node.getAttribute('data-piece-id')!;
|
||||
// Drafts and seizure choices are UI copies, not the physical container.
|
||||
if (!/^C\d+$/.test(id) || node.closest('.bank-lot-draft')) return;
|
||||
if (node.closest('.bank-decision')?.querySelector('[aria-label^="Select for loan default"]')) return;
|
||||
if (nodes.has(id)) duplicates.add(id);
|
||||
else nodes.set(id, node);
|
||||
});
|
||||
duplicates.forEach((id) => nodes.delete(id));
|
||||
return nodes;
|
||||
}
|
||||
|
||||
/** FLIP on the real destination SVG nodes. No ghosts, state delays, or move queue. */
|
||||
export class OffshoreMotion {
|
||||
private animations = new Set<Animation>();
|
||||
private revision = 0;
|
||||
private disposed = false;
|
||||
// engineMove mutates G in-place before replaceState; retain logical snapshots independently.
|
||||
private locations?: Map<string, string>;
|
||||
private logLength?: number;
|
||||
private media =
|
||||
typeof window !== 'undefined' && typeof window.matchMedia === 'function'
|
||||
? window.matchMedia('(prefers-reduced-motion: reduce)')
|
||||
: undefined;
|
||||
private onMotionPreference = () => {
|
||||
if (this.media?.matches) {
|
||||
++this.revision;
|
||||
this.cancel();
|
||||
}
|
||||
};
|
||||
|
||||
constructor() {
|
||||
this.media?.addEventListener?.('change', this.onMotionPreference);
|
||||
}
|
||||
|
||||
transition(
|
||||
root: Element | undefined,
|
||||
before: GameState | null | undefined,
|
||||
after: GameState | null | undefined,
|
||||
nextTick: (callback: () => void) => void
|
||||
) {
|
||||
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);
|
||||
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) {
|
||||
visibleCargo(root).forEach((node, id) => {
|
||||
const from = previous.get(id);
|
||||
const to = next.get(id);
|
||||
if (from && to && from !== to && (from.startsWith('bank:') || to.startsWith('bank:'))) {
|
||||
const matrix = node.getCTM?.();
|
||||
if (matrix) {
|
||||
origins.set(id, matrix);
|
||||
oldNodes.set(id, node);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
this.cancel();
|
||||
if (!root || !origins.size || this.disposed) return;
|
||||
nextTick(() => {
|
||||
if (this.disposed || revision !== this.revision || reduced()) return;
|
||||
visibleCargo(root).forEach((node, id) => {
|
||||
const origin = origins.get(id);
|
||||
const parent = (node.parentNode as SVGGraphicsElement).getCTM?.();
|
||||
const destination = node.getCTM?.();
|
||||
// Persistent pieces already have Piece.vue's own movement tween.
|
||||
if (!origin || oldNodes.get(id) === node || !parent || !destination || !node.animate) return;
|
||||
try {
|
||||
const inverse = parent.inverse();
|
||||
const matrix = (value: DOMMatrix) => {
|
||||
const m = inverse.multiply(value);
|
||||
return `matrix(${m.a}, ${m.b}, ${m.c}, ${m.d}, ${m.e}, ${m.f})`;
|
||||
};
|
||||
const animation = node.animate(
|
||||
[
|
||||
{ transform: matrix(origin), transformOrigin: '0 0' },
|
||||
{ transform: matrix(destination), transformOrigin: '0 0' },
|
||||
],
|
||||
{ duration: 320, easing: 'ease-out' }
|
||||
);
|
||||
this.animations.add(animation);
|
||||
animation.onfinish = animation.oncancel = () => this.animations.delete(animation);
|
||||
} catch (_) {
|
||||
// Detached/hidden SVGs can have a non-invertible CTM. State is already rendered.
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private cancel() {
|
||||
this.animations.forEach((animation) => animation.cancel());
|
||||
this.animations.clear();
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.disposed = true;
|
||||
this.media?.removeEventListener?.('change', this.onMotionPreference);
|
||||
++this.revision;
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
|
|
@ -657,4 +657,20 @@ const scoring: Lesson = {
|
|||
},
|
||||
};
|
||||
export const lessons: Lesson[] = [supply, buildings, selling, bidding, keeping, scoring, ...offshoreLessons];
|
||||
export const chapterCards = lessons.map(({ id, version, title, description }) => ({ id, version, title, description }));
|
||||
export const chapterSections = [
|
||||
{ id: 'base-game', title: 'Base game', description: 'Learn production, trading, shipping and scoring.' },
|
||||
{
|
||||
id: 'offshore-island',
|
||||
title: 'Offshore Island',
|
||||
description: 'Learn the public bank auctions and cargo handling.',
|
||||
},
|
||||
];
|
||||
export const chapterCards = lessons.map(({ id, version, title, description }) => ({
|
||||
id,
|
||||
version,
|
||||
title,
|
||||
description,
|
||||
section: id.startsWith('offshore-') ? 'offshore-island' : 'base-game',
|
||||
}));
|
||||
/** Complete BGS Tutorial settings payload; keep section metadata alongside chapters. */
|
||||
export const tutorialCatalog = { sections: chapterSections, chapters: chapterCards };
|
||||
|
|
|
|||
|
|
@ -6,7 +6,24 @@ require('../../../engine/node_modules/ts-node').register({
|
|||
});
|
||||
const { createTutorial } = require('@boardgamers/protocol/tutorial');
|
||||
const { stripSecret } = require('../../../engine/src/engine');
|
||||
const { lessons } = require('../../src/tutorial/lessons');
|
||||
const { lessons, tutorialCatalog } = require('../../src/tutorial/lessons');
|
||||
test('BGS chapters are grouped into Base game and Offshore Island without changing lesson identities', () => {
|
||||
assert.deepEqual(
|
||||
tutorialCatalog.sections.map(({ id, title }) => [id, title]),
|
||||
[
|
||||
['base-game', 'Base game'],
|
||||
['offshore-island', 'Offshore Island'],
|
||||
]
|
||||
);
|
||||
assert.deepEqual(
|
||||
tutorialCatalog.chapters.map(({ id, version }) => ({ id, version })),
|
||||
lessons.map(({ id, version }) => ({ id, version }))
|
||||
);
|
||||
assert.equal(tutorialCatalog.chapters.filter((c) => c.section === 'base-game').length, 6);
|
||||
assert.equal(tutorialCatalog.chapters.filter((c) => c.section === 'offshore-island').length, 3);
|
||||
for (const chapter of tutorialCatalog.chapters)
|
||||
assert.ok(tutorialCatalog.sections.some((section) => section.id === chapter.section));
|
||||
});
|
||||
const expectedCash = {
|
||||
'supply-chain': 21,
|
||||
buildings: 7,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import OffshoreBank from '@/components/OffshoreBank.vue';
|
|||
import OffshoreCargo from '@/components/OffshoreCargo.vue';
|
||||
import Container from '@/components/pieces/Container.vue';
|
||||
import PlayerToken from '@/components/PlayerToken.vue';
|
||||
import { legalBankAction } from '@/offshore-actions';
|
||||
import { escapeJournal, offshoreJournal } from '@/offshore-journal';
|
||||
import { mount, shallowMount } from '@vue/test-utils';
|
||||
import { availableMoves, MoveName, setup } from 'container-engine';
|
||||
|
|
@ -413,7 +412,7 @@ describe('Offshore bank viewer', () => {
|
|||
wrapper.destroy();
|
||||
});
|
||||
|
||||
it('offers only engine-valid return prices, preserving escrow and holding cargo', () => {
|
||||
it('selects return cargo and offers only original-district store destinations', async () => {
|
||||
const { state, player, own, factory, warehouse, refresh, render } = fixture();
|
||||
own.bankHolding!.push(state.containersLeft.pop()!);
|
||||
state.phase = Phase.BankDecision;
|
||||
|
|
@ -430,11 +429,36 @@ describe('Offshore bank viewer', () => {
|
|||
};
|
||||
refresh();
|
||||
const wrapper = render();
|
||||
const vm = wrapper.vm as any;
|
||||
expect(vm.returnPrices({ name: MoveName.ReturnBankContainer, data: factory })).toEqual([1, 2, 3, 4]);
|
||||
expect(vm.returnPrices({ name: MoveName.ReturnBankContainer, data: warehouse })).toEqual([2, 3, 4, 5, 6]);
|
||||
expect(wrapper.findAll('.bank-choice').length).toBe(2);
|
||||
expect(wrapper.find('.bank-holding [data-piece-id]').exists()).toBe(true);
|
||||
expect(wrapper.find('[aria-label="Return at $3"]').exists()).toBe(false);
|
||||
await wrapper.find(`.bank-choice [data-piece-id="${warehouse.id}"]`).trigger('keydown.enter');
|
||||
expect(wrapper.emitted('select-return')![0]).toEqual([warehouse.id]);
|
||||
expect(wrapper.emitted('move')).toBeUndefined();
|
||||
const game = shallowMount(Game, {
|
||||
propsData: { state, player, emitter: new EventEmitter(), preferences: { sound: false } },
|
||||
});
|
||||
const vm = game.vm as any;
|
||||
vm.selectBankReturn(factory.id);
|
||||
await game.vm.$nextTick();
|
||||
expect(vm.bankReturnPrices).toEqual([1, 2, 3, 4]);
|
||||
expect(game.findAll('.bank-return-destination').length).toBe(4);
|
||||
expect(game.find('.bank-return-destination').attributes('data-district')).toBe('factory');
|
||||
vm.selectBankReturn(warehouse.id);
|
||||
await game.vm.$nextTick();
|
||||
expect(vm.bankReturnPrices).toEqual([2, 3, 4, 5, 6]);
|
||||
expect(game.find('.bank-return-destination').attributes('data-district')).toBe('warehouse');
|
||||
const returned: any[] = [];
|
||||
vm.sendBankMove = (action: any) => returned.push(action);
|
||||
vm.returnBankContainer(1);
|
||||
expect(returned).toEqual([]);
|
||||
await game.find('.bank-return-destination[data-price="6"]').trigger('keydown.space');
|
||||
expect(returned).toEqual([{ name: MoveName.ReturnBankContainer, data: warehouse, extraData: { price: 6 } }]);
|
||||
expect(vm.selectedBankReturn).toBeNull();
|
||||
vm.selectBankReturn(factory.id);
|
||||
await game.setProps({ player: undefined });
|
||||
expect(game.find('.bank-return-destination').exists()).toBe(false);
|
||||
game.destroy();
|
||||
wrapper.destroy();
|
||||
});
|
||||
|
||||
|
|
@ -502,8 +526,8 @@ describe('Offshore bank viewer', () => {
|
|||
await wrapper.find('[aria-label="More 2/3"]').trigger('click');
|
||||
expect(wrapper.findAll('.bank-choice').length).toBe(3);
|
||||
await wrapper.find('.bank-choice [role="button"]').trigger('click');
|
||||
const action = wrapper.emitted('move')![0][0];
|
||||
expect(legalBankAction(state, player, action)).toBe(true);
|
||||
expect(wrapper.emitted('select-return')![0]).toEqual([containers[8].container.piece.id]);
|
||||
expect(wrapper.emitted('move')).toBeUndefined();
|
||||
wrapper.destroy();
|
||||
});
|
||||
|
||||
|
|
|
|||
93
viewer/tests/unit/offshore-motion.spec.ts
Normal file
93
viewer/tests/unit/offshore-motion.spec.ts
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
import { cargoLocations, OffshoreMotion } from '@/offshore-motion';
|
||||
import { setup } from 'container-engine';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
function fixture() {
|
||||
const before = setup(3, { offshoreIsland: true }, 'motion');
|
||||
const piece = before.offshoreBank!.containerLots[0][0];
|
||||
const after = JSON.parse(JSON.stringify(before));
|
||||
after.offshoreBank.containerLots[0].shift();
|
||||
after.players[0].bankHolding = [piece];
|
||||
const root = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
||||
const matrix = { a: 1, b: 0, c: 0, d: 1, e: 10, f: 20 };
|
||||
Object.assign(root, { getCTM: () => ({ inverse: () => ({ multiply: (m: unknown) => m }) }) });
|
||||
const node = () => {
|
||||
const element = document.createElementNS(root.namespaceURI, 'g');
|
||||
element.setAttribute('data-piece-id', piece.id);
|
||||
const animation = { cancel: vi.fn(), onfinish: null, oncancel: null };
|
||||
const animate = vi.fn(() => animation);
|
||||
Object.assign(element, { getCTM: () => matrix, animate });
|
||||
root.replaceChildren(element);
|
||||
return { element, animate, animation };
|
||||
};
|
||||
node();
|
||||
const motion = new OffshoreMotion();
|
||||
const callbacks: Array<() => void> = [];
|
||||
const tick = (fn: () => void) => callbacks.push(fn);
|
||||
return { before, after, piece, root, node, motion, callbacks, tick };
|
||||
}
|
||||
|
||||
describe('offshore physical cargo motion', () => {
|
||||
it('tracks physical ownership across lots, holding, ship and returns', () => {
|
||||
const { before, after, piece } = fixture();
|
||||
expect(cargoLocations(before).get(piece.id)).toBe('bank:lot:0');
|
||||
expect(cargoLocations(after).get(piece.id)).toBe('bank:holding:0');
|
||||
after.players[0].bankHolding = [];
|
||||
after.players[0].ship.containers.push(piece);
|
||||
expect(cargoLocations(after).get(piece.id)).toBe('ship:0');
|
||||
});
|
||||
it('animates the real replacement node and cancels on teardown', () => {
|
||||
const f = fixture();
|
||||
f.motion.transition(f.root, f.before, f.after, f.tick);
|
||||
const destination = f.node();
|
||||
f.callbacks.forEach((fn) => fn());
|
||||
expect(destination.animate).toHaveBeenCalledOnce();
|
||||
expect(f.root.querySelectorAll('[data-piece-id]')).toHaveLength(1);
|
||||
expect(destination.animate.mock.calls[0]).toBeDefined();
|
||||
f.motion.destroy();
|
||||
expect(destination.animation.cancel).toHaveBeenCalledOnce();
|
||||
});
|
||||
it('does not animate initial render, layout-only changes or pagination', () => {
|
||||
const f = fixture();
|
||||
f.motion.transition(f.root, null, f.before, f.tick);
|
||||
f.motion.transition(f.root, f.before, f.before, f.tick);
|
||||
expect(f.callbacks).toHaveLength(0);
|
||||
f.motion.destroy();
|
||||
});
|
||||
it('invalidates pending work on a rapid update or teardown', () => {
|
||||
const f = fixture();
|
||||
f.motion.transition(f.root, f.before, f.after, f.tick);
|
||||
const destination = f.node();
|
||||
f.motion.transition(f.root, f.after, f.after, f.tick);
|
||||
f.callbacks.forEach((fn) => fn());
|
||||
expect(destination.animate).not.toHaveBeenCalled();
|
||||
f.motion.destroy();
|
||||
});
|
||||
it('does not layer a second animation onto a persistent Piece node', () => {
|
||||
const f = fixture();
|
||||
const destination = f.node();
|
||||
f.motion.transition(f.root, f.before, f.after, f.tick);
|
||||
f.callbacks.forEach((fn) => fn());
|
||||
expect(destination.animate).not.toHaveBeenCalled();
|
||||
f.motion.destroy();
|
||||
});
|
||||
it('retains the prior locations when the engine mutates its input in place', () => {
|
||||
const f = fixture();
|
||||
f.motion.transition(undefined, null, null, f.tick);
|
||||
f.motion.transition(f.root, null, f.before, f.tick);
|
||||
Object.assign(f.before, f.after);
|
||||
f.motion.transition(f.root, f.before, f.before, f.tick);
|
||||
const destination = f.node();
|
||||
f.callbacks.forEach((fn) => fn());
|
||||
expect(destination.animate).toHaveBeenCalledOnce();
|
||||
f.motion.destroy();
|
||||
});
|
||||
it('honors reduced motion', () => {
|
||||
vi.stubGlobal('matchMedia', () => ({ matches: true }));
|
||||
const f = fixture();
|
||||
f.motion.transition(f.root, f.before, f.after, f.tick);
|
||||
expect(f.callbacks).toHaveLength(0);
|
||||
f.motion.destroy();
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue