From dac1f59312ae52c5f15ce14d9ae7e2a49e2ef51e Mon Sep 17 00:00:00 2001 From: Sebastian Sebald Date: Mon, 31 Jul 2023 23:38:37 +0200 Subject: [PATCH] fix: more fixes for IDs... (#247) --- __test__/lib/xws.test.ts | 16 +++++++++++ lib/xws.ts | 60 +++++++++++++++++++++++----------------- 2 files changed, 50 insertions(+), 26 deletions(-) create mode 100644 __test__/lib/xws.test.ts diff --git a/__test__/lib/xws.test.ts b/__test__/lib/xws.test.ts new file mode 100644 index 00000000..5831386d --- /dev/null +++ b/__test__/lib/xws.test.ts @@ -0,0 +1,16 @@ +import { parsePilotId } from '@/lib/xws'; + +test('normalize pilot', () => { + expect(parsePilotId('hansoloboy', 'rebelalliance')).toMatchInlineSnapshot( + `"hansolo-battleofyavin"` + ); + expect( + parsePilotId('countdookusoc', 'separatistalliance') + ).toMatchInlineSnapshot(`"countdooku-siegeofcoruscant"`); + expect(parsePilotId('dbs404soc', 'separatistalliance')).toMatchInlineSnapshot( + `"dbs404-siegeofcoruscant"` + ); + expect( + parsePilotId('durgeseparatist', 'separatistalliance') + ).toMatchInlineSnapshot(`"durge-separatistalliance"`); +}); diff --git a/lib/xws.ts b/lib/xws.ts index 13edfaf6..81c8cea7 100644 --- a/lib/xws.ts +++ b/lib/xws.ts @@ -1,4 +1,4 @@ -import type { XWSSquad, XWSUpgrades } from './types'; +import type { XWSFaction, XWSSquad, XWSUpgrades } from './types'; import SL_PILOTS from './data/standard-loadout-pilots.json'; import { getPointsByName } from './yasb'; import { getUpgradeName } from './get-value'; @@ -20,12 +20,7 @@ const PILOT_ID_MAP = { 'herasyndulla-bwing': 'herasyndulla-asf01bwing', corranhornxwing: 'corranhorn-t65xwing', 'bokatankryze-separatistalliance': 'bokatankryze', - lukeskywalkerboy: 'lukeskywalker-battleofyavin', - wampaboy: 'wampa-battleofyavin', durgeseparatist: 'durge-separatistalliance', - dist81soc: 'dist81-siegeofcoruscant', - dbs404soc: 'dbs404-siegeofcoruscant', - dbs32csoc: 'dbs32c-siegeofcoruscant', bosskz95headhunter: 'bossk-z95af4headhunter', fennraurebelfang: 'fennrau-rebel-fang', wedgeantillesawing: 'wedgeantilles-rz1awing', @@ -36,23 +31,43 @@ const PILOT_ID_MAP = { herasyndullaawing: 'herasyndulla-rz1awing', dalanoberosstarviper: 'dalanoberos-starviperclassattackplatform', vultskerristieinterceptor: 'vultskerris-tieininterceptor', - garvendreisboy: 'garvendreis-battleofyavin', - jekporkinsboy: 'jekporkins-battleofyavin', oddballywing: 'oddball-btlbywing', anakinskywalkerywing: 'anakinskywalker-btlbywing', - darkcurseboy: 'darkcurse-battleofyavin', - countdookusoc: 'countdooku-siegeofcoruscant', - darthvaderboy: 'darthvader-battleofyavin', - maulermithelboy: 'maulermithel-battleofyavin', - hansoloboy: 'hansolo-battleofyavin', - holokandboy: 'holokand-battleofyavin', darthvadertiedefender: 'darthvader-tieddefender', - wedgeantillesboy: 'wedgeantilles-battleofyavin', + landocalrissianresistance: 'landocalrissian-scavengedyt1300', + gideonhaskxishuttle: 'gideonhask-xiclasslightshuttle', + sabinewrenawing: 'sabinewren-rz1awing', + ezrabridgergauntletfighter: 'ezrabridger-gauntletfighter', + herasyndullabwing: 'herasyndulla-asf01bwing', + garvendreisxwing: 'garvendreis-t65xwing', + gideonhasktieinterceptor: 'gideonhask-tieininterceptor', + anakinskywalkerdelta7b: 'anakinskywalker-delta7baethersprite', + chewbaccaresistance: 'chewbacca-scavengedyt1300', + macewindudelta7b: 'macewindu-delta7baethersprite', + ahsokatanoawing: 'ahsokatano-rz1awing', + l337escapecraft: 'l337-escapecraft', // These ones are really dumb ... 'hansolo-rebelalliance': 'hansolo-modifiedyt1300lightfreighter', 'durge-separatistalliance': 'durge-separatistalliance', }; +export const parsePilotId = (val: string, faction: XWSFaction) => { + let pilot = val + // Scenarios + .replace(/boy$/, '-battleofyavin') + .replace(/soc$/, '-siegeofcoruscant') + // Factions + .replace(/separatist$/, '-separatistalliance'); + + return ( + //@ts-expect-error (ID accessing allowed to fail) + PILOT_ID_MAP[val] ?? + //@ts-expect-error (ID accessing allowed to fail) + PILOT_ID_MAP[`${val}-${faction}`] ?? + pilot + ); +}; + /** * Adjust some irregularities coming from LBN and Rollbetter. */ @@ -62,17 +77,10 @@ export const normalize = (xws: XWSSquad | null) => { } const pilots = xws.pilots.map(pilot => { - // Fix some broken IDs from builders that don't follow XWS - const pilotId = - //@ts-expect-error (ID accessing allowed to fail) - PILOT_ID_MAP[pilot.id] || PILOT_ID_MAP[`${pilot.id}-${xws.faction}`]; - - if (pilotId) { - pilot = { - ...pilot, - id: pilotId, - }; - } + pilot = { + ...pilot, + id: parsePilotId(pilot.id, xws.faction), + }; // Add loadout and costs to pilots with standard loadouts //@ts-expect-error (ID accessing allowed to fail)