Skip to content

Commit

Permalink
fix: more fixes for IDs... (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebald authored Jul 31, 2023
1 parent 6887433 commit dac1f59
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 26 deletions.
16 changes: 16 additions & 0 deletions __test__/lib/xws.test.ts
Original file line number Diff line number Diff line change
@@ -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"`);
});
60 changes: 34 additions & 26 deletions lib/xws.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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',
Expand All @@ -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.
*/
Expand All @@ -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)
Expand Down

1 comment on commit dac1f59

@vercel
Copy link

@vercel vercel bot commented on dac1f59 Jul 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.