协议修改
This commit is contained in:
@@ -14,6 +14,7 @@ import { ShopData } from "./ShopData";
|
||||
import { OrderData } from "./OrderData";
|
||||
import { GirlData } from "./GirlData";
|
||||
import { EnvData } from "./EnvData";
|
||||
import { GlobalData } from "./GlobalData";
|
||||
|
||||
/**
|
||||
* 集中定义数据ID,避免写错字符串
|
||||
@@ -35,6 +36,7 @@ export enum DataId {
|
||||
GirlChat = "girlChat", // 技师的聊天数据
|
||||
GirlFavorability = "girlFavorability", // 技师的好感度数据
|
||||
Env = "env", // 环境数据
|
||||
Global = "global", // 全局数据
|
||||
}
|
||||
|
||||
/** 构造器类型 */
|
||||
@@ -78,6 +80,7 @@ export class DataManager {
|
||||
this.register(DataId.Order, OrderData);
|
||||
this.register(DataId.Girl, GirlData);
|
||||
this.register(DataId.Env, EnvData);
|
||||
this.register(DataId.Global, GlobalData);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* 全局数据
|
||||
*/
|
||||
import { BaseData } from "./BaseData";
|
||||
import proto from 'db://assets/Scripts/proto/proto.pb.js';
|
||||
|
||||
export class GlobalData extends BaseData {
|
||||
|
||||
|
||||
public reset(): void {
|
||||
|
||||
}
|
||||
|
||||
public clear(): void {
|
||||
|
||||
}
|
||||
|
||||
public destroy(): void {
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
/** 设置全局数据 */
|
||||
public set globals(res: proto.cs.ICSGetResConfigRes) {
|
||||
|
||||
|
||||
console.log("设置全局数据:");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "cc12432f-6e2f-4190-94c6-084037af001f",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import type { ApiResponse } from "../client/types";
|
||||
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
||||
import type { ICommonService } from "./ICommonService";
|
||||
import { HttpCommonService } from "./HttpCommonService";
|
||||
import { MockCommonService } from "./MockCommonService";
|
||||
|
||||
// 模拟开关
|
||||
const USE_MOCK = true;
|
||||
|
||||
export class CommonService implements ICommonService {
|
||||
private static _I: CommonService | null = null;
|
||||
public static get I(): CommonService {
|
||||
if (!CommonService._I) CommonService._I = new CommonService();
|
||||
return CommonService._I;
|
||||
}
|
||||
|
||||
private impl: ICommonService;
|
||||
|
||||
private constructor() {
|
||||
this.impl = USE_MOCK ? new MockCommonService() : new HttpCommonService();
|
||||
}
|
||||
|
||||
/** 运行期切换 */
|
||||
public switch(useMock: boolean) {
|
||||
this.impl = useMock ? new MockCommonService() : new HttpCommonService();
|
||||
}
|
||||
|
||||
// 获取配置
|
||||
public async reqResConfig(req: proto.cs.ICSGetResConfigReq): Promise<ApiResponse<proto.cs.ICSGetResConfigRes>> {
|
||||
return this.impl.reqResConfig(req);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "c53fc890-4e39-4c5e-bf35-ab87a8359139",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
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 type { ICommonService } from "./ICommonService";
|
||||
|
||||
export class HttpCommonService implements ICommonService {
|
||||
constructor(private api = ApiClient.I) {}
|
||||
|
||||
// 获取配置
|
||||
async reqResConfig(req: proto.cs.ICSGetResConfigReq): Promise<ApiResponse<proto.cs.ICSGetResConfigRes>> {
|
||||
const ep: Endpoint<proto.cs.ICSGetResConfigReq, proto.cs.ICSGetResConfigRes> = {
|
||||
path: "api/logic/getResConfig",
|
||||
method: "POST",
|
||||
codec: "json",
|
||||
needsAuth: true,
|
||||
};
|
||||
return this.api.call(ep, req);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "612b35c8-b85f-4ac1-8cbb-e4fd58c5d3c1",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import type { ApiResponse } from "../client/types";
|
||||
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
||||
|
||||
export interface ICommonService {
|
||||
// 获取配置
|
||||
reqResConfig(req: proto.cs.ICSGetResConfigReq): Promise<ApiResponse<proto.cs.ICSGetResConfigRes>>;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "05ed90ec-18c9-42cd-ae17-4a7ea4b3875c",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import type { ApiResponse } from "../client/types";
|
||||
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
||||
import type { ICommonService } from "./ICommonService";
|
||||
import { ConfigManager, ConfigId } from "../../manager/ConfigManager";
|
||||
import { GlobalConfig } from "../../config/GlobalConfig";
|
||||
|
||||
export class MockCommonService implements ICommonService {
|
||||
private delay(ms = 160) { return new Promise<void>(r => setTimeout(r, ms)); }
|
||||
private ok<T>(data: T): ApiResponse<T> {
|
||||
return ({ code: proto.cs.EnmRetCode.SUCCESS, data } as unknown) as ApiResponse<T>;
|
||||
}
|
||||
|
||||
// 获取配置
|
||||
async reqResConfig(req: proto.cs.ICSGetResConfigReq): Promise<ApiResponse<proto.cs.ICSGetResConfigRes>> {
|
||||
// 延时
|
||||
await this.delay();
|
||||
|
||||
let data = "";
|
||||
const resName = req.resName;
|
||||
if (resName === "global_config") {
|
||||
// 全局配置
|
||||
data = this.getGlobalConfig();
|
||||
}
|
||||
|
||||
// 返回数据
|
||||
const res: proto.cs.ICSGetResConfigRes = { data };
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
// 全局配置
|
||||
private getGlobalConfig(): string {
|
||||
|
||||
const configData = ConfigManager.I.getDataById<GlobalConfig>(ConfigId.Global);
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "8fd66f05-3289-4fa5-aed1-69f384223065",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -76,7 +76,7 @@ export class MockGirlService implements IGirlService {
|
||||
}
|
||||
|
||||
// 每日推荐
|
||||
async reqDailyRecommend(_req: proto.cs.ICSDailyRecommendReq): Promise<ApiResponse<proto.cs.ICSDailyRecommendRes>> {
|
||||
async reqDailyRecommend(req: proto.cs.ICSDailyRecommendReq): Promise<ApiResponse<proto.cs.ICSDailyRecommendRes>> {
|
||||
// 延时
|
||||
await this.delay(180);
|
||||
// 配置数据
|
||||
|
||||
@@ -22,7 +22,7 @@ export class MockThemeService implements IThemeService {
|
||||
}
|
||||
|
||||
// 获取大厅分类列表
|
||||
async reqHallTheme(_req: proto.cs.ICSHallThemeReq): Promise<ApiResponse<proto.cs.ICSHallThemeRes>> {
|
||||
async reqHallTheme(req: proto.cs.ICSHallThemeReq): Promise<ApiResponse<proto.cs.ICSHallThemeRes>> {
|
||||
// 延时
|
||||
await this.delay();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user