From 0d2f3e03888c95621f64e3a7dfed29f4e358fdd6 Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Sat, 6 Apr 2024 18:29:17 -0400 Subject: [PATCH] Add battle count splash --- src/data/splash-messages.ts | 3 +++ src/ui/title-ui-handler.ts | 42 +++++++++++++++++++++---------------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/data/splash-messages.ts b/src/data/splash-messages.ts index c68b68c98..72dfc60d5 100644 --- a/src/data/splash-messages.ts +++ b/src/data/splash-messages.ts @@ -1,4 +1,7 @@ +export const battleCountSplashMessage = '{COUNT} Battles Won!'; + export const splashMessages = [ + battleCountSplashMessage, 'Join the Discord!', 'Infinite Levels!', 'Everything Stacks!', diff --git a/src/ui/title-ui-handler.ts b/src/ui/title-ui-handler.ts index 2f4ae045d..48f6e0590 100644 --- a/src/ui/title-ui-handler.ts +++ b/src/ui/title-ui-handler.ts @@ -4,15 +4,16 @@ import OptionSelectUiHandler from "./option-select-ui-handler"; import { Mode } from "./ui"; import * as Utils from "../utils"; import { TextStyle, addTextObject } from "./text"; -import { splashMessages } from "../data/splash-messages"; +import { battleCountSplashMessage, 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 splashMessage: string; + private splashMessageText: Phaser.GameObjects.Text; - private playerCountTimer; + private titleStatsTimer; constructor(scene: BattleScene, mode: Mode = Mode.TITLE) { super(scene, mode); @@ -31,11 +32,6 @@ export default class TitleUiHandler extends OptionSelectUiHandler { logo.setOrigin(0.5, 0); this.titleContainer.add(logo); - this.splashMessage = addTextObject(this.scene, logo.x + 64, logo.y + logo.displayHeight - 8, '', TextStyle.MONEY, { fontSize: '54px' }); - this.splashMessage.setOrigin(0.5, 0.5); - this.splashMessage.setAngle(-20) - this.titleContainer.add(this.splashMessage); - this.dailyRunScoreboard = new DailyRunScoreboard(this.scene, 1, 44); this.dailyRunScoreboard.setup(); @@ -45,10 +41,15 @@ export default class TitleUiHandler extends OptionSelectUiHandler { this.playerCountLabel.setOrigin(1, 0); this.titleContainer.add(this.playerCountLabel); - const originalSplashMessageScale = this.splashMessage.scale; + this.splashMessageText = addTextObject(this.scene, logo.x + 64, logo.y + logo.displayHeight - 8, '', TextStyle.MONEY, { fontSize: '54px' }); + this.splashMessageText.setOrigin(0.5, 0.5); + this.splashMessageText.setAngle(-20) + this.titleContainer.add(this.splashMessageText); + + const originalSplashMessageScale = this.splashMessageText.scale; this.scene.tweens.add({ - targets: this.splashMessage, + targets: this.splashMessageText, duration: Utils.fixedInt(350), scale: originalSplashMessageScale * 1.25, loop: -1, @@ -56,25 +57,30 @@ export default class TitleUiHandler extends OptionSelectUiHandler { }) } - updatePlayerCount(): void { - Utils.apiFetch(`game/playercount`) + updateTitleStats(): void { + Utils.apiFetch(`game/titlestats`) .then(request => request.json()) - .then(count => this.playerCountLabel.setText(`${count} Players Online`)); + .then(stats => { + this.playerCountLabel.setText(`${stats.playerCount} Players Online`); + if (this.splashMessage === battleCountSplashMessage) + this.splashMessageText.setText(battleCountSplashMessage.replace('{COUNT}', stats.battleCount.toLocaleString('en-US'))); + }); } show(args: any[]): boolean { const ret = super.show(args); if (ret) { - this.splashMessage.setText(Utils.randItem(splashMessages)); + this.splashMessage = Utils.randItem(splashMessages); + this.splashMessageText.setText(this.splashMessage.replace('{COUNT}', '?')); const ui = this.getUi(); this.dailyRunScoreboard.update(); - this.updatePlayerCount(); + this.updateTitleStats(); - this.playerCountTimer = setInterval(() => this.updatePlayerCount(), 10000); + this.titleStatsTimer = setInterval(() => this.updateTitleStats(), 10000); this.scene.tweens.add({ targets: [ this.titleContainer, ui.getMessageHandler().bg ], @@ -92,8 +98,8 @@ export default class TitleUiHandler extends OptionSelectUiHandler { const ui = this.getUi(); - clearInterval(this.playerCountTimer); - this.playerCountTimer = null; + clearInterval(this.titleStatsTimer); + this.titleStatsTimer = null; this.scene.tweens.add({ targets: [ this.titleContainer, ui.getMessageHandler().bg ],