Commit 2ad0edeb authored by nanahira's avatar nanahira

migrate to ygopro-cdb-encode

parent 0c1c2ac0
Pipeline #42960 passed with stages
in 37 seconds
This diff is collapsed.
...@@ -18,6 +18,7 @@ import { ...@@ -18,6 +18,7 @@ import {
} from 'koishipro-core.js'; } from 'koishipro-core.js';
import { YGOPRO_CDB_URL, YGOPRO_SCRIPT_ZIP_URL } from './resource-urls'; import { YGOPRO_CDB_URL, YGOPRO_SCRIPT_ZIP_URL } from './resource-urls';
import { OcgcoreCommonConstants } from 'ygopro-msg-encode'; import { OcgcoreCommonConstants } from 'ygopro-msg-encode';
import { YGOProCdb } from 'ygopro-cdb-encode';
type PackageStatus = 'pending' | 'running' | 'done' | 'error'; type PackageStatus = 'pending' | 'running' | 'done' | 'error';
type CdbStatus = 'pending' | 'running' | 'done' | 'error'; type CdbStatus = 'pending' | 'running' | 'done' | 'error';
...@@ -69,12 +70,6 @@ type ProgressSnapshot = { ...@@ -69,12 +70,6 @@ type ProgressSnapshot = {
percent: number; percent: number;
}; };
type SqlCardRow = {
id: number;
name: string | null;
type: number | null;
};
type ZipCdbEntry = { type ZipCdbEntry = {
zipName: string; zipName: string;
displayName: string; displayName: string;
...@@ -608,7 +603,8 @@ export class App { ...@@ -608,7 +603,8 @@ export class App {
const sql = await this.getSqlModule(); const sql = await this.getSqlModule();
const cdbBytes = await zipEntry.async('uint8array'); const cdbBytes = await zipEntry.async('uint8array');
db = new sql.Database(cdbBytes); db = new sql.Database(cdbBytes);
const cards = this.queryTestCards(db); const cdb = new YGOProCdb(db);
const cards = this.queryTestCards(cdb);
if (cards.length === 0) { if (cards.length === 0) {
this.updateCdb(packageIndex, cdbIndex, (cdb) => ({ this.updateCdb(packageIndex, cdbIndex, (cdb) => ({
...@@ -832,34 +828,28 @@ export class App { ...@@ -832,34 +828,28 @@ export class App {
} }
} }
private queryTestCards(db: Database): Array<{ id: number; name: string; skipTest: boolean }> { private queryTestCards(cdb: YGOProCdb): Array<{ id: number; name: string; skipTest: boolean }> {
const normalMonsterType = const normalMonsterType =
(OcgcoreCommonConstants.TYPE_NORMAL | OcgcoreCommonConstants.TYPE_MONSTER) >>> 0; (OcgcoreCommonConstants.TYPE_NORMAL | OcgcoreCommonConstants.TYPE_MONSTER) >>> 0;
const tokenType = OcgcoreCommonConstants.TYPE_TOKEN >>> 0; const tokenType = OcgcoreCommonConstants.TYPE_TOKEN >>> 0;
const stmt = db.prepare(
'SELECT datas.id as id, texts.name as name, datas.type as type FROM datas INNER JOIN texts ON datas.id = texts.id',
);
try { const entries = cdb.find();
const result: Array<{ id: number; name: string; skipTest: boolean }> = []; const result: Array<{ id: number; name: string; skipTest: boolean }> = [];
while (stmt.step()) { for (const entry of entries) {
const row = stmt.getAsObject() as unknown as SqlCardRow; const id = entry.code;
if (!row || row.id == null) { if (!Number.isFinite(id)) {
continue; continue;
}
const typeValue = (row.type ?? 0) >>> 0;
const skipTest =
typeValue === normalMonsterType || (typeValue & tokenType) !== 0;
result.push({
id: row.id,
name: row.name ?? '未命名卡片',
skipTest,
});
} }
return result; const typeValue = (entry.type ?? 0) >>> 0;
} finally { const skipTest =
stmt.free(); typeValue === normalMonsterType || (typeValue & tokenType) !== 0;
} result.push({
id,
name: entry.name || '未命名卡片',
skipTest,
});
}
return result;
} }
private updatePackage( private updatePackage(
......
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