Support translated chat and platform analysis defaults

This commit is contained in:
coyotte508 2026-09-21 20:32:09 +02:00
commit 8664228bc8
9 changed files with 56 additions and 18 deletions

View file

@ -1,6 +1,6 @@
{
"name": "container-engine",
"version": "2.1.0",
"version": "2.1.1",
"description": "An engine for Container",
"main": "dist/index.js",
"types": "index.ts",

View file

@ -499,10 +499,9 @@ describe('wrapper (tentative turns)', () => {
});
describe('saved analyses', () => {
it('requires a finished source and reconstructs historical cash rather than final scores', () => {
it('reconstructs historical cash rather than final scores', () => {
const source = setup(3, {}, 'analysis-cash');
source.players[0].money = 999;
expect(() => wrapper.createAnalysis(source, { to: 0, sourceEnded: false })).to.throw('finished');
const copy = wrapper.createAnalysis(source, { to: 0, sourceEnded: true });
expect(copy.players.map((p) => p.money)).to.deep.equal([20, 20, 20]);
expect(source.players[0].money).to.equal(999);
@ -513,10 +512,10 @@ describe('saved analyses', () => {
it('can continue a historical position using each current player and the real costs', async () => {
let copy = wrapper.createAnalysis(setup(3, {}, 'analysis-turns'), { to: 0, sourceEnded: true });
const actor = copy.currentPlayers[0];
copy = await wrapper.analysisMove(copy, pass, actor);
copy = await wrapper.move(copy, pass, actor);
expect(copy.currentPlayers[0]).not.to.equal(actor);
const next = copy.currentPlayers[0];
copy = await wrapper.analysisMove(copy, pass, next);
copy = await wrapper.move(copy, pass, next);
expect(copy.currentPlayers[0]).not.to.equal(next);
});
});

View file

@ -213,10 +213,7 @@ export function logSlice(G: GameState, options?: { player?: number; start?: numb
};
}
export const analysisPolicy = 'finished';
export function createAnalysis(G: GameState, options: { to: number; sourceEnded: boolean }): GameState {
if (!options.sourceEnded) throw new Error('Analyses are available once this game has finished');
if (options.to < 0 || options.to > G.log.length) throw new Error('Invalid history position');
const copy = replay({ ...cloneDeep(G), log: G.log.slice(0, options.to), hiddenLog: [] });
for (const player of copy.players) {
@ -227,8 +224,6 @@ export function createAnalysis(G: GameState, options: { to: number; sourceEnded:
return copy;
}
export const analysisMove = move;
export function analysisView(G: GameState, options: { player: number; start?: number; end?: number }) {
const state = cloneDeep(G);
return {

10
pnpm-lock.yaml generated
View file

@ -86,8 +86,8 @@ importers:
viewer:
dependencies:
'@boardgamers/protocol':
specifier: 0.3.3
version: 0.3.3
specifier: 0.4.0
version: 0.4.0
container-engine:
specifier: workspace:../engine
version: link:../engine
@ -1042,10 +1042,10 @@ packages:
}
engines: { node: '>=6.9.0' }
'@boardgamers/protocol@0.3.3':
'@boardgamers/protocol@0.4.0':
resolution:
{
integrity: sha512-AS+x84WHXRudW6xt/s/5I3xYmNTQFbZEBp3V+41w0I2RirSr2fWjYnYf0p11nwTbZ6G5upivKz/sjYLtk8HOYA==,
integrity: sha512-dqrU94QGPZAh7vWhHmu2AHY6bFo7NbNVytb3dyUidou8R6P0FfT3xm0qLR8LbrE4EHEYmm99LajdfTfKmgwEzQ==,
}
'@cspotcode/source-map-support@0.8.1':
@ -11586,7 +11586,7 @@ snapshots:
'@babel/helper-string-parser': 7.29.7
'@babel/helper-validator-identifier': 7.29.7
'@boardgamers/protocol@0.3.3':
'@boardgamers/protocol@0.4.0':
dependencies:
zod: 4.6.2

View file

@ -18,6 +18,7 @@ allowBuilds:
autoInstallPeers: false
minimumReleaseAgeExclude:
- '@boardgamers/protocol@0.4.0'
- '@boardgamers/protocol@0.2.2 || 0.3.0 || 0.3.1 || 0.3.3'
# The cli-plugin-typescript fork-ts-checker shim does a bare

View file

@ -1,4 +1,4 @@
module.exports = {
presets: ['@vue/cli-plugin-babel/preset'],
presets: [['@vue/cli-plugin-babel/preset', { forceAllTransforms: true }]],
plugins: ['@babel/plugin-transform-export-namespace-from'],
};

View file

@ -1,6 +1,6 @@
{
"name": "container-viewer",
"version": "2.0.3",
"version": "2.0.4",
"repository": {
"type": "git",
"url": "git+https://github.com/boardgamers/container.git",
@ -19,7 +19,7 @@
"preview:tutorial": "node scripts/tutorial-preview.mjs"
},
"dependencies": {
"@boardgamers/protocol": "0.3.3",
"@boardgamers/protocol": "0.4.0",
"container-engine": "workspace:../engine",
"core-js": "^3.6.5",
"lodash": "^4.17.19",

View file

@ -266,6 +266,48 @@ try {
1,
'tentative move state is rendered without fetching a committed state'
);
await page.evaluate(() => {
window.translationsRequested = [];
host.on('chat:translate', (request) => {
translationsRequested.push(request);
host.emit('chat:translation', { ...request, ok: true, text: 'Bonjour <img src=x>', language: 'en' });
});
host.emit('chat:state', {
canSend: true,
translationTarget: 'fr',
translationLabels: {
translate: 'Traduire',
translating: 'Traduction…',
translated: 'Traduit',
original: 'Voir l’original',
error: 'Indisponible',
retry: 'Réessayer',
},
});
host.emit('chat:messages', [
{ _id: '000000000000000000000070', type: 'text', text: 'Hello', language: 'en' },
]);
});
await page.locator('.chat-translate').click();
await page.getByRole('button', { name: 'Traduit · Voir l’original', exact: true }).waitFor();
assert.equal(await page.evaluate(() => translationsRequested.length), 1);
assert.equal(await page.locator('[data-message-id="000000000000000000000070"] img').count(), 0);
assert.match(
await page.locator('[data-message-id="000000000000000000000070"]').textContent(),
/Bonjour <img src=x>/
);
await page.locator('.chat-translate').click();
assert.match(await page.locator('[data-message-id="000000000000000000000070"]').textContent(), /Hello/);
assert.equal(
await page.evaluate(() => translationsRequested.length),
1,
'showing original needs no new request'
);
await page.evaluate(() => host.emit('preferences', { sound: false, analysis: true }));
await page.waitForFunction(() => !document.querySelector('.chat-translate')?.getBoundingClientRect().height);
await page.screenshot({ path: '/tmp/container-analysis-' + width + '.png', fullPage: true });
await page.evaluate(() => host.emit('preferences', { sound: false, analysis: false }));
await page.screenshot({ path: `/tmp/${game}-protocol-${width}.png`, fullPage: true });
await page.evaluate(
({ state, incoming }) => {

View file

@ -33,6 +33,7 @@ export function mountGameChat(emitter: ViewerEmitter<any, any>, host: Element):
.bgs-game-chat button:disabled{color:#788786;border-color:#b0bcb8;background:#dce3df;cursor:default}
.bgs-game-chat .chat-mention{height:auto;padding:0 2px;border:0;background:transparent;color:inherit;font:inherit;font-weight:bold;text-decoration:underline}
.bgs-game-chat article a{color:inherit;text-decoration:underline}
.bgs-game-chat .chat-translate{height:auto;min-height:24px;padding:2px 4px;margin-left:6px;border:0;background:transparent;color:inherit;font-size:.8em;text-decoration:underline}
.chat-suggestions{display:flex;flex-wrap:wrap;gap:4px;margin-top:4px}
.chat-suggestions:empty{display:none}
.chat-suggestions button[aria-pressed="true"]{outline:2px solid #527f89}