Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to Labyrinth Stager #488

Merged
merged 2 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,6 @@ import * as detailingFuncs from './modules/details/legacy';
"Furoma Rift": stagingFuncs.addFuromaRiftStage,
"Gnawnian Express Station": stagingFuncs.addTrainStage,
"Iceberg": stagingFuncs.addIcebergStage,
"Labyrinth": stagingFuncs.addLabyrinthStage,
"Living Garden": stagingFuncs.addGardenStage,
"Lost City": stagingFuncs.addLostCityStage,
"Muridae Market": stagingFuncs.addMuridaeMarketStage,
Expand Down
24 changes: 24 additions & 0 deletions src/scripts/modules/stages/environments/labyrinth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {type User} from '@scripts/types/hg';
import {type IntakeMessage} from '@scripts/types/mhct';
import {type IStager} from '../stages.types';

export class LabyrinthStager implements IStager {
readonly environment: string = 'Labyrinth';

addStage(message: IntakeMessage, userPre: User, userPost: User, journal: unknown): void {
const quest = userPre.quests.QuestLabyrinth;

if (!quest) {
throw new Error('QuestLabyrinth is undefined');
}

if (quest.status === "hallway") {
const hallway = quest.hallway_name;
// Remove first word (like Short)
message.stage = hallway.substr(hallway.indexOf(" ") + 1).replace(/ hallway/i, '');
} else {
// Not recording intersections at this time.
throw new Error('Not recording labyrinth intersections');
}
}
}
2 changes: 2 additions & 0 deletions src/scripts/modules/stages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {ForbiddenGroveStager} from './environments/forbiddenGrove';
import {FungalCavernStager} from './environments/fungalCavern';
import {HarbourStager} from './environments/harbour';
import {IceFortressStager} from './environments/iceFortress';
import {LabyrinthStager} from './environments/labyrinth';
import {MoussuPicchuStager} from './environments/moussuPicchu';
import {MousoleumStager} from './environments/mousoleum';
import {SuperBrieFactoryStager} from './environments/superBrieFactory';
Expand All @@ -18,6 +19,7 @@ const stageModules: IStager[] = [
new FungalCavernStager(),
new HarbourStager(),
new IceFortressStager(),
new LabyrinthStager(),
new MoussuPicchuStager(),
new MousoleumStager(),
new SuperBrieFactoryStager(),
Expand Down
18 changes: 0 additions & 18 deletions src/scripts/modules/stages/legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,6 @@ export function addWhiskerWoodsRiftStage(message, user, user_post, hunt) {
}
}

/**
* Labyrinth stage reflects the type of hallway.
* @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 addLabyrinthStage(message, user, user_post, hunt) {
if (user.quests.QuestLabyrinth.status === "hallway") {
const hallway = user.quests.QuestLabyrinth.hallway_name;
// Remove first word (like Short)
message.stage = hallway.substr(hallway.indexOf(" ") + 1).replace(/ hallway/i, '');
} else {
// Not recording intersections at this time.
message.location = null;
}
}

/**
* Stage in the FW reflects the current wave only.
* @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 @@ -50,7 +50,7 @@ export interface Quests {
QuestHalloweenBoilingCauldron?: quests.QuestHalloweenBoilingCauldron
QuestIceberg?: quests.QuestIceberg;
QuestIceFortress?: quests.QuestIceFortress;
QuestLabyrinth?: unknown
QuestLabyrinth?: quests.QuestLabyrinth
QuestLivingGarden?: unknown
QuestLostCity?: unknown
QuestMousoleum?: quests.QuestMousoleum
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 @@ -6,6 +6,7 @@ export * from '@scripts/types/quests/halloween';
export * from '@scripts/types/quests/harbour';
export * from '@scripts/types/quests/iceberg';
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/superBrieFactory';
Expand Down
4 changes: 4 additions & 0 deletions src/scripts/types/quests/labyrinth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface QuestLabyrinth {
status: string;
hallway_name: string;
}
57 changes: 57 additions & 0 deletions tests/scripts/modules/stages/environments/labyrinth.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {LabyrinthStager} from "@scripts/modules/stages/environments/labyrinth";
import {User} from "@scripts/types/hg";
import {IntakeMessage} from "@scripts/types/mhct";

describe('Labyrinth stages', () => {
const HallwayLengths = ['Short', 'Medium', 'Long'];
const HallwayTypes = ['Fealty', 'Tech', 'Scholar'];
const HallwayQualities = ['Plain', 'Superior', 'Epic'];

const hallwayCombinations = [
HallwayTypes,
HallwayQualities,
].reduce((a, b) => a.flatMap(x => b.map(y => `${x} ${y}`)), ['']);

it('should be for the "Labyrinth" environment', () => {
const stager = new LabyrinthStager();
expect(stager.environment).toBe('Labyrinth');
});

it('should throw for non hallway', () => {
const stager = new LabyrinthStager();
const message = {} as IntakeMessage;
const preUser = {quests: {QuestLabyrinth:{
status: 'intersection',
}}} as User;
const postUser = {} as User;
const journal = {};
expect(() => stager.addStage(message, preUser, postUser, journal))
.toThrow('Not recording labyrinth intersections');
});

describe.each(hallwayCombinations)('should set hallway stage for each combination', (hallwayType) => {
it.each(HallwayLengths)('hallway length: %p', (length) => {
const stager = new LabyrinthStager();
const message = {} as IntakeMessage;
const preUser = {quests: {QuestLabyrinth:{
hallway_name: `${length} ${hallwayType} Hallway`,
status: 'hallway',
}}} as User;
const postUser = {} as User;
const journal = {};
stager.addStage(message, preUser, postUser, journal);

expect(message.stage).toBe(hallwayType);
});
});

it.each([undefined, null])('should throw when QuestLabyrinth is %p', (quest) => {
const stager = new LabyrinthStager();
const message = {} as IntakeMessage;
const preUser = {quests: {QuestLabyrinth: quest}} as User;
const postUser = {} as User;
const journal = {};
expect(() => stager.addStage(message, preUser, postUser, journal))
.toThrow('QuestLabyrinth is undefined');
});
});