diff --git a/src/constants.ts b/src/constants.ts index 63f00b9f33f..927575c0a28 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -2,7 +2,7 @@ export const PLAYER_PARTY_MAX_SIZE: number = 6; /** Whether to use seasonal splash messages in general */ -export const USE_SEASONAL_SPLASH_MESSAGES: boolean = false; +export const USE_SEASONAL_SPLASH_MESSAGES: boolean = true; /** Name of the session ID cookie */ export const SESSION_ID_COOKIE_NAME: string = "pokerogue_sessionId"; diff --git a/src/data/splash-messages.ts b/src/data/splash-messages.ts index 1f00ce0d555..086a55189d0 100644 --- a/src/data/splash-messages.ts +++ b/src/data/splash-messages.ts @@ -1,4 +1,5 @@ import { USE_SEASONAL_SPLASH_MESSAGES } from "#app/constants"; +import i18next from "i18next"; //#region Interfaces/Types @@ -37,8 +38,6 @@ interface Season { start: `${Month}-${Day}`; /** The end day and month of the season. Format `MM-DD` */ end: `${Month}-${Day}`; - /** Collection of the messages to display (without the `i18next.t()` call!) */ - messages: string[]; } //#region Constants @@ -46,176 +45,57 @@ interface Season { /** The weight multiplier for the battles-won splash message */ const BATTLES_WON_WEIGHT_MULTIPLIER = 10; /** The weight multiplier for the seasonal splash messages */ -const SEASONAL_WEIGHT_MULTIPLIER = 10; - -//#region Common Messages - -const commonSplashMessages = [ - ...Array(BATTLES_WON_WEIGHT_MULTIPLIER).fill("battlesWon"), - "joinTheDiscord", - "infiniteLevels", - "everythingIsStackable", - "optionalSaveScumming", - "biomes", - "openSource", - "playWithSpeed", - "liveBugTesting", - "heavyInfluence", - "pokemonRiskAndPokemonRain", - "nowWithMoreSalt", - "infiniteFusionAtHome", - "brokenEggMoves", - "magnificent", - "doPeopleReadThis", - "thatsCrazy", - "gottaCatchEmAll", - "questionableBalancing", - "coolShaders", - "aiFree", - "suddenDifficultySpikes", - "basedOnAnUnfinishedFlashGame", - "moreAddictiveThanIntended", - "mostlyConsistentSeeds", - "achievementPointsDontDoAnything", - "nothingBeatsAJellyFilledDonut", - "dontTalkAboutTheTinkatonIncident", - "alsoTryPokengine", - "alsoTryEmeraldRogue", - "alsoTryRadicalRed", - "eeveeExpo", - "checkOutYnoproject", - "breedersInSpace", - "alsoTryPokemonUnbound", - "tryTheJohtoDragonChallenge", - "basicReadingAbilityRecommended", - "shoutoutsToTheArtists", - "gamblingNotEncouraged", - "dontForgetToTakeABreak", - "wEvent", - "ifItsNotAccurateItsAccurate", - "everyLossIsProgressMade", - "liveWoChienReaction", - "itsAFeatureNotABug", - "theEggsAreNotForEating", - "7.8outOf10TooManyWaterBiomes", - "butNothingHappened", - "thePowerOfScienceIsAmazing", - "freeToPlay", - "theresATimeAndPlaceForEverything", - "nowWithShinierShinies", - "smilesGoForMiles", - "certainlyNotDragonFree", - "haveANiceDay", - "redacted", - "hi", - "transRights", - "shinyOddsHigherThanYouThink", - "noFalseTrades", - "notForProfit", - "timeForYourDailyRun", - "moreEggsThanADaycare", - "disclaimerHarshSunDoesNotGiveVitaminD", - "whoNeedsAMap", - "luxrayIsNotADarkType", - "selfDestructiveEncounters", - "mostOptionsAreViable", - "pokerogueMorse", - "smiley", - "beAwareOfPassives", - "asSeenOnTheWorldWideWeb", - "vaultinVeluzas", - "tooManyStarters", - "checkTheWiki", - "winWithYourFavorites", - "alsoTryPokerogueWait", - "theWayISeeItKyogreIsSurrounded", - "tryOutHoneyGather", - "notForTheFaintOfHeart", - "p", - "flipYourDeviceToEvolveInkay", - "inArceusWeTrust", - "whyDidTheTorchicCrossTheRoad", - "goodLuck", - "fuseWisely", - "compensation", - "prepareForTroubleAndMakeItDouble", - "anEggForYourTroubles", - "regirock", - "hereForAGoodTime", - "getGoodOrDont", - "checkTheSubreddit", - "betterNerfGreninja", - "inCaseOfUpdateClearYourCache", - "insertTextHere", - "endingEndlessNotFound", - "iLikeMyEggsVouchered", - "YOU", - "noAddedSugar", - "notSponsored", - "notRated", - "justOneMoreWaveMom", - "saltCured", - "onlyOnPokerogueNet", - "pixelPerfection", - "openSource", - "probablyGood", - "itsAMonsterHouse", - "dontForgetYourPassword", - "tripleTripleTripleAxel", - "questionExclamation", - "clownEncounters", - "fullOfBerries", - "limitsAreMeantToBeBrokenSometimes", - "keepItCasual", - "serversProbablyWorking", - "mew", - "makeItRainAndYourProblemsGoAway", - "customMusicTracks", - "youAreValid", - "number591IsLookingOff", - "timeForYourDeliDelivery", - "goodFirstImpression", - "iPreferRarerCandies", -]; +const SEASONAL_WEIGHT_MULTIPLIER = 20; //#region Seasonal Messages const seasonalSplashMessages: Season[] = [ { - name: "Halloween", - start: "09-15", - end: "10-31", - messages: [ "halloween.pumpkabooAbout", "halloween.mayContainSpiders", "halloween.spookyScarySkeledirge", "halloween.gourgeistUsedTrickOrTreat", "halloween.letsSnuggleForever" ], + name: "halloween", + start: "10-15", + end: "10-31" }, { - name: "XMAS", - start: "12-01", - end: "12-26", - messages: [ "xmas.happyHolidays", "xmas.unaffilicatedWithDelibirdServices", "xmas.delibirdSeason", "xmas.diamondsFromTheSky", "xmas.holidayStylePikachuNotIncluded" ], + name: "xmas", + start: "12-16", + end: "12-31" }, { - name: "New Year's", - start: "01-01", - end: "01-31", - messages: [ "newYears.happyNewYear" ], + name: "newYears", + start: "12-31", + end: "01-14" }, ]; //#endregion export function getSplashMessages(): string[] { - const splashMessages: string[] = [ ...commonSplashMessages ]; + const existingKeys = i18next.getResourceBundle(i18next.language, "splashMessages"); + const splashMessages: string[] = [ ...Object.keys(existingKeys["common"]) ].map((message) => `common.${message}`); + if (splashMessages.includes("common.battlesWon")) { + splashMessages.push(...Array(Math.max(BATTLES_WON_WEIGHT_MULTIPLIER - 1, 1)).fill("common.battlesWon")); + } + console.log("use seasonal splash messages", USE_SEASONAL_SPLASH_MESSAGES); if (USE_SEASONAL_SPLASH_MESSAGES) { // add seasonal splash messages if the season is active - for (const { name, start, end, messages } of seasonalSplashMessages) { + for (const { name, start, end } of seasonalSplashMessages) { const now = new Date(); const startDate = new Date(`${start}-${now.getFullYear()}`); const endDate = new Date(`${end}-${now.getFullYear()}`); + if (endDate < startDate) { // If the end date is earlier in the year, that means it's next year + if (now >= startDate) { + endDate.setFullYear(endDate.getFullYear() + 1); //Ends next year + } else if (now <= endDate) { + startDate.setFullYear(startDate.getFullYear() - 1); //Started last year + } + } + console.log(`${name} event starts ${startDate} and ends ${endDate}`); - if (now >= startDate && now <= endDate) { - console.log(`Adding ${messages.length} ${name} splash messages (weight: x${SEASONAL_WEIGHT_MULTIPLIER})`); - messages.forEach((message) => { + if (existingKeys.hasOwnProperty(name) && now >= startDate && now <= endDate) { + const existingMessages: string[] = [ ...Object.keys(existingKeys[name]) ].map(m=>`${name}.${m}`); + console.log(`Adding ${existingMessages.length} ${name} splash messages from ${i18next.language} (weight: x${SEASONAL_WEIGHT_MULTIPLIER})`); + existingMessages.forEach((message) => { const weightedMessage = Array(SEASONAL_WEIGHT_MULTIPLIER).fill(message); splashMessages.push(...weightedMessage); }); diff --git a/src/test/data/splash_messages.test.ts b/src/test/data/splash_messages.test.ts index b9ed5b9d365..e4ad547b704 100644 --- a/src/test/data/splash_messages.test.ts +++ b/src/test/data/splash_messages.test.ts @@ -9,7 +9,7 @@ describe("Data - Splash Messages", () => { // make sure to adjust this test if the weight it changed! it("should add contain 10 `battlesWon` splash messages", () => { - const battlesWonMessages = getSplashMessages().filter((message) => message === "splashMessages:battlesWon"); + const battlesWonMessages = getSplashMessages().filter((message) => message === "splashMessages:common.battlesWon"); expect(battlesWonMessages).toHaveLength(10); }); @@ -22,16 +22,16 @@ describe("Data - Splash Messages", () => { vi.useRealTimers(); // reset system time }); - it("should contain halloween messages from Sep 15 to Oct 31", () => { - testSeason(new Date("2024-09-15"), new Date("2024-10-31"), "halloween"); + it("should contain halloween messages from Oct 15 to Oct 31", () => { + testSeason(new Date("2024-10-15"), new Date("2024-10-31"), "halloween"); }); - it("should contain xmas messages from Dec 1 to Dec 26", () => { - testSeason(new Date("2024-12-01"), new Date("2024-12-26"), "xmas"); + it("should contain xmas messages from Dec 16 to Dec 31", () => { + testSeason(new Date("2024-12-16"), new Date("2024-12-31"), "xmas"); }); - it("should contain new years messages frm Jan 1 to Jan 31", () => { - testSeason(new Date("2024-01-01"), new Date("2024-01-31"), "newYears"); + it("should contain new years messages from Dec 31 '24 to Jan 14 '25", () => { + testSeason(new Date("2024-12-31"), new Date("2025-01-14"), "newYears"); }); }); }); @@ -60,7 +60,7 @@ function testSeason(startDate: Date, endDate: Date, prefix: string) { }); expect(before).toBe(0); - expect(start).toBeGreaterThanOrEqual(10); // make sure to adjust if weight is changed! - expect(end).toBeGreaterThanOrEqual(10); // make sure to adjust if weight is changed! + expect(start).toBeGreaterThanOrEqual(20); // make sure to adjust if weight is changed! + expect(end).toBeGreaterThanOrEqual(20); // make sure to adjust if weight is changed! expect(after).toBe(0); } diff --git a/src/ui/title-ui-handler.ts b/src/ui/title-ui-handler.ts index aec80f049c9..f1b0a673ea0 100644 --- a/src/ui/title-ui-handler.ts +++ b/src/ui/title-ui-handler.ts @@ -83,7 +83,7 @@ export default class TitleUiHandler extends OptionSelectUiHandler { .then(stats => { if (stats) { this.playerCountLabel.setText(`${stats.playerCount} ${i18next.t("menu:playersOnline")}`); - if (this.splashMessage === "splashMessages:battlesWon") { + if (this.splashMessage === "splashMessages:common.battlesWon") { this.splashMessageText.setText(i18next.t(this.splashMessage, { count: stats.battleCount })); } } @@ -98,6 +98,7 @@ export default class TitleUiHandler extends OptionSelectUiHandler { if (ret) { this.splashMessage = Utils.randItem(getSplashMessages()); + console.log(this.splashMessage); this.splashMessageText.setText(i18next.t(this.splashMessage, { count: TitleUiHandler.BATTLES_WON_FALLBACK })); this.appVersionText.setText("v" + version);