Add player count on title screen

pull/16/head
Flashfyre 2024-03-23 21:33:57 -04:00
parent 0d776b5a7a
commit caaacca0ad
1 changed files with 20 additions and 0 deletions

View File

@ -9,8 +9,11 @@ import { splashMessages } from "../data/splash-messages";
export default class TitleUiHandler extends OptionSelectUiHandler {
private titleContainer: Phaser.GameObjects.Container;
private dailyRunScoreboard: DailyRunScoreboard;
private playerCountLabel: Phaser.GameObjects.Text;
private splashMessage: Phaser.GameObjects.Text;
private playerCountTimer;
constructor(scene: BattleScene, mode: Mode = Mode.TITLE) {
super(scene, mode);
}
@ -38,6 +41,10 @@ export default class TitleUiHandler extends OptionSelectUiHandler {
this.titleContainer.add(this.dailyRunScoreboard);
this.playerCountLabel = addTextObject(this.scene, (this.scene.game.canvas.width / 6) - 2, (this.scene.game.canvas.height / 6) - 90, '? Players Online', TextStyle.MESSAGE, { fontSize: '54px' });
this.playerCountLabel.setOrigin(1, 0);
this.titleContainer.add(this.playerCountLabel);
const originalSplashMessageScale = this.splashMessage.scale;
this.scene.tweens.add({
@ -49,6 +56,12 @@ export default class TitleUiHandler extends OptionSelectUiHandler {
})
}
updatePlayerCount(): void {
Utils.apiFetch(`game/playercount`)
.then(request => request.json())
.then(count => this.playerCountLabel.setText(`${count} Players Online`));
}
show(args: any[]): boolean {
const ret = super.show(args);
@ -59,6 +72,10 @@ export default class TitleUiHandler extends OptionSelectUiHandler {
this.dailyRunScoreboard.update();
this.updatePlayerCount();
this.playerCountTimer = setInterval(() => this.updatePlayerCount(), 10000);
this.scene.tweens.add({
targets: [ this.titleContainer, ui.getMessageHandler().bg ],
duration: Utils.fixedInt(325),
@ -75,6 +92,9 @@ export default class TitleUiHandler extends OptionSelectUiHandler {
const ui = this.getUi();
clearInterval(this.playerCountTimer);
this.playerCountTimer = null;
this.scene.tweens.add({
targets: [ this.titleContainer, ui.getMessageHandler().bg ],
duration: Utils.fixedInt(325),