84 lines
3.6 KiB
HTML
84 lines
3.6 KiB
HTML
<!doctype html>
|
|
<html><head><meta charset="utf-8">
|
|
<script type="importmap">{"imports":{"phaser":"/phaser.esm.js"}}</script>
|
|
<style>html,body{margin:0;background:#111}canvas{display:block}</style>
|
|
</head><body>
|
|
<div id="log"></div>
|
|
<script type="module">
|
|
import * as Phaser from 'phaser';
|
|
import JigsawGame from './src/games/jigsaw/JigsawGame.js';
|
|
|
|
const log = (m) => { document.getElementById('log').textContent += m + '\n'; console.log('[t]', m); };
|
|
let failures = 0;
|
|
const check = (ok, msg) => { if (!ok) { failures++; log('FAIL: ' + msg); } else log('ok: ' + msg); };
|
|
const wait = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
|
|
const ART = [
|
|
{ name: 'Alien World', path: 'assets/images/shift/alien-world.png' },
|
|
{ name: 'Aquaroom', path: 'assets/images/shift/aquaroom.png' },
|
|
{ name: 'Aztec Warrior', path: 'assets/images/shift/aztec-warrior.png' },
|
|
{ name: 'Cat On Tiger', path: 'assets/images/shift/cat-on-tiger.png' },
|
|
{ name: 'Cockpit', path: 'assets/images/shift/cockpit.png' },
|
|
];
|
|
|
|
const config = {
|
|
type: Phaser.AUTO,
|
|
width: 1920, height: 1080,
|
|
parent: document.body,
|
|
backgroundColor: '#000',
|
|
scene: [ { key: 'boot', create() {
|
|
this.cache.json.add('shift-artwork', { artwork: ART });
|
|
this.cache.json.add('music', { tracks: [] });
|
|
this.scene.start('jigsaw-game');
|
|
} }, JigsawGame ],
|
|
};
|
|
const game = new Phaser.Game(config);
|
|
const s = () => game.scene.getScene('jigsaw-game');
|
|
|
|
(async () => {
|
|
for (let i = 0; i < 400 && !s(); i++) await wait(50); // boot → jigsaw start is async
|
|
if (!s()) throw new Error('jigsaw scene never started');
|
|
for (let i = 0; i < 400 && !s().menu; i++) await wait(50);
|
|
check(!!s().menu, 'menu built');
|
|
|
|
// Menu is back to the original shape (random-start button reverted).
|
|
check(s().randomStartButton === undefined, 'randomStartButton is gone (menu as before)');
|
|
|
|
// The initial image is random but always a valid artwork entry, and the
|
|
// preview shown in the menu matches it.
|
|
const n = s().artwork.length;
|
|
const i = s().imageIndex;
|
|
check(Number.isInteger(i) && i >= 0 && i < n, `initial imageIndex ${i} is a valid index (0..${n - 1})`);
|
|
check(!!ART.find((a) => a.name === s().currentImage().name), 'initial currentImage() is a known artwork entry');
|
|
|
|
// Preview must be built for the initial image (async image load).
|
|
for (let k = 0; k < 200 && !s().previewImg; k++) await wait(25);
|
|
check(!!s().previewImg, 'initial preview image is displayed');
|
|
check(s().thumbName && s().thumbName.text === s().currentImage().name, `thumb name matches initial image (${s().currentImage().name})`);
|
|
|
|
// Start Puzzle must still start the initial (random) image.
|
|
s().selectedDiff = 'easy';
|
|
s().startPuzzle();
|
|
let playing = false;
|
|
for (let k = 0; k < 400 && !playing; k++) { playing = s().state === 'playing'; await wait(25); }
|
|
check(playing, 'Start Puzzle reaches playing state');
|
|
check(s().pieces.length === 25, '25 pieces built');
|
|
check(s().imageName === ART[i].name, `playing image matches the initial pick (${ART[i].name})`);
|
|
|
|
// The original 🎲 Random button still randomises the preview in the menu.
|
|
s().toMenu();
|
|
const before = s().imageIndex;
|
|
const seen = new Set([before]);
|
|
for (let k = 0; k < 10; k++) { s().randomImage(); seen.add(s().imageIndex); await wait(10); }
|
|
check(seen.size >= 2, '🎲 Random button still changes the selected image');
|
|
|
|
document.__initIndex = i;
|
|
log(failures === 0 ? 'ALL PASS' : failures + ' FAILURES');
|
|
document.title = failures === 0 ? 'PASS' : 'FAIL:' + failures;
|
|
})().catch((e) => {
|
|
log('ERROR: ' + ((e && e.stack) || e));
|
|
document.title = 'FAIL:error';
|
|
});
|
|
</script>
|
|
</body></html>
|