From 1c4ee104a1415dcf4f195dfc599fa282e8b308de Mon Sep 17 00:00:00 2001 From: chen wei bo <1025839511@qq.com> Date: Mon, 25 Aug 2025 18:01:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BB=E9=A2=98=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/Scripts/chat18x/data/DataManager.ts | 11 ++- assets/Scripts/chat18x/data/ThemeData.ts | 97 +++++++++++++++++++ assets/Scripts/chat18x/data/ThemeData.ts.meta | 9 ++ 3 files changed, 112 insertions(+), 5 deletions(-) create mode 100644 assets/Scripts/chat18x/data/ThemeData.ts create mode 100644 assets/Scripts/chat18x/data/ThemeData.ts.meta diff --git a/assets/Scripts/chat18x/data/DataManager.ts b/assets/Scripts/chat18x/data/DataManager.ts index 5a1fee23..7b5680cb 100644 --- a/assets/Scripts/chat18x/data/DataManager.ts +++ b/assets/Scripts/chat18x/data/DataManager.ts @@ -8,6 +8,7 @@ import { PlayerData } from "./PlayerData"; import { AccountData } from "./AccountData"; import { MetaData } from "./MetaData"; import { NetTimeData } from "./NetTimeData"; +import { ThemeData } from "./ThemeData"; /** * 集中定义数据ID,避免写错字符串 @@ -18,6 +19,7 @@ export enum DataId { Account = "account", Meta = "meta", NetTime = "netTime", + Theme = "theme", } /** 构造器类型 */ @@ -43,13 +45,12 @@ export class DataManager { */ public init(): void { console.log("[DataManager] 数据管理器初始化"); - this.register(DataId.Login, LoginData); this.register(DataId.Player, PlayerData); this.register(DataId.Account, AccountData); this.register(DataId.Meta, MetaData); this.register(DataId.NetTime, NetTimeData); - + this.register(DataId.Theme, ThemeData); } /** @@ -66,18 +67,18 @@ export class DataManager { * 获取数据(已存在则直接返回;否则按配置自动实例化并缓存) */ public getDataById(dataId: string): T | null { - // 1) 先从缓存取 + // 先从缓存取 const cached = this._dataMap.get(dataId) as T | undefined; if (cached) return cached; - // 2) 缓存没有→ 查找构造器 + // 缓存没有→ 查找构造器 const Ctor = this._config.get(dataId) as DataCtor | undefined; if (!Ctor) { console.warn(`[DataManager] 未找到 dataId 的构造器配置: ${dataId}`); return null; } - // 3) 动态创建 & init & 缓存 + // 动态创建 & init & 缓存 const instance = new Ctor(); // 若你的 BaseData.init 接受 dataId,可传入 instance.init?.(dataId); diff --git a/assets/Scripts/chat18x/data/ThemeData.ts b/assets/Scripts/chat18x/data/ThemeData.ts new file mode 100644 index 00000000..51f913ff --- /dev/null +++ b/assets/Scripts/chat18x/data/ThemeData.ts @@ -0,0 +1,97 @@ +/** + * 主题数据 + */ +import { BaseData } from "./BaseData"; +import proto from 'db://assets/Scripts/proto/proto.pb.js'; + +export class ThemeData extends BaseData { + // 主题数据 + private _themes = new Map(); + // 主题 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._themeIds = []; + for (const t of list) { + const vo: proto.cs.IHallTheme = { + id: t.id || 0, // 主题 id + key: t.key || "", // 多语言键 + name: t.name || "", // 主题名称 + category: t.category || 0, // 主题枚举 + isRelease: t.isRelease, // 是否解锁 + path: t.path || "", // 图片路径 + }; + this._themes.set(vo.id, vo); + this._themeIds.push(vo.id); + } + console.log("设置主题数据:", this._themes); + } + + /** 获取所有主题数据 */ + public get themes(): Map { 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.IHallTheme | 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; + } +} diff --git a/assets/Scripts/chat18x/data/ThemeData.ts.meta b/assets/Scripts/chat18x/data/ThemeData.ts.meta new file mode 100644 index 00000000..bfe852e4 --- /dev/null +++ b/assets/Scripts/chat18x/data/ThemeData.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.24", + "importer": "typescript", + "imported": true, + "uuid": "e02f9a30-748b-4546-8b52-3c0161352e09", + "files": [], + "subMetas": {}, + "userData": {} +}