fertig-classic-games/public/src/scenes/PreloadScene.js

77 lines
3.1 KiB
JavaScript

import * as Phaser from 'phaser';
import { GAME_HEIGHT, GAME_WIDTH, COLORS } from '../config.js';
import { auth } from '../services/auth.js';
export default class PreloadScene extends Phaser.Scene {
constructor() { super('Preload'); }
preload() {
const w = GAME_WIDTH;
const h = GAME_HEIGHT;
const barWidth = 600;
const bg = this.add.rectangle(w / 2, h / 2, barWidth + 8, 28, COLORS.panel)
.setStrokeStyle(2, COLORS.accent);
const bar = this.add.rectangle(w / 2 - barWidth / 2, h / 2, 0, 20, COLORS.accent)
.setOrigin(0, 0.5);
this.add.text(w / 2, h / 2 - 60, 'Loading…', {
fontFamily: '"Julius Sans One"',
fontSize: '32px',
color: COLORS.textHex,
}).setOrigin(0.5);
this.load.on('progress', (p) => bar.width = barWidth * p);
this.load.on('complete', () => { bg.destroy(); bar.destroy(); });
this.load.spritesheet('opponents', '/assets/images/opponents.png', {
frameWidth: 300,
frameHeight: 300,
});
this.load.spritesheet('cardbacks', '/assets/images/cardbacks.png', {
frameWidth: 320,
frameHeight: 420,
});
this.load.image('bg-menu', '/assets/images/background-menu.png');
this.load.image('bg-room', '/assets/images/background-room.png');
this.load.image('bg-casino', '/assets/images/background-casino.png');
this.load.image('main-title', '/assets/images/main-title.png');
this.load.json('playfields', '/data/playfields.json');
this.load.json('card-backs', '/data/card-backs.json');
this.load.json('music', '/data/music.json');
this.load.audio('sfx-card-deal', '/assets/fx/card-deal.mp3');
this.load.audio('sfx-card-place', '/assets/fx/card-place.mp3');
this.load.audio('sfx-card-show', '/assets/fx/card-show.mp3');
this.load.audio('sfx-card-shuffle', '/assets/fx/card-shuffle.mp3');
this.load.audio('sfx-casino-blackjack', '/assets/fx/casino-blackjack.mp3');
this.load.audio('sfx-casino-lose', '/assets/fx/casino-lose.mp3');
this.load.audio('sfx-casino-win', '/assets/fx/casino-win.mp3');
this.load.audio('sfx-chip-bet', '/assets/fx/chip-bet.mp3');
this.load.audio('sfx-dice-roll', '/assets/fx/dice-roll.mp3');
this.load.audio('sfx-pencil-write', '/assets/fx/pencil-write.mp3');
this.load.audio('sfx-piece-click', '/assets/fx/piece-click.mp3');
this.load.audio('sfx-roulette', '/assets/fx/roulette.mp3');
}
async create() {
// Collect all image assets that need loading from JSON configs
const pfd = this.cache.json.get('playfields');
const cbd = this.cache.json.get('card-backs');
const toLoad = [
...(pfd?.playfields ?? []).filter((pf) => pf.path && !this.textures.exists(pf.key)),
...(cbd?.cardBacks ?? []).filter((cb) => cb.path && !this.textures.exists(cb.key)),
];
if (toLoad.length > 0) {
for (const asset of toLoad) this.load.image(asset.key, asset.path);
await new Promise((resolve) => {
this.load.once('complete', resolve);
this.load.start();
});
}
await auth.refresh();
this.scene.start('Landing');
}
}