Commit c49b53b1 authored by nanahira's avatar nanahira

fixes

parent a0c92c8c
......@@ -4,9 +4,13 @@ import _ from "underscore";
import { CNOCGFetcher } from "./src/cnocg";
import { ExtraCards } from "./src/ExtraCards";
import { DirectFetcher } from "./src/direct";
import Logger from "bunyan";
async function main() {
const dbreader = new DBReader({ name: "Database" });
const dbreader = new DBReader({
name: "Database",
//level: Logger.DEBUG
});
await dbreader.init();
//const cards = await CNOCGFetcher.fetchOnce();
//const missingExtraCards = ExtraCards.filter(c => !cards.some(cc => c.code === cc.code));
......
......@@ -20,6 +20,7 @@ export class SQLQuery {
this.values = values;
}
async perform(db: Database) {
//console.log(db.config.filename, this.sql, this.values);
await db.run(this.sql, this.values);
}
}
......@@ -186,8 +187,8 @@ export class DBReader extends Base {
return cards;
}
async getOtherCardCodes(cnCodes: number[]) {
const sql = `SELECT id FROM datas WHERE 1 AND ${cnCodes.map(m => "id != ?").join(" AND ")}`;
const otherCodes: number[] = (await this.cndb.all(sql, cnCodes)).map(m => m.id);
const sql = `SELECT id FROM datas WHERE id not IN (${cnCodes.join(",")})`;
const otherCodes: number[] = (await this.cndb.all(sql)).map(m => m.id);
return otherCodes;
}
async generateBanlist(codes: number[]) {
......@@ -203,7 +204,7 @@ export class DBReader extends Base {
await fs.writeFile(`${this.config.outputPath}/expansions/lflist.conf`, banlistString);
}
async generatePatch(codes: number[]) {
const patchString = `update datas set ot = ot | 0x8 where ${codes.map(code => `id = ${code}`).join(' or ')};`;
const patchString = `update datas set ot = ot | 0x8 where id IN (${codes.join(',')});`;
await fs.writeFile(`${this.config.outputPath}/patch.sql`, patchString);
}
private async categorizeCards(cards: Card[]): Promise<CardPool> {
......@@ -233,12 +234,12 @@ export class DBReader extends Base {
}
await this.outputdb.run("COMMIT;");
const allCodes = allCards.map(card => card.code);
this.log.debug(`Database created.`);
this.log.info(`Database created.`);
await this.generateBanlist(allCodes);
this.log.debug(`LFList created.`);
this.log.info(`LFList created.`);
await this.generatePatch(allCodes);
this.log.debug(`Patch created.`);
this.log.info(`Patch created.`);
await this.generateDecks(cards);
this.log.debug(`Decks generated.`);
this.log.info(`Decks generated.`);
}
}
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