use api in title-ui-handler

This commit is contained in:
flx-sta 2024-10-03 17:11:56 -07:00
parent a1adc40371
commit 565d80f262

View File

@ -7,6 +7,7 @@ import { getSplashMessages } from "../data/splash-messages";
import i18next from "i18next"; import i18next from "i18next";
import { TimedEventDisplay } from "#app/timed-event-manager"; import { TimedEventDisplay } from "#app/timed-event-manager";
import { version } from "../../package.json"; import { version } from "../../package.json";
import { api } from "#app/plugins/api/api";
export default class TitleUiHandler extends OptionSelectUiHandler { export default class TitleUiHandler extends OptionSelectUiHandler {
/** If the stats can not be retrieved, use this fallback value */ /** If the stats can not be retrieved, use this fallback value */
@ -78,13 +79,14 @@ export default class TitleUiHandler extends OptionSelectUiHandler {
} }
updateTitleStats(): void { updateTitleStats(): void {
Utils.apiFetch("game/titlestats") api.getGameTitleStats()
.then(request => request.json())
.then(stats => { .then(stats => {
if (stats) {
this.playerCountLabel.setText(`${stats.playerCount} ${i18next.t("menu:playersOnline")}`); this.playerCountLabel.setText(`${stats.playerCount} ${i18next.t("menu:playersOnline")}`);
if (this.splashMessage === "splashMessages:battlesWon") { if (this.splashMessage === "splashMessages:battlesWon") {
this.splashMessageText.setText(i18next.t(this.splashMessage, { count: stats.battleCount })); this.splashMessageText.setText(i18next.t(this.splashMessage, { count: stats.battleCount }));
} }
}
}) })
.catch(err => { .catch(err => {
console.error("Failed to fetch title stats:\n", err); console.error("Failed to fetch title stats:\n", err);