feat: workaround for incorrect translate from stat.ink
parent
1c9c03e327
commit
933b438505
24
src/app.ts
24
src/app.ts
|
|
@ -6,7 +6,7 @@ import {
|
||||||
State,
|
State,
|
||||||
StateBackend,
|
StateBackend,
|
||||||
} from "./state.ts";
|
} from "./state.ts";
|
||||||
import { getBattleList, isTokenExpired } from "./splatnet3.ts";
|
import { getBattleList, getGearPower, isTokenExpired } from "./splatnet3.ts";
|
||||||
import { BattleListType, Game, GameExporter } from "./types.ts";
|
import { BattleListType, Game, GameExporter } from "./types.ts";
|
||||||
import { Cache, FileCache } from "./cache.ts";
|
import { Cache, FileCache } from "./cache.ts";
|
||||||
import { StatInkExporter } from "./exporters/stat.ink.ts";
|
import { StatInkExporter } from "./exporters/stat.ink.ts";
|
||||||
|
|
@ -65,6 +65,7 @@ export class App {
|
||||||
await this.fetchToken();
|
await this.fetchToken();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
gearMap: Record<string, number> | null = null;
|
||||||
|
|
||||||
constructor(public opts: Opts) {
|
constructor(public opts: Opts) {
|
||||||
this.stateBackend = opts.stateBackend ??
|
this.stateBackend = opts.stateBackend ??
|
||||||
|
|
@ -88,6 +89,16 @@ export class App {
|
||||||
await this.writeState(DEFAULT_STATE);
|
await this.writeState(DEFAULT_STATE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
async getGearMap() {
|
||||||
|
if (this.gearMap) {
|
||||||
|
return this.gearMap;
|
||||||
|
}
|
||||||
|
const { gearPowers } = await getGearPower(this.state);
|
||||||
|
this.gearMap = Object.fromEntries(
|
||||||
|
gearPowers.nodes.map((i, id) => [i.name, id]),
|
||||||
|
);
|
||||||
|
return this.gearMap;
|
||||||
|
}
|
||||||
getSkipMode(): ("vs" | "coop")[] {
|
getSkipMode(): ("vs" | "coop")[] {
|
||||||
const mode = this.opts.skipMode;
|
const mode = this.opts.skipMode;
|
||||||
if (mode === "vs") {
|
if (mode === "vs") {
|
||||||
|
|
@ -115,10 +126,13 @@ export class App {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
out.push(
|
out.push(
|
||||||
new StatInkExporter(
|
new StatInkExporter({
|
||||||
this.state.statInkApiKey!,
|
statInkApiKey: this.state.statInkApiKey!,
|
||||||
this.opts.monitor ? "Monitoring" : "Manual",
|
uploadMode: this.opts.monitor ? "Monitoring" : "Manual",
|
||||||
),
|
nameDict: {
|
||||||
|
gearPower: await this.getGearMap(),
|
||||||
|
},
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,10 @@ async function _getStage(): Promise<StatInkStage> {
|
||||||
const getAbility = cache(_getAbility);
|
const getAbility = cache(_getAbility);
|
||||||
const getStage = cache(_getStage);
|
const getStage = cache(_getStage);
|
||||||
|
|
||||||
|
export type NameDict = {
|
||||||
|
gearPower: Record<string, number | undefined>;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exporter to stat.ink.
|
* Exporter to stat.ink.
|
||||||
*
|
*
|
||||||
|
|
@ -60,11 +64,23 @@ const getStage = cache(_getStage);
|
||||||
*/
|
*/
|
||||||
export class StatInkExporter implements GameExporter {
|
export class StatInkExporter implements GameExporter {
|
||||||
name = "stat.ink";
|
name = "stat.ink";
|
||||||
|
private statInkApiKey: string;
|
||||||
|
private uploadMode: string;
|
||||||
|
private nameDict: NameDict;
|
||||||
|
|
||||||
constructor(private statInkApiKey: string, private uploadMode: string) {
|
constructor(
|
||||||
|
{ statInkApiKey, uploadMode, nameDict }: {
|
||||||
|
statInkApiKey: string;
|
||||||
|
uploadMode: string;
|
||||||
|
nameDict: NameDict;
|
||||||
|
},
|
||||||
|
) {
|
||||||
if (statInkApiKey.length !== 43) {
|
if (statInkApiKey.length !== 43) {
|
||||||
throw new Error("Invalid stat.ink API key");
|
throw new Error("Invalid stat.ink API key");
|
||||||
}
|
}
|
||||||
|
this.statInkApiKey = statInkApiKey;
|
||||||
|
this.uploadMode = uploadMode;
|
||||||
|
this.nameDict = nameDict;
|
||||||
}
|
}
|
||||||
requestHeaders() {
|
requestHeaders() {
|
||||||
return {
|
return {
|
||||||
|
|
@ -176,12 +192,13 @@ export class StatInkExporter implements GameExporter {
|
||||||
async mapGears(
|
async mapGears(
|
||||||
{ headGear, clothingGear, shoesGear }: VsPlayer,
|
{ headGear, clothingGear, shoesGear }: VsPlayer,
|
||||||
): Promise<StatInkGears> {
|
): Promise<StatInkGears> {
|
||||||
const amap = (await getAbility()).map((i) => ({
|
const amap = await getAbility();
|
||||||
...i,
|
|
||||||
names: Object.values(i.name),
|
|
||||||
}));
|
|
||||||
const mapAbility = ({ name }: { name: string }): string | null => {
|
const mapAbility = ({ name }: { name: string }): string | null => {
|
||||||
const result = amap.find((a) => a.names.includes(name));
|
const abilityIdx = this.nameDict.gearPower[name];
|
||||||
|
if (!abilityIdx) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const result = amap[abilityIdx];
|
||||||
if (!result) {
|
if (!result) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -162,3 +162,12 @@ export async function getCoopHistories(state: State) {
|
||||||
|
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getGearPower(state: State) {
|
||||||
|
const resp = await request(
|
||||||
|
state,
|
||||||
|
Queries.myOutfitCommonDataFilteringConditionQuery,
|
||||||
|
);
|
||||||
|
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
|
|
|
||||||
10
src/types.ts
10
src/types.ts
|
|
@ -9,6 +9,8 @@ export enum Queries {
|
||||||
VsHistoryDetailQuery = "2b085984f729cd51938fc069ceef784a",
|
VsHistoryDetailQuery = "2b085984f729cd51938fc069ceef784a",
|
||||||
CoopHistoryQuery = "817618ce39bcf5570f52a97d73301b30",
|
CoopHistoryQuery = "817618ce39bcf5570f52a97d73301b30",
|
||||||
CoopHistoryDetailQuery = "f3799a033f0a7ad4b1b396f9a3bafb1e",
|
CoopHistoryDetailQuery = "f3799a033f0a7ad4b1b396f9a3bafb1e",
|
||||||
|
myOutfitCommonDataFilteringConditionQuery =
|
||||||
|
"d02ab22c9dccc440076055c8baa0fa7a",
|
||||||
}
|
}
|
||||||
export type VarsMap = {
|
export type VarsMap = {
|
||||||
[Queries.HomeQuery]: [];
|
[Queries.HomeQuery]: [];
|
||||||
|
|
@ -23,6 +25,7 @@ export type VarsMap = {
|
||||||
[Queries.CoopHistoryDetailQuery]: [{
|
[Queries.CoopHistoryDetailQuery]: [{
|
||||||
coopHistoryDetailId: string;
|
coopHistoryDetailId: string;
|
||||||
}];
|
}];
|
||||||
|
[Queries.myOutfitCommonDataFilteringConditionQuery]: [];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Image = {
|
export type Image = {
|
||||||
|
|
@ -240,6 +243,13 @@ export type RespMap = {
|
||||||
[Queries.CoopHistoryDetailQuery]: {
|
[Queries.CoopHistoryDetailQuery]: {
|
||||||
coopHistoryDetail: CoopHistoryDetail;
|
coopHistoryDetail: CoopHistoryDetail;
|
||||||
};
|
};
|
||||||
|
[Queries.myOutfitCommonDataFilteringConditionQuery]: {
|
||||||
|
gearPowers: {
|
||||||
|
nodes: {
|
||||||
|
name: string;
|
||||||
|
}[];
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
export type GraphQLResponse<T> = {
|
export type GraphQLResponse<T> = {
|
||||||
data: T;
|
data: T;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue