Commit dd1a09cb authored by nanahira's avatar nanahira

fix alias

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