import { createBuild } from "./translator/build"; import { translateRotation } from "./translator/rotation"; import type { Catalog, Team } from "./translator/types"; export interface TeamGuideMember { position: number; characterId: string; weaponId: string; artifactOneId: string; artifactTwoId: string | null; constellation: number; refinement: number; } export interface TeamGuideTeam { id: string; title: string; conditionName: string | null; combo: string; members: TeamGuideMember[]; } export interface TeamGuide { id: string; characterId: string; name: string; teams: TeamGuideTeam[]; } export type GuideImportResult = { team: Team; error?: never } | { team?: never; error: string }; export function importGuideTeam(source: TeamGuideTeam, catalog: Catalog): GuideImportResult { const builds = [] as Team["builds"]; for (const member of source.members) { const character = catalog.characters.find((item) => item.id === member.characterId); const weapon = catalog.weapons.find((item) => item.id === member.weaponId); const artifactOne = catalog.artifacts.find((item) => item.id === member.artifactOneId); const artifactTwo = member.artifactTwoId ? catalog.artifacts.find((item) => item.id === member.artifactTwoId) : undefined; if (!character) return { error: `Character ${member.characterId} is missing from the catalog.` }; if (!weapon) return { error: `Weapon ${member.weaponId} is missing from the catalog.` }; if (!artifactOne) return { error: `Artifact ${member.artifactOneId} is missing from the catalog.` }; if (member.artifactTwoId && !artifactTwo) return { error: `Artifact ${member.artifactTwoId} is missing from the catalog.` }; if (character.weaponType && weapon.weaponType !== character.weaponType) return { error: `${weapon.name} is not compatible with ${character.name}.` }; const build = createBuild(catalog, character, `guide-build-${source.id}-${member.position}`); builds.push({ ...build, weaponId: weapon.id, weaponKey: weapon.key, weaponName: weapon.name, refinement: member.refinement, constellation: member.constellation, artifactMode: artifactTwo ? "2+2" : "4pc", artifactOneId: artifactOne.id, artifactOneKey: artifactOne.key, artifactOneName: artifactOne.name, artifactTwoId: artifactTwo?.id ?? "", artifactTwoKey: artifactTwo?.key ?? "", artifactTwoName: artifactTwo?.name ?? "", }); } if (!builds.length) return { error: "This guide team has no characters." }; const team: Team = { id: `guide-team-${source.id}`, name: source.title, builds }; const combo = source.combo.trim(); if (combo && combo !== "-") { team.rotation = { enabled: true, text: combo, repeat: false }; if (translateRotation(team).error) team.rotation.enabled = false; } return { team }; }