diff --git a/src/scripts/main.js b/src/scripts/main.js index 219c4ba1..38ace48d 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1179,7 +1179,6 @@ import * as detailingFuncs from './modules/details/legacy'; "Cursed City": stagingFuncs.addLostCityStage, "Festive Comet": stagingFuncs.addFestiveCometStage, "Frozen Vacant Lot": stagingFuncs.addFestiveCometStage, - "Fiery Warpath": stagingFuncs.addFieryWarpathStage, "Foreword Farm": stagingFuncs.addForewordFarmStage, "Fort Rox": stagingFuncs.addFortRoxStage, "Furoma Rift": stagingFuncs.addFuromaRiftStage, diff --git a/src/scripts/modules/stages/environments/fieryWarpath.ts b/src/scripts/modules/stages/environments/fieryWarpath.ts new file mode 100644 index 00000000..d5037504 --- /dev/null +++ b/src/scripts/modules/stages/environments/fieryWarpath.ts @@ -0,0 +1,25 @@ +import type {FieryWarpathViewingAttributes, ViewingAttributes, User} from '@scripts/types/hg'; +import {type IntakeMessage} from '@scripts/types/mhct'; +import {type IStager} from '../stages.types'; + +export class FieryWarpathStager implements IStager { + readonly environment: string = 'Fiery Warpath'; + + addStage(message: IntakeMessage, userPre: User, userPost: User, journal: unknown): void { + + const viewing_atts = userPre.viewing_atts; + if (!this.isWarpath(viewing_atts)) { + throw new Error('Fiery Warpath viewing attributes are undefined'); + } + + const wave = viewing_atts.desert_warpath.wave; + message.stage = (wave === "portal") ? "Portal" : `Wave ${wave}`; + } + + /** + * Check if the given viewing attributes narrows down to the fiery warpath one + */ + private isWarpath(object: ViewingAttributes): object is FieryWarpathViewingAttributes { + return (object as FieryWarpathViewingAttributes).desert_warpath != null; + } +} diff --git a/src/scripts/modules/stages/index.ts b/src/scripts/modules/stages/index.ts index 531795c4..c3a80263 100644 --- a/src/scripts/modules/stages/index.ts +++ b/src/scripts/modules/stages/index.ts @@ -2,6 +2,7 @@ import {type IStager} from './stages.types'; import {BalacksCoveStager} from './environments/balacksCove'; import {BountifulBeanstalkStager} from './environments/bountifulBeanstalk'; import {ClawShotCityStager} from './environments/clawShotCity'; +import {FieryWarpathStager} from './environments/fieryWarpath'; import {FloatingIslandsStager} from './environments/floatingIslands'; import {ForbiddenGroveStager} from './environments/forbiddenGrove'; import {FungalCavernStager} from './environments/fungalCavern'; @@ -21,6 +22,7 @@ const stageModules: IStager[] = [ new BalacksCoveStager(), new BountifulBeanstalkStager(), new ClawShotCityStager(), + new FieryWarpathStager(), new FloatingIslandsStager(), new ForbiddenGroveStager(), new FungalCavernStager(), diff --git a/src/scripts/modules/stages/legacy.js b/src/scripts/modules/stages/legacy.js index 22f3679a..c7954167 100644 --- a/src/scripts/modules/stages/legacy.js +++ b/src/scripts/modules/stages/legacy.js @@ -73,15 +73,6 @@ export function addWhiskerWoodsRiftStage(message, user, user_post, hunt) { } /** - * Stage in the FW reflects the current wave only. - * @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 addFieryWarpathStage(message, user, user_post, hunt) { - const wave = user.viewing_atts.desert_warpath.wave; - message.stage = (wave === "portal") ? "Portal" : `Wave ${wave}`; } /** diff --git a/src/scripts/types/hg.ts b/src/scripts/types/hg.ts index 8eeec009..0b50d029 100644 --- a/src/scripts/types/hg.ts +++ b/src/scripts/types/hg.ts @@ -73,7 +73,15 @@ export interface Quests { export type EnvironmentAttributes = unknown; -export type ViewingAttributes = unknown; +export type ViewingAttributes = + | FieryWarpathViewingAttributes + | Record; + +export interface FieryWarpathViewingAttributes { + desert_warpath: { + wave: number | "portal" + } +} export interface JournalMarkup { render_data: RenderData; diff --git a/tests/scripts/modules/stages/environments/fieryWarpath.spec.ts b/tests/scripts/modules/stages/environments/fieryWarpath.spec.ts new file mode 100644 index 00000000..c8a37981 --- /dev/null +++ b/tests/scripts/modules/stages/environments/fieryWarpath.spec.ts @@ -0,0 +1,52 @@ +import {FieryWarpathStager} from "@scripts/modules/stages/environments/fieryWarpath"; +import {User} from "@scripts/types/hg"; +import {IntakeMessage} from "@scripts/types/mhct"; + +describe('Fiery Warpath stages', () => { + it('should be for the "Fiery Warpath" environment', () => { + const stager = new FieryWarpathStager(); + expect(stager.environment).toBe('Fiery Warpath'); + }); + + it('sets stage to "Portal" when wave is portal', () => { + const stager = new FieryWarpathStager(); + + const message = {} as IntakeMessage; + const preUser = {viewing_atts:{desert_warpath: { + wave: 'portal', + }}} as User; + const postUser = {} as User; + const journal = {}; + + stager.addStage(message, preUser, postUser, journal); + + expect(message.stage).toBe('Portal'); + }); + + it('sets stage to "Wave #" when wave is numbered waved', () => { + const stager = new FieryWarpathStager(); + + const message = {} as IntakeMessage; + const preUser = {viewing_atts:{desert_warpath: { + wave: 4, + }}} as User; + const postUser = {} as User; + const journal = {}; + + stager.addStage(message, preUser, postUser, journal); + + expect(message.stage).toBe('Wave 4'); + }); + + it.each([undefined, null])('throws when "desert_warpath" viewer atts are null or undefined', (state) => { + const stager = new FieryWarpathStager(); + + const message = {} as IntakeMessage; + const preUser = {viewing_atts:{desert_warpath: state}} as unknown as User; + const postUser = {} as User; + const journal = {}; + + expect(() => stager.addStage(message, preUser, postUser, journal)) + .toThrow('Fiery Warpath viewing attributes are undefined'); + }); +});