feat: add gacha banner id (#45)
This commit is contained in:
parent
7577f0e273
commit
76a1273128
@ -1,6 +1,7 @@
|
||||
import fs from 'fs';
|
||||
import { resolve } from 'path';
|
||||
import {resolve} from 'path';
|
||||
import Logger from './Logger';
|
||||
|
||||
const c = new Logger("Banner");
|
||||
|
||||
type Banner = {
|
||||
@ -18,15 +19,21 @@ function r(...args: string[]) {
|
||||
export default class Banners {
|
||||
public static config: Banner[];
|
||||
|
||||
public static init(){
|
||||
public static init() {
|
||||
Banners.readConfig();
|
||||
}
|
||||
|
||||
private static readConfig(){
|
||||
private static readConfig() {
|
||||
let config: Banner[];
|
||||
const defaultConfig: Banner[] = [
|
||||
{
|
||||
gachaId: 1001,
|
||||
|
||||
const defaultConfig: Banner[] = [];
|
||||
|
||||
// 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: "",
|
||||
rateUpItems4: [
|
||||
1001, 1103
|
||||
@ -35,13 +42,13 @@ export default class Banners {
|
||||
1102
|
||||
],
|
||||
costItemId: 101 // Star Rail Pass
|
||||
} as Banner
|
||||
];
|
||||
} as Banner)
|
||||
}
|
||||
|
||||
try {
|
||||
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));
|
||||
if (missing.length > 0) {
|
||||
c.log(`Missing ${missing.join(', ')}, using default values.`);
|
||||
@ -54,7 +61,7 @@ export default class Banners {
|
||||
Banners.updateConfig(defaultConfig);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static updateConfig(config: Banner[]) {
|
||||
this.config = config;
|
||||
fs.writeFileSync(r('../../banners.json'), JSON.stringify(config, null, 2));
|
||||
|
Loading…
Reference in New Issue
Block a user