From e77737f4221496837f434c3b1ee86abeca17abb0 Mon Sep 17 00:00:00 2001 From: maxswa Date: Mon, 18 Apr 2022 15:44:45 -0400 Subject: [PATCH] Add Guardians of the Rift. --- README.md | 2 ++ __tests__/hiscores.test.ts | 8 ++++++-- __tests__/lynxTitanStats.csv | 1 + src/hiscores.ts | 18 +++++++++++++++--- src/types.ts | 2 ++ src/utils/constants.ts | 7 +++++++ 6 files changed, 33 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c1a52b9..ea3e4e7 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,7 @@ Activities consist of all levels of clue scrolls as well as minigames and bosses | Bounty Hunter (Hunter) | `hunterBH` | | Last Man Standing | `lastManStanding` | | Soul Wars Zeal | `soulWarsZeal` | +| Rifts Closed | `riftsClosed` | ### Leagues @@ -193,6 +194,7 @@ Activities consist of all levels of clue scrolls as well as minigames and bosses bountyHunter: {}, lastManStanding: {}, soulWarsZeal: {}, + riftsClosed: {}, bosses: {} } } diff --git a/__tests__/hiscores.test.ts b/__tests__/hiscores.test.ts index a029ac1..bb4a1c2 100644 --- a/__tests__/hiscores.test.ts +++ b/__tests__/hiscores.test.ts @@ -88,6 +88,7 @@ test('Parse CSV to json', () => { 1,6143 4814,898 37,225 + 23,467 382,2780 944,3000 1981,1452 @@ -171,6 +172,7 @@ test('Parse CSV to json', () => { }, lastManStanding: { rank: 4814, score: 898 }, soulWarsZeal: { rank: 37, score: 225 }, + riftsClosed: { rank: 23, score: 467 }, clues: { all: { rank: 32, score: 12148 }, beginner: { rank: 3105, score: 76 }, @@ -236,9 +238,11 @@ test('Parse CSV to json', () => { }); test('Parse CSV with unknown activity', () => { - const statsWithUnknownActivity = lynxTitanStats + ` + const statsWithUnknownActivity = `${lynxTitanStats} -1,-1`; - expect(() => parseStats(statsWithUnknownActivity)).toThrow(INVALID_FORMAT_ERROR); + expect(() => parseStats(statsWithUnknownActivity)).toThrow( + INVALID_FORMAT_ERROR + ); }); test('Parse invalid CSV', () => { diff --git a/__tests__/lynxTitanStats.csv b/__tests__/lynxTitanStats.csv index 7435c27..08e3331 100644 --- a/__tests__/lynxTitanStats.csv +++ b/__tests__/lynxTitanStats.csv @@ -29,6 +29,7 @@ -1,-1 -1,-1 -1,-1 +-1,-1 347584,22 -1,-1 -1,-1 diff --git a/src/hiscores.ts b/src/hiscores.ts index 28501b1..d7498ac 100644 --- a/src/hiscores.ts +++ b/src/hiscores.ts @@ -28,7 +28,8 @@ import { getActivityPageURL, httpGet, BOSSES, - INVALID_FORMAT_ERROR + INVALID_FORMAT_ERROR, + EXTRA_ACTIVITY_COUNT } from './utils'; /** @@ -75,7 +76,14 @@ export function parseStats(csv: string): Stats { .filter((entry) => !!entry) .map((stat) => stat.split(',')); - if (splitCSV.length !== SKILLS.length + BH_MODES.length + CLUES.length + BOSSES.length + 3) { + if ( + splitCSV.length !== + SKILLS.length + + BH_MODES.length + + CLUES.length + + BOSSES.length + + EXTRA_ACTIVITY_COUNT + ) { throw Error(INVALID_FORMAT_ERROR); } @@ -105,7 +113,10 @@ export function parseStats(csv: string): Stats { const [leaguePoints] = activityObjects.splice(0, 1); const bhObjects = activityObjects.splice(0, BH_MODES.length); const clueObjects = activityObjects.splice(0, CLUES.length); - const [lastManStanding, soulWarsZeal] = activityObjects.splice(0, 2); + const [lastManStanding, soulWarsZeal, riftsClosed] = activityObjects.splice( + 0, + 3 + ); const bossObjects = activityObjects.splice(0, BOSSES.length); const skills: Skills = skillObjects.reduce((prev, curr, index) => { @@ -138,6 +149,7 @@ export function parseStats(csv: string): Stats { bountyHunter, lastManStanding, soulWarsZeal, + riftsClosed, clues, bosses }; diff --git a/src/types.ts b/src/types.ts index 2c5e9cb..215ba4e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -119,6 +119,7 @@ export type ActivityName = | 'rogueBH' | 'lastManStanding' | 'soulWarsZeal' + | 'riftsClosed' | 'allClues' | 'beginnerClues' | 'easyClues' @@ -135,6 +136,7 @@ export interface Stats { bountyHunter: BH; lastManStanding: Activity; soulWarsZeal: Activity; + riftsClosed: Activity; bosses: Bosses; } export type Modes = { [M in Gamemode]?: Stats }; diff --git a/src/utils/constants.ts b/src/utils/constants.ts index b38e8f6..b667043 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -132,6 +132,7 @@ export const ACTIVITIES: ActivityName[] = [ 'masterClues', 'lastManStanding', 'soulWarsZeal', + 'riftsClosed', ...BOSSES ]; @@ -247,5 +248,11 @@ export const FORMATTED_BH_NAMES: FormattedBHNames = { export const FORMATTED_LMS = 'Last Man Standing'; export const FORMATTED_SOUL_WARS = 'Soul Wars Zeal'; export const FORMATTED_LEAGUE_POINTS = 'League Points'; +export const FORMATTED_RIFTS_CLOSED = 'Rifts Closed'; + +/** + * Count of activities not including bosses, bounty hunter, or clues. + */ +export const EXTRA_ACTIVITY_COUNT = 4; export const INVALID_FORMAT_ERROR = 'Invalid hiscores format';