Files
18xchat/assets/Scripts/chat18x/network/services/ShopService.ts
T
2025-09-10 15:27:07 +08:00

38 lines
1.1 KiB
TypeScript

import type { ApiResponse } from "../client/types";
import proto from "db://assets/Scripts/proto/proto.pb.js";
import type { IShopService } from "./IShopService";
import { HttpShopService } from "./HttpShopService";
import { MockShopService } from "./MockShopService";
// 模拟开关
const USE_MOCK = false;
export class ShopService implements IShopService {
private static _I: ShopService | null = null;
public static get I(): ShopService {
if (!ShopService._I) ShopService._I = new ShopService();
return ShopService._I;
}
private impl: IShopService;
private constructor() {
this.impl = USE_MOCK ? new MockShopService() : new HttpShopService();
}
/** 运行期切换 */
public switch(useMock: boolean) {
this.impl = useMock ? new MockShopService() : new HttpShopService();
}
// 获取商品列表
public async reqShopList(req: proto.cs.ICSGetPurchaseReq): Promise<ApiResponse<proto.cs.ICSGetPurchaseRes>> {
return this.impl.reqShopList(req);
}
// 使用余额购买商品
public async reqBuyGood(req: proto.cs.ICSBuyGoodReq): Promise<ApiResponse<proto.cs.ICSBuyGoodRes>> {
return this.impl.reqBuyGood(req);
}
}