From defb9f1d44bb790fd20ff3026af497e639025f78 Mon Sep 17 00:00:00 2001 From: Hank McCord Date: Tue, 4 Apr 2023 20:43:13 -0400 Subject: [PATCH] Add Queso Geyser stager --- src/scripts/main.js | 1 - .../stages/environments/quesoGeyser.ts | 37 +++++++++++++++++++ src/scripts/modules/stages/index.ts | 2 + src/scripts/modules/stages/legacy.js | 18 --------- src/scripts/types/hg.ts | 2 +- src/scripts/types/quests/index.ts | 1 + src/scripts/types/quests/quesoGeyser.ts | 8 ++++ .../stages/environments/quesoGeyser.spec.ts | 33 ++++++++++++++--- 8 files changed, 76 insertions(+), 26 deletions(-) create mode 100644 src/scripts/modules/stages/environments/quesoGeyser.ts create mode 100644 src/scripts/types/quests/quesoGeyser.ts diff --git a/src/scripts/main.js b/src/scripts/main.js index c8a42dc7..62adf542 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1182,7 +1182,6 @@ import * as detailingFuncs from './modules/details/legacy'; "Furoma Rift": stagingFuncs.addFuromaRiftStage, "Gnawnian Express Station": stagingFuncs.addTrainStage, "Iceberg": stagingFuncs.addIcebergStage, - "Queso Geyser": stagingFuncs.addQuesoGeyserStage, "Seasonal Garden": stagingFuncs.addSeasonalGardenStage, "Sunken City": stagingFuncs.addSunkenCityStage, "Table of Contents": stagingFuncs.addTableOfContentsStage, diff --git a/src/scripts/modules/stages/environments/quesoGeyser.ts b/src/scripts/modules/stages/environments/quesoGeyser.ts new file mode 100644 index 00000000..ebd2d6cf --- /dev/null +++ b/src/scripts/modules/stages/environments/quesoGeyser.ts @@ -0,0 +1,37 @@ +import {type User} from '@scripts/types/hg'; +import {IntakeMessage} from '@scripts/types/mhct'; +import {QuesoGeyserState, QuesoGeyserStates} from '@scripts/types/quests/quesoGeyser'; +import {type IStager} from '../stages.types'; + +export class QuesoGeyserStager implements IStager { + readonly environment: string = 'Queso Geyser'; + + /** + * Report the state of corks and eruptions + */ + addStage(message: IntakeMessage, userPre: User, userPost: User, journal: unknown): void { + const quest = userPre.quests.QuestQuesoGeyser; + + if (!quest) { + throw new Error('QuestQuesoGeyser is undefined'); + } + + if (!this.isValidState(quest.state)) { + throw new Error('Skipping hunt due to unknown Queso Geyser state'); + } + + const state = quest.state; + if (state === "collecting" || state === "claim") { + message.stage = "Cork Collecting"; + } else if (state === "corked") { + message.stage = "Pressure Building"; + } else if (state === "eruption") { + // Tiny/Small/Medium/Large/Epic Eruption + message.stage = quest.state_name; + } + } + + private isValidState(value: unknown): value is QuesoGeyserState { + return typeof value === 'string' && QuesoGeyserStates.includes(value as QuesoGeyserState); + } +} diff --git a/src/scripts/modules/stages/index.ts b/src/scripts/modules/stages/index.ts index c4466ec0..28d18ab9 100644 --- a/src/scripts/modules/stages/index.ts +++ b/src/scripts/modules/stages/index.ts @@ -16,6 +16,7 @@ import {LostCityStager} from './environments/lostCity'; import {MoussuPicchuStager} from './environments/moussuPicchu'; import {MousoleumStager} from './environments/mousoleum'; import {MuridaeMarketStager} from './environments/muridaeMarket'; +import {QuesoGeyserStager} from './environments/quesoGeyser'; import {SandDunesStager} from './environments/sandDunes'; import {SlushyShorelineStager} from './environments/slushyShoreline'; import {SuperBrieFactoryStager} from './environments/superBrieFactory'; @@ -40,6 +41,7 @@ const stageModules: IStager[] = [ new MoussuPicchuStager(), new MousoleumStager(), new MuridaeMarketStager(), + new QuesoGeyserStager(), new SandDunesStager(), new SlushyShorelineStager(), new SuperBrieFactoryStager(), diff --git a/src/scripts/modules/stages/legacy.js b/src/scripts/modules/stages/legacy.js index 20b9090f..dd480004 100644 --- a/src/scripts/modules/stages/legacy.js +++ b/src/scripts/modules/stages/legacy.js @@ -384,24 +384,6 @@ export function addFortRoxStage(message, user, user_post, hunt) { } /** - * Report the state of corks and eruptions - * @param {Object } message The message to be sent. - * @param {Object } user The user state object, when the hunt was invoked (pre-hunt). - * @param {Object } user_post The user state object, after the hunt. - * @param {Object } hunt The journal entry corresponding to the active hunt. - */ -export function addQuesoGeyserStage(message, user, user_post, hunt) { - const state = user.quests.QuestQuesoGeyser.state; - if (state === "collecting" || state === "claim") { - message.stage = "Cork Collecting"; - } else if (state === "corked") { - message.stage = "Pressure Building"; - } else if (state === "eruption") { - // Tiny/Small/Medium/Large/Epic Eruption - message.stage = user.quests.QuestQuesoGeyser.state_name; - } -} - /** * Report tower stage: Outside, Eclipse, Floors 1-7, 9-15, 17-23, 25-31+, Umbra * @param {Object } message The message to be sent. diff --git a/src/scripts/types/hg.ts b/src/scripts/types/hg.ts index ba4c8151..04c96823 100644 --- a/src/scripts/types/hg.ts +++ b/src/scripts/types/hg.ts @@ -56,7 +56,7 @@ export interface Quests { QuestMousoleum?: quests.QuestMousoleum QuestMoussuPicchu?: quests.QuestMoussuPicchu QuestPollutionOutbreak?: unknown - QuestQuesoGeyser?: unknown + QuestQuesoGeyser?: quests.QuestQuesoGeyser QuestRelicHunter?: unknown QuestRiftBristleWoods?: quests.QuestRiftBristleWoods QuestRiftBurroughs?: unknown diff --git a/src/scripts/types/quests/index.ts b/src/scripts/types/quests/index.ts index 8f09e2c4..c606b9e6 100644 --- a/src/scripts/types/quests/index.ts +++ b/src/scripts/types/quests/index.ts @@ -13,6 +13,7 @@ export * from '@scripts/types/quests/livingGarden'; export * from '@scripts/types/quests/lostCity'; export * from '@scripts/types/quests/mousoleum'; export * from '@scripts/types/quests/moussuPicchu'; +export * from '@scripts/types/quests/quesoGeyser'; export * from '@scripts/types/quests/sandDunes'; export * from '@scripts/types/quests/superBrieFactory'; export * from '@scripts/types/quests/tableOfContents'; diff --git a/src/scripts/types/quests/quesoGeyser.ts b/src/scripts/types/quests/quesoGeyser.ts new file mode 100644 index 00000000..dcb30d4a --- /dev/null +++ b/src/scripts/types/quests/quesoGeyser.ts @@ -0,0 +1,8 @@ +export interface QuestQuesoGeyser { + state: string // QuesoGeyserState + state_name: string; +} + +export const QuesoGeyserStates = [ 'collecting', 'corked', 'eruption', 'claim' ] as const; + +export type QuesoGeyserState = typeof QuesoGeyserStates[number]; diff --git a/tests/scripts/modules/stages/environments/quesoGeyser.spec.ts b/tests/scripts/modules/stages/environments/quesoGeyser.spec.ts index 452addc0..a17166bf 100644 --- a/tests/scripts/modules/stages/environments/quesoGeyser.spec.ts +++ b/tests/scripts/modules/stages/environments/quesoGeyser.spec.ts @@ -1,14 +1,17 @@ -import {addQuesoGeyserStage} from "@scripts/modules/stages/legacy"; +import {QuesoGeyserStager} from "@scripts/modules/stages/environments/quesoGeyser"; +import {IStager} from "@scripts/modules/stages/stages.types"; import {User} from "@scripts/types/hg"; import {IntakeMessage} from "@scripts/types/mhct"; describe('Queso Geyser stages', () => { + let stager: IStager; let message: IntakeMessage; let preUser: User; let postUser: User; const journal = {}; beforeEach(() => { + stager = new QuesoGeyserStager(); message = {} as IntakeMessage; preUser = {quests: { QuestQuesoGeyser: getDefaultQuest(), @@ -16,15 +19,26 @@ describe('Queso Geyser stages', () => { postUser = {} as User; }); + it('should be for the Queso Geyser environment', () => { + expect(stager.environment).toBe('Queso Geyser'); + }); + + it('should throw when QuestQuesoGeyser is undefined', () => { + preUser.quests.QuestQuesoGeyser = undefined; + + expect(() => stager.addStage(message, preUser, postUser, journal)) + .toThrow('QuestQuesoGeyser is undefined'); + }); + it.each` state | expected ${'collecting'} | ${'Cork Collecting'} ${'claim'} | ${'Cork Collecting'} ${'corked'} | ${'Pressure Building'} `('should set stage to $expected when in $state state', ({state, expected}) => { - preUser.quests.QuestQuesoGeyser.state = state; + preUser.quests.QuestQuesoGeyser!.state = state; - addQuesoGeyserStage(message, preUser, postUser, journal); + stager.addStage(message, preUser, postUser, journal); expect(message.stage).toBe(expected); }); @@ -32,14 +46,21 @@ describe('Queso Geyser stages', () => { it.each( ['Tiny', 'Small', 'Medium', 'Large', 'Epic'] )('should set stage to state name %p when in a %p Eruption ', (name) => { - preUser.quests.QuestQuesoGeyser.state = 'eruption'; - preUser.quests.QuestQuesoGeyser.state_name = `${name} Eruption`; + preUser.quests.QuestQuesoGeyser!.state = 'eruption'; + preUser.quests.QuestQuesoGeyser!.state_name = `${name} Eruption`; - addQuesoGeyserStage(message, preUser, postUser, journal); + stager.addStage(message, preUser, postUser, journal); expect(message.stage).toBe(`${name} Eruption`); }); + it('should throw when state is unknown', () => { + preUser.quests.QuestQuesoGeyser!.state = 'guaranteed_rib_mode'; + + expect(() => stager.addStage(message, preUser, postUser, journal)) + .toThrow('Skipping hunt due to unknown Queso Geyser state'); + }); + function getDefaultQuest() { return { state: '',