Merge branch 'main' of 47.107.44.202:xionglijia/18xchat
This commit is contained in:
@@ -13,7 +13,32 @@ export class AccountData extends BaseData {
|
||||
// 是否新手
|
||||
private _isNewGuide = true;
|
||||
// 是否刚注册
|
||||
private _isNewRegist = true;
|
||||
private _isNewRegist = true;
|
||||
|
||||
public reset(): void {
|
||||
this._identifier = "";
|
||||
this._identityType = 1;
|
||||
this._uid = "";
|
||||
this._isNewGuide = true;
|
||||
this._isNewRegist = true;
|
||||
}
|
||||
|
||||
public clear(): void {
|
||||
this._identifier = "";
|
||||
this._identityType = 1;
|
||||
this._uid = "";
|
||||
this._isNewGuide = true;
|
||||
this._isNewRegist = true;
|
||||
}
|
||||
|
||||
public destroy(): void {
|
||||
super.destroy();
|
||||
this._identifier = null;
|
||||
this._identityType = null;
|
||||
this._uid = null;
|
||||
this._isNewGuide = null;
|
||||
this._isNewRegist = null;
|
||||
}
|
||||
|
||||
/** 设置身份识别码 */
|
||||
public set identifier(value: string) {
|
||||
@@ -64,29 +89,4 @@ export class AccountData extends BaseData {
|
||||
public get isNewRegist(): boolean {
|
||||
return this._isNewRegist;
|
||||
}
|
||||
|
||||
public reset(): void {
|
||||
this._identifier = "";
|
||||
this._identityType = 1;
|
||||
this._uid = "";
|
||||
this._isNewGuide = true;
|
||||
this._isNewRegist = true;
|
||||
}
|
||||
|
||||
public clear(): void {
|
||||
this._identifier = "";
|
||||
this._identityType = 1;
|
||||
this._uid = "";
|
||||
this._isNewGuide = true;
|
||||
this._isNewRegist = true;
|
||||
}
|
||||
|
||||
public destroy(): void {
|
||||
super.destroy();
|
||||
this._identifier = null;
|
||||
this._identityType = null;
|
||||
this._uid = null;
|
||||
this._isNewGuide = null;
|
||||
this._isNewRegist = null;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,8 @@ import { PlayerData } from "./PlayerData";
|
||||
import { AccountData } from "./AccountData";
|
||||
import { MetaData } from "./MetaData";
|
||||
import { NetTimeData } from "./NetTimeData";
|
||||
import { ThemeData } from "./ThemeData";
|
||||
import { WalletData } from "./WalletData";
|
||||
|
||||
/**
|
||||
* 集中定义数据ID,避免写错字符串
|
||||
@@ -18,6 +20,8 @@ export enum DataId {
|
||||
Account = "account",
|
||||
Meta = "meta",
|
||||
NetTime = "netTime",
|
||||
Theme = "theme",
|
||||
Wallet = "wallet",
|
||||
}
|
||||
|
||||
/** 构造器类型 */
|
||||
@@ -43,13 +47,13 @@ export class DataManager {
|
||||
*/
|
||||
public init(): void {
|
||||
console.log("[DataManager] 数据管理器初始化");
|
||||
|
||||
this.register(DataId.Login, LoginData);
|
||||
this.register(DataId.Player, PlayerData);
|
||||
this.register(DataId.Account, AccountData);
|
||||
this.register(DataId.Meta, MetaData);
|
||||
this.register(DataId.NetTime, NetTimeData);
|
||||
|
||||
this.register(DataId.Theme, ThemeData);
|
||||
this.register(DataId.Wallet, WalletData);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,18 +70,18 @@ export class DataManager {
|
||||
* 获取数据(已存在则直接返回;否则按配置自动实例化并缓存)
|
||||
*/
|
||||
public getDataById<T extends BaseData = BaseData>(dataId: string): T | null {
|
||||
// 1) 先从缓存取
|
||||
// 先从缓存取
|
||||
const cached = this._dataMap.get(dataId) as T | undefined;
|
||||
if (cached) return cached;
|
||||
|
||||
// 2) 缓存没有→ 查找构造器
|
||||
// 缓存没有→ 查找构造器
|
||||
const Ctor = this._config.get(dataId) as DataCtor<T> | undefined;
|
||||
if (!Ctor) {
|
||||
console.warn(`[DataManager] 未找到 dataId 的构造器配置: ${dataId}`);
|
||||
return null;
|
||||
}
|
||||
|
||||
// 3) 动态创建 & init & 缓存
|
||||
// 动态创建 & init & 缓存
|
||||
const instance = new Ctor();
|
||||
// 若你的 BaseData.init 接受 dataId,可传入
|
||||
instance.init?.(dataId);
|
||||
|
||||
@@ -10,6 +10,8 @@ export class LoginData extends BaseData {
|
||||
private _token = "";
|
||||
// refresh token
|
||||
private _refreshToken = "";
|
||||
// token 过期时间戳
|
||||
private _expire = 0;
|
||||
// 操作类型,1:登录界面;2:断线重连;3:其他
|
||||
private _operateType = 1;
|
||||
// 公网IP
|
||||
@@ -19,7 +21,44 @@ export class LoginData extends BaseData {
|
||||
// sdk体系的UID
|
||||
private _sdkUid = "";
|
||||
// 上次登陆时间
|
||||
private _lastLoginTime = "";
|
||||
private _lastLoginTime = "";
|
||||
|
||||
public reset(): void {
|
||||
this._loginState = 0;
|
||||
this._token = "";
|
||||
this._refreshToken = "";
|
||||
this._expire = 0;
|
||||
this._operateType = 1;
|
||||
this._ip = "";
|
||||
this._machineIdentifier = "";
|
||||
this._sdkUid = "";
|
||||
this._lastLoginTime = "";
|
||||
}
|
||||
|
||||
public clear(): void {
|
||||
this._loginState = 0;
|
||||
this._token = "";
|
||||
this._refreshToken = "";
|
||||
this._expire = 0;
|
||||
this._operateType = 1;
|
||||
this._ip = "";
|
||||
this._machineIdentifier = "";
|
||||
this._sdkUid = "";
|
||||
this._lastLoginTime = "";
|
||||
}
|
||||
|
||||
public destroy(): void {
|
||||
super.destroy();
|
||||
this._loginState = null;
|
||||
this._token = null;
|
||||
this._refreshToken = null;
|
||||
this._expire = null;
|
||||
this._operateType = null;
|
||||
this._ip = null;
|
||||
this._machineIdentifier = null;
|
||||
this._sdkUid = null;
|
||||
this._lastLoginTime = null;
|
||||
}
|
||||
|
||||
/**是否已登录成功 */
|
||||
public isLogin(): boolean {
|
||||
@@ -55,8 +94,18 @@ export class LoginData extends BaseData {
|
||||
/** 获取登录refresh token */
|
||||
public get refreshToken(): string {
|
||||
return this._refreshToken;
|
||||
}
|
||||
}
|
||||
|
||||
/** 设置token 过期时间戳 */
|
||||
public set expire(value: number) {
|
||||
this._expire = value;
|
||||
}
|
||||
|
||||
/** 获取token 过期时间戳 */
|
||||
public get expire(): number {
|
||||
return this._expire;
|
||||
}
|
||||
|
||||
/** 设置操作类型 */
|
||||
public set operateType(value: number) {
|
||||
this._operateType = value;
|
||||
@@ -106,35 +155,4 @@ export class LoginData extends BaseData {
|
||||
public get lastLoginTime(): string {
|
||||
return this._lastLoginTime;
|
||||
}
|
||||
|
||||
public reset(): void {
|
||||
this._loginState = 0;
|
||||
this._token = "";
|
||||
this._operateType = 1;
|
||||
this._ip = "";
|
||||
this._machineIdentifier = "";
|
||||
this._sdkUid = "";
|
||||
this._lastLoginTime = "";
|
||||
}
|
||||
|
||||
public clear(): void {
|
||||
this._loginState = 0;
|
||||
this._token = "";
|
||||
this._operateType = 1;
|
||||
this._ip = "";
|
||||
this._machineIdentifier = "";
|
||||
this._sdkUid = "";
|
||||
this._lastLoginTime = "";
|
||||
}
|
||||
|
||||
public destroy(): void {
|
||||
super.destroy();
|
||||
this._loginState = null;
|
||||
this._token = null;
|
||||
this._operateType = null;
|
||||
this._ip = null;
|
||||
this._machineIdentifier = null;
|
||||
this._sdkUid = null;
|
||||
this._lastLoginTime = null;
|
||||
}
|
||||
}
|
||||
@@ -4,29 +4,59 @@
|
||||
import { BaseData } from "./BaseData";
|
||||
|
||||
export class PlayerData extends BaseData {
|
||||
// 用户名
|
||||
private _name: string = '';
|
||||
private _score: number = 0;
|
||||
// 钻石数
|
||||
private _diamond: number = 0;
|
||||
// vip失效时间戳
|
||||
private _vipExpire: number = 0;
|
||||
|
||||
public reset(): void {
|
||||
this._name = '';
|
||||
this._score = 0;
|
||||
this._diamond = 0;
|
||||
this._vipExpire = 0;
|
||||
}
|
||||
|
||||
public clear(): void {
|
||||
this._name = '';
|
||||
this._score = 0;
|
||||
this._diamond = 0;
|
||||
this._vipExpire = 0;
|
||||
}
|
||||
|
||||
public destroy(): void {
|
||||
super.destroy();
|
||||
// 这里可以做额外释放资源的操作
|
||||
this._name = null;
|
||||
this._diamond = null;
|
||||
this._vipExpire = null;
|
||||
}
|
||||
|
||||
public setName(name: string): void {
|
||||
this._name = name;
|
||||
/** 设置用户名 */
|
||||
public set name(value: string) {
|
||||
this._name = value;
|
||||
}
|
||||
|
||||
public getName(): string {
|
||||
/** 获取用户名 */
|
||||
public get name(): string {
|
||||
return this._name;
|
||||
}
|
||||
|
||||
/** 设置钻石数 */
|
||||
public set diamond(value: number) {
|
||||
this._diamond = value;
|
||||
}
|
||||
|
||||
/** 获取钻石数 */
|
||||
public get diamond(): number {
|
||||
return this._diamond;
|
||||
}
|
||||
|
||||
/** 设置vip失效时间戳 */
|
||||
public set vipExpire(value: number) {
|
||||
this._vipExpire = value;
|
||||
}
|
||||
|
||||
/** 获取vip失效时间戳 */
|
||||
public get vipExpire(): number {
|
||||
return this._vipExpire;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/**
|
||||
* 主题数据
|
||||
*/
|
||||
import { BaseData } from "./BaseData";
|
||||
import proto from 'db://assets/Scripts/proto/proto.pb.js';
|
||||
|
||||
export class ThemeData extends BaseData {
|
||||
// 主题数据
|
||||
private _themes = new Map<number, proto.cs.IHallTheme>();
|
||||
// 主题 id
|
||||
private _themeIds: number[] = [];
|
||||
|
||||
public reset(): void {
|
||||
this._themes.clear();
|
||||
this._themeIds = [];
|
||||
}
|
||||
|
||||
public clear(): void {
|
||||
this._themes.clear();
|
||||
this._themeIds = [];
|
||||
}
|
||||
|
||||
public destroy(): void {
|
||||
super.destroy();
|
||||
this._themes = null;
|
||||
this._themeIds = null;
|
||||
}
|
||||
|
||||
/** 设置主题数据 */
|
||||
public set themes(res: proto.cs.ICSHallThemeRes) {
|
||||
const list = res.themes ?? [];
|
||||
this._themeIds = [];
|
||||
for (const t of list) {
|
||||
const vo: proto.cs.IHallTheme = {
|
||||
id: t.id || 0, // 主题 id
|
||||
key: t.key || "", // 多语言键
|
||||
name: t.name || "", // 主题名称
|
||||
category: t.category || 0, // 主题枚举
|
||||
isRelease: t.isRelease, // 是否解锁
|
||||
path: t.path || "", // 图片路径
|
||||
};
|
||||
this._themes.set(vo.id, vo);
|
||||
this._themeIds.push(vo.id);
|
||||
}
|
||||
console.log("设置主题数据:", this._themes);
|
||||
}
|
||||
|
||||
/** 获取所有主题数据 */
|
||||
public get themes(): Map<number, proto.cs.IHallTheme> { return this._themes; }
|
||||
|
||||
/** 获取所有主题数据的数量 */
|
||||
public get themesCount(): number { return this._themes ? this._themes.size : 0; }
|
||||
|
||||
/** 获取所有主题 id */
|
||||
public get themeIds(): number[] { return this._themeIds; }
|
||||
|
||||
/** 根据主题 id 获取主题数据 */
|
||||
private getThemeDataById(id: number): proto.cs.IHallTheme | null {
|
||||
if (!this._themes) return null;
|
||||
return this._themes.get(id) ?? null;
|
||||
}
|
||||
|
||||
/** 根据主题 id 获取多语言键 */
|
||||
public getLanKeyById(id: number): string | null {
|
||||
let oneData = this.getThemeDataById(id);
|
||||
if (!oneData) return null;
|
||||
return oneData.key;
|
||||
}
|
||||
|
||||
/** 根据主题 id 获取主题名称 */
|
||||
public getNameById(id: number): string | null {
|
||||
let oneData = this.getThemeDataById(id);
|
||||
if (!oneData) return null;
|
||||
return oneData.name;
|
||||
}
|
||||
|
||||
/** 根据主题 id 获取主题枚举 */
|
||||
public getCategoryById(id: number): number | null {
|
||||
let oneData = this.getThemeDataById(id);
|
||||
if (!oneData) return null;
|
||||
return oneData.category;
|
||||
}
|
||||
|
||||
/** 根据主题 id 获取是否解锁 */
|
||||
public getIsReleaseById(id: number): boolean | null {
|
||||
let oneData = this.getThemeDataById(id);
|
||||
if (!oneData) return null;
|
||||
return oneData.isRelease;
|
||||
}
|
||||
|
||||
/** 根据主题 id 获取图片路径 */
|
||||
public getPathById(id: number): string | null {
|
||||
let oneData = this.getThemeDataById(id);
|
||||
if (!oneData) return null;
|
||||
return oneData.path;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "e02f9a30-748b-4546-8b52-3c0161352e09",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* 钱包数据
|
||||
*/
|
||||
import { BaseData } from "./BaseData";
|
||||
|
||||
export class WalletData extends BaseData {
|
||||
// 钻石数
|
||||
private _diamond = 0;
|
||||
// vip失效时间戳
|
||||
private _vipExpire = 0;
|
||||
|
||||
public reset(): void {
|
||||
this._diamond = 0;
|
||||
this._vipExpire = 0;
|
||||
}
|
||||
|
||||
public clear(): void {
|
||||
this._diamond = 0;
|
||||
this._vipExpire = 0;
|
||||
}
|
||||
|
||||
public destroy(): void {
|
||||
super.destroy();
|
||||
this._diamond = null;
|
||||
this._vipExpire = null;
|
||||
}
|
||||
|
||||
/** 设置钻石数 */
|
||||
public set diamond(value: number) {
|
||||
this._diamond = value;
|
||||
}
|
||||
|
||||
/** 获取钻石数 */
|
||||
public get diamond(): number {
|
||||
return this._diamond;
|
||||
}
|
||||
|
||||
/** 设置vip失效时间戳 */
|
||||
public set vipExpire(value: number) {
|
||||
this._vipExpire = value;
|
||||
}
|
||||
|
||||
/** 获取vip失效时间戳 */
|
||||
public get vipExpire(): number {
|
||||
return this._vipExpire;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "7f33f0b6-bb9e-4794-b277-ce1ffc18aee7",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -11,25 +11,14 @@ export class PlayerDataService {
|
||||
}
|
||||
private constructor(private api = ApiClient.I) {}
|
||||
|
||||
// 拉取玩家数据
|
||||
public async reqQueryPlayerData(req: proto.ProtoMsg.IQueryPlayerDataReq): Promise<ApiResponse<proto.ProtoMsg.IQueryPlayerDataRsp>> {
|
||||
let epData: Endpoint<proto.ProtoMsg.IQueryPlayerDataReq, proto.ProtoMsg.IQueryPlayerDataRsp> = {
|
||||
path: "playerdata/query_player_data",
|
||||
// 获取个人信息
|
||||
public async reqMyInfo(req: proto.cs.ICSMyInfoReq): Promise<ApiResponse<proto.cs.ICSMyInfoRes>> {
|
||||
let epData: Endpoint<proto.cs.ICSMyInfoReq, proto.cs.ICSMyInfoRes> = {
|
||||
path: "api/acc/info",
|
||||
method: "POST",
|
||||
codec: "json",
|
||||
needsAuth: true
|
||||
};
|
||||
return this.api.call(epData, req);
|
||||
}
|
||||
|
||||
// 保存玩家数据
|
||||
public async reqSavePlayerData(req: proto.ProtoMsg.ISavePlayerDataReq): Promise<ApiResponse<proto.ProtoMsg.ISavePlayerDataRsp>> {
|
||||
let epData: Endpoint<proto.ProtoMsg.ISavePlayerDataReq, proto.ProtoMsg.ISavePlayerDataRsp> = {
|
||||
path: "playerdata/save_player_data",
|
||||
method: "POST",
|
||||
codec: "json",
|
||||
needsAuth: true
|
||||
};
|
||||
return this.api.call(epData, req);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user