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) {
(num >>> 16) & 0xffff,
// (num >>> 32) & 0xffff,
// (num >>> 48) & 0xffff,
].filter(x => x !== 0);
].filter((x) => x !== 0);
// console.error(possibleSetValues)
return possibleSetValues.flatMap((set) => {
......@@ -54,19 +54,21 @@ function getSets(num: number) {
// console.error(possibleExtraCodes);
return [
baseSet,
...possibleExtraCodes.map((extraCode) => {
...possibleExtraCodes
.map((extraCode) => {
const extraSet = setcodeStrings.get(extraCode);
if (!extraSet) return;
return extraSet;
}).filter((s) => s)
]
})
.filter((s) => s),
];
});
}
async function loadString(path: string) {
const stringsFile = await fs.promises.readFile(path, 'utf8');
const stringsLines = stringsFile.split('\n');
for(const line of stringsLines) {
for (const line of stringsLines) {
const [type, idStr, string] = line.split(' ');
if (!type.startsWith('!')) continue;
const map = stringsMap[type.slice(1)];
......@@ -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);
statement.bind(params);
const results: T[] = [];
......@@ -115,6 +121,7 @@ interface YGOProCard extends YGOProCardLike {
linkMarkers: string[];
sets: string[];
overallString: string;
picUrl: string;
}
const ygoproConstants = {
......@@ -203,10 +210,13 @@ function formatCard(data: YGOProCardLike): YGOProCard {
cardRScale: (data.level >>> 4) & 0xff,
displayAtk: toDisplayAdValue(data.atk),
displayRace: getStringValueByMysticalNumber(raceOffset, data.race),
displayAttribute: getStringValueByMysticalNumber(attrOffset, data.attribute),
displayAttribute: getStringValueByMysticalNumber(
attrOffset,
data.attribute,
),
displayType: getStringValueByMysticalNumber(typeOffset, data.type),
sets: getSets(data.setcode),
}
};
if (!isType(data.type, 'TYPE_LINK')) {
result.displayDef = toDisplayAdValue(data.def);
} else {
......@@ -229,23 +239,29 @@ function formatCard(data: YGOProCardLike): YGOProCard {
result.linkMarkers.push('[↓]');
if (result.def & ygoproConstants.LINK_MARKERS.LINK_MARKER_BOTTOM_RIGHT)
result.linkMarkers.push('[↘]');
result.displayDef = '-'
result.displayDef = '-';
}
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;
}
async function main() {
await Promise.all(
process.argv.slice(3).map((path) => loadString(path))
)
await Promise.all(process.argv.slice(3).map((path) => loadString(path)));
const SQL = await initSqlJs();
const dbBuffer = await fs.promises.readFile(process.argv[2]);
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);
console.log(JSON.stringify(formattedCards, null, 2));
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