Add battle count splash
parent
4377596f46
commit
0d2f3e0388
|
@ -1,4 +1,7 @@
|
||||||
|
export const battleCountSplashMessage = '{COUNT} Battles Won!';
|
||||||
|
|
||||||
export const splashMessages = [
|
export const splashMessages = [
|
||||||
|
battleCountSplashMessage,
|
||||||
'Join the Discord!',
|
'Join the Discord!',
|
||||||
'Infinite Levels!',
|
'Infinite Levels!',
|
||||||
'Everything Stacks!',
|
'Everything Stacks!',
|
||||||
|
|
|
@ -4,15 +4,16 @@ import OptionSelectUiHandler from "./option-select-ui-handler";
|
||||||
import { Mode } from "./ui";
|
import { Mode } from "./ui";
|
||||||
import * as Utils from "../utils";
|
import * as Utils from "../utils";
|
||||||
import { TextStyle, addTextObject } from "./text";
|
import { TextStyle, addTextObject } from "./text";
|
||||||
import { splashMessages } from "../data/splash-messages";
|
import { battleCountSplashMessage, splashMessages } from "../data/splash-messages";
|
||||||
|
|
||||||
export default class TitleUiHandler extends OptionSelectUiHandler {
|
export default class TitleUiHandler extends OptionSelectUiHandler {
|
||||||
private titleContainer: Phaser.GameObjects.Container;
|
private titleContainer: Phaser.GameObjects.Container;
|
||||||
private dailyRunScoreboard: DailyRunScoreboard;
|
private dailyRunScoreboard: DailyRunScoreboard;
|
||||||
private playerCountLabel: Phaser.GameObjects.Text;
|
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) {
|
constructor(scene: BattleScene, mode: Mode = Mode.TITLE) {
|
||||||
super(scene, mode);
|
super(scene, mode);
|
||||||
|
@ -31,11 +32,6 @@ export default class TitleUiHandler extends OptionSelectUiHandler {
|
||||||
logo.setOrigin(0.5, 0);
|
logo.setOrigin(0.5, 0);
|
||||||
this.titleContainer.add(logo);
|
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 = new DailyRunScoreboard(this.scene, 1, 44);
|
||||||
this.dailyRunScoreboard.setup();
|
this.dailyRunScoreboard.setup();
|
||||||
|
|
||||||
|
@ -45,10 +41,15 @@ export default class TitleUiHandler extends OptionSelectUiHandler {
|
||||||
this.playerCountLabel.setOrigin(1, 0);
|
this.playerCountLabel.setOrigin(1, 0);
|
||||||
this.titleContainer.add(this.playerCountLabel);
|
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({
|
this.scene.tweens.add({
|
||||||
targets: this.splashMessage,
|
targets: this.splashMessageText,
|
||||||
duration: Utils.fixedInt(350),
|
duration: Utils.fixedInt(350),
|
||||||
scale: originalSplashMessageScale * 1.25,
|
scale: originalSplashMessageScale * 1.25,
|
||||||
loop: -1,
|
loop: -1,
|
||||||
|
@ -56,25 +57,30 @@ export default class TitleUiHandler extends OptionSelectUiHandler {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
updatePlayerCount(): void {
|
updateTitleStats(): void {
|
||||||
Utils.apiFetch(`game/playercount`)
|
Utils.apiFetch(`game/titlestats`)
|
||||||
.then(request => request.json())
|
.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 {
|
show(args: any[]): boolean {
|
||||||
const ret = super.show(args);
|
const ret = super.show(args);
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
this.splashMessage.setText(Utils.randItem(splashMessages));
|
this.splashMessage = Utils.randItem(splashMessages);
|
||||||
|
this.splashMessageText.setText(this.splashMessage.replace('{COUNT}', '?'));
|
||||||
|
|
||||||
const ui = this.getUi();
|
const ui = this.getUi();
|
||||||
|
|
||||||
this.dailyRunScoreboard.update();
|
this.dailyRunScoreboard.update();
|
||||||
|
|
||||||
this.updatePlayerCount();
|
this.updateTitleStats();
|
||||||
|
|
||||||
this.playerCountTimer = setInterval(() => this.updatePlayerCount(), 10000);
|
this.titleStatsTimer = setInterval(() => this.updateTitleStats(), 10000);
|
||||||
|
|
||||||
this.scene.tweens.add({
|
this.scene.tweens.add({
|
||||||
targets: [ this.titleContainer, ui.getMessageHandler().bg ],
|
targets: [ this.titleContainer, ui.getMessageHandler().bg ],
|
||||||
|
@ -92,8 +98,8 @@ export default class TitleUiHandler extends OptionSelectUiHandler {
|
||||||
|
|
||||||
const ui = this.getUi();
|
const ui = this.getUi();
|
||||||
|
|
||||||
clearInterval(this.playerCountTimer);
|
clearInterval(this.titleStatsTimer);
|
||||||
this.playerCountTimer = null;
|
this.titleStatsTimer = null;
|
||||||
|
|
||||||
this.scene.tweens.add({
|
this.scene.tweens.add({
|
||||||
targets: [ this.titleContainer, ui.getMessageHandler().bg ],
|
targets: [ this.titleContainer, ui.getMessageHandler().bg ],
|
||||||
|
|
Loading…
Reference in New Issue