diff --git a/utils/database.ts b/utils/database.ts index 233b990..05f0b71 100644 --- a/utils/database.ts +++ b/utils/database.ts @@ -8,7 +8,7 @@ import { getImageHash, getVsSelfPlayer } from "./ui"; let db: SQLite.SQLiteDatabase | undefined = undefined; -const VERSION = 10; +const VERSION = 11; export const open = async () => { if (db) { @@ -240,6 +240,26 @@ export const upgrade = async () => { } await db!.execAsync("VACUUM"); } + if (version < 11) { + await beginTransaction(); + try { + const statement = await db!.prepareAsync("UPDATE brief SET brief = ? WHERE id = ?"); + for await (const row of queryDetailEach()) { + if (row.mode === "salmon_run") { + await statement.executeAsync( + JSON.stringify(getCoopBrief(JSON.parse(row.detail))), + row.id + ); + } + } + await statement.finalizeAsync(); + await db!.execAsync("PRAGMA user_version=11"); + await commit(); + } catch (e) { + await rollback(); + throw e; + } + } }; export const close = () => { db!.closeAsync(); diff --git a/utils/stats.ts b/utils/stats.ts index 7b3e423..8fa530e 100644 --- a/utils/stats.ts +++ b/utils/stats.ts @@ -302,6 +302,7 @@ export interface CoopBrief { id: string; result: number; time: number; + private: boolean; rule: CoopRule; stage: string; suppliedWeapons: string[]; @@ -481,6 +482,7 @@ export const getCoopBrief = (coop: CoopHistoryDetailResult): CoopBrief => { id: coop.coopHistoryDetail!.id, result: coop.coopHistoryDetail!.resultWave, time: new Date(coop.coopHistoryDetail!.playedTime).valueOf(), + private: coop.coopHistoryDetail!.jobPoint === null, rule: coop.coopHistoryDetail!.rule as CoopRule, stage: coop.coopHistoryDetail!.coopStage.id, suppliedWeapons: coop.coopHistoryDetail!.weapons.map((weapon) => diff --git a/views/ResultView.tsx b/views/ResultView.tsx index d0db06d..e77a3f0 100644 --- a/views/ResultView.tsx +++ b/views/ResultView.tsx @@ -204,22 +204,48 @@ const ResultView = (props: ResultViewProps) => { return false; }; const canGroupCoop = (coop: CoopBrief, group: Brief[]) => { - // Coops with the same rule, stage and supplied weapons in the 48 hours (2 hours period) will be - // regarded in the same group. There is also a 2 minutes grace period for coops when certain - // conditions are met. + // Coops with the same rule, stage (no restriction for Big Run, since there are random stages) + // and supplied weapons in the 48 hours (2 hours period) will be regarded in the same group. + // Coops without points will be regarded as privates and will be grouped without any condition. + // There is also a 2 minutes grace period for coops when certain conditions are met. if (group[0]?.coop) { - if ( - coop.rule === group[0].coop.rule && - coop.stage === group[0].coop.stage && - coop.suppliedWeapons.join(",") === group[0].coop.suppliedWeapons.join(",") && - (Math.ceil(dayjs(coop.time).valueOf() / 7200000) - - Math.floor(dayjs(group[0].coop.time).valueOf() / 7200000) <= - 24 || - Math.ceil(dayjs(coop.time).valueOf() / 7200000) - - Math.floor(dayjs(group[0].coop.time).subtract(2, "minute").valueOf() / 7200000) <= - 24) - ) { - return true; + if (coop.private || group[0].coop.private) { + if (coop.private && group[0].coop.private) { + return true; + } + return false; + } + switch (coop.rule) { + case CoopRule.REGULAR: + case CoopRule.TEAM_CONTEST: + if ( + coop.rule === group[0].coop.rule && + coop.stage === group[0].coop.stage && + coop.suppliedWeapons.join(",") === group[0].coop.suppliedWeapons.join(",") && + (Math.ceil(dayjs(coop.time).valueOf() / 7200000) - + Math.floor(dayjs(group[0].coop.time).valueOf() / 7200000) <= + 24 || + Math.ceil(dayjs(coop.time).valueOf() / 7200000) - + Math.floor(dayjs(group[0].coop.time).subtract(2, "minute").valueOf() / 7200000) <= + 24) + ) { + return true; + } + break; + case CoopRule.BIG_RUN: + if ( + coop.rule === group[0].coop.rule && + coop.suppliedWeapons.join(",") === group[0].coop.suppliedWeapons.join(",") && + (Math.ceil(dayjs(coop.time).valueOf() / 7200000) - + Math.floor(dayjs(group[0].coop.time).valueOf() / 7200000) <= + 24 || + Math.ceil(dayjs(coop.time).valueOf() / 7200000) - + Math.floor(dayjs(group[0].coop.time).subtract(2, "minute").valueOf() / 7200000) <= + 24) + ) { + return true; + } + break; } } return false;