Skip to content

Commit

Permalink
Merge pull request #499 from hymccord/fw-stage
Browse files Browse the repository at this point in the history
Fiery Warpath stager
  • Loading branch information
AardWolf authored Dec 12, 2023
2 parents 32ada98 + 2bceee1 commit 021664d
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
25 changes: 25 additions & 0 deletions src/scripts/modules/stages/environments/fieryWarpath.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 2 additions & 0 deletions src/scripts/modules/stages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -21,6 +22,7 @@ const stageModules: IStager[] = [
new BalacksCoveStager(),
new BountifulBeanstalkStager(),
new ClawShotCityStager(),
new FieryWarpathStager(),
new FloatingIslandsStager(),
new ForbiddenGroveStager(),
new FungalCavernStager(),
Expand Down
9 changes: 0 additions & 9 deletions src/scripts/modules/stages/legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,6 @@ export function addWhiskerWoodsRiftStage(message, user, user_post, hunt) {
}

/**
* Stage in the FW reflects the current wave only.
* @param {Object <string, any>} message The message to be sent.
* @param {Object <string, any>} user The user state object, when the hunt was invoked (pre-hunt).
* @param {Object <string, any>} user_post The user state object, after the hunt.
* @param {Object <string, any>} 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}`;
}
/**
Expand Down
10 changes: 9 additions & 1 deletion src/scripts/types/hg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,15 @@ export interface Quests {

export type EnvironmentAttributes = unknown;

export type ViewingAttributes = unknown;
export type ViewingAttributes =
| FieryWarpathViewingAttributes
| Record<string, never>;

export interface FieryWarpathViewingAttributes {
desert_warpath: {
wave: number | "portal"
}
}

export interface JournalMarkup {
render_data: RenderData;
Expand Down
52 changes: 52 additions & 0 deletions tests/scripts/modules/stages/environments/fieryWarpath.spec.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});

0 comments on commit 021664d

Please sign in to comment.