fix: coop weapon map failed due to a dot (#33)
parent
d13d75d40a
commit
707d7204dc
|
|
@ -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
|
## 0.1.30
|
||||||
|
|
||||||
feat: use /api/v3/salmon/weapon
|
feat: use /api/v3/salmon/weapon
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import type { StatInkPostBody, VsHistoryDetail } from "./types.ts";
|
import type { StatInkPostBody, VsHistoryDetail } from "./types.ts";
|
||||||
|
|
||||||
export const AGENT_NAME = "s3si.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 NSOAPP_VERSION = "2.3.1";
|
||||||
export const WEB_VIEW_VERSION = "1.0.0-433ec0e8";
|
export const WEB_VIEW_VERSION = "1.0.0-433ec0e8";
|
||||||
export const S3SI_LINK = "https://github.com/spacemeowx2/s3si.ts";
|
export const S3SI_LINK = "https://github.com/spacemeowx2/s3si.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<string, string>();
|
||||||
|
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 = () =>
|
getSalmonWeapon = () =>
|
||||||
this._getCached<StatInkWeapon>(
|
this._getCached<StatInkWeapon>(
|
||||||
`${this.statInk}/api/v3/salmon/weapon?full=1`,
|
`${this.statInk}/api/v3/salmon/weapon?full=1`,
|
||||||
|
|
@ -483,9 +519,8 @@ export class StatInkExporter implements GameExporter {
|
||||||
async mapCoopWeapon(
|
async mapCoopWeapon(
|
||||||
{ name, image }: { name: string; image: Image | null },
|
{ name, image }: { name: string; image: Image | null },
|
||||||
): Promise<string | null> {
|
): Promise<string | null> {
|
||||||
const weaponMap = await this.api.getSalmonWeapon();
|
const weaponMap = await this.api.getSalmonWeaponMap();
|
||||||
const weapon = weaponMap.find((i) => Object.values(i.name).includes(name))
|
const weapon = weaponMap.get(name);
|
||||||
?.key;
|
|
||||||
|
|
||||||
if (!weapon) {
|
if (!weapon) {
|
||||||
if (this.isRandomWeapon(image)) {
|
if (this.isRandomWeapon(image)) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue