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

34 lines
1.0 KiB
TypeScript
Raw Normal View History

2025-08-29 16:39:41 +08:00
// assets/Scripts/services/logic/ChatService.ts
2025-08-27 17:33:51 +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 { IChatService } from "./IChatService";
import { HttpChatService } from "./HttpChatService";
import { MockChatService } from "./MockChatService";
2025-08-27 17:33:51 +08:00
2025-08-29 16:39:41 +08:00
// 模拟开关
const USE_MOCK = true;
export class ChatService implements IChatService {
2025-08-27 17:33:51 +08:00
private static _I: ChatService | null = null;
public static get I(): ChatService {
if (!ChatService._I) ChatService._I = new ChatService();
return ChatService._I;
}
2025-08-29 16:39:41 +08:00
private impl: IChatService;
private constructor() {
this.impl = USE_MOCK ? new MockChatService() : new HttpChatService();
}
/** 运行期动态切换 */
public switch(useMock: boolean) {
this.impl = useMock ? new MockChatService() : new HttpChatService();
}
// 对外 API 保持不变
2025-08-27 17:33:51 +08:00
public async reqBuyChat(req: proto.cs.ICSBuyChatReq): Promise<ApiResponse<proto.cs.ICSBuyChatRes>> {
2025-08-29 16:39:41 +08:00
return this.impl.reqBuyChat(req);
2025-08-27 17:33:51 +08:00
}
}