init
This commit is contained in:
+125
@@ -0,0 +1,125 @@
|
||||
System.register(["__unresolved_0", "cc", "__unresolved_1", "__unresolved_2"], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, js, resources, SingletonBase, setClassName, _dec, _class, _crd, ccclass, property, DataMgr;
|
||||
|
||||
function _reportPossibleCrUseOfSingletonBase(extras) {
|
||||
_reporterNs.report("SingletonBase", "../SingletonBase", _context.meta, extras);
|
||||
}
|
||||
|
||||
function _reportPossibleCrUseOfsetClassName(extras) {
|
||||
_reporterNs.report("setClassName", "../../data/ConfigData", _context.meta, extras);
|
||||
}
|
||||
|
||||
return {
|
||||
setters: [function (_unresolved_) {
|
||||
_reporterNs = _unresolved_;
|
||||
}, function (_cc) {
|
||||
_cclegacy = _cc.cclegacy;
|
||||
__checkObsolete__ = _cc.__checkObsolete__;
|
||||
__checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
|
||||
_decorator = _cc._decorator;
|
||||
js = _cc.js;
|
||||
resources = _cc.resources;
|
||||
}, function (_unresolved_2) {
|
||||
SingletonBase = _unresolved_2.SingletonBase;
|
||||
}, function (_unresolved_3) {
|
||||
setClassName = _unresolved_3.setClassName;
|
||||
}],
|
||||
execute: function () {
|
||||
_crd = true;
|
||||
|
||||
_cclegacy._RF.push({}, "70a16xMXkFGCoewS0CQ22w8", "DataMgr", undefined);
|
||||
|
||||
__checkObsolete__(['_decorator', 'Component', 'js', 'JsonAsset', 'Node', 'resources', 'TypeScript']);
|
||||
|
||||
({
|
||||
ccclass,
|
||||
property
|
||||
} = _decorator);
|
||||
|
||||
_export("DataMgr", DataMgr = (_dec = ccclass('DataMgr'), _dec(_class = class DataMgr extends (_crd && SingletonBase === void 0 ? (_reportPossibleCrUseOfSingletonBase({
|
||||
error: Error()
|
||||
}), SingletonBase) : SingletonBase) {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.datas = new Map();
|
||||
}
|
||||
|
||||
start() {
|
||||
(_crd && setClassName === void 0 ? (_reportPossibleCrUseOfsetClassName({
|
||||
error: Error()
|
||||
}), setClassName) : setClassName)();
|
||||
this.initAllConfig();
|
||||
}
|
||||
|
||||
createInstance(className) {
|
||||
var Constructor = window.ConfigData[className];
|
||||
|
||||
if (typeof Constructor === 'function') {
|
||||
return new Constructor();
|
||||
} else {
|
||||
console.error("Class " + className + " is not a constructor");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
initAllConfig() {
|
||||
resources.loadDir("data", null, null, (err, assets) => {
|
||||
for (var i = 0; i < assets.length; i++) {
|
||||
var jsonAsset = assets[i];
|
||||
var className = jsonAsset.name;
|
||||
var array = new Array(); // this.datas.set((window as any)[className].name, array)
|
||||
|
||||
console.log("是否有类", window.ConfigData, className, window.ConfigData[className]);
|
||||
this.datas.set(js.getClassName(window.ConfigData[className]), array);
|
||||
console.log("设置data", className, js.getClassName(window.ConfigData[className]));
|
||||
|
||||
for (var j = 0; j < jsonAsset.json.length; j++) {
|
||||
var myClassInstance = new window.ConfigData[className]();
|
||||
var targetData = jsonAsset.json[j];
|
||||
this.initDataItem(myClassInstance, targetData);
|
||||
array.push(myClassInstance);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
GetDataById(dataClass, id) {
|
||||
var name = js.getClassName(dataClass);
|
||||
console.log("GetDataById", name);
|
||||
var datas = this.datas.get(name);
|
||||
|
||||
for (var i = 0; i < datas.length; i++) {
|
||||
if (datas[i].id == id) {
|
||||
return datas[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
initDataItem(obj, record) {
|
||||
for (var key in record) {
|
||||
if (record.hasOwnProperty(key) && obj.hasOwnProperty(key)) {
|
||||
obj[key] = record[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GetDatas(dataClass) {
|
||||
var name = js.getClassName(dataClass);
|
||||
console.log(this.datas.get(name));
|
||||
console.log(dataClass);
|
||||
console.log(name);
|
||||
console.log(this.datas);
|
||||
return this.datas.get(name);
|
||||
}
|
||||
|
||||
}) || _class));
|
||||
|
||||
_cclegacy._RF.pop();
|
||||
|
||||
_crd = false;
|
||||
}
|
||||
};
|
||||
});
|
||||
//# sourceMappingURL=74492fc9d685cee57174a4cb2d83681be8c897ae.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user