Commit dd1a09cb authored by nanahira's avatar nanahira

fix alias

parent 0f08da69
......@@ -28,6 +28,10 @@ export class Card {
code: number;
datas: any;
texts: any;
preDatas: any;
preTexts: any;
loadedDatas: any;
loadedTexts: any;
constructor(code: number) {
this.code = code;
this.datas = {};
......@@ -47,11 +51,21 @@ export class Card {
}
return ret;
}
private async createCardFromRelatedCode(code: number, db: Database) {
const card = new Card(code);
await card.loadData(db);
if (this.loadedTexts.name === card.loadedTexts.name) { // is alias
card.texts = _.clone(this.texts);
card.datas = _.clone(this.datas);
card.texts.id = code;
card.datas.id = code;
}
return card;
}
async getRelatedCards(db: Database) {
const code = this.code;
const moreCodes: number[] = (await db.all('SELECT id FROM datas WHERE id > ? AND id <= ?', [code, code + 10])).map(m => m.id);
const cards = moreCodes.map(code => new Card(code));
await Promise.all(cards.map(card => card.loadData(db)));
const cards = await Promise.all(moreCodes.map(code => this.createCardFromRelatedCode(code, db)));
return cards;
}
isInMainDeck() {
......@@ -69,17 +83,19 @@ export class Card {
return (cardType & (0x4000000 | 0x800000 | 0x2000 | 0x40)) > 0;
}
async loadData(db: Database) {
const datas = await db.get("select * from datas where id = ?", [this.code]);
const texts = await db.get("select * from texts where id = ?", [this.code]);
texts.desc += '\r\n\r\n\u2605简体中文卡';
this.preDatas = this.datas;
this.preTexts = this.texts;
this.loadedDatas = await db.get("select * from datas where id = ?", [this.code]);
this.loadedTexts = await db.get("select * from texts where id = ?", [this.code]);
this.datas = {
...this.datas,
...datas
...this.loadedDatas,
...this.preDatas
}
this.texts = {
...this.texts,
...texts
...this.loadedTexts,
...this.preTexts
}
this.texts.desc += '\r\n\r\n\u2605简体中文卡';
}
getSQLQueries() {
const datasArray = this.getDatasArray();
......@@ -153,7 +169,9 @@ export class DBReader extends Base {
}
const code: number = output.id;
this.log.debug(`${name} => ${code}`);
return new Card(code);
const card = new Card(code);
//card.texts.name = name;
return card;
}
async getAllCardsFromJapaneseNames(names: string[]) {
const cards: Card[] = [];
......
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