fertig-classic-games/__jig_init_test.html

61 lines
2.2 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); };
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);
if (!s().menu) throw new Error('menu never built');
// The preview image is loaded asynchronously; give it a moment.
for (let i = 0; i < 200 && !s().previewImg; i++) await wait(25);
const sc = s();
const item = sc.currentImage();
document.title = 'RESULT:' + JSON.stringify({
idx: sc.imageIndex,
n: sc.artwork.length,
name: item && item.name,
validName: ART.some((a) => a.name === item.name),
preview: !!sc.previewImg,
menuVisible: sc.menu.visible,
});
log('initial image: ' + item.name + ' (index ' + sc.imageIndex + ' of ' + sc.artwork.length + ')');
})().catch((e) => {
log('ERROR: ' + ((e && e.stack) || e));
document.title = 'FAIL:' + ((e && e.message) || e);
});
</script>
</body></html>