Commit 885327ee authored by nanahira's avatar nanahira

add picUrl

parent e7976819
Pipeline #24038 passed with stages
in 52 seconds
...@@ -33,7 +33,7 @@ function getSets(num: number) { ...@@ -33,7 +33,7 @@ function getSets(num: number) {
(num >>> 16) & 0xffff, (num >>> 16) & 0xffff,
// (num >>> 32) & 0xffff, // (num >>> 32) & 0xffff,
// (num >>> 48) & 0xffff, // (num >>> 48) & 0xffff,
].filter(x => x !== 0); ].filter((x) => x !== 0);
// console.error(possibleSetValues) // console.error(possibleSetValues)
return possibleSetValues.flatMap((set) => { return possibleSetValues.flatMap((set) => {
...@@ -54,19 +54,21 @@ function getSets(num: number) { ...@@ -54,19 +54,21 @@ function getSets(num: number) {
// console.error(possibleExtraCodes); // console.error(possibleExtraCodes);
return [ return [
baseSet, baseSet,
...possibleExtraCodes.map((extraCode) => { ...possibleExtraCodes
.map((extraCode) => {
const extraSet = setcodeStrings.get(extraCode); const extraSet = setcodeStrings.get(extraCode);
if (!extraSet) return; if (!extraSet) return;
return extraSet; return extraSet;
}).filter((s) => s)
]
}) })
.filter((s) => s),
];
});
} }
async function loadString(path: string) { async function loadString(path: string) {
const stringsFile = await fs.promises.readFile(path, 'utf8'); const stringsFile = await fs.promises.readFile(path, 'utf8');
const stringsLines = stringsFile.split('\n'); const stringsLines = stringsFile.split('\n');
for(const line of stringsLines) { for (const line of stringsLines) {
const [type, idStr, string] = line.split(' '); const [type, idStr, string] = line.split(' ');
if (!type.startsWith('!')) continue; if (!type.startsWith('!')) continue;
const map = stringsMap[type.slice(1)]; const map = stringsMap[type.slice(1)];
...@@ -76,7 +78,11 @@ async function loadString(path: string) { ...@@ -76,7 +78,11 @@ async function loadString(path: string) {
} }
} }
async function querySQL<T = any>(db: SQL.Database, sql: string, params: any = {}) { async function querySQL<T = any>(
db: SQL.Database,
sql: string,
params: any = {},
) {
const statement = db.prepare(sql); const statement = db.prepare(sql);
statement.bind(params); statement.bind(params);
const results: T[] = []; const results: T[] = [];
...@@ -115,6 +121,7 @@ interface YGOProCard extends YGOProCardLike { ...@@ -115,6 +121,7 @@ interface YGOProCard extends YGOProCardLike {
linkMarkers: string[]; linkMarkers: string[];
sets: string[]; sets: string[];
overallString: string; overallString: string;
picUrl: string;
} }
const ygoproConstants = { const ygoproConstants = {
...@@ -203,10 +210,13 @@ function formatCard(data: YGOProCardLike): YGOProCard { ...@@ -203,10 +210,13 @@ function formatCard(data: YGOProCardLike): YGOProCard {
cardRScale: (data.level >>> 4) & 0xff, cardRScale: (data.level >>> 4) & 0xff,
displayAtk: toDisplayAdValue(data.atk), displayAtk: toDisplayAdValue(data.atk),
displayRace: getStringValueByMysticalNumber(raceOffset, data.race), displayRace: getStringValueByMysticalNumber(raceOffset, data.race),
displayAttribute: getStringValueByMysticalNumber(attrOffset, data.attribute), displayAttribute: getStringValueByMysticalNumber(
attrOffset,
data.attribute,
),
displayType: getStringValueByMysticalNumber(typeOffset, data.type), displayType: getStringValueByMysticalNumber(typeOffset, data.type),
sets: getSets(data.setcode), sets: getSets(data.setcode),
} };
if (!isType(data.type, 'TYPE_LINK')) { if (!isType(data.type, 'TYPE_LINK')) {
result.displayDef = toDisplayAdValue(data.def); result.displayDef = toDisplayAdValue(data.def);
} else { } else {
...@@ -229,23 +239,29 @@ function formatCard(data: YGOProCardLike): YGOProCard { ...@@ -229,23 +239,29 @@ function formatCard(data: YGOProCardLike): YGOProCard {
result.linkMarkers.push('[↓]'); result.linkMarkers.push('[↓]');
if (result.def & ygoproConstants.LINK_MARKERS.LINK_MARKER_BOTTOM_RIGHT) if (result.def & ygoproConstants.LINK_MARKERS.LINK_MARKER_BOTTOM_RIGHT)
result.linkMarkers.push('[↘]'); result.linkMarkers.push('[↘]');
result.displayDef = '-' result.displayDef = '-';
} }
result.overallString = getMetaText(result); result.overallString = getMetaText(result);
result.picUrl =
(process.env.YGOPRO_PIC_URL_PREFIX ||
'https://cdn02.moecube.com:444/images/ygopro-images-zh-CN/') +
data.id.toString() +
(process.env.YGOPRO_PIC_URL_SUFFIX || '.jpg');
return result as YGOProCard; return result as YGOProCard;
} }
async function main() { async function main() {
await Promise.all( await Promise.all(process.argv.slice(3).map((path) => loadString(path)));
process.argv.slice(3).map((path) => loadString(path))
)
const SQL = await initSqlJs(); const SQL = await initSqlJs();
const dbBuffer = await fs.promises.readFile(process.argv[2]); const dbBuffer = await fs.promises.readFile(process.argv[2]);
const db = new SQL.Database(dbBuffer); const db = new SQL.Database(dbBuffer);
const cards = await querySQL<YGOProCardLike>(db, 'select datas.*,texts.name,texts.desc from datas,texts where datas.id = texts.id and datas.type & 0x4000 = 0 and (datas.alias = 0 or datas.id - datas.alias > 10 or datas.id - datas.alias < -10)'); const cards = await querySQL<YGOProCardLike>(
db,
'select datas.*,texts.name,texts.desc from datas,texts where datas.id = texts.id and datas.type & 0x4000 = 0 and (datas.alias = 0 or datas.id - datas.alias > 10 or datas.id - datas.alias < -10)',
);
const formattedCards = cards.map(formatCard); const formattedCards = cards.map(formatCard);
console.log(JSON.stringify(formattedCards, null, 2)); console.log(JSON.stringify(formattedCards, null, 2));
process.exit(0); process.exit(0);
} }
main() main();
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