Files
18xchat/assets/Scripts/chat18x/network/services/PlayerDataService.ts
T

33 lines
1.1 KiB
TypeScript
Raw Normal View History

2025-08-18 15:22:54 +08:00
import type { ApiResponse } from "../client/types";
2025-08-29 16:39:41 +08:00
import proto from "db://assets/Scripts/proto/proto.pb.js";
import type { IPlayerDataService } from "./IPlayerDataService";
import { HttpPlayerDataService } from "./HttpPlayerDataService";
import { MockPlayerDataService } from "./MockPlayerDataService";
2025-08-18 15:22:54 +08:00
2025-08-29 16:39:41 +08:00
// 模拟开关
const USE_MOCK = true;
export class PlayerDataService implements IPlayerDataService {
2025-08-18 15:22:54 +08:00
private static _I: PlayerDataService | null = null;
public static get I(): PlayerDataService {
if (!PlayerDataService._I) PlayerDataService._I = new PlayerDataService();
return PlayerDataService._I;
}
2025-08-29 16:39:41 +08:00
private impl: IPlayerDataService;
private constructor() {
this.impl = USE_MOCK ? new MockPlayerDataService() : new HttpPlayerDataService();
}
/** 运行期切换 */
public switch(useMock: boolean) {
this.impl = useMock ? new MockPlayerDataService() : new HttpPlayerDataService();
}
// 获取个人信息
2025-08-25 16:27:18 +08:00
public async reqMyInfo(req: proto.cs.ICSMyInfoReq): Promise<ApiResponse<proto.cs.ICSMyInfoRes>> {
2025-08-29 16:39:41 +08:00
return this.impl.reqMyInfo(req);
2025-08-18 15:22:54 +08:00
}
}