feat: 重构关卡接口

This commit is contained in:
richarjiang
2026-04-26 17:08:27 +08:00
parent e5d6c3a674
commit 25d196263b
13 changed files with 437 additions and 327 deletions

View File

@@ -0,0 +1,35 @@
import { Level } from '../wechat-game/entities/level.entity';
import { NextLevelDto } from './dto/next-level.dto';
import { pickLevelImageFields } from '../wechat-game/level-fields.helper';
/**
* Convert a Level entity to a NextLevelDto for client consumption.
*/
export function toNextLevelDto(level: Level): NextLevelDto {
return {
id: level.id,
level: level.sortOrder,
...pickLevelImageFields(level),
answer: level.answer,
timeLimit: level.timeLimit,
};
}
/**
* Given all levels (sorted by sortOrder ASC) and the set of completed level IDs,
* return the next `count` uncompleted levels.
*/
export function findNextUncompletedLevels(
allLevelsOrdered: Level[],
completedLevelIds: Set<string>,
count: number,
): Level[] {
const result: Level[] = [];
for (const level of allLevelsOrdered) {
if (!completedLevelIds.has(level.id)) {
result.push(level);
if (result.length >= count) break;
}
}
return result;
}