feat: add gacha banner id (#45)

This commit is contained in:
Dang Hoang Phuc 2022-08-05 03:27:30 +07:00 committed by GitHub
parent 7577f0e273
commit 76a1273128
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,7 @@
import fs from 'fs'; import fs from 'fs';
import { resolve } from 'path'; import {resolve} from 'path';
import Logger from './Logger'; import Logger from './Logger';
const c = new Logger("Banner"); const c = new Logger("Banner");
type Banner = { type Banner = {
@ -18,15 +19,21 @@ function r(...args: string[]) {
export default class Banners { export default class Banners {
public static config: Banner[]; public static config: Banner[];
public static init(){ public static init() {
Banners.readConfig(); Banners.readConfig();
} }
private static readConfig(){ private static readConfig() {
let config: Banner[]; let config: Banner[];
const defaultConfig: Banner[] = [
{ const defaultConfig: Banner[] = [];
gachaId: 1001,
// TODO: figure where is GachaBasicInfoConfigExcelTable. Temporary hardcode
const bannersID = [1001, 2001, 2002, 3001, 3002, 4001]
for (let i = 0; i < bannersID.length; i++) {
defaultConfig.push({
gachaId: bannersID[i],
detailWebview: "", detailWebview: "",
rateUpItems4: [ rateUpItems4: [
1001, 1103 1001, 1103
@ -35,13 +42,13 @@ export default class Banners {
1102 1102
], ],
costItemId: 101 // Star Rail Pass costItemId: 101 // Star Rail Pass
} as Banner } as Banner)
]; }
try { try {
config = JSON.parse(fs.readFileSync(r('../../banners.json')).toString()); config = JSON.parse(fs.readFileSync(r('../../banners.json')).toString());
for(const [index, gachaBanner] of Object.entries(config)){ for (const [index, gachaBanner] of Object.entries(config)) {
const missing = Object.keys(defaultConfig[0]).filter(key => !gachaBanner.hasOwnProperty(key)); const missing = Object.keys(defaultConfig[0]).filter(key => !gachaBanner.hasOwnProperty(key));
if (missing.length > 0) { if (missing.length > 0) {
c.log(`Missing ${missing.join(', ')}, using default values.`); c.log(`Missing ${missing.join(', ')}, using default values.`);
@ -54,7 +61,7 @@ export default class Banners {
Banners.updateConfig(defaultConfig); Banners.updateConfig(defaultConfig);
} }
} }
private static updateConfig(config: Banner[]) { private static updateConfig(config: Banner[]) {
this.config = config; this.config = config;
fs.writeFileSync(r('../../banners.json'), JSON.stringify(config, null, 2)); fs.writeFileSync(r('../../banners.json'), JSON.stringify(config, null, 2));