diff --git a/CHANGELOG.md b/CHANGELOG.md index 4779142..3190ac2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.1.33 + +fix: RankTracker::getRankStateById (fix +[#36](https://github.com/spacemeowx2/s3si.ts/issues/36)) + ## 0.1.32 fix: auto promotion will miss point tracking duration an export diff --git a/src/RankTracker.test.ts b/src/RankTracker.test.ts index 36ab49b..b5d6c0f 100644 --- a/src/RankTracker.test.ts +++ b/src/RankTracker.test.ts @@ -153,6 +153,67 @@ Deno.test("RankTracker autotrack after promotion", async () => { }); }); +Deno.test("RankTracker issue #36", async () => { + const tracker = new TestRankTracker(undefined); + assertEquals(tracker.testGet(), { + state: undefined, + deltaMap: new Map(), + }); + + const finalState = await tracker.updateState([{ + bankaraMatchChallenge: { + winCount: 3, + loseCount: 0, + maxWinCount: 3, + maxLoseCount: 3, + state: "SUCCEEDED", + isPromo: true, + isUdemaeUp: true, + udemaeAfter: "S+20", + earnedUdemaePoint: null, + }, + historyDetails: { + nodes: [{ + id: genId(1), + udemae: "S+19", + judgement: "WIN", + bankaraMatch: { + earnedUdemaePoint: null, + }, + }, { + id: genId(0), + udemae: "S+19", + judgement: "WIN", + bankaraMatch: { + earnedUdemaePoint: null, + }, + }], + }, + }]); + + const gameId1 = await gameId(genId(1)); + assertEquals(finalState, { + gameId: gameId1, + rank: "S+20", + rankPoint: 300, + }); + + assertEquals(await tracker.getRankStateById(genId(0)), undefined); + + assertEquals(await tracker.getRankStateById(genId(1)), { + before: { + gameId: await gameId(genId(0)), + rank: "S+19", + rankPoint: -1, + }, + after: { + gameId: gameId1, + rank: "S+20", + rankPoint: 300, + }, + }); +}); + Deno.test("RankTracker tracks promotion, ignoring INPROGRESS", async () => { const INIT_STATE = { gameId: await gameId(genId(0)), diff --git a/src/RankTracker.ts b/src/RankTracker.ts index 0975082..0acda6d 100644 --- a/src/RankTracker.ts +++ b/src/RankTracker.ts @@ -251,6 +251,11 @@ export class RankTracker { let cur = this.state; let before = cur; + + // there is no delta for first game + if (cur.gameId === gid) { + return; + } while (cur.gameId !== gid) { const delta = this.deltaMap.get(cur.gameId); if (!delta) { diff --git a/src/constant.ts b/src/constant.ts index 60638e5..e1b9f38 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.32"; +export const S3SI_VERSION = "0.1.33"; 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";