fix: 修复关卡排序
This commit is contained in:
@@ -131,6 +131,36 @@ export class LevelDataManager {
|
||||
return this._apiData[index].completed;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取第一个未通关的关卡索引
|
||||
* 遍历关卡列表,返回第一个 completed === false 的索引
|
||||
* 如果全部通关,返回最后一关的索引
|
||||
* @returns 第一个未通关关卡索引(0-based)
|
||||
*/
|
||||
getFirstUncompletedIndex(): number {
|
||||
for (let i = 0; i < this._apiData.length; i++) {
|
||||
if (!this._apiData[i].completed) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
// 全部通关,返回最后一关
|
||||
return Math.max(0, this._apiData.length - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定索引之后第一个未通关的关卡索引
|
||||
* @param afterIndex 从该索引之后开始查找(不含该索引)
|
||||
* @returns 下一个未通关关卡索引,如果后续全部通关则返回 -1
|
||||
*/
|
||||
getNextUncompletedIndex(afterIndex: number): number {
|
||||
for (let i = afterIndex + 1; i < this._apiData.length; i++) {
|
||||
if (!this._apiData[i].completed) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 标记指定关卡为已通关(本地缓存更新)
|
||||
* @param index 关卡索引
|
||||
|
||||
Reference in New Issue
Block a user