feat: 提交资源
This commit is contained in:
9
assets/configs/generated/core/Beans.ts
Normal file
9
assets/configs/generated/core/Beans.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* 自动生成的Bean类型定义
|
||||
* 请勿手动修改此文件
|
||||
* 生成时间: 2025-10-13T13:51:42.231Z
|
||||
*/
|
||||
|
||||
import { ConfigParseUtils } from "./ConfigParseUtils";
|
||||
|
||||
// 没有找到Bean定义
|
||||
9
assets/configs/generated/core/Beans.ts.meta
Normal file
9
assets/configs/generated/core/Beans.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "793d74d0-b0fc-446a-a36e-7ea0476da99a",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
257
assets/configs/generated/core/ConfigParseUtils.ts
Normal file
257
assets/configs/generated/core/ConfigParseUtils.ts
Normal file
@@ -0,0 +1,257 @@
|
||||
|
||||
import { Vec2, Vec3, Vec4, Color, Size, Rect, Quat, Mat4 } from 'cc';
|
||||
|
||||
import LogUtils from '@max-studio/core/utils/LogUtils';
|
||||
|
||||
/**
|
||||
* 配置表解析工具类
|
||||
* 提供通用的数据类型解析函数
|
||||
*
|
||||
* ⚠️ 此文件由配置表生成器自动生成,请勿手动修改!
|
||||
* 如需修改,请编辑 configs/plugins/ConfigTableGenerator.ts 中的 generateConfigParseUtils 方法
|
||||
*/
|
||||
export class ConfigParseUtils {
|
||||
/**
|
||||
* 解析Vec2类型
|
||||
*/
|
||||
public static parseVec2(value: any): Vec2 {
|
||||
if (typeof value === 'string') {
|
||||
const parts = value.split(',').map(v => Number.parseFloat(v.trim()) || 0);
|
||||
return new Vec2(parts[0] || 0, parts[1] || 0);
|
||||
}
|
||||
return new Vec2(0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析Vec3类型
|
||||
*/
|
||||
public static parseVec3(value: any): Vec3 {
|
||||
if (typeof value === 'string') {
|
||||
const parts = value.split(',').map(v => Number.parseFloat(v.trim()) || 0);
|
||||
return new Vec3(parts[0] || 0, parts[1] || 0, parts[2] || 0);
|
||||
}
|
||||
return new Vec3(0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析Vec4类型
|
||||
*/
|
||||
public static parseVec4(value: any): Vec4 {
|
||||
if (typeof value === 'string') {
|
||||
const parts = value.split(',').map(v => Number.parseFloat(v.trim()) || 0);
|
||||
return new Vec4(parts[0] || 0, parts[1] || 0, parts[2] || 0, parts[3] || 0);
|
||||
}
|
||||
return new Vec4(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析Color类型
|
||||
*/
|
||||
public static parseColor(value: any): Color {
|
||||
if (typeof value === 'string') {
|
||||
if (value.startsWith('#')) {
|
||||
// 十六进制颜色
|
||||
const hex = value.slice(1);
|
||||
const r = Number.parseInt(hex.substring(0, 2), 16);
|
||||
const g = Number.parseInt(hex.substring(2, 4), 16);
|
||||
const b = Number.parseInt(hex.substring(4, 6), 16);
|
||||
const a = hex.length > 6 ? Number.parseInt(hex.substring(6, 8), 16) : 255;
|
||||
return new Color(r, g, b, a);
|
||||
} else {
|
||||
// 逗号分隔的RGBA值
|
||||
const parts = value.split(',').map(v => Number.parseFloat(v.trim()) || 0);
|
||||
return new Color(parts[0] || 0, parts[1] || 0, parts[2] || 0, parts[3] !== undefined ? parts[3] : 255);
|
||||
}
|
||||
}
|
||||
return new Color(0, 0, 0, 255);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析Size类型
|
||||
*/
|
||||
public static parseSize(value: any): Size {
|
||||
if (typeof value === 'string') {
|
||||
const parts = value.split(',').map(v => Number.parseFloat(v.trim()) || 0);
|
||||
return new Size(parts[0] || 0, parts[1] || 0);
|
||||
}
|
||||
return new Size(0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析Rect类型
|
||||
*/
|
||||
public static parseRect(value: any): Rect {
|
||||
if (typeof value === 'string') {
|
||||
const parts = value.split(',').map(v => Number.parseFloat(v.trim()) || 0);
|
||||
return new Rect(parts[0] || 0, parts[1] || 0, parts[2] || 0, parts[3] || 0);
|
||||
}
|
||||
return new Rect(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析Quat类型
|
||||
*/
|
||||
public static parseQuat(value: any): Quat {
|
||||
if (typeof value === 'string') {
|
||||
const parts = value.split(',').map(v => Number.parseFloat(v.trim()) || 0);
|
||||
return new Quat(parts[0] || 0, parts[1] || 0, parts[2] || 0, parts[3] !== undefined ? parts[3] : 1);
|
||||
}
|
||||
return new Quat(0, 0, 0, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析Mat4类型
|
||||
*/
|
||||
public static parseMat4(value: any): Mat4 {
|
||||
if (typeof value === 'string') {
|
||||
const parts = value.split(',').map(v => Number.parseFloat(v.trim()) || 0);
|
||||
const mat = new Mat4();
|
||||
try {
|
||||
mat.set(
|
||||
parts[0], parts[1], parts[2], parts[3],
|
||||
parts[4], parts[5], parts[6], parts[7],
|
||||
parts[8], parts[9], parts[10], parts[11],
|
||||
parts[12], parts[13], parts[14], parts[15]
|
||||
);
|
||||
} catch (err) {
|
||||
LogUtils.error('ConfigParseUtils', '解析Mat4失败:', err);
|
||||
}
|
||||
return mat;
|
||||
}
|
||||
return new Mat4();
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析布尔值
|
||||
*/
|
||||
static parseBoolean(value: any): boolean {
|
||||
if (typeof value === 'boolean') {
|
||||
return value;
|
||||
}
|
||||
if (typeof value === 'string') {
|
||||
const lowerValue = value.toLowerCase();
|
||||
return lowerValue === 'true' || lowerValue === '1' || lowerValue === 'yes';
|
||||
}
|
||||
if (typeof value === 'number') {
|
||||
return value !== 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析整数
|
||||
*/
|
||||
public static parseInt(value: string | number): number {
|
||||
if (typeof value === 'number') return Math.floor(value);
|
||||
if (typeof value === 'string') return Number.parseInt(value.trim()) || 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析浮点数
|
||||
*/
|
||||
static parseFloat(value: any): number {
|
||||
return Number.parseFloat(value) || 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析字符串
|
||||
*/
|
||||
static parseString(value: any): string {
|
||||
return String(value || '');
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析字符串数组
|
||||
*/
|
||||
static parseStringArray(value: any): string[] {
|
||||
if (Array.isArray(value)) {
|
||||
return value.map(item => String(item || ''));
|
||||
}
|
||||
if (typeof value === 'string') {
|
||||
return value.split(',').map(item => item.trim()).filter(item => item.length > 0);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析数字数组
|
||||
*/
|
||||
static parseNumberArray(value: any): number[] {
|
||||
if (Array.isArray(value)) {
|
||||
return value.map(item => Number.parseFloat(item) || 0);
|
||||
}
|
||||
if (typeof value === 'string') {
|
||||
return value.split(',').map(item => Number.parseFloat(item.trim()) || 0);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 深度冻结对象,确保所有嵌套属性都不可修改
|
||||
*/
|
||||
public static deepFreeze<T>(obj: T): T {
|
||||
if (obj === null || typeof obj !== 'object') {
|
||||
return obj;
|
||||
}
|
||||
|
||||
// 检查是否为 ArrayBuffer views 或其他不可冻结的对象
|
||||
if (ArrayBuffer.isView(obj) || obj instanceof ArrayBuffer) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
// 检查是否为 Date、RegExp 等内置对象
|
||||
if (obj instanceof Date || obj instanceof RegExp) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
try {
|
||||
// 递归冻结所有属性(先冻结子对象)
|
||||
Object.getOwnPropertyNames(obj).forEach(prop => {
|
||||
const value = (obj as any)[prop];
|
||||
if (value !== null && typeof value === 'object') {
|
||||
this.deepFreeze(value);
|
||||
}
|
||||
});
|
||||
|
||||
// 最后冻结对象本身
|
||||
Object.freeze(obj);
|
||||
|
||||
// 对于数组,还需要防止索引赋值
|
||||
if (Array.isArray(obj)) {
|
||||
Object.seal(obj);
|
||||
}
|
||||
} catch (err) {
|
||||
// 如果冻结失败,记录警告但不中断程序
|
||||
LogUtils.warn('ConfigParseUtils', '无法冻结对象:', obj, err);
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建配置数据的只读代理,提供更好的错误提示
|
||||
*/
|
||||
public static createReadonlyProxy<T extends object>(obj: T, configName: string = '配置数据'): T {
|
||||
return new Proxy(obj, {
|
||||
set(target, property, value) {
|
||||
const errorMsg = `❌ 禁止修改${configName}的属性 "${String(property)}"!配置数据在运行时应保持不可变。`;
|
||||
LogUtils.error('ConfigParseUtils', errorMsg);
|
||||
throw new Error(errorMsg);
|
||||
},
|
||||
defineProperty(target, property, descriptor) {
|
||||
const errorMsg = `❌ 禁止定义${configName}的属性 "${String(property)}"!配置数据在运行时应保持不可变。`;
|
||||
LogUtils.error('ConfigParseUtils', errorMsg);
|
||||
throw new Error(errorMsg);
|
||||
},
|
||||
deleteProperty(target, property) {
|
||||
const errorMsg = `❌ 禁止删除${configName}的属性 "${String(property)}"!配置数据在运行时应保持不可变。`;
|
||||
LogUtils.error('ConfigParseUtils', errorMsg);
|
||||
throw new Error(errorMsg);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 导出便捷的解析函数
|
||||
export const { parseVec2, parseVec3, parseVec4, parseColor, parseSize, parseRect, parseQuat, parseMat4, parseBoolean, parseInt, parseFloat, parseString, parseStringArray, parseNumberArray, deepFreeze, createReadonlyProxy } = ConfigParseUtils;
|
||||
9
assets/configs/generated/core/ConfigParseUtils.ts.meta
Normal file
9
assets/configs/generated/core/ConfigParseUtils.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "e6350dd1-e9ea-4a64-9823-a20c6bf82990",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
16
assets/configs/generated/core/Enums.ts
Normal file
16
assets/configs/generated/core/Enums.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* 自动生成的枚举类型定义
|
||||
* 请勿手动修改此文件
|
||||
* 生成时间: 2025-10-13T13:51:42.230Z
|
||||
*/
|
||||
|
||||
export enum DressSourceType {
|
||||
/** 无 */
|
||||
NONE = 0,
|
||||
/** 插槽 */
|
||||
SLOT = 1,
|
||||
/** 挂点静态图 */
|
||||
SOCKET_TEX = 2,
|
||||
/** 挂点动画 */
|
||||
SOCKET_SPINE = 3
|
||||
}
|
||||
9
assets/configs/generated/core/Enums.ts.meta
Normal file
9
assets/configs/generated/core/Enums.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "e46d8a30-83a4-4635-951a-84486ebeec96",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
166
assets/configs/generated/core/PetConfigData.ts
Normal file
166
assets/configs/generated/core/PetConfigData.ts
Normal file
@@ -0,0 +1,166 @@
|
||||
|
||||
|
||||
|
||||
import { Color } from 'cc';
|
||||
|
||||
|
||||
|
||||
import { ConfigParseUtils } from './ConfigParseUtils';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* PetConfig数据结构
|
||||
*/
|
||||
export class PetConfigData {
|
||||
|
||||
private _id: number;
|
||||
|
||||
private _key: string;
|
||||
|
||||
private _bundle: string;
|
||||
|
||||
private _path: string;
|
||||
|
||||
private _name: string;
|
||||
|
||||
private _color: Color;
|
||||
|
||||
private _desc: string;
|
||||
|
||||
|
||||
|
||||
|
||||
/** id */
|
||||
|
||||
public get id(): number {
|
||||
|
||||
return this._id;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** key */
|
||||
|
||||
public get key(): string {
|
||||
|
||||
return this._key;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** bundle */
|
||||
|
||||
public get bundle(): string {
|
||||
|
||||
return this._bundle;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** 资源路径 */
|
||||
|
||||
public get path(): string {
|
||||
|
||||
return this._path;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** 宠物名称 */
|
||||
|
||||
public get name(): string {
|
||||
|
||||
return this._name;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** 颜色 */
|
||||
|
||||
public get color(): Color {
|
||||
|
||||
return ConfigParseUtils.createReadonlyProxy(ConfigParseUtils.deepFreeze(this._color), '颜色');
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** 描述 */
|
||||
|
||||
public get desc(): string {
|
||||
|
||||
return this._desc;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public constructor(
|
||||
|
||||
id: number,
|
||||
|
||||
key: string,
|
||||
|
||||
bundle: string,
|
||||
|
||||
path: string,
|
||||
|
||||
name: string,
|
||||
|
||||
color: Color,
|
||||
|
||||
desc: string
|
||||
|
||||
) {
|
||||
|
||||
this._id = id;
|
||||
|
||||
this._key = key;
|
||||
|
||||
this._bundle = bundle;
|
||||
|
||||
this._path = path;
|
||||
|
||||
this._name = name;
|
||||
|
||||
this._color = color;
|
||||
|
||||
this._desc = desc;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 解析配置数据
|
||||
*/
|
||||
export function parsePetConfigData(data: any): PetConfigData {
|
||||
return new PetConfigData(
|
||||
|
||||
ConfigParseUtils.parseInt(data.id),
|
||||
|
||||
ConfigParseUtils.parseString(data.key),
|
||||
|
||||
ConfigParseUtils.parseString(data.bundle),
|
||||
|
||||
ConfigParseUtils.parseString(data.path),
|
||||
|
||||
ConfigParseUtils.parseString(data.name),
|
||||
|
||||
ConfigParseUtils.parseColor(data.color),
|
||||
|
||||
ConfigParseUtils.parseString(data.desc)
|
||||
|
||||
);
|
||||
}
|
||||
9
assets/configs/generated/core/PetConfigData.ts.meta
Normal file
9
assets/configs/generated/core/PetConfigData.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "0b58225d-8d7f-429c-af23-1548e8acb583",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
88
assets/configs/generated/core/PetConfigManager.ts
Normal file
88
assets/configs/generated/core/PetConfigManager.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
import { JsonAsset } from "cc";
|
||||
|
||||
import { ResManager } from "@max-studio/core/res/ResManager";
|
||||
import { singleton, Singleton } from "@max-studio/core/Singleton";
|
||||
import LogUtils from "@max-studio/core/utils/LogUtils";
|
||||
|
||||
import { ConfigParseUtils } from "./ConfigParseUtils";
|
||||
import { PetConfigData, parsePetConfigData } from "./PetConfigData";
|
||||
|
||||
/**
|
||||
* PetConfig配置管理器
|
||||
*
|
||||
* ⚠️ 此文件由配置表生成器自动生成,请勿手动修改!
|
||||
* 如需修改,请编辑对应的Excel配置文件,然后重新生成
|
||||
*/
|
||||
@singleton()
|
||||
export class PetConfigManager extends Singleton {
|
||||
private configList: readonly PetConfigData[] = [];
|
||||
private configMap = new Map<number, PetConfigData>();
|
||||
private isLoaded = false;
|
||||
|
||||
protected async onInit(): Promise<void> {
|
||||
await this.loadConfig();
|
||||
}
|
||||
|
||||
private async loadConfig(): Promise<void> {
|
||||
try {
|
||||
const asset = await ResManager.getInstance().loadAsset<JsonAsset>(
|
||||
"generated/data/PetConfig",
|
||||
JsonAsset,
|
||||
"configs",
|
||||
);
|
||||
this.parseConfig(<any>asset.json);
|
||||
this.isLoaded = true;
|
||||
} catch (err) {
|
||||
LogUtils.error(
|
||||
"PetConfigManager",
|
||||
"加载 PetConfig 配置失败:",
|
||||
err,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private parseConfig(data: any[]): void {
|
||||
this.configList = Object.freeze(
|
||||
data.map((item) => {
|
||||
const config = parsePetConfigData(item);
|
||||
const frozenConfig = ConfigParseUtils.deepFreeze(config);
|
||||
return ConfigParseUtils.createReadonlyProxy(
|
||||
frozenConfig,
|
||||
"PetConfigData配置",
|
||||
);
|
||||
}),
|
||||
);
|
||||
this.configMap.clear();
|
||||
for (const config of this.configList) {
|
||||
this.configMap.set(config.id, config);
|
||||
}
|
||||
// 深度冻结配置映射,防止运行时修改
|
||||
ConfigParseUtils.deepFreeze(this.configMap);
|
||||
}
|
||||
|
||||
public getConfig(id: number): PetConfigData | null {
|
||||
if (!this.isLoaded) {
|
||||
LogUtils.warn(
|
||||
"PetConfigManager",
|
||||
"PetConfig 配置尚未加载完成,请等待加载完成",
|
||||
);
|
||||
return null;
|
||||
}
|
||||
return this.configMap.get(id) || null;
|
||||
}
|
||||
|
||||
public getAllConfigs(): PetConfigData[] {
|
||||
if (!this.isLoaded) {
|
||||
LogUtils.warn(
|
||||
"PetConfigManager",
|
||||
"PetConfig 配置尚未加载完成,请等待加载完成",
|
||||
);
|
||||
return [];
|
||||
}
|
||||
return [...this.configList];
|
||||
}
|
||||
|
||||
public isConfigLoaded(): boolean {
|
||||
return this.isLoaded;
|
||||
}
|
||||
}
|
||||
9
assets/configs/generated/core/PetConfigManager.ts.meta
Normal file
9
assets/configs/generated/core/PetConfigManager.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "a2093a8e-f81a-4bf2-a7a8-6bb20c02484c",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
130
assets/configs/generated/core/PetPartConfigData.ts
Normal file
130
assets/configs/generated/core/PetPartConfigData.ts
Normal file
@@ -0,0 +1,130 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import { ConfigParseUtils } from './ConfigParseUtils';
|
||||
|
||||
|
||||
|
||||
import { DressSourceType } from './Enums';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* PetPartConfig数据结构
|
||||
*/
|
||||
export class PetPartConfigData {
|
||||
|
||||
private _id: number;
|
||||
|
||||
private _name: string;
|
||||
|
||||
private _bundle: string;
|
||||
|
||||
private _path: string;
|
||||
|
||||
private _sourceType: DressSourceType;
|
||||
|
||||
|
||||
|
||||
|
||||
/** id */
|
||||
|
||||
public get id(): number {
|
||||
|
||||
return this._id;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** 装扮名称 */
|
||||
|
||||
public get name(): string {
|
||||
|
||||
return this._name;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** bundle */
|
||||
|
||||
public get bundle(): string {
|
||||
|
||||
return this._bundle;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** 资源路径 */
|
||||
|
||||
public get path(): string {
|
||||
|
||||
return this._path;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** 资源类型 */
|
||||
|
||||
public get sourceType(): DressSourceType {
|
||||
|
||||
return this._sourceType;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public constructor(
|
||||
|
||||
id: number,
|
||||
|
||||
name: string,
|
||||
|
||||
bundle: string,
|
||||
|
||||
path: string,
|
||||
|
||||
sourceType: DressSourceType
|
||||
|
||||
) {
|
||||
|
||||
this._id = id;
|
||||
|
||||
this._name = name;
|
||||
|
||||
this._bundle = bundle;
|
||||
|
||||
this._path = path;
|
||||
|
||||
this._sourceType = sourceType;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 解析配置数据
|
||||
*/
|
||||
export function parsePetPartConfigData(data: any): PetPartConfigData {
|
||||
return new PetPartConfigData(
|
||||
|
||||
ConfigParseUtils.parseInt(data.id),
|
||||
|
||||
ConfigParseUtils.parseString(data.name),
|
||||
|
||||
ConfigParseUtils.parseString(data.bundle),
|
||||
|
||||
ConfigParseUtils.parseString(data.path),
|
||||
|
||||
data.sourceType as DressSourceType
|
||||
|
||||
);
|
||||
}
|
||||
9
assets/configs/generated/core/PetPartConfigData.ts.meta
Normal file
9
assets/configs/generated/core/PetPartConfigData.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "eb6f0ae1-9c7b-4d26-a8b1-b96d2e65631f",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
88
assets/configs/generated/core/PetPartConfigManager.ts
Normal file
88
assets/configs/generated/core/PetPartConfigManager.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
import { JsonAsset } from "cc";
|
||||
|
||||
import { ResManager } from "@max-studio/core/res/ResManager";
|
||||
import { singleton, Singleton } from "@max-studio/core/Singleton";
|
||||
import LogUtils from "@max-studio/core/utils/LogUtils";
|
||||
|
||||
import { ConfigParseUtils } from "./ConfigParseUtils";
|
||||
import { PetPartConfigData, parsePetPartConfigData } from "./PetPartConfigData";
|
||||
|
||||
/**
|
||||
* PetPartConfig配置管理器
|
||||
*
|
||||
* ⚠️ 此文件由配置表生成器自动生成,请勿手动修改!
|
||||
* 如需修改,请编辑对应的Excel配置文件,然后重新生成
|
||||
*/
|
||||
@singleton()
|
||||
export class PetPartConfigManager extends Singleton {
|
||||
private configList: readonly PetPartConfigData[] = [];
|
||||
private configMap = new Map<number, PetPartConfigData>();
|
||||
private isLoaded = false;
|
||||
|
||||
protected async onInit(): Promise<void> {
|
||||
await this.loadConfig();
|
||||
}
|
||||
|
||||
private async loadConfig(): Promise<void> {
|
||||
try {
|
||||
const asset = await ResManager.getInstance().loadAsset<JsonAsset>(
|
||||
"generated/data/PetPartConfig",
|
||||
JsonAsset,
|
||||
"configs",
|
||||
);
|
||||
this.parseConfig(<any>asset.json);
|
||||
this.isLoaded = true;
|
||||
} catch (err) {
|
||||
LogUtils.error(
|
||||
"PetPartConfigManager",
|
||||
"加载 PetPartConfig 配置失败:",
|
||||
err,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private parseConfig(data: any[]): void {
|
||||
this.configList = Object.freeze(
|
||||
data.map((item) => {
|
||||
const config = parsePetPartConfigData(item);
|
||||
const frozenConfig = ConfigParseUtils.deepFreeze(config);
|
||||
return ConfigParseUtils.createReadonlyProxy(
|
||||
frozenConfig,
|
||||
"PetPartConfigData配置",
|
||||
);
|
||||
}),
|
||||
);
|
||||
this.configMap.clear();
|
||||
for (const config of this.configList) {
|
||||
this.configMap.set(config.id, config);
|
||||
}
|
||||
// 深度冻结配置映射,防止运行时修改
|
||||
ConfigParseUtils.deepFreeze(this.configMap);
|
||||
}
|
||||
|
||||
public getConfig(id: number): PetPartConfigData | null {
|
||||
if (!this.isLoaded) {
|
||||
LogUtils.warn(
|
||||
"PetPartConfigManager",
|
||||
"PetPartConfig 配置尚未加载完成,请等待加载完成",
|
||||
);
|
||||
return null;
|
||||
}
|
||||
return this.configMap.get(id) || null;
|
||||
}
|
||||
|
||||
public getAllConfigs(): PetPartConfigData[] {
|
||||
if (!this.isLoaded) {
|
||||
LogUtils.warn(
|
||||
"PetPartConfigManager",
|
||||
"PetPartConfig 配置尚未加载完成,请等待加载完成",
|
||||
);
|
||||
return [];
|
||||
}
|
||||
return [...this.configList];
|
||||
}
|
||||
|
||||
public isConfigLoaded(): boolean {
|
||||
return this.isLoaded;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "de6a1d46-109e-47ff-bb2a-f9b9f1241e30",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user