diff --git a/CHANGELOG.md b/CHANGELOG.md index ecc93cd..8511f5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.1.31 + +fix: coop weapon map failed due to a dot +([#33](https://github.com/spacemeowx2/s3si.ts/issues/33)) + ## 0.1.30 feat: use /api/v3/salmon/weapon diff --git a/src/constant.ts b/src/constant.ts index 626b8b4..2f91da6 100644 --- a/src/constant.ts +++ b/src/constant.ts @@ -1,7 +1,7 @@ import type { StatInkPostBody, VsHistoryDetail } from "./types.ts"; export const AGENT_NAME = "s3si.ts"; -export const S3SI_VERSION = "0.1.30"; +export const S3SI_VERSION = "0.1.31"; export const NSOAPP_VERSION = "2.3.1"; export const WEB_VIEW_VERSION = "1.0.0-433ec0e8"; export const S3SI_LINK = "https://github.com/spacemeowx2/s3si.ts"; diff --git a/src/exporters/stat.ink.ts b/src/exporters/stat.ink.ts index ad92e83..0863ad4 100644 --- a/src/exporters/stat.ink.ts +++ b/src/exporters/stat.ink.ts @@ -156,6 +156,42 @@ class StatInkAPI { } } + // Splatnet returns `14式竹筒槍‧甲`, and stat.ink returns `14式竹筒槍·甲`. + // Maybe a typo of splatnet? + private _getAliasName(name: string): string[] { + const STAT_INK_DOT = "·"; + const SPLATNET_DOT = "‧"; + + if (name.includes(STAT_INK_DOT)) { + return [name, name.replaceAll(STAT_INK_DOT, SPLATNET_DOT)]; + } else { + return [name]; + } + } + + _salmonWeaponMap = new Map(); + async getSalmonWeaponMap() { + if (this._salmonWeaponMap.size === 0) { + const weapons = await this.getSalmonWeapon(); + for (const weapon of weapons) { + for ( + const name of Object.values(weapon.name).flatMap((n) => + this._getAliasName(n) + ) + ) { + const prevKey = this._salmonWeaponMap.get(name); + if (prevKey !== undefined && prevKey !== weapon.key) { + console.warn(`Duplicate weapon name: ${name}`); + } + this._salmonWeaponMap.set(name, weapon.key); + } + } + if (this._salmonWeaponMap.size === 0) { + throw new Error("Failed to get salmon weapon map"); + } + } + return this._salmonWeaponMap; + } getSalmonWeapon = () => this._getCached( `${this.statInk}/api/v3/salmon/weapon?full=1`, @@ -483,9 +519,8 @@ export class StatInkExporter implements GameExporter { async mapCoopWeapon( { name, image }: { name: string; image: Image | null }, ): Promise { - const weaponMap = await this.api.getSalmonWeapon(); - const weapon = weaponMap.find((i) => Object.values(i.name).includes(name)) - ?.key; + const weaponMap = await this.api.getSalmonWeaponMap(); + const weapon = weaponMap.get(name); if (!weapon) { if (this.isRandomWeapon(image)) {