ca0f1935-b748-48c8-99d1-b14ac848657e.js
3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"use strict";
cc._RF.push(module, 'ca0f1k1t0hIyJnRsUrISGV+', 'PresenterCCViewFactory');
// script/game/ui/PresenterCCViewFactory.ts
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RegSubview = exports.RegSubpresenter = exports.RegView = exports.RegPresenter = void 0;
const PresenterBase_1 = require("../../common/classbase/PresenterBase");
const simba_cc_resutils_1 = require("simba-cc-resutils");
const PresenterMap = {};
const ViewMap = {};
function RegPresenter(viewType) {
return function (target) {
PresenterMap[target.uuid] = viewType;
};
}
exports.RegPresenter = RegPresenter;
function RegView(viewType, prefabPath) {
return function (target) {
ViewMap[viewType] = { cls: target, prefab: prefabPath };
};
}
exports.RegView = RegView;
const ViewTypeSubviewMap = {};
const ViewTypeSubpresenterMap = {};
function RegSubpresenter(viewType) {
return function (target) {
ViewTypeSubpresenterMap[viewType] = { cls: target };
Object.defineProperty(target, "_viewType", { configurable: false, enumerable: false, value: viewType, writable: false });
};
}
exports.RegSubpresenter = RegSubpresenter;
function RegSubview(viewType) {
return function (target) {
ViewTypeSubviewMap[viewType] = { cls: target };
Object.defineProperty(target, "_viewType", { configurable: false, enumerable: false, value: viewType, writable: false });
};
}
exports.RegSubview = RegSubview;
let factory = async (presenterCls) => {
let ret = ViewMap[PresenterMap[presenterCls.uuid]];
if (ret) {
let node = await simba_cc_resutils_1.ResUtils.createWithPrefab(ret.prefab);
let comp = node.getComponent(ret.cls);
if (!comp) {
comp = node.addComponent(ret.cls);
}
return comp;
}
throw new Error("Create view failed. " + presenterCls.uuid);
};
factory.preloadView = async (presenterCls) => {
let ret = ViewMap[PresenterMap[presenterCls.uuid]];
if (ret) {
await simba_cc_resutils_1.ResUtils.loadRes(ret.prefab, cc.Prefab);
}
};
PresenterBase_1.setPresenterViewFactory(factory);
// setSubviewFactory(async (p: Subpresenter) => {
// if (p.view) throw new Error("Subpresenter already has view.");
// const viewType = p.constructor["_viewType"];
// if (!viewType) throw new Error("Subpresenter not registered.");
// if (!ViewTypeSubviewMap[viewType]) throw new Error("Subview not registered. " + viewType);
// const data = ViewTypeSubviewMap[viewType];
// if (!data.prefab) throw new Error("Subview prefab not registered. " + viewType);
// let node = await ResUtils.createWithPrefab(data.prefab);
// let ret = node.getComponent(data.cls);
// if (!ret) {
// ret = node.addComponent(data.cls);
// }
// p.attachView(ret);
// return ret;
// });
PresenterBase_1.setSubpresenterwFactory((v) => {
const viewType = v.constructor["_viewType"];
if (!viewType)
throw new Error("Subview not registered.");
let data = ViewTypeSubpresenterMap[viewType];
if (!data)
throw new Error("Subpresenter not registered for view type. " + viewType);
let presenter = new data.cls;
presenter.attachView(v);
return presenter;
});
cc._RF.pop();