Commit fe9fa2b0 authored by nanahira's avatar nanahira

support multiple languages

parent 6db538d8
Pipeline #41240 passed with stages
in 2 minutes and 16 seconds
...@@ -147,7 +147,7 @@ export class AppService extends ConsoleLogger { ...@@ -147,7 +147,7 @@ export class AppService extends ConsoleLogger {
); );
await this.drawTextService.drawTextInBox( await this.drawTextService.drawTextInBox(
doc, doc,
cardData.name, cardData[`${dto.lang || 'sc'}_name`] || '',
moveDown(cord.name, j), moveDown(cord.name, j),
i + 1, i + 1,
); );
......
...@@ -12,11 +12,14 @@ import * as fs from 'node:fs'; ...@@ -12,11 +12,14 @@ import * as fs from 'node:fs';
export class CardData { export class CardData {
@CacheKey() @CacheKey()
cacheKey() { cacheKey() {
return this.id.toString(); return '0:' + this.id.toString();
} }
id: number; id: number;
name: string; sc_name: string;
cn_name: string;
en_name: string;
jp_name: string;
type: number; // 0x1 for monster, 0x2 for spell, 0x4 for trap type: number; // 0x1 for monster, 0x2 for spell, 0x4 for trap
} }
...@@ -24,6 +27,8 @@ type YGOCDBData = { ...@@ -24,6 +27,8 @@ type YGOCDBData = {
id: number; id: number;
sc_name: string; sc_name: string;
cn_name: string; cn_name: string;
en_name: string;
jp_name: string;
data: { type: number }; data: { type: number };
}; };
...@@ -40,8 +45,17 @@ export class CardDataService { ...@@ -40,8 +45,17 @@ export class CardDataService {
// console.log(card); // console.log(card);
const data = new CardData(); const data = new CardData();
if (!card.id || !card.data?.type) return; if (!card.id || !card.data?.type) return;
data.id = card.id; for (const field of [
data.name = card.sc_name || card.cn_name || '未知卡片'; 'id',
'sc_name',
'cn_name',
'en_name',
'jp_name',
] as const) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
data[field] = card[field];
}
data.type = card.data.type & 0x7; data.type = card.data.type & 0x7;
return data; return data;
} }
...@@ -73,7 +87,7 @@ export class CardDataService { ...@@ -73,7 +87,7 @@ export class CardDataService {
).toException(); ).toException();
} }
this.logger.log( this.logger.log(
`Fetched card data for ID ${id}: ${data.type} ${data.name}`, `Fetched card data for ID ${id}: ${data.type} ${data.sc_name}`,
); );
return data; return data;
} }
...@@ -89,6 +103,7 @@ export class CardDataService { ...@@ -89,6 +103,7 @@ export class CardDataService {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return // eslint-disable-next-line @typescript-eslint/no-unsafe-return
return JSON.parse(content.toString('utf-8')); return JSON.parse(content.toString('utf-8'));
}; };
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const content = await loadJson('cards'); const content = await loadJson('cards');
const cards: YGOCDBData[] = Object.values(content); const cards: YGOCDBData[] = Object.values(content);
this.logger.log(`Loading ${cards.length} cards from YGOCDB data`); this.logger.log(`Loading ${cards.length} cards from YGOCDB data`);
......
...@@ -28,6 +28,7 @@ export class DrawTextService { ...@@ -28,6 +28,7 @@ export class DrawTextService {
options: DrawTextOptions, options: DrawTextOptions,
pageCount = 0, pageCount = 0,
) { ) {
if (!text) return;
const { x, y, width, height, fontSize } = options; const { x, y, width, height, fontSize } = options;
const page = doc.getPage(pageCount); const page = doc.getPage(pageCount);
......
import { IsDateString, IsOptional, IsString } from 'class-validator'; import { IsEnum, IsOptional, IsString } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger'; import { ApiProperty } from '@nestjs/swagger';
import moment from 'moment'; import moment from 'moment';
export enum Lang {
sc = 'sc',
cn = 'cn',
en = 'en',
jp = 'jp',
}
export class FillOptionsDto { export class FillOptionsDto {
@IsOptional()
@IsEnum(Lang)
@ApiProperty({
description: '语言选项',
enum: Lang,
example: Lang.sc,
default: Lang.sc,
})
lang?: Lang;
@IsString() @IsString()
@IsOptional() @IsOptional()
@ApiProperty({ @ApiProperty({
......
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