40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import type { ApiResponse } from "../client/types";
|
|||
|
|
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
||
|
|
import type { IThemeService } from "./IThemeService";
|
||
|
|
|
||
|
|
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>;
|
||
|
|
}
|
||
|
|
|
||
|
|
private makeTheme(id: number, name: string, category: number, isRelease = true): proto.cs.IHallTheme {
|
||
|
|
return {
|
||
|
|
id,
|
||
|
|
key: `theme_${id}`,
|
||
|
|
name,
|
||
|
|
category,
|
||
|
|
isRelease,
|
||
|
|
path: `https://dummy.local/theme/${id}.png`,
|
||
|
|
};
|
||
|
|
// 若你使用资源服路径,可替换 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 res: proto.cs.ICSHallThemeRes = { themes };
|
||
|
|
return this.ok(res);
|
||
|
|
}
|
||
|
|
}
|