diff --git a/src/app.ts b/src/app.ts index a994008..64a1247 100644 --- a/src/app.ts +++ b/src/app.ts @@ -9,6 +9,7 @@ import { } from "./splatnet3.ts"; import { BattleExporter, + ChallengeProgress, HistoryGroups, VsBattle, VsHistoryDetail, @@ -84,6 +85,7 @@ class BattleFetcher { if (!group) { return { + challengeProgress: null, bankaraMatchChallenge: null, listNode: null, }; @@ -92,10 +94,27 @@ class BattleFetcher { const { bankaraMatchChallenge } = group; const listNode = group.historyDetails.nodes.find((i) => i._bid === bid) ?? null; + const index = group.historyDetails.nodes.indexOf(listNode!); + + let challengeProgress: null | ChallengeProgress = null; + if (bankaraMatchChallenge) { + const pastBattles = group.historyDetails.nodes.slice(0, index); + const { winCount, loseCount } = bankaraMatchChallenge; + challengeProgress = { + index, + winCount: winCount - + pastBattles.filter((i) => i.judgement == "WIN").length, + loseCount: loseCount - + pastBattles.filter((i) => + ["LOSE", "DEEMED_LOSE"].includes(i.judgement) + ).length, + }; + } return { bankaraMatchChallenge, listNode, + challengeProgress, }; } async getBattleDetail(id: string): Promise { diff --git a/src/constant.ts b/src/constant.ts index b7194ae..5a94857 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.3"; +export const S3SI_VERSION = "0.1.4"; export const NSOAPP_VERSION = "2.3.1"; export const WEB_VIEW_VERSION = "1.0.0-216d0219"; diff --git a/src/exporters/stat.ink.ts b/src/exporters/stat.ink.ts index eae86a8..e471050 100644 --- a/src/exporters/stat.ink.ts +++ b/src/exporters/stat.ink.ts @@ -164,7 +164,8 @@ export class StatInkExporter implements BattleExporter { return result; } async mapBattle( - { bankaraMatchChallenge, listNode, detail: vsDetail }: VsBattle, + { challengeProgress, bankaraMatchChallenge, listNode, detail: vsDetail }: + VsBattle, ): Promise { const { knockout, @@ -256,11 +257,13 @@ export class StatInkExporter implements BattleExporter { result.rank_after = result.rank_before; result.rank_after_s_plus = result.rank_before_s_plus; } - result.challenge_win = bankaraMatchChallenge.winCount; - result.challenge_lose = bankaraMatchChallenge.loseCount; result.rank_exp_change = bankaraMatchChallenge.earnedUdemaePoint ?? undefined; } + if (challengeProgress) { + result.challenge_win = challengeProgress.winCount; + result.challenge_lose = challengeProgress.loseCount; + } return result; } diff --git a/src/types.ts b/src/types.ts index 4590dff..a2fb8cf 100644 --- a/src/types.ts +++ b/src/types.ts @@ -44,6 +44,7 @@ export type BattleListNode = { _bid: string; id: string; udemae: string; + judgement: "LOSE" | "WIN" | "DEEMED_LOSE" | "EXEMPTED_LOSE"; }; export type HistoryGroups = { nodes: { @@ -89,10 +90,16 @@ export type VsRule = | "CLAM" | "TRI_COLOR"; +export type ChallengeProgress = { + index: number; + winCount: number; + loseCount: number; +}; // With challenge info export type VsBattle = { listNode: null | BattleListNode; bankaraMatchChallenge: null | BankaraMatchChallenge; + challengeProgress: null | ChallengeProgress; detail: VsHistoryDetail; }; export type VsHistoryDetail = {