2025-08-25 18:01:40 +08:00
|
|
|
/**
|
|
|
|
|
* 主题数据
|
|
|
|
|
*/
|
|
|
|
|
import { BaseData } from "./BaseData";
|
|
|
|
|
import proto from 'db://assets/Scripts/proto/proto.pb.js';
|
|
|
|
|
|
|
|
|
|
export class ThemeData extends BaseData {
|
|
|
|
|
// 主题数据
|
2025-09-08 15:10:51 +08:00
|
|
|
private _themes = new Map<number, proto.cs.IThemes>();
|
2025-08-25 18:01:40 +08:00
|
|
|
// 主题 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 ?? [];
|
2025-08-26 11:10:15 +08:00
|
|
|
this._themes.clear();
|
2025-08-25 18:01:40 +08:00
|
|
|
this._themeIds = [];
|
|
|
|
|
for (const t of list) {
|
2025-09-08 15:10:51 +08:00
|
|
|
const vo: proto.cs.IThemes = {
|
2025-09-09 10:30:46 +08:00
|
|
|
id: t.id, // 主题 id
|
|
|
|
|
key: t.key, // 多语言键
|
|
|
|
|
name: t.name, // 主题名称
|
|
|
|
|
category: t.category, // 主题枚举
|
2025-08-25 18:01:40 +08:00
|
|
|
isRelease: t.isRelease, // 是否解锁
|
2025-09-09 10:30:46 +08:00
|
|
|
path: t.path, // 图片路径
|
2025-08-25 18:01:40 +08:00
|
|
|
};
|
|
|
|
|
this._themes.set(vo.id, vo);
|
|
|
|
|
this._themeIds.push(vo.id);
|
|
|
|
|
}
|
|
|
|
|
console.log("设置主题数据:", this._themes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 获取所有主题数据 */
|
2025-09-08 15:10:51 +08:00
|
|
|
public get themes(): Map<number, proto.cs.IThemes> { return this._themes; }
|
2025-08-25 18:01:40 +08:00
|
|
|
|
|
|
|
|
/** 获取所有主题数据的数量 */
|
|
|
|
|
public get themesCount(): number { return this._themes ? this._themes.size : 0; }
|
|
|
|
|
|
|
|
|
|
/** 获取所有主题 id */
|
|
|
|
|
public get themeIds(): number[] { return this._themeIds; }
|
|
|
|
|
|
|
|
|
|
/** 根据主题 id 获取主题数据 */
|
2025-09-08 15:10:51 +08:00
|
|
|
private getThemeDataById(id: number): proto.cs.IThemes | null {
|
2025-08-25 18:01:40 +08:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|