diff --git a/assets/Scripts/Sub/UI/PreloadUI.ts b/assets/Scripts/Sub/UI/PreloadUI.ts index 8c57d816..4dc55434 100644 --- a/assets/Scripts/Sub/UI/PreloadUI.ts +++ b/assets/Scripts/Sub/UI/PreloadUI.ts @@ -28,6 +28,7 @@ import LanguageUtils, { LanguageType } from "../../Main/Common/LanguageUtils"; import { DataManager, DataId } from "../../chat18x/data/DataManager"; import { LoginData } from "../../chat18x/data/LoginData"; import { PlayerData } from "../../chat18x/data/PlayerData"; +import { WalletData } from "../../chat18x/data/WalletData"; import { AccountData } from "../../chat18x/data/AccountData"; import { MetaData } from "../../chat18x/data/MetaData"; import { NetTimeData } from "../../chat18x/data/NetTimeData"; @@ -304,11 +305,15 @@ export class PreloadUI extends Component { const reqData = { }; - console.log("玩家数据请求数据:", reqData); + console.log("个人信息请求数据:", reqData); let res = await PlayerDataService.I.reqMyInfo(reqData); - console.log("玩家数据响应数据:", res); + console.log("个人信息响应数据:", res); if (res && res.code === proto.cs.EnmRetCode.SUCCESS) { - + const resData = res.data; + // 保存数据 + const walletData = DataManager.I.getDataById(DataId.Wallet); + walletData.diamond = resData.diamond; + walletData.vipExpire = resData.vipExpire; } } diff --git a/assets/Scripts/chat18x/data/DataManager.ts b/assets/Scripts/chat18x/data/DataManager.ts index 07949d1b..584c6e49 100644 --- a/assets/Scripts/chat18x/data/DataManager.ts +++ b/assets/Scripts/chat18x/data/DataManager.ts @@ -10,6 +10,7 @@ import { MetaData } from "./MetaData"; import { NetTimeData } from "./NetTimeData"; import { ThemeData } from "./ThemeData"; import { WalletData } from "./WalletData"; +import { ShopData } from "./ShopData"; /** * 集中定义数据ID,避免写错字符串 @@ -22,6 +23,7 @@ export enum DataId { NetTime = "netTime", Theme = "theme", Wallet = "wallet", + Shop = "shop", } /** 构造器类型 */ @@ -54,6 +56,7 @@ export class DataManager { this.register(DataId.NetTime, NetTimeData); this.register(DataId.Theme, ThemeData); this.register(DataId.Wallet, WalletData); + this.register(DataId.Shop, ShopData); } /** diff --git a/assets/Scripts/chat18x/data/GirlData.ts b/assets/Scripts/chat18x/data/GirlData.ts new file mode 100644 index 00000000..93a070a5 --- /dev/null +++ b/assets/Scripts/chat18x/data/GirlData.ts @@ -0,0 +1,148 @@ +/** + * 技师数据 + */ +import { BaseData } from "./BaseData"; +import proto from 'db://assets/Scripts/proto/proto.pb.js'; + +export interface GirlBriefVO { + id: number; + name: string; + age: number; + tagKey: string; + priceType: number; + price: number; // 用 number 存(i64 转) + avatar: string; + star: number; +} + +export interface GirlPhotoVO { + pic: string; + isRelease: boolean; + price: number; +} + +export interface GirlDetailVO { + id: number; // = brief.id + desc: string; + isRelease: boolean; + chatCount: number; + photos: GirlPhotoVO[]; +} + +export class GirlData extends BaseData { + // 实体归一化 + private _briefs = new Map(); + private _details = new Map(); + + // 列表索引 + private _dailyRecommend: number[] = []; + private _categoryPages = new Map>(); // category -> (page -> [girlId]) + + get briefById() { return this._briefs; } + get detailById() { return this._details; } + get dailyRecommendIds() { return this._dailyRecommend; } + + + public reset(): void { + this._briefs.clear(); + this._details.clear(); + this._dailyRecommend = []; + this._categoryPages.clear(); + } + + public clear(): void { + this._briefs.clear(); + this._details.clear(); + this._dailyRecommend = []; + this._categoryPages.clear(); + } + + public destroy(): void { + super.destroy(); + this._briefs = null; + this._details = null; + this._dailyRecommend = null; + this._categoryPages = null; + } + + /** 合并 Brief 列表到缓存(去重+覆盖最新字段) */ + mergeBriefs(list: pb.cs.IGirlBrief[] | pb.cs.GirlBrief[]): void { + for (const g of list) { + const id = g.id!; + this._briefs.set(id, { + id, + name: g.name || "", + age: g.age || 0, + tagKey: g.tagKey || "", + priceType: g.priceType || 0, + price: i64(g.price), + avatar: g.avatar || "", + star: g.star || 0, + }); + } + } + + /** 每日推荐:只维护 id 索引,实体来自 _briefs */ + applyDailyRecommend(res: pb.cs.ICSDailyRecommendRes): void { + const girls = res.girls ?? []; + this.mergeBriefs(girls); + this._dailyRecommend = girls.map(g => g.id!); + } + + /** 分类分页列表:category + page -> id[] */ + applyGirlList(category: number, page: number, res: pb.cs.ICSGetGirlListRes): void { + const girls = res.girls ?? []; + this.mergeBriefs(girls); + + if (!this._categoryPages.has(category)) { + this._categoryPages.set(category, new Map()); + } + const pages = this._categoryPages.get(category)!; + pages.set(page, girls.map(g => g.id!)); + } + + /** 详情:合并 brief + detail */ + applyGirlDetail(res: pb.cs.ICSGetGirlDetailRes): void { + const d = res.detail!; + const b = d.brief!; + this.mergeBriefs([b]); + + const vo: GirlDetailVO = { + id: b.id!, + desc: d.desc || "", + isRelease: !!d.isRelease, + chatCount: d.chatCount || 0, + photos: (d.photos ?? []).map(p => ({ + pic: p.pic || "", + isRelease: !!p.isRelease, + price: p.price || 0, + })), + }; + this._details.set(vo.id, vo); + } + + /** 页面读取:根据分类+页获取 id 列表 */ + getPageIds(category: number, page: number): number[] { + const pages = this._categoryPages.get(category); + return pages?.get(page) ?? []; + } + + /** 本地变更:聊天次数变更(成功买次数后) */ + incChatCount(girlId: number, delta: number) { + const d = this._details.get(girlId); + if (d) d.chatCount = Math.max(0, d.chatCount + delta); + } + + /** 本地变更:解锁技师/照片(例如购买后或服务器回调) */ + setGirlReleased(girlId: number, v: boolean) { + const d = this._details.get(girlId); + if (d) d.isRelease = v; + } + setPhotoReleased(girlId: number, pic: string, v: boolean) { + const d = this._details.get(girlId); + if (!d) return; + const p = d.photos.find(x => x.pic === pic); + if (p) p.isRelease = v; + } + +} diff --git a/assets/Scripts/chat18x/data/GirlData.ts.meta b/assets/Scripts/chat18x/data/GirlData.ts.meta new file mode 100644 index 00000000..965343cd --- /dev/null +++ b/assets/Scripts/chat18x/data/GirlData.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.24", + "importer": "typescript", + "imported": true, + "uuid": "fcbd75b6-cda1-4c93-80a8-79eda1ab5e54", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/Scripts/chat18x/data/ShopData.ts b/assets/Scripts/chat18x/data/ShopData.ts new file mode 100644 index 00000000..49ef5850 --- /dev/null +++ b/assets/Scripts/chat18x/data/ShopData.ts @@ -0,0 +1,100 @@ +/** + * 商品数据 + */ +import { BaseData } from "./BaseData"; +import proto from 'db://assets/Scripts/proto/proto.pb.js'; + +export class ShopData extends BaseData { + // 商品数据 + private _goods = new Map(); + // 商品 id + private _goodIds: number[] = []; + + public reset(): void { + this._goods.clear(); + this._goodIds = []; + } + + public clear(): void { + this._goods.clear(); + this._goodIds = []; + } + + public destroy(): void { + super.destroy(); + this._goods = null; + this._goodIds = null; + } + + /** 设置商品数据 */ + public set goods(res: proto.cs.ICSGetShopRes) { + const list = res.Goods ?? []; + this._goods.clear(); + this._goodIds = []; + for (const g of list) { + const vo: proto.cs.IGood = { + id: g.id, // 商品 id + name: g.name || "", // 商品名字 + desc: g.desc || "", // 商品描述 + price: g.price || "0.00", // 商品价格 + count: g.count || 0, // 商品数量 + }; + this._goods.set(vo.id, vo); + this._goodIds.push(vo.id); + } + console.log("设置商品数据:", this._goods); + } + + /** 获取所有商品数据 */ + public get goods(): Map { return this._goods; } + + /** 获取所有商品数据的数量 */ + public get goodsCount(): number { return this._goods ? this._goods.size : 0; } + + /** 获取所有商品 id */ + public get goodIds(): number[] { return this._goodIds; } + + /** 获取vip商品数据 */ + public get vipGoods(): proto.cs.IGood[] { + return this._goodIds.map(id => this._goods.get(id)!).filter(g => g.id > 2000); + } + + /** 获取普通商品数据 */ + public get normalGoods(): proto.cs.IGood[] { + return this._goodIds.map(id => this._goods.get(id)!).filter(g => g.id <= 2000); + } + + /** 根据商品 id 获取商品数据 */ + private getGoodDataById(id: number): proto.cs.IGood | null { + if (!this._goods) return null; + return this._goods.get(id) ?? null; + } + + /** 根据商品 id 获取商品名字 */ + public getNameById(id: number): string | null { + let oneData = this.getGoodDataById(id); + if (!oneData) return null; + return oneData.name; + } + + /** 根据商品 id 获取商品描述 */ + public getDescById(id: number): string | null { + let oneData = this.getGoodDataById(id); + if (!oneData) return null; + return oneData.desc; + } + + /** 根据商品 id 获取商品价格 */ + public getPriceById(id: number): string | null { + let oneData = this.getGoodDataById(id); + if (!oneData) return null; + return oneData.price; + } + + /** 根据商品 id 获取商品数量 */ + public getCountById(id: number): number | null { + let oneData = this.getGoodDataById(id); + if (!oneData) return null; + return oneData.count; + } +} diff --git a/assets/Scripts/chat18x/data/ShopData.ts.meta b/assets/Scripts/chat18x/data/ShopData.ts.meta new file mode 100644 index 00000000..d01611b4 --- /dev/null +++ b/assets/Scripts/chat18x/data/ShopData.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.24", + "importer": "typescript", + "imported": true, + "uuid": "c6e24881-4575-4e81-a204-1219d51625b6", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/Scripts/chat18x/data/ThemeData.ts b/assets/Scripts/chat18x/data/ThemeData.ts index 51f913ff..458c26c0 100644 --- a/assets/Scripts/chat18x/data/ThemeData.ts +++ b/assets/Scripts/chat18x/data/ThemeData.ts @@ -29,6 +29,7 @@ export class ThemeData extends BaseData { /** 设置主题数据 */ public set themes(res: proto.cs.ICSHallThemeRes) { const list = res.themes ?? []; + this._themes.clear(); this._themeIds = []; for (const t of list) { const vo: proto.cs.IHallTheme = {