模拟主题数据
This commit is contained in:
@@ -1,38 +1,43 @@
|
||||
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 ({ ok: true, data } as unknown) as ApiResponse<T>;
|
||||
return ({ code: proto.cs.EnmRetCode.SUCCESS, data } as unknown) as ApiResponse<T>;
|
||||
}
|
||||
|
||||
private makeTheme(id: number, name: string, category: number, isRelease = true): proto.cs.IHallTheme {
|
||||
private makeTheme(id: number, key: string, name: string, category: number, isRelease: boolean, path: string): proto.cs.IHallTheme {
|
||||
return {
|
||||
id,
|
||||
key: `theme_${id}`,
|
||||
key,
|
||||
name,
|
||||
category,
|
||||
isRelease,
|
||||
path: `https://dummy.local/theme/${id}.png`,
|
||||
path,
|
||||
};
|
||||
// 若你使用资源服路径,可替换 path 为实际地址或 db:// 本地资源
|
||||
}
|
||||
|
||||
// 获取大厅分类列表
|
||||
async reqHallTheme(_req: proto.cs.ICSHallThemeReq): Promise<ApiResponse<proto.cs.ICSHallThemeRes>> {
|
||||
// 延时
|
||||
await this.delay();
|
||||
|
||||
const themes: proto.cs.IHallTheme[] = [
|
||||
this.makeTheme(1, "Hot", 1, true),
|
||||
this.makeTheme(2, "New", 2, true),
|
||||
this.makeTheme(3, "Popular", 3, true),
|
||||
this.makeTheme(4, "VIP Only", 4, false),
|
||||
this.makeTheme(5, "Classic", 5, true),
|
||||
this.makeTheme(6, "Editor Pick",6, true),
|
||||
];
|
||||
|
||||
const configData = ConfigManager.I.getDataById<ThemeConfig>(ConfigId.Theme);
|
||||
const allId = configData.getAllId();
|
||||
let themes: proto.cs.IHallTheme[] = [];
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user