协议数据模拟测试

This commit is contained in:
chen wei bo
2025-08-29 16:40:14 +08:00
parent 5f51c19bc6
commit 1e7f2cf466
42 changed files with 702 additions and 90 deletions
@@ -1,24 +1,32 @@
import { ApiClient } from "../client/ApiClient";
import type { Endpoint } from "../client/endpoints";
import type { ApiResponse } from "../client/types";
import proto from 'db://assets/Scripts/proto/proto.pb.js';
import proto from "db://assets/Scripts/proto/proto.pb.js";
import type { IPlayerDataService } from "./IPlayerDataService";
import { HttpPlayerDataService } from "./HttpPlayerDataService";
import { MockPlayerDataService } from "./MockPlayerDataService";
export class PlayerDataService {
// 模拟开关
const USE_MOCK = true;
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 constructor(private api = ApiClient.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>> {
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);
return this.impl.reqMyInfo(req);
}
}