You need to sign in or sign up before continuing.
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 {
} from 'koishipro-core.js';
import { YGOPRO_CDB_URL, YGOPRO_SCRIPT_ZIP_URL } from './resource-urls';
import { OcgcoreCommonConstants } from 'ygopro-msg-encode';
import { YGOProCdb } from 'ygopro-cdb-encode';
type PackageStatus = 'pending' | 'running' | 'done' | 'error';
type CdbStatus = 'pending' | 'running' | 'done' | 'error';
......@@ -69,12 +70,6 @@ type ProgressSnapshot = {
percent: number;
};
type SqlCardRow = {
id: number;
name: string | null;
type: number | null;
};
type ZipCdbEntry = {
zipName: string;
displayName: string;
......@@ -608,7 +603,8 @@ export class App {
const sql = await this.getSqlModule();
const cdbBytes = await zipEntry.async('uint8array');
db = new sql.Database(cdbBytes);
const cards = this.queryTestCards(db);
const cdb = new YGOProCdb(db);
const cards = this.queryTestCards(cdb);
if (cards.length === 0) {
this.updateCdb(packageIndex, cdbIndex, (cdb) => ({
......@@ -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 =
(OcgcoreCommonConstants.TYPE_NORMAL | OcgcoreCommonConstants.TYPE_MONSTER) >>> 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 result: Array<{ id: number; name: string; skipTest: boolean }> = [];
while (stmt.step()) {
const row = stmt.getAsObject() as unknown as SqlCardRow;
if (!row || row.id == null) {
continue;
}
const typeValue = (row.type ?? 0) >>> 0;
const skipTest =
typeValue === normalMonsterType || (typeValue & tokenType) !== 0;
result.push({
id: row.id,
name: row.name ?? '未命名卡片',
skipTest,
});
const entries = cdb.find();
const result: Array<{ id: number; name: string; skipTest: boolean }> = [];
for (const entry of entries) {
const id = entry.code;
if (!Number.isFinite(id)) {
continue;
}
return result;
} finally {
stmt.free();
}
const typeValue = (entry.type ?? 0) >>> 0;
const skipTest =
typeValue === normalMonsterType || (typeValue & tokenType) !== 0;
result.push({
id,
name: entry.name || '未命名卡片',
skipTest,
});
}
return result;
}
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