Commit e6e38cd6 authored by nanahira's avatar nanahira

update CN generation

parent 5072e052
Pipeline #37909 passed with stages
in 5 minutes and 10 seconds
...@@ -99,6 +99,14 @@ upload_to_minio: ...@@ -99,6 +99,14 @@ upload_to_minio:
deploy_server_env408: deploy_server_env408:
extends: .deploy_server extends: .deploy_server
deploy_server_cn:
extends: .deploy_server
dependencies:
- zh-CN
variables:
OUTPUT_ENV: cn-zh-CN
SERVER_IDENTIFIER: 'cn'
deploy_server_env706: deploy_server_env706:
extends: .deploy_server extends: .deploy_server
dependencies: dependencies:
......
...@@ -5,6 +5,8 @@ import { CNOCGFetcher } from "./src/cnocg"; ...@@ -5,6 +5,8 @@ import { CNOCGFetcher } from "./src/cnocg";
import { ExtraCards } from "./src/ExtraCards"; import { ExtraCards } from "./src/ExtraCards";
import { DirectFetcher } from "./src/direct"; import { DirectFetcher } from "./src/direct";
import Logger from "bunyan"; import Logger from "bunyan";
import { readLFList } from "./src/utility";
import fs from 'fs';
async function main() { async function main() {
const dbreader = new DBReader({ const dbreader = new DBReader({
...@@ -16,7 +18,10 @@ async function main() { ...@@ -16,7 +18,10 @@ async function main() {
//const missingExtraCards = ExtraCards.filter(c => !cards.some(cc => c.code === cc.code)); //const missingExtraCards = ExtraCards.filter(c => !cards.some(cc => c.code === cc.code));
//await dbreader.run(cards.concat(missingExtraCards)); //await dbreader.run(cards.concat(missingExtraCards));
const cards = await DirectFetcher.fetchOnce(); const cards = await DirectFetcher.fetchOnce();
await dbreader.run(cards); const lflist = await readLFList(await fs.promises.readFile("./lflist/lflist.conf", "utf-8"));
await dbreader.run(cards, {
extraBanlists: lflist,
});
process.exit(); process.exit();
} }
main(); main();
...@@ -198,17 +198,17 @@ export class DBReader extends Base { ...@@ -198,17 +198,17 @@ export class DBReader extends Base {
} }
async generateBanlist(codes: number[], extraBanlists: Banlist[] = []) { async generateBanlist(codes: number[], extraBanlists: Banlist[] = []) {
const otherCodes = await this.getOtherCardCodes(codes); const otherCodes = await this.getOtherCardCodes(codes);
const banlistString = await generateBanlistFromCode([ const generatedBanlist: Banlist = {
mergeBanlists([
...extraBanlists,
{
name: moment().format('YYYY.MM') + ' ' + this.config.descSymbol, name: moment().format('YYYY.MM') + ' ' + this.config.descSymbol,
list: [ list: [
otherCodes otherCodes
] ]
} };
]), const banlistString = await generateBanlistFromCode(
]); extraBanlists?.length
? extraBanlists.map(l => mergeBanlists([generatedBanlist, l], extraBanlists.length === 1 ? generatedBanlist.name : l.name))
: [generatedBanlist]
);
await fs.writeFile(`${this.config.outputPath}/expansions/lflist.conf`, banlistString); await fs.writeFile(`${this.config.outputPath}/expansions/lflist.conf`, banlistString);
} }
async generatePatch(codes: number[]) { async generatePatch(codes: number[]) {
...@@ -259,8 +259,10 @@ export class DBReader extends Base { ...@@ -259,8 +259,10 @@ export class DBReader extends Base {
this.log.info(`Database created.`); this.log.info(`Database created.`);
await this.generateBanlist(allCodes, options.extraBanlists || []); await this.generateBanlist(allCodes, options.extraBanlists || []);
this.log.info(`LFList created.`); this.log.info(`LFList created.`);
if (this.config.fileSymbol === 'cn') {
await this.generatePatch(allCodes); await this.generatePatch(allCodes);
this.log.info(`Patch created.`); this.log.info(`Patch created.`);
}
await this.generateDecks(cards); await this.generateDecks(cards);
this.log.info(`Decks generated.`); this.log.info(`Decks generated.`);
} }
......
import Base from "./base"; import Base from "./base";
import { promises as fs } from "fs"; import { promises as fs } from "fs";
import { Card } from "./dbreader"; import { Card, DBReader } from "./dbreader";
import { CNOCGFetcher } from "./cnocg"; import { CNOCGFetcher } from "./cnocg";
export class DirectFetcher extends Base { export class DirectFetcher extends Base {
static async fetchOnce() { static async fetchOnce() {
const fetcher = new DirectFetcher({ name: "Temp Direct Fetcher", level: 'info' }); const fetcher = new DirectFetcher({ name: "Temp Direct Fetcher", level: 'debug' });
await fetcher.init(); await fetcher.init();
return await fetcher.fetch(); return await fetcher.fetch();
} }
...@@ -53,6 +53,17 @@ export class DirectFetcher extends Base { ...@@ -53,6 +53,17 @@ export class DirectFetcher extends Base {
this.addCode(code); this.addCode(code);
} }
} }
private async workWithExisting() {
const cnDb = await new DBReader({ name: 'Existing Reader', level: 'info' }).openDatabase(this.config.cnDatabasePath);
this.log.info(`Reading existing YGOPro database.`);
const cnDbData = await cnDb.all<{ id: number }[]>("SELECT id FROM datas where (ot & 0x8) > 0 and (type & 0x4000) = 0");
this.log.info(`${cnDbData.length} existing cards found.`);
for (const row of cnDbData) {
this.addCode(row.id);
}
}
async fetch(): Promise<Card[]> { async fetch(): Promise<Card[]> {
//this.log.info(`Started fetching from CNOCG.`); //this.log.info(`Started fetching from CNOCG.`);
this.cardCodes = []; this.cardCodes = [];
...@@ -62,6 +73,7 @@ export class DirectFetcher extends Base { ...@@ -62,6 +73,7 @@ export class DirectFetcher extends Base {
for (let file of ydkFiles) { for (let file of ydkFiles) {
await this.workWithYdk(file); await this.workWithYdk(file);
} }
await this.workWithExisting();
const finalCodes = this.cardCodes; const finalCodes = this.cardCodes;
this.log.info(`${finalCodes.length} cards in total.`); this.log.info(`${finalCodes.length} cards in total.`);
return finalCodes.map(code => new Card(code)); return finalCodes.map(code => new Card(code));
......
...@@ -47,8 +47,8 @@ export async function readLFList(content: string): Promise<Banlist[]> { ...@@ -47,8 +47,8 @@ export async function readLFList(content: string): Promise<Banlist[]> {
return ret; return ret;
} }
export function mergeBanlists(lists: Banlist[]): Banlist { export function mergeBanlists(lists: Banlist[], name?: string): Banlist {
const ret: Banlist = { name: lists[0].name, list: [] }; const ret: Banlist = { name: name || lists[0].name, list: [] };
const existingCodes = new Set<number>(); const existingCodes = new Set<number>();
for (let status = 0; status < 3; ++status) { for (let status = 0; status < 3; ++status) {
for (let list of lists) { for (let list of lists) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment