33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import type { ApiResponse } from "../client/types";
|
|
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
|
import type { IPlayerDataService } from "./IPlayerDataService";
|
|
import { HttpPlayerDataService } from "./HttpPlayerDataService";
|
|
import { MockPlayerDataService } from "./MockPlayerDataService";
|
|
|
|
// 模拟开关
|
|
const USE_MOCK = false;
|
|
|
|
export class PlayerDataService implements IPlayerDataService {
|
|
private static _I: PlayerDataService | null = null;
|
|
public static get I(): PlayerDataService {
|
|
if (!PlayerDataService._I) PlayerDataService._I = new PlayerDataService();
|
|
return PlayerDataService._I;
|
|
}
|
|
|
|
private impl: IPlayerDataService;
|
|
|
|
private constructor() {
|
|
this.impl = USE_MOCK ? new MockPlayerDataService() : new HttpPlayerDataService();
|
|
}
|
|
|
|
/** 运行期切换 */
|
|
public switch(useMock: boolean) {
|
|
this.impl = useMock ? new MockPlayerDataService() : new HttpPlayerDataService();
|
|
}
|
|
|
|
// 获取个人信息
|
|
public async reqMyInfo(req: proto.cs.ICSMyInfoReq): Promise<ApiResponse<proto.cs.ICSMyInfoRes>> {
|
|
return this.impl.reqMyInfo(req);
|
|
}
|
|
}
|