60 lines
1.7 KiB
TypeScript
60 lines
1.7 KiB
TypeScript
import { _decorator } from "cc";
|
|
import Utils from "../Common/Utils";
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
//配置表管理器
|
|
@ccclass('Resource')
|
|
export default class Resource {
|
|
|
|
static instance: Resource = null;
|
|
private _config = {};//策划数值表
|
|
|
|
static getInstance() {
|
|
if (!this.instance) this.init();
|
|
return this.instance;
|
|
}
|
|
//初始化
|
|
static init() {
|
|
if (!this.instance) {
|
|
this.instance = new Resource();
|
|
(window as any).Resource = this;
|
|
}
|
|
}
|
|
|
|
/**加载子包时添加 */
|
|
static addSubJsonConfig(name, tab) {
|
|
let _instance = this.getInstance();
|
|
if (!_instance._config) _instance._config = {};
|
|
if (!_instance._config[name]) _instance._config[name] = {};
|
|
let json_SS, json_key1, json_key2
|
|
for (const key in tab) {
|
|
json_SS = tab[key];
|
|
if (!json_key1){
|
|
json_key1 = json_SS.id ? "id" : "ID" //默认用id
|
|
}
|
|
json_key2 = json_SS[json_key1]
|
|
_instance._config[name][json_key2] = json_SS;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取表数据
|
|
* @param table 表名
|
|
*/
|
|
static getConfig(table: string) {
|
|
if (!table) {
|
|
Utils.Log('策划数值表名为空!', table);
|
|
return null;
|
|
}
|
|
let _instance = this.getInstance();
|
|
if (!_instance._config) _instance._config = {};
|
|
if (!_instance._config[table]) {
|
|
// _instance._config[table] = {};
|
|
Utils.Error("配置表未找到:", table)
|
|
return null;
|
|
}
|
|
let config_D = _instance._config[table];
|
|
return config_D;
|
|
}
|
|
} |