fix: 更新提交
This commit is contained in:
@@ -1,9 +1,17 @@
|
||||
/**
|
||||
* 自动生成的Bean类型定义
|
||||
* 请勿手动修改此文件
|
||||
* 生成时间: 2025-10-13T13:51:42.231Z
|
||||
*/
|
||||
|
||||
import { ConfigParseUtils } from "./ConfigParseUtils";
|
||||
|
||||
// 没有找到Bean定义
|
||||
/** Bean: Beans */
|
||||
export interface Beans {
|
||||
ClassName: string;
|
||||
FieldName: string;
|
||||
FieldType: string;
|
||||
Comment: string;
|
||||
}
|
||||
export function parseBeans(data: any): Beans {
|
||||
return {
|
||||
ClassName: ConfigParseUtils.parseString(data.ClassName),
|
||||
FieldName: ConfigParseUtils.parseString(data.FieldName),
|
||||
FieldType: ConfigParseUtils.parseString(data.FieldType),
|
||||
Comment: ConfigParseUtils.parseString(data.Comment),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { Vec2, Vec3, Vec4, Color, Size, Rect, Quat, Mat4 } from "cc";
|
||||
|
||||
import { Vec2, Vec3, Vec4, Color, Size, Rect, Quat, Mat4 } from 'cc';
|
||||
|
||||
import LogUtils from '@max-studio/core/utils/LogUtils';
|
||||
import LogUtils from "@max-studio/core/utils/LogUtils";
|
||||
|
||||
/**
|
||||
* 配置表解析工具类
|
||||
* 提供通用的数据类型解析函数
|
||||
*
|
||||
*
|
||||
* ⚠️ 此文件由配置表生成器自动生成,请勿手动修改!
|
||||
* 如需修改,请编辑 configs/plugins/ConfigTableGenerator.ts 中的 generateConfigParseUtils 方法
|
||||
*/
|
||||
@@ -15,8 +14,8 @@ 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);
|
||||
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);
|
||||
@@ -26,8 +25,8 @@ export class ConfigParseUtils {
|
||||
* 解析Vec3类型
|
||||
*/
|
||||
public static parseVec3(value: any): Vec3 {
|
||||
if (typeof value === 'string') {
|
||||
const parts = value.split(',').map(v => Number.parseFloat(v.trim()) || 0);
|
||||
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);
|
||||
@@ -37,8 +36,8 @@ export class ConfigParseUtils {
|
||||
* 解析Vec4类型
|
||||
*/
|
||||
public static parseVec4(value: any): Vec4 {
|
||||
if (typeof value === 'string') {
|
||||
const parts = value.split(',').map(v => Number.parseFloat(v.trim()) || 0);
|
||||
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);
|
||||
@@ -48,8 +47,8 @@ export class ConfigParseUtils {
|
||||
* 解析Color类型
|
||||
*/
|
||||
public static parseColor(value: any): Color {
|
||||
if (typeof value === 'string') {
|
||||
if (value.startsWith('#')) {
|
||||
if (typeof value === "string") {
|
||||
if (value.startsWith("#")) {
|
||||
// 十六进制颜色
|
||||
const hex = value.slice(1);
|
||||
const r = Number.parseInt(hex.substring(0, 2), 16);
|
||||
@@ -59,7 +58,7 @@ export class ConfigParseUtils {
|
||||
return new Color(r, g, b, a);
|
||||
} else {
|
||||
// 逗号分隔的RGBA值
|
||||
const parts = value.split(',').map(v => Number.parseFloat(v.trim()) || 0);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -70,8 +69,8 @@ export class ConfigParseUtils {
|
||||
* 解析Size类型
|
||||
*/
|
||||
public static parseSize(value: any): Size {
|
||||
if (typeof value === 'string') {
|
||||
const parts = value.split(',').map(v => Number.parseFloat(v.trim()) || 0);
|
||||
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);
|
||||
@@ -81,8 +80,8 @@ export class ConfigParseUtils {
|
||||
* 解析Rect类型
|
||||
*/
|
||||
public static parseRect(value: any): Rect {
|
||||
if (typeof value === 'string') {
|
||||
const parts = value.split(',').map(v => Number.parseFloat(v.trim()) || 0);
|
||||
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);
|
||||
@@ -92,8 +91,8 @@ export class ConfigParseUtils {
|
||||
* 解析Quat类型
|
||||
*/
|
||||
public static parseQuat(value: any): Quat {
|
||||
if (typeof value === 'string') {
|
||||
const parts = value.split(',').map(v => Number.parseFloat(v.trim()) || 0);
|
||||
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);
|
||||
@@ -103,18 +102,30 @@ export class ConfigParseUtils {
|
||||
* 解析Mat4类型
|
||||
*/
|
||||
public static parseMat4(value: any): Mat4 {
|
||||
if (typeof value === 'string') {
|
||||
const parts = value.split(',').map(v => Number.parseFloat(v.trim()) || 0);
|
||||
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]
|
||||
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);
|
||||
LogUtils.error("ConfigParseUtils", "解析Mat4失败:", err);
|
||||
}
|
||||
return mat;
|
||||
}
|
||||
@@ -125,14 +136,14 @@ export class ConfigParseUtils {
|
||||
* 解析布尔值
|
||||
*/
|
||||
static parseBoolean(value: any): boolean {
|
||||
if (typeof value === 'boolean') {
|
||||
if (typeof value === "boolean") {
|
||||
return value;
|
||||
}
|
||||
if (typeof value === 'string') {
|
||||
if (typeof value === "string") {
|
||||
const lowerValue = value.toLowerCase();
|
||||
return lowerValue === 'true' || lowerValue === '1' || lowerValue === 'yes';
|
||||
return lowerValue === "true" || lowerValue === "1" || lowerValue === "yes";
|
||||
}
|
||||
if (typeof value === 'number') {
|
||||
if (typeof value === "number") {
|
||||
return value !== 0;
|
||||
}
|
||||
return false;
|
||||
@@ -142,8 +153,8 @@ export class ConfigParseUtils {
|
||||
* 解析整数
|
||||
*/
|
||||
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;
|
||||
if (typeof value === "number") return Math.floor(value);
|
||||
if (typeof value === "string") return Number.parseInt(value.trim()) || 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -158,7 +169,7 @@ export class ConfigParseUtils {
|
||||
* 解析字符串
|
||||
*/
|
||||
static parseString(value: any): string {
|
||||
return String(value || '');
|
||||
return String(value || "");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,10 +177,13 @@ export class ConfigParseUtils {
|
||||
*/
|
||||
static parseStringArray(value: any): string[] {
|
||||
if (Array.isArray(value)) {
|
||||
return value.map(item => String(item || ''));
|
||||
return value.map((item) => String(item || ""));
|
||||
}
|
||||
if (typeof value === 'string') {
|
||||
return value.split(',').map(item => item.trim()).filter(item => item.length > 0);
|
||||
if (typeof value === "string") {
|
||||
return value
|
||||
.split(",")
|
||||
.map((item) => item.trim())
|
||||
.filter((item) => item.length > 0);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
@@ -179,10 +193,10 @@ export class ConfigParseUtils {
|
||||
*/
|
||||
static parseNumberArray(value: any): number[] {
|
||||
if (Array.isArray(value)) {
|
||||
return value.map(item => Number.parseFloat(item) || 0);
|
||||
return value.map((item) => Number.parseFloat(item) || 0);
|
||||
}
|
||||
if (typeof value === 'string') {
|
||||
return value.split(',').map(item => Number.parseFloat(item.trim()) || 0);
|
||||
if (typeof value === "string") {
|
||||
return value.split(",").map((item) => Number.parseFloat(item.trim()) || 0);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
@@ -191,7 +205,7 @@ export class ConfigParseUtils {
|
||||
* 深度冻结对象,确保所有嵌套属性都不可修改
|
||||
*/
|
||||
public static deepFreeze<T>(obj: T): T {
|
||||
if (obj === null || typeof obj !== 'object') {
|
||||
if (obj === null || typeof obj !== "object") {
|
||||
return obj;
|
||||
}
|
||||
|
||||
@@ -207,23 +221,23 @@ export class ConfigParseUtils {
|
||||
|
||||
try {
|
||||
// 递归冻结所有属性(先冻结子对象)
|
||||
Object.getOwnPropertyNames(obj).forEach(prop => {
|
||||
Object.getOwnPropertyNames(obj).forEach((prop) => {
|
||||
const value = (obj as any)[prop];
|
||||
if (value !== null && typeof value === 'object') {
|
||||
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);
|
||||
LogUtils.warn("ConfigParseUtils", "无法冻结对象:", obj, err);
|
||||
}
|
||||
|
||||
return obj;
|
||||
@@ -232,26 +246,43 @@ export class ConfigParseUtils {
|
||||
/**
|
||||
* 创建配置数据的只读代理,提供更好的错误提示
|
||||
*/
|
||||
public static createReadonlyProxy<T extends object>(obj: T, configName: string = '配置数据'): T {
|
||||
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);
|
||||
LogUtils.error("ConfigParseUtils", errorMsg);
|
||||
throw new Error(errorMsg);
|
||||
},
|
||||
defineProperty(target, property, descriptor) {
|
||||
const errorMsg = `❌ 禁止定义${configName}的属性 "${String(property)}"!配置数据在运行时应保持不可变。`;
|
||||
LogUtils.error('ConfigParseUtils', errorMsg);
|
||||
LogUtils.error("ConfigParseUtils", errorMsg);
|
||||
throw new Error(errorMsg);
|
||||
},
|
||||
deleteProperty(target, property) {
|
||||
const errorMsg = `❌ 禁止删除${configName}的属性 "${String(property)}"!配置数据在运行时应保持不可变。`;
|
||||
LogUtils.error('ConfigParseUtils', errorMsg);
|
||||
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;
|
||||
export const {
|
||||
parseVec2,
|
||||
parseVec3,
|
||||
parseVec4,
|
||||
parseColor,
|
||||
parseSize,
|
||||
parseRect,
|
||||
parseQuat,
|
||||
parseMat4,
|
||||
parseBoolean,
|
||||
parseInt,
|
||||
parseFloat,
|
||||
parseString,
|
||||
parseStringArray,
|
||||
parseNumberArray,
|
||||
deepFreeze,
|
||||
createReadonlyProxy,
|
||||
} = ConfigParseUtils;
|
||||
|
||||
@@ -1,16 +1,7 @@
|
||||
/**
|
||||
* 自动生成的枚举类型定义
|
||||
* 请勿手动修改此文件
|
||||
* 生成时间: 2025-10-13T13:51:42.230Z
|
||||
*/
|
||||
|
||||
/** 自动生成的枚举定义 */
|
||||
export enum DressSourceType {
|
||||
/** 无 */
|
||||
NONE = 0,
|
||||
/** 插槽 */
|
||||
SLOT = 1,
|
||||
/** 挂点静态图 */
|
||||
SOCKET_TEX = 2,
|
||||
/** 挂点动画 */
|
||||
SOCKET_SPINE = 3
|
||||
NONE = 0, // 无
|
||||
SLOT = 1, // 插槽
|
||||
SOCKET_TEX = 2, // 挂点静态图
|
||||
SOCKET_SPINE = 3, // 挂点动画
|
||||
}
|
||||
|
||||
@@ -1,19 +1,5 @@
|
||||
|
||||
|
||||
|
||||
import { Color } from 'cc';
|
||||
|
||||
|
||||
|
||||
import { ConfigParseUtils } from './ConfigParseUtils';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import { Color } from "cc";
|
||||
import { ConfigParseUtils } from "./ConfigParseUtils";
|
||||
|
||||
/**
|
||||
* PetConfig数据结构
|
||||
@@ -21,133 +7,64 @@ import { ConfigParseUtils } from './ConfigParseUtils';
|
||||
export class PetConfigData {
|
||||
|
||||
private _id: number;
|
||||
public get id(): number {
|
||||
return this._id;
|
||||
}
|
||||
|
||||
private _key: string;
|
||||
public get key(): string {
|
||||
return this._key;
|
||||
}
|
||||
|
||||
private _bundle: string;
|
||||
public get bundle(): string {
|
||||
return this._bundle;
|
||||
}
|
||||
|
||||
private _path: string;
|
||||
public get path(): string {
|
||||
return this._path;
|
||||
}
|
||||
|
||||
private _name: string;
|
||||
public get name(): string {
|
||||
return this._name;
|
||||
}
|
||||
|
||||
private _color: Color;
|
||||
public get color(): Color {
|
||||
return this._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),
|
||||
@@ -161,6 +78,5 @@ export function parsePetConfigData(data: any): PetConfigData {
|
||||
ConfigParseUtils.parseColor(data.color),
|
||||
|
||||
ConfigParseUtils.parseString(data.desc)
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
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";
|
||||
import ResManager from "@max-studio/core/res/ResManager";
|
||||
|
||||
/**
|
||||
* PetConfig配置管理器
|
||||
@@ -13,10 +13,11 @@ import { PetConfigData, parsePetConfigData } from "./PetConfigData";
|
||||
* ⚠️ 此文件由配置表生成器自动生成,请勿手动修改!
|
||||
* 如需修改,请编辑对应的Excel配置文件,然后重新生成
|
||||
*/
|
||||
@singleton()
|
||||
@singleton({ auto: true })
|
||||
export class PetConfigManager extends Singleton {
|
||||
private configList: readonly PetConfigData[] = [];
|
||||
private configMap = new Map<number, PetConfigData>();
|
||||
|
||||
private isLoaded = false;
|
||||
|
||||
protected async onInit(): Promise<void> {
|
||||
@@ -25,19 +26,15 @@ export class PetConfigManager extends Singleton {
|
||||
|
||||
private async loadConfig(): Promise<void> {
|
||||
try {
|
||||
const asset = await ResManager.getInstance().loadAsset<JsonAsset>(
|
||||
"generated/data/PetConfig",
|
||||
JsonAsset,
|
||||
"configs",
|
||||
);
|
||||
const { err, asset } = await ResManager.getInstance().loadAsset<JsonAsset>({
|
||||
path: "generated/data/PetConfig",
|
||||
type: JsonAsset,
|
||||
bundle: "configs",
|
||||
});
|
||||
this.parseConfig(<any>asset.json);
|
||||
this.isLoaded = true;
|
||||
} catch (err) {
|
||||
LogUtils.error(
|
||||
"PetConfigManager",
|
||||
"加载 PetConfig 配置失败:",
|
||||
err,
|
||||
);
|
||||
LogUtils.error("PetConfigManager", "加载 PetConfig 配置失败:", err);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,26 +43,20 @@ export class PetConfigManager extends Singleton {
|
||||
data.map((item) => {
|
||||
const config = parsePetConfigData(item);
|
||||
const frozenConfig = ConfigParseUtils.deepFreeze(config);
|
||||
return ConfigParseUtils.createReadonlyProxy(
|
||||
frozenConfig,
|
||||
"PetConfigData配置",
|
||||
);
|
||||
return ConfigParseUtils.createReadonlyProxy(frozenConfig, "PetConfigData配置");
|
||||
}),
|
||||
);
|
||||
this.configMap.clear();
|
||||
|
||||
for (const config of this.configList) {
|
||||
this.configMap.set(config.id, config);
|
||||
this.configMap.set((config as any).id, config);
|
||||
}
|
||||
// 深度冻结配置映射,防止运行时修改
|
||||
ConfigParseUtils.deepFreeze(this.configMap);
|
||||
}
|
||||
|
||||
public getConfig(id: number): PetConfigData | null {
|
||||
if (!this.isLoaded) {
|
||||
LogUtils.warn(
|
||||
"PetConfigManager",
|
||||
"PetConfig 配置尚未加载完成,请等待加载完成",
|
||||
);
|
||||
LogUtils.warn("PetConfigManager", "PetConfig 配置尚未加载完成,请等待加载完成");
|
||||
return null;
|
||||
}
|
||||
return this.configMap.get(id) || null;
|
||||
@@ -73,10 +64,7 @@ export class PetConfigManager extends Singleton {
|
||||
|
||||
public getAllConfigs(): PetConfigData[] {
|
||||
if (!this.isLoaded) {
|
||||
LogUtils.warn(
|
||||
"PetConfigManager",
|
||||
"PetConfig 配置尚未加载完成,请等待加载完成",
|
||||
);
|
||||
LogUtils.warn("PetConfigManager", "PetConfig 配置尚未加载完成,请等待加载完成");
|
||||
return [];
|
||||
}
|
||||
return [...this.configList];
|
||||
|
||||
@@ -1,130 +1,71 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import { ConfigParseUtils } from './ConfigParseUtils';
|
||||
|
||||
|
||||
|
||||
import { DressSourceType } from './Enums';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import { ConfigParseUtils } from "./ConfigParseUtils";
|
||||
|
||||
/**
|
||||
* PetPartConfig数据结构
|
||||
*/
|
||||
export class PetPartConfigData {
|
||||
|
||||
private _id: number;
|
||||
public get id(): number {
|
||||
return this._id;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
private _sourceName: string;
|
||||
public get sourceName(): string {
|
||||
return this._sourceName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** 资源路径 */
|
||||
|
||||
public get path(): string {
|
||||
|
||||
return this._path;
|
||||
|
||||
private _type: number;
|
||||
public get type(): number {
|
||||
return this._type;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** 资源类型 */
|
||||
|
||||
public get sourceType(): DressSourceType {
|
||||
|
||||
private _sourceType: number;
|
||||
public get sourceType(): number {
|
||||
return this._sourceType;
|
||||
|
||||
}
|
||||
|
||||
private _quality: number;
|
||||
public get quality(): number {
|
||||
return this._quality;
|
||||
}
|
||||
|
||||
public constructor(
|
||||
|
||||
id: number,
|
||||
|
||||
name: string,
|
||||
|
||||
bundle: string,
|
||||
|
||||
path: string,
|
||||
|
||||
sourceType: DressSourceType
|
||||
|
||||
sourceName: string,
|
||||
type: number,
|
||||
sourceType: number,
|
||||
quality: number,
|
||||
) {
|
||||
|
||||
this._id = id;
|
||||
|
||||
this._name = name;
|
||||
|
||||
this._bundle = bundle;
|
||||
|
||||
this._path = path;
|
||||
|
||||
this._sourceName = sourceName;
|
||||
this._type = type;
|
||||
this._sourceType = sourceType;
|
||||
|
||||
this._quality = quality;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 解析配置数据
|
||||
*/
|
||||
export function parsePetPartConfigData(data: any): PetPartConfigData {
|
||||
return new PetPartConfigData(
|
||||
|
||||
ConfigParseUtils.parseInt(data.id),
|
||||
|
||||
ConfigParseUtils.parseString(data.name),
|
||||
|
||||
ConfigParseUtils.parseString(data.bundle),
|
||||
ConfigParseUtils.parseString(data.sourceName),
|
||||
|
||||
ConfigParseUtils.parseString(data.path),
|
||||
ConfigParseUtils.parseInt(data.type),
|
||||
|
||||
data.sourceType as DressSourceType
|
||||
ConfigParseUtils.parseInt(data.sourceType),
|
||||
|
||||
ConfigParseUtils.parseInt(data.quality),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
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";
|
||||
import ResManager from "@max-studio/core/res/ResManager";
|
||||
|
||||
/**
|
||||
* PetPartConfig配置管理器
|
||||
@@ -13,10 +13,11 @@ import { PetPartConfigData, parsePetPartConfigData } from "./PetPartConfigData";
|
||||
* ⚠️ 此文件由配置表生成器自动生成,请勿手动修改!
|
||||
* 如需修改,请编辑对应的Excel配置文件,然后重新生成
|
||||
*/
|
||||
@singleton()
|
||||
@singleton({ auto: true })
|
||||
export class PetPartConfigManager extends Singleton {
|
||||
private configList: readonly PetPartConfigData[] = [];
|
||||
private configMap = new Map<number, PetPartConfigData>();
|
||||
|
||||
private isLoaded = false;
|
||||
|
||||
protected async onInit(): Promise<void> {
|
||||
@@ -25,19 +26,15 @@ export class PetPartConfigManager extends Singleton {
|
||||
|
||||
private async loadConfig(): Promise<void> {
|
||||
try {
|
||||
const asset = await ResManager.getInstance().loadAsset<JsonAsset>(
|
||||
"generated/data/PetPartConfig",
|
||||
JsonAsset,
|
||||
"configs",
|
||||
);
|
||||
const { err, asset } = await ResManager.getInstance().loadAsset<JsonAsset>({
|
||||
path: "generated/data/PetPartConfig",
|
||||
type: JsonAsset,
|
||||
bundle: "configs",
|
||||
});
|
||||
this.parseConfig(<any>asset.json);
|
||||
this.isLoaded = true;
|
||||
} catch (err) {
|
||||
LogUtils.error(
|
||||
"PetPartConfigManager",
|
||||
"加载 PetPartConfig 配置失败:",
|
||||
err,
|
||||
);
|
||||
LogUtils.error("PetPartConfigManager", "加载 PetPartConfig 配置失败:", err);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,26 +43,20 @@ export class PetPartConfigManager extends Singleton {
|
||||
data.map((item) => {
|
||||
const config = parsePetPartConfigData(item);
|
||||
const frozenConfig = ConfigParseUtils.deepFreeze(config);
|
||||
return ConfigParseUtils.createReadonlyProxy(
|
||||
frozenConfig,
|
||||
"PetPartConfigData配置",
|
||||
);
|
||||
return ConfigParseUtils.createReadonlyProxy(frozenConfig, "PetPartConfigData配置");
|
||||
}),
|
||||
);
|
||||
this.configMap.clear();
|
||||
|
||||
for (const config of this.configList) {
|
||||
this.configMap.set(config.id, config);
|
||||
this.configMap.set((config as any).id, config);
|
||||
}
|
||||
// 深度冻结配置映射,防止运行时修改
|
||||
ConfigParseUtils.deepFreeze(this.configMap);
|
||||
}
|
||||
|
||||
public getConfig(id: number): PetPartConfigData | null {
|
||||
if (!this.isLoaded) {
|
||||
LogUtils.warn(
|
||||
"PetPartConfigManager",
|
||||
"PetPartConfig 配置尚未加载完成,请等待加载完成",
|
||||
);
|
||||
LogUtils.warn("PetPartConfigManager", "PetPartConfig 配置尚未加载完成,请等待加载完成");
|
||||
return null;
|
||||
}
|
||||
return this.configMap.get(id) || null;
|
||||
@@ -73,10 +64,7 @@ export class PetPartConfigManager extends Singleton {
|
||||
|
||||
public getAllConfigs(): PetPartConfigData[] {
|
||||
if (!this.isLoaded) {
|
||||
LogUtils.warn(
|
||||
"PetPartConfigManager",
|
||||
"PetPartConfig 配置尚未加载完成,请等待加载完成",
|
||||
);
|
||||
LogUtils.warn("PetPartConfigManager", "PetPartConfig 配置尚未加载完成,请等待加载完成");
|
||||
return [];
|
||||
}
|
||||
return [...this.configList];
|
||||
|
||||
@@ -1,186 +1,272 @@
|
||||
[
|
||||
{
|
||||
"id": 1001,
|
||||
"id": "1001",
|
||||
"key": "chenghuang",
|
||||
"bundle": "pet-spine",
|
||||
"path": "ChengHuang",
|
||||
"color": "#00000000"
|
||||
"name": "",
|
||||
"color": "#00000000",
|
||||
"desc": ""
|
||||
},
|
||||
{
|
||||
"id": 1002,
|
||||
"id": "1002",
|
||||
"key": "dangkang",
|
||||
"bundle": "pet-spine",
|
||||
"path": "DangKang",
|
||||
"color": "#00000000"
|
||||
"name": "",
|
||||
"color": "#00000000",
|
||||
"desc": ""
|
||||
},
|
||||
{
|
||||
"id": 1003,
|
||||
"id": "1003",
|
||||
"key": "shuoshu",
|
||||
"bundle": "pet-spine",
|
||||
"path": "ShuoShu"
|
||||
"path": "ShuoShu",
|
||||
"name": "",
|
||||
"color": "",
|
||||
"desc": ""
|
||||
},
|
||||
{
|
||||
"id": 1004,
|
||||
"id": "1004",
|
||||
"key": "jiuwei",
|
||||
"bundle": "pet-spine",
|
||||
"path": "JiuWei",
|
||||
"name": "精卫"
|
||||
"name": "精卫",
|
||||
"color": "",
|
||||
"desc": ""
|
||||
},
|
||||
{
|
||||
"id": 1005,
|
||||
"id": "1005",
|
||||
"key": "qiongqi",
|
||||
"bundle": "pet-spine",
|
||||
"path": "QiongQi",
|
||||
"name": "穷奇"
|
||||
"name": "穷奇",
|
||||
"color": "",
|
||||
"desc": ""
|
||||
},
|
||||
{
|
||||
"id": 1006,
|
||||
"id": "1006",
|
||||
"key": "tiangou",
|
||||
"bundle": "pet-spine",
|
||||
"path": "TianGou"
|
||||
"path": "TianGou",
|
||||
"name": "",
|
||||
"color": "",
|
||||
"desc": ""
|
||||
},
|
||||
{
|
||||
"id": 1007,
|
||||
"id": "1007",
|
||||
"key": "xiangliu",
|
||||
"bundle": "pet-spine",
|
||||
"path": "XiangLiu"
|
||||
"path": "XiangLiu",
|
||||
"name": "",
|
||||
"color": "",
|
||||
"desc": ""
|
||||
},
|
||||
{
|
||||
"id": 1008,
|
||||
"id": "1008",
|
||||
"key": "lili",
|
||||
"bundle": "pet-spine",
|
||||
"path": "LiLi"
|
||||
"path": "LiLi",
|
||||
"name": "",
|
||||
"color": "",
|
||||
"desc": ""
|
||||
},
|
||||
{
|
||||
"id": 1009,
|
||||
"id": "1009",
|
||||
"key": "yugong",
|
||||
"bundle": "pet-spine",
|
||||
"path": "YuGong"
|
||||
"path": "YuGong",
|
||||
"name": "",
|
||||
"color": "",
|
||||
"desc": ""
|
||||
},
|
||||
{
|
||||
"id": 1010,
|
||||
"id": "1010",
|
||||
"key": "yutu",
|
||||
"bundle": "pet-spine",
|
||||
"path": "YuTu"
|
||||
"path": "YuTu",
|
||||
"name": "",
|
||||
"color": "",
|
||||
"desc": ""
|
||||
},
|
||||
{
|
||||
"id": 1011,
|
||||
"id": "1011",
|
||||
"key": "zhurong",
|
||||
"bundle": "pet-spine",
|
||||
"path": "ZhuRong"
|
||||
"path": "ZhuRong",
|
||||
"name": "",
|
||||
"color": "",
|
||||
"desc": ""
|
||||
},
|
||||
{
|
||||
"id": 1012,
|
||||
"id": "1012",
|
||||
"key": "changyou",
|
||||
"bundle": "pet-spine",
|
||||
"path": "Changyou"
|
||||
"path": "Changyou",
|
||||
"name": "",
|
||||
"color": "",
|
||||
"desc": ""
|
||||
},
|
||||
{
|
||||
"id": 1013,
|
||||
"id": "1013",
|
||||
"key": "dijiang",
|
||||
"bundle": "pet-spine",
|
||||
"path": "Dijiang"
|
||||
"path": "Dijiang",
|
||||
"name": "",
|
||||
"color": "",
|
||||
"desc": ""
|
||||
},
|
||||
{
|
||||
"id": 1014,
|
||||
"id": "1014",
|
||||
"key": "jili",
|
||||
"bundle": "pet-spine",
|
||||
"path": "Jili"
|
||||
"path": "Jili",
|
||||
"name": "",
|
||||
"color": "",
|
||||
"desc": ""
|
||||
},
|
||||
{
|
||||
"id": 1015,
|
||||
"id": "1015",
|
||||
"key": "shusi",
|
||||
"bundle": "pet-spine",
|
||||
"path": "Shusi"
|
||||
"path": "Shusi",
|
||||
"name": "",
|
||||
"color": "",
|
||||
"desc": ""
|
||||
},
|
||||
{
|
||||
"id": 1016,
|
||||
"id": "1016",
|
||||
"key": "wanv",
|
||||
"bundle": "pet-spine",
|
||||
"path": "Wanv"
|
||||
"path": "Wanv",
|
||||
"name": "",
|
||||
"color": "",
|
||||
"desc": ""
|
||||
},
|
||||
{
|
||||
"id": 1017,
|
||||
"id": "1017",
|
||||
"key": "xuangui",
|
||||
"bundle": "pet-spine",
|
||||
"path": "Xuangui"
|
||||
"path": "Xuangui",
|
||||
"name": "",
|
||||
"color": "",
|
||||
"desc": ""
|
||||
},
|
||||
{
|
||||
"id": 1018,
|
||||
"id": "1018",
|
||||
"key": "yingyu",
|
||||
"bundle": "pet-spine",
|
||||
"path": "Yingyu"
|
||||
"path": "Yingyu",
|
||||
"name": "",
|
||||
"color": "",
|
||||
"desc": ""
|
||||
},
|
||||
{
|
||||
"id": 1019,
|
||||
"id": "1019",
|
||||
"key": "yunque",
|
||||
"bundle": "pet-spine",
|
||||
"path": "Yunque"
|
||||
"path": "Yunque",
|
||||
"name": "",
|
||||
"color": "",
|
||||
"desc": ""
|
||||
},
|
||||
{
|
||||
"id": 1020,
|
||||
"id": "1020",
|
||||
"key": "pangding",
|
||||
"bundle": "pet-spine",
|
||||
"path": "PangDing"
|
||||
"path": "PangDing",
|
||||
"name": "",
|
||||
"color": "",
|
||||
"desc": ""
|
||||
},
|
||||
{
|
||||
"id": 1021,
|
||||
"id": "1021",
|
||||
"key": "shanyuan",
|
||||
"bundle": "pet-spine",
|
||||
"path": "ShanYuan"
|
||||
"path": "ShanYuan",
|
||||
"name": "",
|
||||
"color": "",
|
||||
"desc": ""
|
||||
},
|
||||
{
|
||||
"id": 1022,
|
||||
"id": "1022",
|
||||
"key": "zhuyin",
|
||||
"bundle": "pet-spine",
|
||||
"path": "ZhuYin"
|
||||
"path": "ZhuYin",
|
||||
"name": "",
|
||||
"color": "",
|
||||
"desc": ""
|
||||
},
|
||||
{
|
||||
"id": 1023,
|
||||
"id": "1023",
|
||||
"key": "yingwu",
|
||||
"bundle": "pet-spine",
|
||||
"path": "YingWu"
|
||||
"path": "YingWu",
|
||||
"name": "",
|
||||
"color": "",
|
||||
"desc": ""
|
||||
},
|
||||
{
|
||||
"id": 1024,
|
||||
"id": "1024",
|
||||
"key": "linghu",
|
||||
"bundle": "pet-spine",
|
||||
"path": "LingHu"
|
||||
"path": "LingHu",
|
||||
"name": "",
|
||||
"color": "",
|
||||
"desc": ""
|
||||
},
|
||||
{
|
||||
"id": 1025,
|
||||
"id": "1025",
|
||||
"key": "bailuwang",
|
||||
"bundle": "pet-spine",
|
||||
"path": "BaiLuWang"
|
||||
"path": "BaiLuWang",
|
||||
"name": "",
|
||||
"color": "",
|
||||
"desc": ""
|
||||
},
|
||||
{
|
||||
"id": 1026,
|
||||
"id": "1026",
|
||||
"key": "xuanwu",
|
||||
"bundle": "pet-spine",
|
||||
"path": "XuanWu"
|
||||
"path": "XuanWu",
|
||||
"name": "",
|
||||
"color": "",
|
||||
"desc": ""
|
||||
},
|
||||
{
|
||||
"id": 1027,
|
||||
"id": "1027",
|
||||
"key": "fengyou",
|
||||
"bundle": "pet-spine",
|
||||
"path": "FengYou"
|
||||
"path": "FengYou",
|
||||
"name": "",
|
||||
"color": "",
|
||||
"desc": ""
|
||||
},
|
||||
{
|
||||
"id": 1028,
|
||||
"id": "1028",
|
||||
"key": "nianshou",
|
||||
"bundle": "pet-spine",
|
||||
"path": "NianShou"
|
||||
"path": "NianShou",
|
||||
"name": "",
|
||||
"color": "",
|
||||
"desc": ""
|
||||
},
|
||||
{
|
||||
"id": 1029,
|
||||
"id": "1029",
|
||||
"key": "fenghuang",
|
||||
"bundle": "pet-spine",
|
||||
"path": "FengHuang"
|
||||
"path": "FengHuang",
|
||||
"name": "",
|
||||
"color": "",
|
||||
"desc": ""
|
||||
},
|
||||
{
|
||||
"id": 1030,
|
||||
"id": "1030",
|
||||
"key": "touzishe",
|
||||
"bundle": "pet-spine",
|
||||
"path": "TouZiShe"
|
||||
"path": "TouZiShe",
|
||||
"name": "",
|
||||
"color": "",
|
||||
"desc": ""
|
||||
}
|
||||
]
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user