Files
18xchat/assets/Scripts/chat18x/data/ThemeData.ts
T
2025-09-21 20:25:42 +08:00

100 lines
2.8 KiB
TypeScript

/**
* 主题数据
*/
import { BaseData } from "./BaseData";
import proto from 'db://assets/Scripts/proto/proto.pb.js';
import { logger } from "db://assets/Scripts/Main/Common/Logger";
export class ThemeData extends BaseData {
// 主题数据
private _themes = new Map<number, proto.cs.IThemes>();
// 主题 id
private _themeIds: number[] = [];
public reset(): void {
this._themes.clear();
this._themeIds = [];
}
public clear(): void {
this._themes.clear();
this._themeIds = [];
}
public destroy(): void {
super.destroy();
this._themes = null;
this._themeIds = null;
}
/** 设置主题数据 */
public set themes(res: proto.cs.ICSHallThemeRes) {
const list = res.themes ?? [];
this._themes.clear();
this._themeIds = [];
for (const t of list) {
const vo: proto.cs.IThemes = {
id: t.id, // 主题 id
key: t.key, // 多语言键
name: t.name, // 主题名称
category: t.category, // 主题枚举
isRelease: t.isRelease, // 是否解锁
path: t.path, // 图片路径
};
this._themes.set(vo.id, vo);
this._themeIds.push(vo.id);
}
logger.log("设置主题数据:", this._themes);
}
/** 获取所有主题数据 */
public get themes(): Map<number, proto.cs.IThemes> { return this._themes; }
/** 获取所有主题数据的数量 */
public get themesCount(): number { return this._themes ? this._themes.size : 0; }
/** 获取所有主题 id */
public get themeIds(): number[] { return this._themeIds; }
/** 根据主题 id 获取主题数据 */
private getThemeDataById(id: number): proto.cs.IThemes | null {
if (!this._themes) return null;
return this._themes.get(id) ?? null;
}
/** 根据主题 id 获取多语言键 */
public getLanKeyById(id: number): string | null {
let oneData = this.getThemeDataById(id);
if (!oneData) return null;
return oneData.key;
}
/** 根据主题 id 获取主题名称 */
public getNameById(id: number): string | null {
let oneData = this.getThemeDataById(id);
if (!oneData) return null;
return oneData.name;
}
/** 根据主题 id 获取主题枚举 */
public getCategoryById(id: number): number | null {
let oneData = this.getThemeDataById(id);
if (!oneData) return null;
return oneData.category;
}
/** 根据主题 id 获取是否解锁 */
public getIsReleaseById(id: number): boolean | null {
let oneData = this.getThemeDataById(id);
if (!oneData) return null;
return oneData.isRelease;
}
/** 根据主题 id 获取图片路径 */
public getPathById(id: number): string | null {
let oneData = this.getThemeDataById(id);
if (!oneData) return null;
return oneData.path;
}
}