69 lines
2.5 KiB
JavaScript
69 lines
2.5 KiB
JavaScript
/**
|
|
* Missionsbriefing im Schreibmaschinenstil. Leertaste/Klick zeigt zuerst den ganzen
|
|
* Text, ein zweiter Druck startet den Einsatz.
|
|
* @module scenes/BriefingScene
|
|
*/
|
|
|
|
import { BRIEFING_CONTINUE, BRIEFINGS, PRESIDENT } from '../content/texts.js';
|
|
import { oncePerEvent } from '../systems/keyboard.js';
|
|
import { textStyle, UI } from '../ui/theme.js';
|
|
|
|
/** Tippgeschwindigkeit der Schreibmaschine in Zeichen pro Sekunde. */
|
|
const CHARS_PER_SECOND = 70;
|
|
|
|
export class BriefingScene extends Phaser.Scene {
|
|
constructor() {
|
|
super('Briefing');
|
|
}
|
|
|
|
create() {
|
|
const { width, height } = this.scale;
|
|
this.input.setDefaultCursor('default');
|
|
const briefing = BRIEFINGS[Math.floor(Math.random() * BRIEFINGS.length)];
|
|
|
|
const bg = this.add.graphics();
|
|
bg.fillStyle(0x0d1321, 1);
|
|
bg.fillRect(0, 0, width, height);
|
|
bg.lineStyle(3, 0xf2c14e, 1);
|
|
bg.strokeRect(60, 50, width - 120, height - 100);
|
|
bg.fillStyle(0xc1121f, 1);
|
|
bg.fillRect(60, 50, width - 120, 64);
|
|
|
|
this.add.text(width / 2, 82, briefing.title, textStyle({ fontSize: '26px', strokeThickness: 0 })).setOrigin(0.5);
|
|
this.add.text(96, 140, `AN: ${PRESIDENT.toUpperCase()}`, textStyle({ fontSize: '18px', color: UI.colors.gold }));
|
|
|
|
this.fullText = briefing.lines.join('\n\n');
|
|
this.bodyText = this.add.text(96, 185, '', {
|
|
...textStyle({ fontSize: '21px', strokeThickness: 0 }),
|
|
fontFamily: 'Consolas, "Courier New", monospace',
|
|
wordWrap: { width: width - 192 },
|
|
lineSpacing: 6,
|
|
});
|
|
this.typed = 0;
|
|
|
|
this.add.text(width / 2, height - 80, BRIEFING_CONTINUE, textStyle({ fontSize: '17px', color: UI.colors.muted })).setOrigin(0.5);
|
|
|
|
const advance = oncePerEvent((event) => {
|
|
// Gedrückt gehaltene Tasten sollen das Briefing nicht versehentlich überspringen.
|
|
if (event?.repeat) return;
|
|
if (this.typed < this.fullText.length) {
|
|
this.typed = this.fullText.length;
|
|
this.bodyText.setText(this.fullText);
|
|
} else {
|
|
this.scene.start('Game');
|
|
}
|
|
});
|
|
this.input.on('pointerup', advance);
|
|
this.input.keyboard.on('keydown-SPACE', advance);
|
|
this.input.keyboard.on('keydown-ENTER', advance);
|
|
this.input.keyboard.on('keydown-ESC', oncePerEvent(() => this.scene.start('Menu')));
|
|
this.input.keyboard.addCapture('SPACE');
|
|
}
|
|
|
|
update(_time, delta) {
|
|
if (this.typed >= this.fullText.length) return;
|
|
this.typed = Math.min(this.fullText.length, this.typed + (CHARS_PER_SECOND * delta) / 1000);
|
|
this.bodyText.setText(this.fullText.slice(0, Math.floor(this.typed)));
|
|
}
|
|
}
|