Skip to content

Commit

Permalink
Add Sand Dunes stager
Browse files Browse the repository at this point in the history
  • Loading branch information
hymccord committed Nov 30, 2023
1 parent 6a95d4e commit 2716aed
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 16 deletions.
1 change: 0 additions & 1 deletion src/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,6 @@ import * as detailingFuncs from './modules/details/legacy';
"Lost City": stagingFuncs.addLostCityStage,
"Muridae Market": stagingFuncs.addMuridaeMarketStage,
"Queso Geyser": stagingFuncs.addQuesoGeyserStage,
"Sand Dunes": stagingFuncs.addSandDunesStage,
"Seasonal Garden": stagingFuncs.addSeasonalGardenStage,
"Sunken City": stagingFuncs.addSunkenCityStage,
"Table of Contents": stagingFuncs.addTableOfContentsStage,
Expand Down
16 changes: 16 additions & 0 deletions src/scripts/modules/stages/environments/sandDunes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as hg from '@scripts/types/hg';
import * as mhct from '@scripts/types/mhct';
import {type IStager} from '../stages.types';

export class SandDunesStager implements IStager {
readonly environment: string = 'Sand Dunes';

addStage(message: mhct.IntakeMessage, userPre: hg.User, userPost: hg.User, journal: unknown): void {
const quest = userPre.quests.QuestSandDunes;
if (!quest) {
throw new Error('QuestSandDunes is undefined');
}

message.stage = (quest.minigame.has_stampede) ? "Stampede" : "No Stampede";
}
}
2 changes: 2 additions & 0 deletions src/scripts/modules/stages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {IceFortressStager} from './environments/iceFortress';
import {LabyrinthStager} from './environments/labyrinth';
import {MoussuPicchuStager} from './environments/moussuPicchu';
import {MousoleumStager} from './environments/mousoleum';
import {SandDunesStager} from './environments/sandDunes';
import {SlushyShorelineStager} from './environments/slushyShoreline';
import {SuperBrieFactoryStager} from './environments/superBrieFactory';

Expand All @@ -25,6 +26,7 @@ const stageModules: IStager[] = [
new LabyrinthStager(),
new MoussuPicchuStager(),
new MousoleumStager(),
new SandDunesStager(),
new SlushyShorelineStager(),
new SuperBrieFactoryStager(),
];
Expand Down
11 changes: 0 additions & 11 deletions src/scripts/modules/stages/legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,6 @@ export function addGardenStage(message, user, user_post, hunt) {
message.stage = (container_status === "dumped") ? "Pouring" : "Not Pouring";
}

/**
* Determine if there is a stampede active
* @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 addSandDunesStage(message, user, user_post, hunt) {
message.stage = (user.quests.QuestSandDunes.minigame.has_stampede) ? "Stampede" : "No Stampede";
}

/**
* Indicate whether or not the Cursed / Corrupt mouse is present
* @param {Object <string, any>} message The message to be sent.
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/types/hg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export interface Quests {
QuestRiftBurroughs?: unknown
QuestRiftFuroma?: unknown
QuestRiftWhiskerWoods?: unknown
QuestSandDunes?: unknown
QuestSandDunes?: quests.QuestSandDunes
QuestSunkenCity?: unknown
QuestSuperBrieFactory?: quests.QuestSuperBrieFactory
QuestSpringHunt?: quests.QuestSpringHunt
Expand Down
1 change: 1 addition & 0 deletions src/scripts/types/quests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export * from '@scripts/types/quests/iceFortress';
export * from '@scripts/types/quests/labyrinth';
export * from '@scripts/types/quests/mousoleum';
export * from '@scripts/types/quests/moussuPicchu';
export * from '@scripts/types/quests/sandDunes';
export * from '@scripts/types/quests/superBrieFactory';
export * from '@scripts/types/quests/tableOfContents';
export * from '@scripts/types/quests/springHunt';
6 changes: 6 additions & 0 deletions src/scripts/types/quests/sandDunes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface QuestSandDunes {
// this is for Sand Dunes only. Not currently needed for Sand Crypts. See QuestLivingGarden for example of both
minigame: {
has_stampede: boolean
}
}
24 changes: 21 additions & 3 deletions tests/scripts/modules/stages/environments/sandDunes.spec.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,49 @@
import {addSandDunesStage} from "@scripts/modules/stages/legacy";
import {SandDunesStager} from "@scripts/modules/stages/environments/sandDunes";
import {User} from "@scripts/types/hg";
import {IntakeMessage} from "@scripts/types/mhct";

describe('Sand Dunes stages', () => {
it('should be for the "Sand Dunes" environment', () => {
const stager = new SandDunesStager();
expect(stager.environment).toBe('Sand Dunes');
});

it('should set stage to "Stampede" when there is a stampede', () => {
const stager = new SandDunesStager();
const message = {} as IntakeMessage;
const preUser = {quests: {QuestSandDunes: {minigame: {
has_stampede: true,
}}}} as User;
const postUser = {} as User;
const journal = {};

addSandDunesStage(message, preUser, postUser, journal);
stager.addStage(message, preUser, postUser, journal);

expect(message.stage).toBe('Stampede');
});

it('should set stage to "No Stampede" when there is not a stampede', () => {
const stager = new SandDunesStager();
const message = {} as IntakeMessage;
const preUser = {quests: {QuestSandDunes: {minigame: {
has_stampede: false,
}}}} as User;
const postUser = {} as User;
const journal = {};

addSandDunesStage(message, preUser, postUser, journal);
stager.addStage(message, preUser, postUser, journal);

expect(message.stage).toBe('No Stampede');
});

it.each([undefined, null])('should throw if quest is %p', (quest) => {
const stager = new SandDunesStager();
const message = {} as IntakeMessage;
const preUser = {quests: {QuestSandDunes: quest}} as User;
const postUser = {} as User;
const journal = {};

expect(() => stager.addStage(message, preUser, postUser, journal))
.toThrow('QuestSandDunes is undefined');
});
});

0 comments on commit 2716aed

Please sign in to comment.