新增协议:推荐列表
This commit is contained in:
@@ -38,6 +38,7 @@ export enum DataId {
|
||||
GirlChat = "girlChat", // 技师的聊天数据
|
||||
GirlFavorability = "girlFavorability", // 技师的好感度数据
|
||||
GirlRank = "girlRank", // 技师的排行榜数据
|
||||
GirlRecommend = "girlRecommend", // 技师的推荐数据
|
||||
GirlOther = "girlOther", // 技师的其他数据
|
||||
Env = "env", // 环境数据
|
||||
Global = "global", // 全局数据
|
||||
|
||||
@@ -8,6 +8,7 @@ import { GirlUnlockData } from "./GirlUnlockData";
|
||||
import { GirlChatData } from "./GirlChatData";
|
||||
import { GirlFavorabilityData } from "./GirlFavorabilityData";
|
||||
import { GirlRankData } from "./GirlRankData";
|
||||
import { GirlRecommendData } from "./GirlRecommendData";
|
||||
import { GirlOtherData } from "./GirlOtherData";
|
||||
import { DataId } from "./DataManager";
|
||||
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
||||
@@ -40,27 +41,34 @@ export class GirlData extends BaseData {
|
||||
private _categories = new Map<string, CategoryBucket>();
|
||||
// 排行榜数据
|
||||
private _rankData: GirlRankData;
|
||||
// 推荐数据
|
||||
private _recommendData: GirlRecommendData;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this._rankData = new GirlRankData();
|
||||
this._rankData.init?.(DataId.GirlRank);
|
||||
this._recommendData = new GirlRecommendData();
|
||||
this._recommendData.init?.(DataId.GirlRecommend);
|
||||
}
|
||||
|
||||
public reset(): void {
|
||||
this._categories.clear();
|
||||
this._rankData.clear();
|
||||
this._recommendData.clear();
|
||||
}
|
||||
|
||||
public clear(): void {
|
||||
this._categories.clear();
|
||||
this._rankData.clear();
|
||||
this._recommendData.clear();
|
||||
}
|
||||
|
||||
public destroy(): void {
|
||||
super.destroy();
|
||||
this._categories = null;
|
||||
this._rankData = null;
|
||||
this._recommendData = null;
|
||||
}
|
||||
|
||||
/** 保障 _categories 存在 */
|
||||
@@ -90,6 +98,39 @@ export class GirlData extends BaseData {
|
||||
return bucket;
|
||||
}
|
||||
|
||||
/** 清空分类桶,单个 */
|
||||
private clearOneBucket(categoryId: string): void {
|
||||
const cats = this.ensureCategories();
|
||||
const bucket = cats.get(categoryId);
|
||||
if (bucket) {
|
||||
// 清空具体分类的所有数据
|
||||
bucket.briefs.clear();
|
||||
bucket.details.clear();
|
||||
bucket.unlocks.clear();
|
||||
bucket.chats.clear();
|
||||
bucket.favorability.clear();
|
||||
bucket.other.clear();
|
||||
bucket.girlIds.splice(0); // 使用 splice 清空 girlIds 数组
|
||||
logger.log(`清空分类桶 ${categoryId}`);
|
||||
}
|
||||
}
|
||||
|
||||
/** 清空分类桶,所有 */
|
||||
private clearAllBucket(): void {
|
||||
const cats = this.ensureCategories();
|
||||
// 遍历所有分类桶并清空
|
||||
cats.forEach((bucket, categoryId) => {
|
||||
bucket.briefs.clear();
|
||||
bucket.details.clear();
|
||||
bucket.unlocks.clear();
|
||||
bucket.chats.clear();
|
||||
bucket.favorability.clear();
|
||||
bucket.other.clear();
|
||||
bucket.girlIds.splice(0); // 使用 splice 清空 girlIds 数组
|
||||
});
|
||||
logger.log("清空所有分类桶");
|
||||
}
|
||||
|
||||
/** 取分类下的全部 girlIds(若分类不存在返回空数组) */
|
||||
public getGirlIds(categoryId: string): number[] {
|
||||
const b = this.ensureCategories().get(categoryId);
|
||||
@@ -206,6 +247,61 @@ export class GirlData extends BaseData {
|
||||
return oneData.getGrilAvatar();
|
||||
}
|
||||
|
||||
/** --------------------------------------------------------- 技师的推荐数据 --------------------------------------------------------- */
|
||||
|
||||
/** 清空 推荐数据 */
|
||||
public clearRecommendData(): void {
|
||||
if (!this._recommendData) return;
|
||||
this._recommendData.clear();
|
||||
}
|
||||
|
||||
/** 保存 推荐列表 */
|
||||
public setRecommendList(data: proto.cs.ICSRecommendRes): void {
|
||||
if (!data) return;
|
||||
let arrayData = data.girls;
|
||||
// 遍历
|
||||
for (const oneData of arrayData) {
|
||||
let briefData = oneData.girl;
|
||||
let categoryId = briefData.category;
|
||||
this.mergeOneBrief(categoryId.toString(), briefData);
|
||||
let theArray = [];
|
||||
theArray.push(oneData);
|
||||
this.setGirlUnlock(categoryId.toString(), theArray);
|
||||
this.setGirlFavorability(categoryId.toString(), theArray);
|
||||
this.setGirlOther(categoryId.toString(), theArray);
|
||||
}
|
||||
this._recommendData.setRecommendList(arrayData);
|
||||
const cats = this.ensureCategories();
|
||||
logger.log("保存推荐列表后,大分类的数据: ", cats);
|
||||
}
|
||||
|
||||
/** 添加 推荐列表 */
|
||||
public addRecommendList(data: proto.cs.ICSRecommendRes): void {
|
||||
if (!data) return;
|
||||
let arrayData = data.girls;
|
||||
// 遍历
|
||||
for (const oneData of arrayData) {
|
||||
let briefData = oneData.girl;
|
||||
let categoryId = briefData.category;
|
||||
this.mergeOneBrief(categoryId.toString(), briefData);
|
||||
let theArray = [];
|
||||
theArray.push(oneData);
|
||||
this.setGirlUnlock(categoryId.toString(), theArray);
|
||||
this.setGirlFavorability(categoryId.toString(), theArray);
|
||||
this.setGirlOther(categoryId.toString(), theArray);
|
||||
}
|
||||
this._recommendData.addRecommendList(arrayData);
|
||||
const cats = this.ensureCategories();
|
||||
logger.log("添加推荐列表后,大分类的数据: ", cats);
|
||||
}
|
||||
|
||||
/** 获取 推荐列表 id */
|
||||
public getRecommendListIds(): number[] {
|
||||
if (!this._recommendData) return [];
|
||||
const ids = this._recommendData.getRecommendListIds();
|
||||
return ids;
|
||||
}
|
||||
|
||||
/** --------------------------------------------------------- 技师的排行榜数据 --------------------------------------------------------- */
|
||||
|
||||
/** 清空 排行榜数据 */
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* 技师的推荐数据
|
||||
*/
|
||||
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 GirlRecommendData extends BaseData {
|
||||
// 推荐列表,id
|
||||
private idList: number[];
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.idList = [];
|
||||
}
|
||||
|
||||
public reset(): void {
|
||||
this.idList = [];
|
||||
}
|
||||
|
||||
public clear(): void {
|
||||
this.idList = [];
|
||||
}
|
||||
|
||||
public destroy(): void {
|
||||
super.destroy();
|
||||
this.idList = null;
|
||||
}
|
||||
|
||||
/** 保存 推荐列表 */
|
||||
public setRecommendList(data: proto.cs.IGirlData[]): void {
|
||||
if (!data || data.length === 0) return;
|
||||
|
||||
// 清空现有 idList
|
||||
this.idList = [];
|
||||
|
||||
// 使用 Set 去重并提取 id
|
||||
const idSet = new Set<number>();
|
||||
|
||||
for (const item of data) {
|
||||
if (item && item.id != null) {
|
||||
idSet.add(item.id); // 添加到 Set 中去重
|
||||
}
|
||||
}
|
||||
|
||||
// 将去重后的 id 转换为数组并赋值给 idList
|
||||
this.idList = Array.from(idSet);
|
||||
logger.log("保存推荐列表:", this.idList);
|
||||
}
|
||||
|
||||
/** 添加 推荐列表 */
|
||||
public addRecommendList(data: proto.cs.IGirlData[]): void {
|
||||
if (!data || data.length === 0) return;
|
||||
|
||||
// 使用 Set 来去重
|
||||
const idSet = new Set(this.idList); // 创建一个基于当前 idList 的 Set
|
||||
|
||||
// 依次添加新的 id(保持顺序 + 去重)
|
||||
for (const item of data) {
|
||||
if (item && item.id != null && !idSet.has(item.id)) {
|
||||
idSet.add(item.id); // 添加到 Set 中去重
|
||||
this.idList.push(item.id); // 添加到 idList 中
|
||||
}
|
||||
}
|
||||
logger.log("添加推荐列表:", this.idList);
|
||||
}
|
||||
|
||||
/** 获取 推荐列表 id */
|
||||
public getRecommendListIds(): number[] {
|
||||
return this.idList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "38b5e732-c4b2-45e1-825f-1dc189c4f630",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user