// assets/Scripts/services/logic/ChatService.ts import type { ApiResponse } from "../client/types"; import proto from "db://assets/Scripts/proto/proto.pb.js"; import type { IChatService } from "./IChatService"; import { HttpChatService } from "./HttpChatService"; import { MockChatService } from "./MockChatService"; // 模拟开关 const USE_MOCK = true; export class ChatService implements IChatService { private static _I: ChatService | null = null; public static get I(): ChatService { if (!ChatService._I) ChatService._I = new ChatService(); return ChatService._I; } 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 保持不变 public async reqBuyChat(req: proto.cs.ICSBuyChatReq): Promise> { return this.impl.reqBuyChat(req); } }