refactor: settin up and displaying splash messages.

They are now stored with their i18next keys and only get translated as soon as they are displayed. This also allows for better display of the `battlesWon` parameter which now supports better number formatting and the count is an interpolation
This commit is contained in:
flx-sta 2024-09-18 14:52:03 -07:00
parent 56f9015265
commit c9fcec8eaa
12 changed files with 110 additions and 70 deletions

View File

@ -1,8 +1,37 @@
import i18next from "i18next";
//#region Interfaces/Types //#region Interfaces/Types
type Day = "01" | "02" | "03" | "04" | "05" | "06" | "07" | "08" | "09" | "10" | "11" | "12" | "13" | "14" | "15" | "16" | "17" | "18" | "19" | "20" | "21" | "22" | "23" | "24" | "25" | "26" | "27" | "28" | "29" | "30" | "31"; type Day =
| "01"
| "02"
| "03"
| "04"
| "05"
| "06"
| "07"
| "08"
| "09"
| "10"
| "11"
| "12"
| "13"
| "14"
| "15"
| "16"
| "17"
| "18"
| "19"
| "20"
| "21"
| "22"
| "23"
| "24"
| "25"
| "26"
| "27"
| "28"
| "29"
| "30"
| "31";
type Month = "Jan" | "Feb" | "Mar" | "Apr" | "May" | "Jun" | "Jul" | "Aug" | "Sep" | "Oct" | "Nov" | "Dec"; type Month = "Jan" | "Feb" | "Mar" | "Apr" | "May" | "Jun" | "Jul" | "Aug" | "Sep" | "Oct" | "Nov" | "Dec";
/** /**
@ -28,76 +57,72 @@ const BATTLES_WON_WEIGHT_MULTIPLIER = 10;
/** The weight multiplier for the seasonal splash messages */ /** The weight multiplier for the seasonal splash messages */
const SEASONAL_WEIGHT_MULTIPLIER = 10; const SEASONAL_WEIGHT_MULTIPLIER = 10;
//#endregion //#region Common Messages
const commonSplashMessages = [
...Array(BATTLES_WON_WEIGHT_MULTIPLIER).fill("battlesWon"),
"joinTheDiscord",
"infiniteLevels",
"everythingStacks",
"optionalSaveScumming",
"biomes",
"openSource",
"playWithSpeed",
"liveBugTesting",
"heavyInfluence",
"pokemonRiskAndPokemonRain",
"nowWithMoreSalt",
"infiniteFusionAtHome",
"brokenEggMoves",
"magnificent",
"mubstitute",
"thatsCrazy",
"oranceJuice",
"questionableBalancing",
"coolShaders",
"aiFree",
"suddenDifficultySpikes",
"basedOnAnUnfinishedFlashGame",
"moreAddictiveThanIntended",
"mostlyConsistentSeeds",
"achievementPointsDontDoAnything",
"youDoNotStartAtLevel",
"dontTalkAboutTheManaphyEggIncident",
"alsoTryPokengine",
"alsoTryEmeraldRogue",
"alsoTryRadicalRed",
"eeveeExpo",
"ynoproject",
"breedersInSpace",
];
//#region Seasonal Messages
const seasonalSplashMessages: Season[] = [ const seasonalSplashMessages: Season[] = [
{ {
name: "Halloween", name: "Halloween",
start: "15-Sep", start: "15-Sep",
end: "31-Oct", end: "31-Oct",
messages: [ messages: ["halloween.pumpkaboosAbout", "halloween.mayContainSpiders", "halloween.spookyScaryDuskulls"],
// add messages here. E.g. "splashMessages:happyHalloween"
],
}, },
{ {
name: "XMAS", name: "XMAS",
start: "01-Dec", start: "01-Dec",
end: "26-Dec", end: "26-Dec",
messages: [ messages: ["xmas.happyHolidays", "xmas.delibirdSeason"],
// add messages here. E.g. "splashMessages:happyHolidays"
],
}, },
{ {
name: "New Year's", name: "New Year's",
start: "01-Jan", start: "01-Jan",
end: "31-Jan", end: "31-Jan",
messages: [ messages: ["newYears.happyNewYear"],
// add messages here. E.g. "splashMessages:happyNewYear"
],
}, },
]; ];
export function getBattleCountSplashMessage(): string { //#endregion
return `{COUNT} ${i18next.t("splashMessages:battlesWon")}`;
}
export function getSplashMessages(): string[] { export function getSplashMessages(): string[] {
const splashMessages = Array(BATTLES_WON_WEIGHT_MULTIPLIER).fill(getBattleCountSplashMessage()); const splashMessages: string[] = [...commonSplashMessages];
splashMessages.push(
i18next.t("splashMessages:joinTheDiscord"),
i18next.t("splashMessages:infiniteLevels"),
i18next.t("splashMessages:everythingStacks"),
i18next.t("splashMessages:optionalSaveScumming"),
i18next.t("splashMessages:biomes"),
i18next.t("splashMessages:openSource"),
i18next.t("splashMessages:playWithSpeed"),
i18next.t("splashMessages:liveBugTesting"),
i18next.t("splashMessages:heavyInfluence"),
i18next.t("splashMessages:pokemonRiskAndPokemonRain"),
i18next.t("splashMessages:nowWithMoreSalt"),
i18next.t("splashMessages:infiniteFusionAtHome"),
i18next.t("splashMessages:brokenEggMoves"),
i18next.t("splashMessages:magnificent"),
i18next.t("splashMessages:mubstitute"),
i18next.t("splashMessages:thatsCrazy"),
i18next.t("splashMessages:oranceJuice"),
i18next.t("splashMessages:questionableBalancing"),
i18next.t("splashMessages:coolShaders"),
i18next.t("splashMessages:aiFree"),
i18next.t("splashMessages:suddenDifficultySpikes"),
i18next.t("splashMessages:basedOnAnUnfinishedFlashGame"),
i18next.t("splashMessages:moreAddictiveThanIntended"),
i18next.t("splashMessages:mostlyConsistentSeeds"),
i18next.t("splashMessages:achievementPointsDontDoAnything"),
i18next.t("splashMessages:youDoNotStartAtLevel"),
i18next.t("splashMessages:dontTalkAboutTheManaphyEggIncident"),
i18next.t("splashMessages:alsoTryPokengine"),
i18next.t("splashMessages:alsoTryEmeraldRogue"),
i18next.t("splashMessages:alsoTryRadicalRed"),
i18next.t("splashMessages:eeveeExpo"),
i18next.t("splashMessages:ynoproject"),
i18next.t("splashMessages:breedersInSpace")
);
// add seasonal splash messages if the season is active // add seasonal splash messages if the season is active
for (const { name, start, end, messages } of seasonalSplashMessages) { for (const { name, start, end, messages } of seasonalSplashMessages) {
@ -106,13 +131,13 @@ export function getSplashMessages(): string[] {
const endDate = new Date(`${end}-${now.getFullYear()}`); const endDate = new Date(`${end}-${now.getFullYear()}`);
if (now >= startDate && now <= endDate) { if (now >= startDate && now <= endDate) {
console.log( `Adding ${messages.length} seasonal splash messages for`, name, `(weight: x${SEASONAL_WEIGHT_MULTIPLIER})` ); console.log(`Adding ${messages.length} ${name} splash messages (weight: x${SEASONAL_WEIGHT_MULTIPLIER})`);
messages.forEach((message) => { messages.forEach((message) => {
const weightedMessage = Array(SEASONAL_WEIGHT_MULTIPLIER).fill(i18next.t(message)); const weightedMessage = Array(SEASONAL_WEIGHT_MULTIPLIER).fill(message);
splashMessages.push(...weightedMessage); splashMessages.push(...weightedMessage);
}); });
} }
} }
return splashMessages; return splashMessages.map((message) => `splashMessages:${message}`);
} }

View File

@ -1,5 +1,5 @@
{ {
"battlesWon": "Kämpfe gewonnen!", "battlesWon": "{{count, number}} Kämpfe gewonnen!",
"joinTheDiscord": "Tritt dem Discord bei!", "joinTheDiscord": "Tritt dem Discord bei!",
"infiniteLevels": "Unendliche Level!", "infiniteLevels": "Unendliche Level!",
"everythingStacks": "Alles stapelt sich!", "everythingStacks": "Alles stapelt sich!",

View File

@ -1,5 +1,5 @@
{ {
"battlesWon": "Battles Won!", "battlesWon": "{{count, number}} Battles Won!",
"joinTheDiscord": "Join the Discord!", "joinTheDiscord": "Join the Discord!",
"infiniteLevels": "Infinite Levels!", "infiniteLevels": "Infinite Levels!",
"everythingStacks": "Everything Stacks!", "everythingStacks": "Everything Stacks!",
@ -32,5 +32,17 @@
"alsoTryRadicalRed": "Also Try Radical Red!", "alsoTryRadicalRed": "Also Try Radical Red!",
"eeveeExpo": "Eevee Expo!", "eeveeExpo": "Eevee Expo!",
"ynoproject": "YNOproject!", "ynoproject": "YNOproject!",
"breedersInSpace": "Breeders in space!" "breedersInSpace": "Breeders in space!",
"halloween": {
"pumpkaboosAbout": "Pumpkaboos about!",
"mayContainSpiders": "May contain spiders!",
"spookyScaryDuskulls": "Spooky, Scary Duskulls!"
},
"xmas": {
"happyHolidays": "Happy Holidays!",
"delibirdSeason": "Delibird Season!"
},
"newYears": {
"happyNewYear": "Happy New Year!"
}
} }

View File

@ -1,5 +1,5 @@
{ {
"battlesWon": Batallas ganadas!", "battlesWon": {{count}} Batallas ganadas!",
"joinTheDiscord": "¡Únete al Discord!", "joinTheDiscord": "¡Únete al Discord!",
"infiniteLevels": "¡Niveles infinitos!", "infiniteLevels": "¡Niveles infinitos!",
"everythingStacks": "¡Todo se acumula!", "everythingStacks": "¡Todo se acumula!",

View File

@ -1,5 +1,5 @@
{ {
"battlesWon": "combats gagnés !", "battlesWon": "{{count, number}} combats gagnés !",
"joinTheDiscord": "Rejoins le Discord !", "joinTheDiscord": "Rejoins le Discord !",
"infiniteLevels": "Niveaux infinis !", "infiniteLevels": "Niveaux infinis !",
"everythingStacks": "Tout se cumule !", "everythingStacks": "Tout se cumule !",

View File

@ -1,5 +1,5 @@
{ {
"battlesWon": "Battaglie Vinte!", "battlesWon": "{{count, number}} Battaglie Vinte!",
"joinTheDiscord": "Entra nel Discord!", "joinTheDiscord": "Entra nel Discord!",
"infiniteLevels": "Livelli Infiniti!", "infiniteLevels": "Livelli Infiniti!",
"everythingStacks": "Tutto si impila!", "everythingStacks": "Tutto si impila!",

View File

@ -1,5 +1,5 @@
{ {
"battlesWon": "Battles Won!", "battlesWon": "{{count, number}} Battles Won!",
"joinTheDiscord": "Join the Discord!", "joinTheDiscord": "Join the Discord!",
"infiniteLevels": "Infinite Levels!", "infiniteLevels": "Infinite Levels!",
"everythingStacks": "Everything Stacks!", "everythingStacks": "Everything Stacks!",

View File

@ -1,5 +1,5 @@
{ {
"battlesWon": "전투에서 승리하세요!", "battlesWon": "{{count, number}} 전투에서 승리하세요!",
"joinTheDiscord": "디스코드에 가입하세요!", "joinTheDiscord": "디스코드에 가입하세요!",
"infiniteLevels": "무한한 레벨!", "infiniteLevels": "무한한 레벨!",
"everythingStacks": "모든 것이 누적됩니다!", "everythingStacks": "모든 것이 누적됩니다!",

View File

@ -1,5 +1,5 @@
{ {
"battlesWon": "Batalhas Ganhas!", "battlesWon": "{{count, number}} Batalhas Ganhas!",
"joinTheDiscord": "Junte-se ao Discord!", "joinTheDiscord": "Junte-se ao Discord!",
"infiniteLevels": "Níveis Infinitos!", "infiniteLevels": "Níveis Infinitos!",
"everythingStacks": "Tudo Acumula!", "everythingStacks": "Tudo Acumula!",

View File

@ -1,5 +1,5 @@
{ {
"battlesWon": "场胜利!", "battlesWon": "{{count, number}} 场胜利!",
"joinTheDiscord": "加入Discord", "joinTheDiscord": "加入Discord",
"infiniteLevels": "等级无限!", "infiniteLevels": "等级无限!",
"everythingStacks": "道具全部叠加!", "everythingStacks": "道具全部叠加!",

View File

@ -1,5 +1,5 @@
{ {
"battlesWon": "勝利場數!", "battlesWon": "{{count, number}} 勝利場數!",
"joinTheDiscord": "加入Discord", "joinTheDiscord": "加入Discord",
"infiniteLevels": "無限等級!", "infiniteLevels": "無限等級!",
"everythingStacks": "所有效果都能疊加!", "everythingStacks": "所有效果都能疊加!",

View File

@ -3,11 +3,14 @@ import OptionSelectUiHandler from "./settings/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, getTextStyleOptions } from "./text"; import { TextStyle, addTextObject, getTextStyleOptions } from "./text";
import { getBattleCountSplashMessage, getSplashMessages } from "../data/splash-messages"; 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";
export default class TitleUiHandler extends OptionSelectUiHandler { export default class TitleUiHandler extends OptionSelectUiHandler {
/** If the stats can not be retrieved, use this fallback value */
private static readonly BATTLES_WON_FALLBACK: number = -99999999;
private titleContainer: Phaser.GameObjects.Container; private titleContainer: Phaser.GameObjects.Container;
private playerCountLabel: Phaser.GameObjects.Text; private playerCountLabel: Phaser.GameObjects.Text;
private splashMessage: string; private splashMessage: string;
@ -72,8 +75,8 @@ export default class TitleUiHandler extends OptionSelectUiHandler {
.then(request => request.json()) .then(request => request.json())
.then(stats => { .then(stats => {
this.playerCountLabel.setText(`${stats.playerCount} ${i18next.t("menu:playersOnline")}`); this.playerCountLabel.setText(`${stats.playerCount} ${i18next.t("menu:playersOnline")}`);
if (this.splashMessage === getBattleCountSplashMessage()) { if (this.splashMessage === "battlesWon") {
this.splashMessageText.setText(getBattleCountSplashMessage().replace("{COUNT}", stats.battleCount.toLocaleString("en-US"))); this.splashMessageText.setText(i18next.t(this.splashMessage, { count: stats.battlesWon }));
} }
}) })
.catch(err => { .catch(err => {
@ -86,7 +89,7 @@ export default class TitleUiHandler extends OptionSelectUiHandler {
if (ret) { if (ret) {
this.splashMessage = Utils.randItem(getSplashMessages()); this.splashMessage = Utils.randItem(getSplashMessages());
this.splashMessageText.setText(this.splashMessage.replace("{COUNT}", "?")); this.splashMessageText.setText(i18next.t(this.splashMessage, { count: TitleUiHandler.BATTLES_WON_FALLBACK }));
const ui = this.getUi(); const ui = this.getUi();