80 lines
2.1 KiB
TypeScript
80 lines
2.1 KiB
TypeScript
/**
|
|||
|
|
* 技师的排行榜数据
|
||
|
|
*/
|
||
|
|
import { BaseData } from "./BaseData";
|
||
|
|
import proto from 'db://assets/Scripts/proto/proto.pb.js';
|
||
|
|
import { logger } from "db://assets/Scripts/Main/Common/Logger";
|
||
|
|
|
||
|
|
export class GirlRankData extends BaseData {
|
||
|
|
// 技师的简要数据
|
||
|
|
rankMap: Map<number, number[]>;
|
||
|
|
|
||
|
|
constructor() {
|
||
|
|
super();
|
||
|
|
this.rankMap = new Map<number, number[]>();
|
||
|
|
}
|
||
|
|
|
||
|
|
public reset(): void {
|
||
|
|
this.rankMap.clear();
|
||
|
|
}
|
||
|
|
|
||
|
|
public clear(): void {
|
||
|
|
this.rankMap.clear();
|
||
|
|
}
|
||
|
|
|
||
|
|
public destroy(): void {
|
||
|
|
super.destroy();
|
||
|
|
this.rankMap = null;
|
||
|
|
}
|
||
|
|
|
||
|
|
/** 保存 排行榜数据 */
|
||
|
|
public setRankData(rankType: proto.cs.EnmRankType, data: proto.cs.IGirlData[]): void {
|
||
|
|
if (!data || data.length === 0) return;
|
||
|
|
|
||
|
|
// 如果该 rankType 已存在数据,先清空
|
||
|
|
if (this.rankMap.has(rankType)) {
|
||
|
|
this.rankMap.set(rankType, []);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 新建 Set 去重
|
||
|
|
const idSet = new Set<number>();
|
||
|
|
|
||
|
|
for (const item of data) {
|
||
|
|
if (item && item.id != null) {
|
||
|
|
idSet.add(item.id);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
this.rankMap.set(rankType, Array.from(idSet));
|
||
|
|
logger.log("保存排行榜数据:",this.rankMap);
|
||
|
|
}
|
||
|
|
|
||
|
|
/** 添加 排行榜数据 */
|
||
|
|
public addRankData(rankType: proto.cs.EnmRankType, data: proto.cs.IGirlData[]): void {
|
||
|
|
if (!data || data.length === 0) return;
|
||
|
|
|
||
|
|
// 获取旧的 ID 列表(可能为空)
|
||
|
|
const oldList = this.rankMap.get(rankType) || [];
|
||
|
|
const idSet = new Set(oldList);
|
||
|
|
|
||
|
|
// 依次追加(保持顺序 + 去重)
|
||
|
|
for (const item of data) {
|
||
|
|
if (item && item.id != null && !idSet.has(item.id)) {
|
||
|
|
idSet.add(item.id);
|
||
|
|
oldList.push(item.id);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
this.rankMap.set(rankType, oldList);
|
||
|
|
logger.log("添加排行榜数据:",this.rankMap);
|
||
|
|
}
|
||
|
|
|
||
|
|
/** 获取排行榜技师 id,根据排行榜类型 */
|
||
|
|
public getRankIdsByType(rankType: proto.cs.EnmRankType): number[] {
|
||
|
|
if (!this.rankMap) return [];
|
||
|
|
const ids = this.rankMap.get(rankType);
|
||
|
|
// 返回副本,防止外部修改内部数据
|
||
|
|
return ids ? [...ids] : [];
|
||
|
|
}
|
||
|
|
}
|