feat: 重构关卡接口
This commit is contained in:
35
src/modules/level/next-level.helper.ts
Normal file
35
src/modules/level/next-level.helper.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user