Fix trainer mobile map and entrance hazard limits
This commit is contained in:
1 parent
eb04ce3e48
commit
ba25b64190
10 files changed
+208
-39
No files matched your search
+104
-11
@@ -37,6 +37,27 @@ async function checkTransitions(page, expectedExit) {
|
||||
return exit;
|
||||
}
|
||||
|
||||
async function assertEntranceLevel(page, value, current = true) {
|
||||
for (const grid of ['scene-grid','map-grid']) {
|
||||
const entrance = page.locator(`#${grid} .entrance button[data-id="0"]`);
|
||||
assert.equal(await valueText(entrance,'.cell-value'),value === null ? '↥' : `↥ ${value}`);
|
||||
assert.equal(await entrance.getAttribute('aria-label'),`x1 y1: вход${value === null ? '' : `, опасностей рядом: ${value}`}${current ? ', персонаж здесь' : ''}`);
|
||||
assert.equal(await page.locator(`#${grid} .entrance.opened`).count(),0);
|
||||
}
|
||||
assert.equal(await valueText(page.locator('#scene-grid .entrance button'),'.cell-coord'),'x1 y1');
|
||||
}
|
||||
|
||||
async function finishDialog(page, dialogId, openerId, action) {
|
||||
await page.locator(`#${dialogId}`).evaluate(dialog=>{
|
||||
dialog.closeSeen = false;
|
||||
dialog.addEventListener('close',()=>{ dialog.closeSeen = true; },{once:true});
|
||||
});
|
||||
await action();
|
||||
// The native dialog can become hidden before its close handler restores focus.
|
||||
await page.waitForFunction(id=>document.getElementById(id).closeSeen,dialogId);
|
||||
assert(await page.locator(`#${openerId}`).evaluate(n=>n===document.activeElement));
|
||||
}
|
||||
|
||||
async function run() {
|
||||
const {generateField, DEFAULTS, coordinate, neighbors} = await import(pathToFileURL(path.resolve(__dirname,'../../web/lu-trainer/engine.js')));
|
||||
const field = generateField(DEFAULTS,seeded());
|
||||
@@ -50,8 +71,8 @@ async function run() {
|
||||
const captures = [];
|
||||
try {
|
||||
if (shotDir) await mkdir(shotDir,{recursive:true});
|
||||
for (const [width,height,touch = false] of [[1920,1080],[1366,768],[768,1024],[390,844,true],[1024,768,true]]) {
|
||||
const mobile = width <= 700, compact = mobile || touch;
|
||||
for (const [width,height,touch = false] of [[1920,1080],[1366,768],[768,1024],[390,844,true],[844,390,true],[1024,768,true]]) {
|
||||
const mobile = width <= 700 || width === 844, compact = mobile || touch;
|
||||
const context = await browser.newContext({viewport:{width,height}, reducedMotion:'reduce', locale:'ru-RU', hasTouch:touch, isMobile:mobile});
|
||||
try {
|
||||
await context.addInitScript(() => {
|
||||
@@ -185,7 +206,27 @@ async function run() {
|
||||
assert(await scene(9).evaluate(n=>n===document.activeElement));
|
||||
await page.keyboard.press('Home'); assert(await scene(0).evaluate(n=>n===document.activeElement));
|
||||
// Click/tap an eligible neighbor on the map: selection and rating must never jump.
|
||||
if (mobile) await page.locator('#map-open').click();
|
||||
if (mobile) {
|
||||
const historyState = await page.evaluate(()=>({url:location.href,length:window.history.length}));
|
||||
await page.evaluate(()=>window.scrollTo(0,0));
|
||||
const grid = page.locator('#map-grid');
|
||||
assert(await grid.isVisible(),'the phone map must be in the page before activating its shortcut');
|
||||
assert(await page.locator('#map-home').evaluate(n=>n.getBoundingClientRect().top >= document.querySelector('.location').getBoundingClientRect().bottom));
|
||||
await page.mouse.move(width - 4,height / 2);
|
||||
await page.mouse.wheel(0,(await grid.boundingBox()).y - height / 3);
|
||||
await page.waitForFunction(()=>{
|
||||
const {top} = document.querySelector('#map-grid').getBoundingClientRect();
|
||||
return scrollY > 0 && top >= 0 && top < innerHeight;
|
||||
});
|
||||
await page.locator('#map-open').press('Enter');
|
||||
const heading = page.getByRole('heading',{name:'Минное поле',exact:true});
|
||||
assert(await heading.evaluate(n=>n===document.activeElement && n.getBoundingClientRect().top >= 0 && n.getBoundingClientRect().bottom <= innerHeight));
|
||||
assert(await page.locator('#scene-grid').isVisible(),'the scene stays in the document');
|
||||
assert(await page.locator('#panel-dialog').isHidden(),'the shortcut only scrolls the page');
|
||||
assert.deepEqual(await page.evaluate(()=>({url:location.href,length:window.history.length})),historyState);
|
||||
await page.keyboard.press('Tab');
|
||||
assert(await grid.evaluate(n=>n.contains(document.activeElement)));
|
||||
}
|
||||
const ratingCell = 11;
|
||||
const mapSelection = page.locator('#map-selection');
|
||||
const mapMark = page.locator('#map-mark');
|
||||
@@ -289,38 +330,48 @@ async function run() {
|
||||
assert.equal(await page.locator('#map-grid .opened').count(),2);
|
||||
assert.equal(await history.count(),beforeFlag + 2);
|
||||
if (mobile) {
|
||||
await page.keyboard.press('Escape');
|
||||
assert(await page.locator('#map-open').evaluate(n=>n===document.activeElement));
|
||||
await page.locator('#history-open').click();
|
||||
assert(await page.locator('#panel-dialog #history').isVisible());
|
||||
await page.keyboard.press('Escape');
|
||||
await page.locator('#history-home #history').waitFor({state:'attached'});
|
||||
assert(await page.locator('#history-open').evaluate(n=>n===document.activeElement));
|
||||
} else {
|
||||
await page.locator('#map-toggle').click(); assert(await page.locator('#map-body').isHidden());
|
||||
await page.locator('#map-expand').click(); assert(await page.locator('#panel-dialog #map-grid').isVisible());
|
||||
await page.keyboard.press('Escape'); assert(await page.locator('#map-body').isHidden());
|
||||
await page.keyboard.press('Escape');
|
||||
await page.locator('#map-home #map-body[hidden]').waitFor({state:'attached'});
|
||||
assert(await page.locator('#map-expand').evaluate(n=>n===document.activeElement));
|
||||
if (width === 768) {
|
||||
await page.setViewportSize({width:690,height});
|
||||
await page.locator('#map-grid').waitFor({state:'visible'});
|
||||
await page.setViewportSize({width,height});
|
||||
await page.locator('#map-body').waitFor({state:'hidden'});
|
||||
}
|
||||
await page.locator('#map-toggle').click();
|
||||
}
|
||||
if (shotDir) {
|
||||
const file = `${shotDir}/lu-${width}.png`;
|
||||
// Full-page capture temporarily resizes emulation and can reset the wide coarse-pointer mode.
|
||||
await page.screenshot({path:file,fullPage:!touch || mobile});
|
||||
await page.screenshot({path:file,fullPage:!touch || width <= 700});
|
||||
captures.push(file);
|
||||
}
|
||||
// Restart confirmations preserve/cancel the existing state; settings are staged until submit.
|
||||
await page.locator('#new-game').click(); await page.keyboard.press('Escape');
|
||||
const escape = () => page.keyboard.press('Escape');
|
||||
await page.locator('#new-game').click();
|
||||
await finishDialog(page,'confirm-dialog','new-game',escape);
|
||||
assert.equal(await page.locator('#scene-grid .opened').count(),2);
|
||||
await page.locator('#settings-open').click(); await page.locator('#setting-height').selectOption('2');
|
||||
await page.keyboard.press('Escape'); assert.match(await page.locator('#height-value').textContent(),/^1/);
|
||||
await finishDialog(page,'settings-dialog','settings-open',escape);
|
||||
assert.match(await page.locator('#height-value').textContent(),/^1/);
|
||||
await page.locator('#settings-open').click();
|
||||
assert.equal(await page.locator('#setting-height').inputValue(),'1');
|
||||
await page.locator('#setting-height').selectOption('2');
|
||||
await page.getByRole('button',{name:'Начать новую игру',exact:true}).click();
|
||||
await finishDialog(page,'settings-dialog','settings-open',()=>page.getByRole('button',{name:'Начать новую игру',exact:true}).click());
|
||||
assert.match(await page.locator('#height-value').textContent(),/^2/);
|
||||
assert.equal(await page.locator('#scene-grid .opened').count(),0);
|
||||
assert.equal(await page.locator('#history li').count(),0);
|
||||
assert.equal(await page.locator('#timer').textContent(),'00:00');
|
||||
assert.match(await scene(0).getAttribute('aria-label'), /вход, персонаж здесь/);
|
||||
assert.match(await scene(0).getAttribute('aria-label'), /^x1 y1: вход(?:, опасностей рядом: [0-2])?, персонаж здесь$/);
|
||||
await checkTransitions(page);
|
||||
await assertAvailable([1,10,11]);
|
||||
// Mark and unmark with compact buttons or Shift+Enter without moving the character.
|
||||
@@ -374,6 +425,46 @@ async function run() {
|
||||
assert.deepEqual([...exits].sort((a,b)=>a-b),allowedExits);
|
||||
console.log('PASS all permitted exit cells, synchronized transitions, exit cannot be jumped to or marked');
|
||||
} finally { await boundary.close(); }
|
||||
// Seed one entrance at each legal level, including a real zero.
|
||||
const entrances = await browser.newContext({viewport:{width:390,height:844},isMobile:true,hasTouch:true});
|
||||
try {
|
||||
for (const [entranceSeed, value] of [[1,0],[2,1],[6,2]]) {
|
||||
assert.equal(generateField(DEFAULTS,seeded(entranceSeed)).values[0],value);
|
||||
const page = await entrances.newPage();
|
||||
try {
|
||||
await page.addInitScript(seed => {
|
||||
Math.random = () => { seed = (Math.imul(seed,1664525)+1013904223) >>> 0; return seed / 2 ** 32; };
|
||||
window.entranceCues = 0;
|
||||
window.AudioContext = class extends AudioContext {
|
||||
createBuffer(...args) { window.entranceCues++; return super.createBuffer(...args); }
|
||||
};
|
||||
},entranceSeed);
|
||||
await page.goto(`${origin}/trainer`);
|
||||
await page.locator('#scene-grid .entrance button').waitFor();
|
||||
const replay = page.locator('#replay-sound'), simple = page.locator('#simple-mode');
|
||||
await assertEntranceLevel(page,null);
|
||||
assert.equal(await page.evaluate(()=>window.entranceCues),0,'no entrance audio plays automatically');
|
||||
assert.equal(await replay.isDisabled(),value === 0);
|
||||
if (value > 0) {
|
||||
await replay.tap();
|
||||
await page.waitForFunction(()=>window.entranceCues === 1);
|
||||
}
|
||||
await simple.check();
|
||||
await assertEntranceLevel(page,value);
|
||||
if (shotDir && value === 2) {
|
||||
const file = `${shotDir}/lu-entrance-390.png`;
|
||||
await page.screenshot({path:file});
|
||||
captures.push(file);
|
||||
}
|
||||
assert(await replay.isDisabled());
|
||||
await simple.uncheck();
|
||||
await assertEntranceLevel(page,null);
|
||||
assert.equal(await page.evaluate(()=>window.entranceCues),value > 0 ? 1 : 0,'mode changes do not play a cue');
|
||||
assert.equal(await page.locator('#history li').count(),0,'replaying an entrance cue is not a jump');
|
||||
} finally { await page.close(); }
|
||||
}
|
||||
console.log('PASS entrance 0–2, mode-dependent arrow/level and ARIA, manual replay only');
|
||||
} finally { await entrances.close(); }
|
||||
// The same opened cell can display both the player's rating and the model's actual value.
|
||||
const audio = await browser.newContext({viewport:{width:1366,height:768}});
|
||||
try {
|
||||
@@ -476,6 +567,8 @@ async function run() {
|
||||
await cell(hazard).click();
|
||||
assert(await page.locator('#result').isVisible());
|
||||
assert((await page.locator('#result').textContent()).includes(`Падение на ${coordinate(hazard)}`));
|
||||
await assertEntranceLevel(page,field.values[0],false);
|
||||
assert(await page.locator('#replay-sound').isDisabled());
|
||||
assert.equal(await page.locator('#scene-grid .hazard').count(),field.hazards.size);
|
||||
const count = await page.locator('#history li').count();
|
||||
await cell(11).click(); // Previously opened, adjacent to the current cell: blocked only by the result lock.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { Training, generateField, neighbors, hintChance, START, coordinate } from '../../web/lu-trainer/engine.js';
|
||||
import { Training, generateField, neighbors, hintChance, START, COLS, coordinate } from '../../web/lu-trainer/engine.js';
|
||||
import { rustleSamples } from '../../web/lu-trainer/audio.js';
|
||||
|
||||
function seeded(seed = 19) {
|
||||
@@ -52,6 +52,49 @@ test('entrance is always x1 y1 and exits vary only on the allowed edges', () =>
|
||||
assert.deepEqual([...exits].sort((a,b)=>a-b), allowed);
|
||||
});
|
||||
|
||||
test('entrance-area limits apply to actual hazards without making either lower cell safe', () => {
|
||||
const dense = {...options, height: 5, growth: 25, season: 5};
|
||||
const limits = [[START, 2], [COLS, 3], [2 * COLS, 4]];
|
||||
const levels = limits.map(() => new Set());
|
||||
const edgeHazards = new Set();
|
||||
for (let seed = 0; seed < 100; seed++) {
|
||||
const field = generateField(dense, seeded(seed));
|
||||
assert.equal(field.hazards.size, 38, `seed ${seed}`);
|
||||
assert(!field.hazards.has(START));
|
||||
limits.forEach(([id, max], i) => {
|
||||
const actual = neighbors(id).filter(neighbor => field.hazards.has(neighbor)).length;
|
||||
assert(actual <= max, `seed ${seed}: ${coordinate(id)} has ${actual} hazards, expected at most ${max}`);
|
||||
assert.equal(field.values[id], actual);
|
||||
levels[i].add(actual);
|
||||
if (field.hazards.has(id)) edgeHazards.add(id);
|
||||
});
|
||||
}
|
||||
assert.deepEqual(levels[0], new Set([0, 1, 2]));
|
||||
assert(levels[1].has(3));
|
||||
assert(levels[2].has(4));
|
||||
assert.deepEqual(edgeHazards, new Set([COLS, 2 * COLS]));
|
||||
});
|
||||
|
||||
test('the ready snapshot reveals the entrance number but does not open the transition', () => {
|
||||
const dense = {...options, height: 5, growth: 25, season: 5};
|
||||
for (const seed of [0, 2, 5]) {
|
||||
const {field, game} = fixture(dense, seed);
|
||||
const view = game.view();
|
||||
const start = view.cells[view.start];
|
||||
assert.equal(start.value, field.values[START]);
|
||||
assert.equal(start.opened, false);
|
||||
assert.equal(start.available, false);
|
||||
assert.equal(view.opened, 0);
|
||||
assert(view.cells.every(cell => cell.entrance || cell.value === null));
|
||||
assert.equal(game.jump(START).code, 'transition');
|
||||
assert.equal(game.mark(START).code, 'transition');
|
||||
assert.equal(game.rate(START, 1).code, 'transition');
|
||||
assert.equal(game.jump(1).code, 'opened');
|
||||
assert.equal(game.view().cells[START].value, start.value);
|
||||
assert.equal(game.view().opened, 1);
|
||||
}
|
||||
});
|
||||
|
||||
test('generation covers every settings combination with safe transitions, base and connecting route', () => {
|
||||
for (let height = 1; height <= 5; height++) for (const growth of [12,15,18,22,25]) for (const season of [-3,0,5]) {
|
||||
const field = generateField({...options, height, growth, season}, seeded(height * growth + season));
|
||||
|
||||
Reference in new issue
Block a user