From 56f90152653dcd2302cc4625d599bfc81dfca468 Mon Sep 17 00:00:00 2001 From: flx-sta <50131232+flx-sta@users.noreply.github.com> Date: Wed, 18 Sep 2024 11:59:03 -0700 Subject: [PATCH 1/9] add: seasonsl splash messages logic + scaffolding --- src/data/splash-messages.ts | 76 ++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 2 deletions(-) diff --git a/src/data/splash-messages.ts b/src/data/splash-messages.ts index 8e95bba0591..5aac46ec19b 100644 --- a/src/data/splash-messages.ts +++ b/src/data/splash-messages.ts @@ -1,11 +1,68 @@ import i18next from "i18next"; +//#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 Month = "Jan" | "Feb" | "Mar" | "Apr" | "May" | "Jun" | "Jul" | "Aug" | "Sep" | "Oct" | "Nov" | "Dec"; + +/** + * Represents a season with its {@linkcode name}, + * {@linkcode start} day+month, {@linkcode end} day+month + * and {@linkcode messages}. + */ +interface Season { + /** The name of the season (internal use only) */ + name: string; + /** The start day and month of the season. Format `DD-MMM` */ + start: `${Day}-${Month}`; + /** The end day and month of the season. Format `DD-MMM` */ + end: `${Day}-${Month}`; + /** Collection of the messages to display (without the `i18next.t()` call!) */ + messages: string[]; +} + +//#region Constants + +/** 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; + +//#endregion + +const seasonalSplashMessages: Season[] = [ + { + name: "Halloween", + start: "15-Sep", + end: "31-Oct", + messages: [ + // add messages here. E.g. "splashMessages:happyHalloween" + ], + }, + { + name: "XMAS", + start: "01-Dec", + end: "26-Dec", + messages: [ + // add messages here. E.g. "splashMessages:happyHolidays" + ], + }, + { + name: "New Year's", + start: "01-Jan", + end: "31-Jan", + messages: [ + // add messages here. E.g. "splashMessages:happyNewYear" + ], + }, +]; + export function getBattleCountSplashMessage(): string { return `{COUNT} ${i18next.t("splashMessages:battlesWon")}`; } export function getSplashMessages(): string[] { - const splashMessages = Array(10).fill(getBattleCountSplashMessage()); + const splashMessages = Array(BATTLES_WON_WEIGHT_MULTIPLIER).fill(getBattleCountSplashMessage()); splashMessages.push( i18next.t("splashMessages:joinTheDiscord"), i18next.t("splashMessages:infiniteLevels"), @@ -39,8 +96,23 @@ export function getSplashMessages(): string[] { i18next.t("splashMessages:alsoTryRadicalRed"), i18next.t("splashMessages:eeveeExpo"), i18next.t("splashMessages:ynoproject"), - i18next.t("splashMessages:breedersInSpace"), + i18next.t("splashMessages:breedersInSpace") ); + // add seasonal splash messages if the season is active + for (const { name, start, end, messages } of seasonalSplashMessages) { + const now = new Date(); + const startDate = new Date(`${start}-${now.getFullYear()}`); + const endDate = new Date(`${end}-${now.getFullYear()}`); + + if (now >= startDate && now <= endDate) { + console.log( `Adding ${messages.length} seasonal splash messages for`, name, `(weight: x${SEASONAL_WEIGHT_MULTIPLIER})` ); + messages.forEach((message) => { + const weightedMessage = Array(SEASONAL_WEIGHT_MULTIPLIER).fill(i18next.t(message)); + splashMessages.push(...weightedMessage); + }); + } + } + return splashMessages; } From c9fcec8eaa9a529a8aae5258d03b988fd9abc952 Mon Sep 17 00:00:00 2001 From: flx-sta <50131232+flx-sta@users.noreply.github.com> Date: Wed, 18 Sep 2024 14:52:03 -0700 Subject: [PATCH 2/9] 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 --- src/data/splash-messages.ts | 135 +++++++++++++++---------- src/locales/de/splash-messages.json | 2 +- src/locales/en/splash-messages.json | 16 ++- src/locales/es/splash-messages.json | 2 +- src/locales/fr/splash-messages.json | 2 +- src/locales/it/splash-messages.json | 2 +- src/locales/ja/splash-messages.json | 2 +- src/locales/ko/splash-messages.json | 2 +- src/locales/pt_BR/splash-messages.json | 2 +- src/locales/zh_CN/splash-messages.json | 2 +- src/locales/zh_TW/splash-messages.json | 2 +- src/ui/title-ui-handler.ts | 11 +- 12 files changed, 110 insertions(+), 70 deletions(-) diff --git a/src/data/splash-messages.ts b/src/data/splash-messages.ts index 5aac46ec19b..be0231ecdcc 100644 --- a/src/data/splash-messages.ts +++ b/src/data/splash-messages.ts @@ -1,8 +1,37 @@ -import i18next from "i18next"; - //#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"; /** @@ -28,76 +57,72 @@ const BATTLES_WON_WEIGHT_MULTIPLIER = 10; /** The weight multiplier for the seasonal splash messages */ 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[] = [ { name: "Halloween", start: "15-Sep", end: "31-Oct", - messages: [ - // add messages here. E.g. "splashMessages:happyHalloween" - ], + messages: ["halloween.pumpkaboosAbout", "halloween.mayContainSpiders", "halloween.spookyScaryDuskulls"], }, { name: "XMAS", start: "01-Dec", end: "26-Dec", - messages: [ - // add messages here. E.g. "splashMessages:happyHolidays" - ], + messages: ["xmas.happyHolidays", "xmas.delibirdSeason"], }, { name: "New Year's", start: "01-Jan", end: "31-Jan", - messages: [ - // add messages here. E.g. "splashMessages:happyNewYear" - ], + messages: ["newYears.happyNewYear"], }, ]; -export function getBattleCountSplashMessage(): string { - return `{COUNT} ${i18next.t("splashMessages:battlesWon")}`; -} +//#endregion export function getSplashMessages(): string[] { - const splashMessages = Array(BATTLES_WON_WEIGHT_MULTIPLIER).fill(getBattleCountSplashMessage()); - 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") - ); + const splashMessages: string[] = [...commonSplashMessages]; // add seasonal splash messages if the season is active for (const { name, start, end, messages } of seasonalSplashMessages) { @@ -106,13 +131,13 @@ export function getSplashMessages(): string[] { const endDate = new Date(`${end}-${now.getFullYear()}`); 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) => { - const weightedMessage = Array(SEASONAL_WEIGHT_MULTIPLIER).fill(i18next.t(message)); + const weightedMessage = Array(SEASONAL_WEIGHT_MULTIPLIER).fill(message); splashMessages.push(...weightedMessage); }); } } - return splashMessages; + return splashMessages.map((message) => `splashMessages:${message}`); } diff --git a/src/locales/de/splash-messages.json b/src/locales/de/splash-messages.json index ac3fd345f3f..ba126393ccb 100644 --- a/src/locales/de/splash-messages.json +++ b/src/locales/de/splash-messages.json @@ -1,5 +1,5 @@ { - "battlesWon": "Kämpfe gewonnen!", + "battlesWon": "{{count, number}} Kämpfe gewonnen!", "joinTheDiscord": "Tritt dem Discord bei!", "infiniteLevels": "Unendliche Level!", "everythingStacks": "Alles stapelt sich!", diff --git a/src/locales/en/splash-messages.json b/src/locales/en/splash-messages.json index c0686e6ad75..168974525f8 100644 --- a/src/locales/en/splash-messages.json +++ b/src/locales/en/splash-messages.json @@ -1,5 +1,5 @@ { - "battlesWon": "Battles Won!", + "battlesWon": "{{count, number}} Battles Won!", "joinTheDiscord": "Join the Discord!", "infiniteLevels": "Infinite Levels!", "everythingStacks": "Everything Stacks!", @@ -32,5 +32,17 @@ "alsoTryRadicalRed": "Also Try Radical Red!", "eeveeExpo": "Eevee Expo!", "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!" + } } \ No newline at end of file diff --git a/src/locales/es/splash-messages.json b/src/locales/es/splash-messages.json index b1d4820b06e..50cd987d862 100644 --- a/src/locales/es/splash-messages.json +++ b/src/locales/es/splash-messages.json @@ -1,5 +1,5 @@ { - "battlesWon": "¡Batallas ganadas!", + "battlesWon": "¡{{count}} Batallas ganadas!", "joinTheDiscord": "¡Únete al Discord!", "infiniteLevels": "¡Niveles infinitos!", "everythingStacks": "¡Todo se acumula!", diff --git a/src/locales/fr/splash-messages.json b/src/locales/fr/splash-messages.json index 9dd3e86fb32..2ac85680e58 100644 --- a/src/locales/fr/splash-messages.json +++ b/src/locales/fr/splash-messages.json @@ -1,5 +1,5 @@ { - "battlesWon": "combats gagnés !", + "battlesWon": "{{count, number}} combats gagnés !", "joinTheDiscord": "Rejoins le Discord !", "infiniteLevels": "Niveaux infinis !", "everythingStacks": "Tout se cumule !", diff --git a/src/locales/it/splash-messages.json b/src/locales/it/splash-messages.json index 55018d0ada0..d4b411241b6 100644 --- a/src/locales/it/splash-messages.json +++ b/src/locales/it/splash-messages.json @@ -1,5 +1,5 @@ { - "battlesWon": "Battaglie Vinte!", + "battlesWon": "{{count, number}} Battaglie Vinte!", "joinTheDiscord": "Entra nel Discord!", "infiniteLevels": "Livelli Infiniti!", "everythingStacks": "Tutto si impila!", diff --git a/src/locales/ja/splash-messages.json b/src/locales/ja/splash-messages.json index b7378e7a916..6f95e3859b8 100644 --- a/src/locales/ja/splash-messages.json +++ b/src/locales/ja/splash-messages.json @@ -1,5 +1,5 @@ { - "battlesWon": "Battles Won!", + "battlesWon": "{{count, number}} Battles Won!", "joinTheDiscord": "Join the Discord!", "infiniteLevels": "Infinite Levels!", "everythingStacks": "Everything Stacks!", diff --git a/src/locales/ko/splash-messages.json b/src/locales/ko/splash-messages.json index 6cf7ce050b7..1e89713ccde 100644 --- a/src/locales/ko/splash-messages.json +++ b/src/locales/ko/splash-messages.json @@ -1,5 +1,5 @@ { - "battlesWon": "전투에서 승리하세요!", + "battlesWon": "{{count, number}} 전투에서 승리하세요!", "joinTheDiscord": "디스코드에 가입하세요!", "infiniteLevels": "무한한 레벨!", "everythingStacks": "모든 것이 누적됩니다!", diff --git a/src/locales/pt_BR/splash-messages.json b/src/locales/pt_BR/splash-messages.json index 55c0b1b9e74..237b0f21202 100644 --- a/src/locales/pt_BR/splash-messages.json +++ b/src/locales/pt_BR/splash-messages.json @@ -1,5 +1,5 @@ { - "battlesWon": "Batalhas Ganhas!", + "battlesWon": "{{count, number}} Batalhas Ganhas!", "joinTheDiscord": "Junte-se ao Discord!", "infiniteLevels": "Níveis Infinitos!", "everythingStacks": "Tudo Acumula!", diff --git a/src/locales/zh_CN/splash-messages.json b/src/locales/zh_CN/splash-messages.json index 4d2d208edfd..24981513afe 100644 --- a/src/locales/zh_CN/splash-messages.json +++ b/src/locales/zh_CN/splash-messages.json @@ -1,5 +1,5 @@ { - "battlesWon": "场胜利!", + "battlesWon": "{{count, number}} 场胜利!", "joinTheDiscord": "加入Discord!", "infiniteLevels": "等级无限!", "everythingStacks": "道具全部叠加!", diff --git a/src/locales/zh_TW/splash-messages.json b/src/locales/zh_TW/splash-messages.json index a25e7dab97b..60b03549c2f 100644 --- a/src/locales/zh_TW/splash-messages.json +++ b/src/locales/zh_TW/splash-messages.json @@ -1,5 +1,5 @@ { - "battlesWon": "勝利場數!", + "battlesWon": "{{count, number}} 勝利場數!", "joinTheDiscord": "加入Discord!", "infiniteLevels": "無限等級!", "everythingStacks": "所有效果都能疊加!", diff --git a/src/ui/title-ui-handler.ts b/src/ui/title-ui-handler.ts index 67a4f7260e6..25cae6e5f06 100644 --- a/src/ui/title-ui-handler.ts +++ b/src/ui/title-ui-handler.ts @@ -3,11 +3,14 @@ import OptionSelectUiHandler from "./settings/option-select-ui-handler"; import { Mode } from "./ui"; import * as Utils from "../utils"; import { TextStyle, addTextObject, getTextStyleOptions } from "./text"; -import { getBattleCountSplashMessage, getSplashMessages } from "../data/splash-messages"; +import { getSplashMessages } from "../data/splash-messages"; import i18next from "i18next"; import { TimedEventDisplay } from "#app/timed-event-manager"; 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 playerCountLabel: Phaser.GameObjects.Text; private splashMessage: string; @@ -72,8 +75,8 @@ export default class TitleUiHandler extends OptionSelectUiHandler { .then(request => request.json()) .then(stats => { this.playerCountLabel.setText(`${stats.playerCount} ${i18next.t("menu:playersOnline")}`); - if (this.splashMessage === getBattleCountSplashMessage()) { - this.splashMessageText.setText(getBattleCountSplashMessage().replace("{COUNT}", stats.battleCount.toLocaleString("en-US"))); + if (this.splashMessage === "battlesWon") { + this.splashMessageText.setText(i18next.t(this.splashMessage, { count: stats.battlesWon })); } }) .catch(err => { @@ -86,7 +89,7 @@ export default class TitleUiHandler extends OptionSelectUiHandler { if (ret) { 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(); From a0ec2cc71c4fbfdc312954f993caa6d7ff9c88ca Mon Sep 17 00:00:00 2001 From: flx-sta <50131232+flx-sta@users.noreply.github.com> Date: Wed, 18 Sep 2024 16:31:00 -0700 Subject: [PATCH 3/9] fix: updateTitleStats not checking the namespace of battlesWon --- src/ui/title-ui-handler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/title-ui-handler.ts b/src/ui/title-ui-handler.ts index 25cae6e5f06..a85e670eaba 100644 --- a/src/ui/title-ui-handler.ts +++ b/src/ui/title-ui-handler.ts @@ -75,7 +75,7 @@ export default class TitleUiHandler extends OptionSelectUiHandler { .then(request => request.json()) .then(stats => { this.playerCountLabel.setText(`${stats.playerCount} ${i18next.t("menu:playersOnline")}`); - if (this.splashMessage === "battlesWon") { + if (this.splashMessage === "splashMessages:battlesWon") { this.splashMessageText.setText(i18next.t(this.splashMessage, { count: stats.battlesWon })); } }) From 14099a5bd58d0541b5cd2f58fb3ed1bdbd433d69 Mon Sep 17 00:00:00 2001 From: flx-sta <50131232+flx-sta@users.noreply.github.com> Date: Wed, 18 Sep 2024 17:19:22 -0700 Subject: [PATCH 4/9] add tests for splash_messages --- src/test/data/splash_messages.test.ts | 66 +++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/test/data/splash_messages.test.ts diff --git a/src/test/data/splash_messages.test.ts b/src/test/data/splash_messages.test.ts new file mode 100644 index 00000000000..181777c5e18 --- /dev/null +++ b/src/test/data/splash_messages.test.ts @@ -0,0 +1,66 @@ +import { getSplashMessages } from "#app/data/splash-messages"; +import { afterEach } from "node:test"; +import { describe, expect, it, vi } from "vitest"; + +const Jan = 1; +const Sep = 8; +const Oct = 9; +const Dec = 11; + +describe("Data - Splash Messages", () => { + it("should contain at least 15 splash messages", () => { + expect(getSplashMessages().length).toBeGreaterThanOrEqual(15); + }); + + // 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"); + expect(battlesWonMessages).toHaveLength(10); + }); + + describe("Seasonal", () => { + afterEach(() => { + vi.useRealTimers(); // reset system time + }); + + it("should contain halloween messages from Sep 15 to Oct 31", () => { + testSeason(new Date(2023, Sep, 15), new Date(2023, Oct, 31), "halloween"); + }); + + it("should contain xmas messages from Dec 1 to Dec 26", () => { + testSeason(new Date(2023, Dec, 1), new Date(2023, Dec, 26), "xmas"); + }); + + it("should contain new years messages frm Jan 1 to Jan 31", () => { + testSeason(new Date(2024, Jan, 1), new Date(2024, Jan, 31), "newYears"); + }); + }); +}); + +/** + * Helpoer method to test seasonal messages + * @param startDate The seasons start date + * @param endDate The seasons end date + * @param prefix the splash message prefix (e.g. `newYears` or `xmas`) + */ +function testSeason(startDate: Date, endDate: Date, prefix: string) { + const filterFn = (message: string) => message.startsWith(`splashMessages:${prefix}.`); + + const beforeDate = new Date(startDate); + beforeDate.setDate(startDate.getDate() - 1); + + const afterDate = new Date(endDate); + afterDate.setDate(endDate.getDate() + 1); + + const dates: Date[] = [beforeDate, startDate, endDate, afterDate]; + const [before, start, end, after] = dates.map((date) => { + vi.setSystemTime(date); + console.log("System time set to", date); + return getSplashMessages().filter(filterFn).length; + }); + + expect(before).toBe(0); + expect(start).toBeGreaterThan(0); + expect(end).toBeGreaterThan(0); + expect(after).toBe(0); +} From 99a60226b81974508b306cd58373e031d263ff69 Mon Sep 17 00:00:00 2001 From: flx-sta <50131232+flx-sta@users.noreply.github.com> Date: Wed, 18 Sep 2024 17:41:39 -0700 Subject: [PATCH 5/9] test: always use UTC time --- src/test/vitest.setup.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/vitest.setup.ts b/src/test/vitest.setup.ts index 3bb5c240d94..74129f20d26 100644 --- a/src/test/vitest.setup.ts +++ b/src/test/vitest.setup.ts @@ -14,6 +14,8 @@ import { initStatsKeys } from "#app/ui/game-stats-ui-handler"; import { initMysteryEncounters } from "#app/data/mystery-encounters/mystery-encounters"; import { beforeAll, vi } from "vitest"; +process.env.TZ = "UTC"; + /** Mock the override import to always return default values, ignoring any custom overrides. */ vi.mock("#app/overrides", async (importOriginal) => { const { defaultOverrides } = await importOriginal(); From 0f97c830622ce277ed8a6d82ac58df4d4e310bbb Mon Sep 17 00:00:00 2001 From: flx-sta <50131232+flx-sta@users.noreply.github.com> Date: Wed, 18 Sep 2024 17:41:58 -0700 Subject: [PATCH 6/9] fix: time-pattern to MM-DD --- src/data/splash-messages.ts | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/src/data/splash-messages.ts b/src/data/splash-messages.ts index be0231ecdcc..a628e585a5e 100644 --- a/src/data/splash-messages.ts +++ b/src/data/splash-messages.ts @@ -1,18 +1,8 @@ //#region Interfaces/Types +type Month = "01" | "02" | "03" | "04" | "05" | "06" | "07" | "08" | "09" | "10" | "11" | "12"; type Day = - | "01" - | "02" - | "03" - | "04" - | "05" - | "06" - | "07" - | "08" - | "09" - | "10" - | "11" - | "12" + | Month | "13" | "14" | "15" @@ -32,7 +22,6 @@ type Day = | "29" | "30" | "31"; -type Month = "Jan" | "Feb" | "Mar" | "Apr" | "May" | "Jun" | "Jul" | "Aug" | "Sep" | "Oct" | "Nov" | "Dec"; /** * Represents a season with its {@linkcode name}, @@ -42,10 +31,10 @@ type Month = "Jan" | "Feb" | "Mar" | "Apr" | "May" | "Jun" | "Jul" | "Aug" | "Se interface Season { /** The name of the season (internal use only) */ name: string; - /** The start day and month of the season. Format `DD-MMM` */ - start: `${Day}-${Month}`; - /** The end day and month of the season. Format `DD-MMM` */ - end: `${Day}-${Month}`; + /** The start day and month of the season. Format `MM-DD` */ + 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[]; } @@ -101,20 +90,20 @@ const commonSplashMessages = [ const seasonalSplashMessages: Season[] = [ { name: "Halloween", - start: "15-Sep", - end: "31-Oct", + start: "09-15", + end: "10-31", messages: ["halloween.pumpkaboosAbout", "halloween.mayContainSpiders", "halloween.spookyScaryDuskulls"], }, { name: "XMAS", - start: "01-Dec", - end: "26-Dec", + start: "12-01", + end: "12-26", messages: ["xmas.happyHolidays", "xmas.delibirdSeason"], }, { name: "New Year's", - start: "01-Jan", - end: "31-Jan", + start: "01-01", + end: "01-31", messages: ["newYears.happyNewYear"], }, ]; From 90641df85f8396a3d775a0996d069bddeb2ea324 Mon Sep 17 00:00:00 2001 From: flx-sta <50131232+flx-sta@users.noreply.github.com> Date: Wed, 18 Sep 2024 17:42:29 -0700 Subject: [PATCH 7/9] fix splash_messages test --- src/test/data/splash_messages.test.ts | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/test/data/splash_messages.test.ts b/src/test/data/splash_messages.test.ts index 181777c5e18..a638a481472 100644 --- a/src/test/data/splash_messages.test.ts +++ b/src/test/data/splash_messages.test.ts @@ -1,11 +1,5 @@ import { getSplashMessages } from "#app/data/splash-messages"; -import { afterEach } from "node:test"; -import { describe, expect, it, vi } from "vitest"; - -const Jan = 1; -const Sep = 8; -const Oct = 9; -const Dec = 11; +import { describe, expect, it, vi, afterEach } from "vitest"; describe("Data - Splash Messages", () => { it("should contain at least 15 splash messages", () => { @@ -24,15 +18,15 @@ describe("Data - Splash Messages", () => { }); it("should contain halloween messages from Sep 15 to Oct 31", () => { - testSeason(new Date(2023, Sep, 15), new Date(2023, Oct, 31), "halloween"); + testSeason(new Date("2024-09-15"), new Date("2024-10-31"), "halloween"); }); it("should contain xmas messages from Dec 1 to Dec 26", () => { - testSeason(new Date(2023, Dec, 1), new Date(2023, Dec, 26), "xmas"); + testSeason(new Date("2024-12-01"), new Date("2024-12-26"), "xmas"); }); it("should contain new years messages frm Jan 1 to Jan 31", () => { - testSeason(new Date(2024, Jan, 1), new Date(2024, Jan, 31), "newYears"); + testSeason(new Date("2024-01-01"), new Date("2024-01-31"), "newYears"); }); }); }); @@ -56,11 +50,12 @@ function testSeason(startDate: Date, endDate: Date, prefix: string) { const [before, start, end, after] = dates.map((date) => { vi.setSystemTime(date); console.log("System time set to", date); - return getSplashMessages().filter(filterFn).length; + const count = getSplashMessages().filter(filterFn).length; + return count; }); expect(before).toBe(0); - expect(start).toBeGreaterThan(0); - expect(end).toBeGreaterThan(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(after).toBe(0); } From 8dc228125b1cefde53d2f28d71bfc95b69f5df4c Mon Sep 17 00:00:00 2001 From: flx-sta <50131232+flx-sta@users.noreply.github.com> Date: Wed, 18 Sep 2024 17:43:56 -0700 Subject: [PATCH 8/9] add: const to control usage of seasonal splash messages --- src/data/splash-messages.ts | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/data/splash-messages.ts b/src/data/splash-messages.ts index a628e585a5e..3e6f3643dae 100644 --- a/src/data/splash-messages.ts +++ b/src/data/splash-messages.ts @@ -41,6 +41,8 @@ interface Season { //#region Constants +/** Whether to use seasonal splash messages in general */ +const USE_SEASONAL_SPLASH_MESSAGES = false; /** The weight multiplier for the battles-won splash message */ const BATTLES_WON_WEIGHT_MULTIPLIER = 10; /** The weight multiplier for the seasonal splash messages */ @@ -113,18 +115,20 @@ const seasonalSplashMessages: Season[] = [ export function getSplashMessages(): string[] { const splashMessages: string[] = [...commonSplashMessages]; - // add seasonal splash messages if the season is active - for (const { name, start, end, messages } of seasonalSplashMessages) { - const now = new Date(); - const startDate = new Date(`${start}-${now.getFullYear()}`); - const endDate = new Date(`${end}-${now.getFullYear()}`); + if (USE_SEASONAL_SPLASH_MESSAGES) { + // add seasonal splash messages if the season is active + for (const { name, start, end, messages } of seasonalSplashMessages) { + const now = new Date(); + const startDate = new Date(`${start}-${now.getFullYear()}`); + const endDate = new Date(`${end}-${now.getFullYear()}`); - if (now >= startDate && now <= endDate) { - console.log(`Adding ${messages.length} ${name} splash messages (weight: x${SEASONAL_WEIGHT_MULTIPLIER})`); - messages.forEach((message) => { - const weightedMessage = Array(SEASONAL_WEIGHT_MULTIPLIER).fill(message); - splashMessages.push(...weightedMessage); - }); + if (now >= startDate && now <= endDate) { + console.log(`Adding ${messages.length} ${name} splash messages (weight: x${SEASONAL_WEIGHT_MULTIPLIER})`); + messages.forEach((message) => { + const weightedMessage = Array(SEASONAL_WEIGHT_MULTIPLIER).fill(message); + splashMessages.push(...weightedMessage); + }); + } } } From cb0960671133daba4dc22d105e6dd549cbd0a920 Mon Sep 17 00:00:00 2001 From: flx-sta <50131232+flx-sta@users.noreply.github.com> Date: Wed, 18 Sep 2024 17:52:05 -0700 Subject: [PATCH 9/9] fix tests (splashj) --- src/constants.ts | 6 +++++- src/data/splash-messages.ts | 6 +++--- src/test/data/splash_messages.test.ts | 7 ++++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index a2f7e47b996..0b1261ad814 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1 +1,5 @@ -export const PLAYER_PARTY_MAX_SIZE = 6; +/** The maximum size of the player's party */ +export const PLAYER_PARTY_MAX_SIZE: number = 6; + +/** Whether to use seasonal splash messages in general */ +export const USE_SEASONAL_SPLASH_MESSAGES: boolean = false; diff --git a/src/data/splash-messages.ts b/src/data/splash-messages.ts index 3e6f3643dae..b8069f77737 100644 --- a/src/data/splash-messages.ts +++ b/src/data/splash-messages.ts @@ -1,3 +1,5 @@ +import { USE_SEASONAL_SPLASH_MESSAGES } from "#app/constants"; + //#region Interfaces/Types type Month = "01" | "02" | "03" | "04" | "05" | "06" | "07" | "08" | "09" | "10" | "11" | "12"; @@ -41,8 +43,6 @@ interface Season { //#region Constants -/** Whether to use seasonal splash messages in general */ -const USE_SEASONAL_SPLASH_MESSAGES = false; /** The weight multiplier for the battles-won splash message */ const BATTLES_WON_WEIGHT_MULTIPLIER = 10; /** The weight multiplier for the seasonal splash messages */ @@ -114,7 +114,7 @@ const seasonalSplashMessages: Season[] = [ export function getSplashMessages(): string[] { const splashMessages: string[] = [...commonSplashMessages]; - + 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) { diff --git a/src/test/data/splash_messages.test.ts b/src/test/data/splash_messages.test.ts index a638a481472..7e07b9a6e77 100644 --- a/src/test/data/splash_messages.test.ts +++ b/src/test/data/splash_messages.test.ts @@ -1,5 +1,6 @@ import { getSplashMessages } from "#app/data/splash-messages"; -import { describe, expect, it, vi, afterEach } from "vitest"; +import { describe, expect, it, vi, afterEach, beforeEach } from "vitest"; +import * as Constants from "#app/constants"; describe("Data - Splash Messages", () => { it("should contain at least 15 splash messages", () => { @@ -13,6 +14,10 @@ describe("Data - Splash Messages", () => { }); describe("Seasonal", () => { + beforeEach(() => { + vi.spyOn(Constants, "USE_SEASONAL_SPLASH_MESSAGES", "get").mockReturnValue(true); + }); + afterEach(() => { vi.useRealTimers(); // reset system time });