46 lines
1.6 KiB
TypeScript
46 lines
1.6 KiB
TypeScript
import type { ApiResponse } from "../client/types";
|
|
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
|
import type { IThemeService } from "./IThemeService";
|
|
import { ConfigManager, ConfigId } from "../../manager/ConfigManager";
|
|
import { ThemeConfig } from "../../config/ThemeConfig";
|
|
|
|
export class MockThemeService implements IThemeService {
|
|
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>;
|
|
}
|
|
|
|
private makeTheme(id: number, key: string, name: string, category: number, isRelease: boolean, path: string): proto.cs.IThemes {
|
|
return {
|
|
id,
|
|
key,
|
|
name,
|
|
category,
|
|
isRelease,
|
|
path,
|
|
};
|
|
}
|
|
|
|
// 获取大厅分类列表
|
|
async reqHallTheme(req: proto.cs.ICSHallThemeReq): Promise<ApiResponse<proto.cs.ICSHallThemeRes>> {
|
|
// 延时
|
|
await this.delay();
|
|
|
|
const configData = ConfigManager.I.getDataById<ThemeConfig>(ConfigId.Theme);
|
|
const allId = configData.getAllId();
|
|
let themes: proto.cs.IThemes[] = [];
|
|
for (let oneId of allId) {
|
|
let key = configData.getLanKeyById(oneId);
|
|
let name = configData.getNameById(oneId);
|
|
let category = configData.getCategoryById(oneId);
|
|
let isRelease = configData.getIsReleaseById(oneId);
|
|
let path = configData.getPathById(oneId);
|
|
let oneData = this.makeTheme(oneId, key, name, category, isRelease, path);
|
|
themes.push(oneData);
|
|
}
|
|
// 返回数据
|
|
const res: proto.cs.ICSHallThemeRes = { themes };
|
|
return this.ok(res);
|
|
}
|
|
}
|