@cc-component/cc-core 1.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.cc-ex-component.md +12 -0
- package/assets/core/config/CommonEnum.ts +94 -0
- package/assets/core/config/CommonEnum.ts.meta +9 -0
- package/assets/core/config/IConfig.ts +89 -0
- package/assets/core/config/IConfig.ts.meta +9 -0
- package/assets/core/config/LayerType.ts +44 -0
- package/assets/core/config/LayerType.ts.meta +9 -0
- package/assets/core/config/LayerUI.ts +113 -0
- package/assets/core/config/LayerUI.ts.meta +9 -0
- package/assets/core/config.meta +9 -0
- package/assets/core/editor/LanguageManager.ts +323 -0
- package/assets/core/editor/LanguageManager.ts.meta +9 -0
- package/assets/core/editor/SpineRunner.ts +39 -0
- package/assets/core/editor/SpineRunner.ts.meta +9 -0
- package/assets/core/editor/i18nEditorComponent.ts +137 -0
- package/assets/core/editor/i18nEditorComponent.ts.meta +9 -0
- package/assets/core/editor.meta +9 -0
- package/assets/core/home/AudioUtil.ts +164 -0
- package/assets/core/home/AudioUtil.ts.meta +9 -0
- package/assets/core/home/BaseBoxView.ts +60 -0
- package/assets/core/home/BaseBoxView.ts.meta +9 -0
- package/assets/core/home/BaseLaunchComponent.ts +9 -0
- package/assets/core/home/BaseLaunchComponent.ts.meta +9 -0
- package/assets/core/home/BaseLoading.ts +136 -0
- package/assets/core/home/BaseLoading.ts.meta +9 -0
- package/assets/core/home/BaseSkeleton.ts +39 -0
- package/assets/core/home/BaseSkeleton.ts.meta +9 -0
- package/assets/core/home/CameraAngel.ts +326 -0
- package/assets/core/home/CameraAngel.ts.meta +9 -0
- package/assets/core/home/DouYinShow.ts +27 -0
- package/assets/core/home/DouYinShow.ts.meta +9 -0
- package/assets/core/home/EventManager.ts +39 -0
- package/assets/core/home/EventManager.ts.meta +9 -0
- package/assets/core/home/ExView.ts +9 -0
- package/assets/core/home/ExView.ts.meta +9 -0
- package/assets/core/home/FollowCamera.ts +205 -0
- package/assets/core/home/FollowCamera.ts.meta +9 -0
- package/assets/core/home/InViewCenter.ts +52 -0
- package/assets/core/home/InViewCenter.ts.meta +9 -0
- package/assets/core/home/JsonUtil.ts +102 -0
- package/assets/core/home/JsonUtil.ts.meta +9 -0
- package/assets/core/home/LoadingWindow.ts +44 -0
- package/assets/core/home/LoadingWindow.ts.meta +9 -0
- package/assets/core/home/ParabolaTween.ts +110 -0
- package/assets/core/home/ParabolaTween.ts.meta +9 -0
- package/assets/core/home/ProgessView.ts +96 -0
- package/assets/core/home/ProgessView.ts.meta +9 -0
- package/assets/core/home/Quaternion.ts +237 -0
- package/assets/core/home/Quaternion.ts.meta +9 -0
- package/assets/core/home/ResUtil.ts +132 -0
- package/assets/core/home/ResUtil.ts.meta +9 -0
- package/assets/core/home/ResourceManager.ts +430 -0
- package/assets/core/home/ResourceManager.ts.meta +9 -0
- package/assets/core/home/StateMachine.ts +93 -0
- package/assets/core/home/StateMachine.ts.meta +9 -0
- package/assets/core/home/StorageManager.ts +161 -0
- package/assets/core/home/StorageManager.ts.meta +9 -0
- package/assets/core/home/ThirdFreeLookCamera.ts +201 -0
- package/assets/core/home/ThirdFreeLookCamera.ts.meta +9 -0
- package/assets/core/home/TimeManager.ts +486 -0
- package/assets/core/home/TimeManager.ts.meta +9 -0
- package/assets/core/home/Tools.ts +103 -0
- package/assets/core/home/Tools.ts.meta +9 -0
- package/assets/core/home/prefabs.meta +12 -0
- package/assets/core/home/util/EncryptUtil.ts +60 -0
- package/assets/core/home/util/EncryptUtil.ts.meta +11 -0
- package/assets/core/home/util/MathUtil.ts +22 -0
- package/assets/core/home/util/MathUtil.ts.meta +9 -0
- package/assets/core/home/util/Md5.ts +202 -0
- package/assets/core/home/util/Md5.ts.meta +11 -0
- package/assets/core/home/util/RandomUtil.ts +61 -0
- package/assets/core/home/util/RandomUtil.ts.meta +9 -0
- package/assets/core/home/util/ResUtil.ts +129 -0
- package/assets/core/home/util/ResUtil.ts.meta +9 -0
- package/assets/core/home/util/crypto-js.d.ts +30 -0
- package/assets/core/home/util/crypto-js.d.ts.meta +11 -0
- package/assets/core/home/util/crypto-js.js +6030 -0
- package/assets/core/home/util/crypto-js.js.meta +9 -0
- package/assets/core/home/util.meta +12 -0
- package/assets/core/home.meta +12 -0
- package/assets/core/interface/ISceneParam.ts +11 -0
- package/assets/core/interface/ISceneParam.ts.meta +9 -0
- package/assets/core/interface/Interface.ts +160 -0
- package/assets/core/interface/Interface.ts.meta +1 -0
- package/assets/core/interface/MainModule.ts +1019 -0
- package/assets/core/interface/MainModule.ts.meta +9 -0
- package/assets/core/interface.meta +9 -0
- package/assets/core/lib/Logger.ts +286 -0
- package/assets/core/lib/Logger.ts.meta +9 -0
- package/assets/core/lib/language/.language.md +1 -0
- package/assets/core/lib/language/Language.ts +133 -0
- package/assets/core/lib/language/Language.ts.meta +13 -0
- package/assets/core/lib/language/LanguageData.ts +114 -0
- package/assets/core/lib/language/LanguageData.ts.meta +9 -0
- package/assets/core/lib/language/LanguageLabel.ts +172 -0
- package/assets/core/lib/language/LanguageLabel.ts.meta +13 -0
- package/assets/core/lib/language/LanguagePack.ts +126 -0
- package/assets/core/lib/language/LanguagePack.ts.meta +13 -0
- package/assets/core/lib/language/LanguagePointLabel.ts.meta +16 -0
- package/assets/core/lib/language/LanguageSpine.ts +60 -0
- package/assets/core/lib/language/LanguageSpine.ts.meta +9 -0
- package/assets/core/lib/language/LanguageSprite.ts +138 -0
- package/assets/core/lib/language/LanguageSprite.ts.meta +13 -0
- package/assets/core/lib/language.meta +9 -0
- package/assets/core/lib/logger/ELoggerLevel.ts +16 -0
- package/assets/core/lib/logger/ELoggerLevel.ts.meta +9 -0
- package/assets/core/lib/logger/MLogger.ts +118 -0
- package/assets/core/lib/logger/MLogger.ts.meta +9 -0
- package/assets/core/lib/logger.meta +9 -0
- package/assets/core/lib/net/libs/proto/output/protobuf.d.ts +2729 -0
- package/assets/core/lib/net/libs/proto/output/protobuf.d.ts.meta +9 -0
- package/assets/core/lib/net/libs/proto/output/protobuf.min.js +8 -0
- package/assets/core/lib/net/libs/proto/output/protobuf.min.js.meta +9 -0
- package/assets/core/lib/net/libs/proto/output/protobuf_custom.d.ts +102 -0
- package/assets/core/lib/net/libs/proto/output/protobuf_custom.d.ts.meta +9 -0
- package/assets/core/lib/net/libs/proto/output/protobuf_custom.js +222 -0
- package/assets/core/lib/net/libs/proto/output/protobuf_custom.js.meta +9 -0
- package/assets/core/lib/net/libs/proto/output.meta +9 -0
- package/assets/core/lib/net/libs/proto/source/Cmd.proto +6 -0
- package/assets/core/lib/net/libs/proto/source/Cmd.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/UserLogin.proto +12 -0
- package/assets/core/lib/net/libs/proto/source/UserLogin.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/base.proto +24 -0
- package/assets/core/lib/net/libs/proto/source/base.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/command.proto +31 -0
- package/assets/core/lib/net/libs/proto/source/command.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/domain/boos_battle_info.proto +13 -0
- package/assets/core/lib/net/libs/proto/source/domain/boos_battle_info.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/domain/player_auth.proto +26 -0
- package/assets/core/lib/net/libs/proto/source/domain/player_auth.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/domain.meta +9 -0
- package/assets/core/lib/net/libs/proto/source/message/game_push.proto +23 -0
- package/assets/core/lib/net/libs/proto/source/message/game_push.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/message/game_request.proto +24 -0
- package/assets/core/lib/net/libs/proto/source/message/game_request.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/message/game_response.proto +24 -0
- package/assets/core/lib/net/libs/proto/source/message/game_response.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/message.meta +9 -0
- package/assets/core/lib/net/libs/proto/source/push/boss_battle_events.proto +43 -0
- package/assets/core/lib/net/libs/proto/source/push/boss_battle_events.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/push.meta +9 -0
- package/assets/core/lib/net/libs/proto/source.meta +12 -0
- package/assets/core/lib/net/libs/proto.meta +9 -0
- package/assets/core/lib/net/libs.meta +9 -0
- package/assets/core/lib/net/net/HttpManager.ts +307 -0
- package/assets/core/lib/net/net/HttpManager.ts.meta +9 -0
- package/assets/core/lib/net/net/NetInterface.ts +114 -0
- package/assets/core/lib/net/net/NetInterface.ts.meta +9 -0
- package/assets/core/lib/net/net/NetManager.ts +77 -0
- package/assets/core/lib/net/net/NetManager.ts.meta +9 -0
- package/assets/core/lib/net/net/NetNode.ts +471 -0
- package/assets/core/lib/net/net/NetNode.ts.meta +9 -0
- package/assets/core/lib/net/net/WebSock.ts +81 -0
- package/assets/core/lib/net/net/WebSock.ts.meta +9 -0
- package/assets/core/lib/net/net/custom/NetChannelManager.ts +41 -0
- package/assets/core/lib/net/net/custom/NetChannelManager.ts.meta +9 -0
- package/assets/core/lib/net/net/custom/NetConfig.ts +11 -0
- package/assets/core/lib/net/net/custom/NetConfig.ts.meta +9 -0
- package/assets/core/lib/net/net/custom/NetErrorCode.ts +4 -0
- package/assets/core/lib/net/net/custom/NetErrorCode.ts.meta +9 -0
- package/assets/core/lib/net/net/custom/NetGameTips.ts +53 -0
- package/assets/core/lib/net/net/custom/NetGameTips.ts.meta +9 -0
- package/assets/core/lib/net/net/custom/NetNodeGame.ts +105 -0
- package/assets/core/lib/net/net/custom/NetNodeGame.ts.meta +9 -0
- package/assets/core/lib/net/net/custom.meta +9 -0
- package/assets/core/lib/net/net/protocol/NetProtocolJson.ts +39 -0
- package/assets/core/lib/net/net/protocol/NetProtocolJson.ts.meta +9 -0
- package/assets/core/lib/net/net/protocol/NetProtocolProtobuf.ts +85 -0
- package/assets/core/lib/net/net/protocol/NetProtocolProtobuf.ts.meta +9 -0
- package/assets/core/lib/net/net/protocol.meta +9 -0
- package/assets/core/lib/net/net.meta +9 -0
- package/assets/core/lib/net/prompt.meta +9 -0
- package/assets/core/lib/net.meta +9 -0
- package/assets/core/lib/old/VM2.ts +619 -0
- package/assets/core/lib/old/VM2.ts.meta +9 -0
- package/assets/core/lib/old/ViewModel.ts +905 -0
- package/assets/core/lib/old/ViewModel.ts.meta +9 -0
- package/assets/core/lib/old/ViewSearch.ts +125 -0
- package/assets/core/lib/old/ViewSearch.ts.meta +9 -0
- package/assets/core/lib/old.meta +9 -0
- package/assets/core/lib/tabbar/TabBarComponent.ts +113 -0
- package/assets/core/lib/tabbar/TabBarComponent.ts.meta +9 -0
- package/assets/core/lib/tabbar/TabBarController.ts +86 -0
- package/assets/core/lib/tabbar/TabBarController.ts.meta +9 -0
- package/assets/core/lib/tabbar/TabBarItem.ts +52 -0
- package/assets/core/lib/tabbar/TabBarItem.ts.meta +9 -0
- package/assets/core/lib/tabbar.meta +9 -0
- package/assets/core/lib.meta +12 -0
- package/assets/core.meta +9 -0
- package/assets.meta +9 -0
- package/index.ts +3 -0
- package/index.ts.meta +9 -0
- package/package.json +19 -0
- package/package.json.meta +11 -0
|
@@ -0,0 +1,905 @@
|
|
|
1
|
+
import {
|
|
2
|
+
_decorator,
|
|
3
|
+
assetManager,
|
|
4
|
+
ImageAsset,
|
|
5
|
+
SpriteFrame,
|
|
6
|
+
Texture2D,
|
|
7
|
+
resources,
|
|
8
|
+
log,
|
|
9
|
+
instantiate,
|
|
10
|
+
Node,
|
|
11
|
+
isValid,
|
|
12
|
+
error,
|
|
13
|
+
Label,
|
|
14
|
+
Sprite,
|
|
15
|
+
ProgressBar,
|
|
16
|
+
RichText,
|
|
17
|
+
Slider,
|
|
18
|
+
Toggle,
|
|
19
|
+
EditBox,
|
|
20
|
+
Button,
|
|
21
|
+
UITransform,
|
|
22
|
+
UIOpacity,
|
|
23
|
+
Widget,
|
|
24
|
+
LabelOutline,
|
|
25
|
+
js,
|
|
26
|
+
} from "cc";
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* DateTime = Mon Sep 26 2022 13:36:06 GMT+0800 (中国标准时间)
|
|
30
|
+
* Author = 柏白
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
const isObject = (val) => val !== null && typeof val === "object";
|
|
35
|
+
|
|
36
|
+
type vforType = { component: any; prefab: string; data: string };
|
|
37
|
+
|
|
38
|
+
type TargetMapItem = { type: string; property: string; key: string; handle: any };
|
|
39
|
+
|
|
40
|
+
export const hasChanged = (value: any, oldValue: any): boolean => !Object.is(value, oldValue);
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 数据绑定
|
|
44
|
+
*/
|
|
45
|
+
const dataBindingContainer = new WeakMap();
|
|
46
|
+
|
|
47
|
+
export const enum PropertyType {
|
|
48
|
+
V_BIND = "vbind",
|
|
49
|
+
V_FOR = "vfor",
|
|
50
|
+
V_SHOW = "vshow",
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const reactive = function (target: any, obj: any) {
|
|
54
|
+
let thiz = this;
|
|
55
|
+
const handler = {
|
|
56
|
+
get(target: object, propertyKey: PropertyKey, receiver?: any) {
|
|
57
|
+
const result = Reflect.get(target, propertyKey);
|
|
58
|
+
|
|
59
|
+
if (isObject(result) && Reflect.isExtensible(result)) {
|
|
60
|
+
const tag = thiz.rawMap.get(result) || propertyKey;
|
|
61
|
+
thiz.rawMap.set(result, tag);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// log(`get--${String(propertyKey)} -- ${result}`);
|
|
65
|
+
return isObject(result) ? reactive.call(thiz, result) : result;
|
|
66
|
+
},
|
|
67
|
+
set(target: object, propertyKey: PropertyKey, value: any, receiver?: any) {
|
|
68
|
+
// log(`set--${String(propertyKey)}--${value}`);
|
|
69
|
+
const extraInfo = { oldValue: target[propertyKey], newValue: value };
|
|
70
|
+
|
|
71
|
+
const result = Reflect.set(target, propertyKey, value);
|
|
72
|
+
emit.call(thiz, target, propertyKey, extraInfo);
|
|
73
|
+
return result;
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
deleteProperty(target: object, propertyKey) {
|
|
77
|
+
// log(`${target}--${propertyKey}被刪除`);
|
|
78
|
+
const result = Reflect.deleteProperty(target, propertyKey);
|
|
79
|
+
emit.call(thiz, target, propertyKey, {});
|
|
80
|
+
return result;
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
return new Proxy(target, handler);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const emit_handle_vbind = function (element: TargetMapItem) {
|
|
88
|
+
let { type, property, key, handle } = element;
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
const setValue = (objKey, key, value, self) => {
|
|
92
|
+
let ok = false;
|
|
93
|
+
if (!objKey && Reflect.has(self, key)) {
|
|
94
|
+
self[key] = value;
|
|
95
|
+
ok = true;
|
|
96
|
+
}
|
|
97
|
+
else if (Reflect.has(objKey, key)) {
|
|
98
|
+
objKey[key] = value;
|
|
99
|
+
ok = true;
|
|
100
|
+
}
|
|
101
|
+
else if (Reflect.has(objKey, "node")) {
|
|
102
|
+
let node = objKey.node;
|
|
103
|
+
if (Reflect.has(node, key)) {
|
|
104
|
+
node[key] = value;
|
|
105
|
+
ok = true;
|
|
106
|
+
} else {
|
|
107
|
+
if (key.indexOf(".") != -1) {
|
|
108
|
+
const keyarr = key.split(".");
|
|
109
|
+
const componentName = "cc." + keyarr[0];
|
|
110
|
+
const componentKey = keyarr[1];
|
|
111
|
+
let component = node.getComponent(componentName);
|
|
112
|
+
if (!component) component = node.addComponent(componentName);
|
|
113
|
+
if (Reflect.has(component, componentKey)) {
|
|
114
|
+
component[componentKey] = value;
|
|
115
|
+
if (component instanceof Widget) {
|
|
116
|
+
component.updateAlignment();
|
|
117
|
+
}
|
|
118
|
+
ok = true;
|
|
119
|
+
}
|
|
120
|
+
} else {
|
|
121
|
+
ok = false;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
} else if (key.indexOf(".") != -1) {
|
|
125
|
+
let node = objKey;
|
|
126
|
+
const keyarr = key.split(".");
|
|
127
|
+
const componentName = "cc." + keyarr[0];
|
|
128
|
+
const componentKey = keyarr[1];
|
|
129
|
+
let component = node.getComponent(componentName);
|
|
130
|
+
if (!component) component = node.addComponent(componentName);
|
|
131
|
+
if (Reflect.has(component, componentKey)) {
|
|
132
|
+
component[componentKey] = value;
|
|
133
|
+
if (component instanceof Widget) {
|
|
134
|
+
component.updateAlignment();
|
|
135
|
+
}
|
|
136
|
+
ok = true;
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
ok = false;
|
|
140
|
+
}
|
|
141
|
+
return ok;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
if ("string" == typeof handle) {
|
|
145
|
+
let func = funcList[key];
|
|
146
|
+
if (!func) {
|
|
147
|
+
func = commonHandler;
|
|
148
|
+
}
|
|
149
|
+
func(this, handle)
|
|
150
|
+
.then((value) => {
|
|
151
|
+
const result = setValue(this[property], key, value, this);
|
|
152
|
+
if (result == false) {
|
|
153
|
+
error(`${property} -> ${key} not find`);
|
|
154
|
+
}
|
|
155
|
+
})
|
|
156
|
+
.catch((e) => {
|
|
157
|
+
log(e);
|
|
158
|
+
});
|
|
159
|
+
} else if ("function" == typeof handle) {
|
|
160
|
+
let value = handle.call(this, this);
|
|
161
|
+
const result = setValue(this[property], key, value, this);
|
|
162
|
+
if (result == false) {
|
|
163
|
+
error(`${property} -> ${key} not find`);
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
let value = handle;
|
|
167
|
+
const result = setValue(this[property], key, value, this);
|
|
168
|
+
if (result == false) {
|
|
169
|
+
error(`${property} -> ${key} not find`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const emit_handle_vfor = function (element: TargetMapItem) {
|
|
175
|
+
let { type, property, key, handle } = element;
|
|
176
|
+
let func = vforHandler;
|
|
177
|
+
func(this, property, handle)
|
|
178
|
+
.then((result) => {
|
|
179
|
+
// log(result);
|
|
180
|
+
})
|
|
181
|
+
.catch((e) => {
|
|
182
|
+
log(e);
|
|
183
|
+
});
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const emit_handle_vshow = function (element: TargetMapItem) {
|
|
187
|
+
let { type, property, key, handle } = element;
|
|
188
|
+
let func = vshowHandler;
|
|
189
|
+
func(this, property, handle)
|
|
190
|
+
.then((result) => {
|
|
191
|
+
// log(result);
|
|
192
|
+
})
|
|
193
|
+
.catch((e) => {
|
|
194
|
+
log(e);
|
|
195
|
+
});
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
const _emit_func = {
|
|
199
|
+
vbind: emit_handle_vbind,
|
|
200
|
+
vfor: emit_handle_vfor,
|
|
201
|
+
vshow: emit_handle_vshow,
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const emit = function (target, propertyKey, extraInfo) {
|
|
205
|
+
let newValue = extraInfo?.newValue;
|
|
206
|
+
let oldValue = extraInfo?.oldValue;
|
|
207
|
+
|
|
208
|
+
if (oldValue && !hasChanged(newValue, oldValue)) return;
|
|
209
|
+
|
|
210
|
+
let cacheKey = this.rawMap.get(target);
|
|
211
|
+
|
|
212
|
+
if (isObject(newValue) && Reflect.isExtensible(newValue)) {
|
|
213
|
+
let tag = cacheKey || propertyKey;
|
|
214
|
+
this.rawMap.set(newValue, tag);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (cacheKey) {
|
|
218
|
+
propertyKey = cacheKey;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// log(`emit ${propertyKey}`)
|
|
222
|
+
let map = this.targetMap[propertyKey] || [];
|
|
223
|
+
// map.push({
|
|
224
|
+
// property: property,
|
|
225
|
+
// key: key,
|
|
226
|
+
// handle:handle
|
|
227
|
+
// })
|
|
228
|
+
for (let i = 0; i < map.length; i++) {
|
|
229
|
+
const element = map[i];
|
|
230
|
+
let { type, property, key, handle } = element;
|
|
231
|
+
_emit_func[type].call(this, element);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
const addToTagetMap = function (type, targetKeyArr, propertyKey, key, handle) {
|
|
236
|
+
if (targetKeyArr.length > 0) {
|
|
237
|
+
for (let i = 0; i < targetKeyArr.length; i++) {
|
|
238
|
+
const element = targetKeyArr[i];
|
|
239
|
+
let map = this.targetMap[element] || [];
|
|
240
|
+
map.push({
|
|
241
|
+
type: type,
|
|
242
|
+
property: propertyKey,
|
|
243
|
+
key: key,
|
|
244
|
+
handle: handle,
|
|
245
|
+
});
|
|
246
|
+
this.targetMap[element] = map;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
let funcGet = function (target: object, data: string[]) {
|
|
252
|
+
let property = data.shift();
|
|
253
|
+
if (target) {
|
|
254
|
+
if (data.length == 0) {
|
|
255
|
+
return target[property];
|
|
256
|
+
}
|
|
257
|
+
return funcGet(target[property], data);
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
let funcSet = function (target: object, data: string[], value: any) {
|
|
262
|
+
let property = data.shift();
|
|
263
|
+
if (target) {
|
|
264
|
+
if (data.length == 0) {
|
|
265
|
+
target[property] = value;
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
funcSet(target[property], data, value);
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
let getValue = function (target: object, arrStr: string[]) {
|
|
273
|
+
let values = [];
|
|
274
|
+
for (let i = 0; i < arrStr.length; i++) {
|
|
275
|
+
let element = new String(arrStr[i]);
|
|
276
|
+
element = element.replace("?", "");
|
|
277
|
+
let pointArr = element.split(".");
|
|
278
|
+
let value = funcGet(target, pointArr);
|
|
279
|
+
values.push(value);
|
|
280
|
+
}
|
|
281
|
+
return values;
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
let setValue = function (target: object, propertyStr: string, value: any) {
|
|
285
|
+
let element = new String(propertyStr);
|
|
286
|
+
element = element.replace("?", "");
|
|
287
|
+
let pointArr = element.split(".");
|
|
288
|
+
funcSet(target, pointArr, value);
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
const getHandleString = function (handle: any) {
|
|
292
|
+
if ("function" == typeof handle) {
|
|
293
|
+
handle = handle.toString();
|
|
294
|
+
} else if ("string" == typeof handle) {
|
|
295
|
+
} else {
|
|
296
|
+
handle = String(handle);
|
|
297
|
+
}
|
|
298
|
+
return handle;
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
const getTargetKeyArray = function (handle: string) {
|
|
302
|
+
let targetKeyArr = [];
|
|
303
|
+
let keys = Object.keys(this.viewModel);
|
|
304
|
+
for (let i = 0; i < keys.length; i++) {
|
|
305
|
+
const targetKey = keys[i];
|
|
306
|
+
if (handle.indexOf(`${targetKey}.`) != -1) {
|
|
307
|
+
targetKeyArr.push(targetKey);
|
|
308
|
+
}
|
|
309
|
+
if (handle.indexOf(`${targetKey}?.`) != -1) {
|
|
310
|
+
targetKeyArr.push(targetKey);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
if (handle == targetKey) {
|
|
314
|
+
targetKeyArr.push(targetKey);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (handle.indexOf(`\$\{${targetKey}\}`) != -1) {
|
|
318
|
+
targetKeyArr.push(targetKey);
|
|
319
|
+
}
|
|
320
|
+
if (handle.indexOf(`data.${targetKey}`) != -1) {
|
|
321
|
+
targetKeyArr.push(targetKey);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return targetKeyArr;
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
const getDefaultKey = function (propertyKey) {
|
|
329
|
+
let obj = this[propertyKey];
|
|
330
|
+
if (obj instanceof Label) {
|
|
331
|
+
return "string";
|
|
332
|
+
} else if (obj instanceof Sprite) {
|
|
333
|
+
return "spriteFrame";
|
|
334
|
+
} else if (obj instanceof ProgressBar) {
|
|
335
|
+
return "progress";
|
|
336
|
+
} else if (obj instanceof RichText) {
|
|
337
|
+
return "string";
|
|
338
|
+
} else if (obj instanceof Slider) {
|
|
339
|
+
return "progress";
|
|
340
|
+
} else if (obj instanceof Toggle) {
|
|
341
|
+
return "isChecked";
|
|
342
|
+
} else if (obj instanceof EditBox) {
|
|
343
|
+
return "string";
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
return "string";
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
const getEventTargetKeyString = function (handle: string) {
|
|
350
|
+
let KeyString = null;
|
|
351
|
+
let keys = Object.keys(this.viewModel);
|
|
352
|
+
for (let i = 0; i < keys.length; i++) {
|
|
353
|
+
const targetKey = keys[i];
|
|
354
|
+
if (handle == targetKey) {
|
|
355
|
+
KeyString = handle;
|
|
356
|
+
break;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
if (/\$\{(.+?)\}/.test(handle) == true) {
|
|
360
|
+
KeyString = handle.match(/\$\{(.+?)\}/g)[0];
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (handle.indexOf(`${targetKey}.`) != -1) {
|
|
364
|
+
KeyString = handle;
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (handle.indexOf(`${targetKey}?.`) != -1) {
|
|
369
|
+
KeyString = handle.replace("?", "");
|
|
370
|
+
break;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
return KeyString;
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* 双向绑定事件
|
|
379
|
+
* @param propertyKey
|
|
380
|
+
* @param key
|
|
381
|
+
* @param targetKeyString
|
|
382
|
+
*/
|
|
383
|
+
const onEvent = function (propertyKey, key, targetKeyString) {
|
|
384
|
+
if (targetKeyString) {
|
|
385
|
+
const evalValue = (keyString, value) => {
|
|
386
|
+
if ("string" == typeof value) {
|
|
387
|
+
value = `${value}`;
|
|
388
|
+
}
|
|
389
|
+
setValue(this.viewModel, keyString, value);
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
const event = (obj) => {
|
|
393
|
+
if (obj instanceof Slider) {
|
|
394
|
+
return "slide";
|
|
395
|
+
} else if (obj instanceof Toggle) {
|
|
396
|
+
return "toggle";
|
|
397
|
+
} else if (obj instanceof EditBox) {
|
|
398
|
+
return "editing-did-ended";
|
|
399
|
+
}
|
|
400
|
+
return null;
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
let obj = this[propertyKey];
|
|
404
|
+
let targetEvent = event(obj);
|
|
405
|
+
if (targetEvent) {
|
|
406
|
+
obj.node.on(
|
|
407
|
+
targetEvent,
|
|
408
|
+
(target) => {
|
|
409
|
+
evalValue(targetKeyString, target[key]);
|
|
410
|
+
},
|
|
411
|
+
this
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
const track_vbind = function (iterator: any) {
|
|
418
|
+
let { type, propertyKey, handler } = iterator;
|
|
419
|
+
|
|
420
|
+
if ("string" == typeof handler) {
|
|
421
|
+
let key = getDefaultKey.call(this, propertyKey);
|
|
422
|
+
let handle = getHandleString(handler);
|
|
423
|
+
let targetKeyArr = getTargetKeyArray.call(this, handle);
|
|
424
|
+
addToTagetMap.call(this, type, targetKeyArr, propertyKey, key, handler);
|
|
425
|
+
|
|
426
|
+
const eventTargetKeyArray = getEventTargetKeyString.call(this, handle);
|
|
427
|
+
onEvent.call(this, propertyKey, key, eventTargetKeyArray);
|
|
428
|
+
} else if ("function" == typeof handler) {
|
|
429
|
+
let key = getDefaultKey.call(this, propertyKey);
|
|
430
|
+
let handle = getHandleString(handler);
|
|
431
|
+
let targetKeyArr = getTargetKeyArray.call(this, handle);
|
|
432
|
+
addToTagetMap.call(this, type, targetKeyArr, propertyKey, key, handler);
|
|
433
|
+
} else {
|
|
434
|
+
for (const key in handler) {
|
|
435
|
+
// log(handler,propertyKey,key)
|
|
436
|
+
let handle = handler[key];
|
|
437
|
+
handle = getHandleString(handle);
|
|
438
|
+
let targetKeyArr = getTargetKeyArray.call(this, handle);
|
|
439
|
+
addToTagetMap.call(this, type, targetKeyArr, propertyKey, key, handler[key]);
|
|
440
|
+
|
|
441
|
+
if ("string" == typeof handle) {
|
|
442
|
+
const eventTargetKeyArray = getEventTargetKeyString.call(this, handle);
|
|
443
|
+
onEvent.call(this, propertyKey, key, eventTargetKeyArray);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
const track_vfor = function (iterator: any) {
|
|
450
|
+
let { type, propertyKey, handler } = iterator;
|
|
451
|
+
|
|
452
|
+
let key = "data";
|
|
453
|
+
let handle = handler[key];
|
|
454
|
+
handle = getHandleString(handle);
|
|
455
|
+
let targetKeyArr = getTargetKeyArray.call(this, handle);
|
|
456
|
+
addToTagetMap.call(this, type, targetKeyArr, propertyKey, key, handler);
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
const track_vshow = function (iterator: any) {
|
|
460
|
+
let { type, propertyKey, handler } = iterator;
|
|
461
|
+
|
|
462
|
+
let key = "show";
|
|
463
|
+
let handle = handler;
|
|
464
|
+
handle = getHandleString(handle);
|
|
465
|
+
let targetKeyArr = getTargetKeyArray.call(this, handle);
|
|
466
|
+
addToTagetMap.call(this, type, targetKeyArr, propertyKey, key, handler);
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
const _track_func = {
|
|
470
|
+
vbind: track_vbind,
|
|
471
|
+
vfor: track_vfor,
|
|
472
|
+
vshow: track_vshow,
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
const track = function (iterator: any) {
|
|
476
|
+
let { type, propertyKey, handler } = iterator;
|
|
477
|
+
_track_func[type].call(this, iterator);
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
const inject_define_data = function (key, targetDataBinding) {
|
|
481
|
+
//targetMap
|
|
482
|
+
Object.defineProperty(this, "targetMap", { value: {}, configurable: true, writable: true, enumerable: true });
|
|
483
|
+
Object.defineProperty(this, "rawMap", { value: new WeakMap(), configurable: true, writable: true, enumerable: true });
|
|
484
|
+
|
|
485
|
+
//data 数据响应注入
|
|
486
|
+
const iterator = "viewModel";
|
|
487
|
+
let newProerty = `_${iterator}`;
|
|
488
|
+
let value = this[iterator];
|
|
489
|
+
if (!value) { value = {} }
|
|
490
|
+
delete this[iterator];
|
|
491
|
+
Object.defineProperty(this, newProerty, { value: value, configurable: true, writable: true, enumerable: true });
|
|
492
|
+
this[iterator] = reactive.call(this, this[newProerty]);
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
const inject_vsearch = function (key, targetDataBinding) {
|
|
496
|
+
let propertys = targetDataBinding["vsearch"] || [];
|
|
497
|
+
if (propertys.length == 0) return;
|
|
498
|
+
|
|
499
|
+
let allNodeMap = new Map();
|
|
500
|
+
vsearchHandler(this.node, allNodeMap);
|
|
501
|
+
for (const property of propertys) {
|
|
502
|
+
let className = property.className;
|
|
503
|
+
let tag = property.tag || property.name;
|
|
504
|
+
|
|
505
|
+
let instance = allNodeMap.get(tag);
|
|
506
|
+
if (className.prototype.__classname__ != "cc.Node") {
|
|
507
|
+
instance = instance?.getComponent(className) ?? null;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
if (instance == null) {
|
|
511
|
+
error(`没有找到属性 ${key}->${tag}`);
|
|
512
|
+
continue;
|
|
513
|
+
}
|
|
514
|
+
this[property.name] = instance;
|
|
515
|
+
}
|
|
516
|
+
allNodeMap = null;
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
const inject_vclick = function (key, targetDataBinding) {
|
|
520
|
+
let propertys = targetDataBinding["vclick"] || [];
|
|
521
|
+
|
|
522
|
+
let getButtonNode = (obj) => {
|
|
523
|
+
let button = null;
|
|
524
|
+
let buttonNode = null;
|
|
525
|
+
buttonNode = obj instanceof Node ? obj : obj.node;
|
|
526
|
+
button = buttonNode.getComponent(Button);
|
|
527
|
+
if (!button) {
|
|
528
|
+
button = buttonNode.addComponent(Button);
|
|
529
|
+
}
|
|
530
|
+
return buttonNode;
|
|
531
|
+
};
|
|
532
|
+
|
|
533
|
+
for (const property of propertys) {
|
|
534
|
+
let { tag, name, handler } = property;
|
|
535
|
+
|
|
536
|
+
let func = null;
|
|
537
|
+
if ("string" == typeof handler) {
|
|
538
|
+
func = this[handler];
|
|
539
|
+
} else {
|
|
540
|
+
func = handler;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
if (!func) {
|
|
544
|
+
error(`没有找到function ${handler}`);
|
|
545
|
+
continue;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
getButtonNode(this[name]).on(
|
|
549
|
+
"click",
|
|
550
|
+
(button) => {
|
|
551
|
+
func.call(this, button, tag);
|
|
552
|
+
},
|
|
553
|
+
this
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
|
|
558
|
+
const inject_track = function (key, targetDataBinding) {
|
|
559
|
+
let property = targetDataBinding["property"] || [];
|
|
560
|
+
for (const iterator of property) {
|
|
561
|
+
track.call(this, iterator);
|
|
562
|
+
}
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
const inject_emit_default = function (key, targetDataBinding) {
|
|
566
|
+
let keys = Object.keys(this.viewModel);
|
|
567
|
+
for (let i = 0; i < keys.length; i++) {
|
|
568
|
+
const targetKey = keys[i];
|
|
569
|
+
if (this.viewModel[targetKey] != null) {
|
|
570
|
+
emit.call(this, this.viewModel, targetKey, null);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
|
|
575
|
+
const _inject_func = [inject_define_data, inject_vclick, inject_track, inject_emit_default];
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* ViewModel
|
|
579
|
+
* @param target
|
|
580
|
+
*/
|
|
581
|
+
export function ViewModel(target: any) {
|
|
582
|
+
const onLoad = target.prototype.onLoad;
|
|
583
|
+
/**
|
|
584
|
+
* 重载onload 注入更新
|
|
585
|
+
*/
|
|
586
|
+
target.prototype.onLoad = function () {
|
|
587
|
+
let classKey = js.getClassName(target);
|
|
588
|
+
let targetDataBinding = dataBindingContainer.get(target.prototype) || {};
|
|
589
|
+
console.log("vm onload", classKey, targetDataBinding);
|
|
590
|
+
for (const func of _inject_func) {
|
|
591
|
+
func.call(this, classKey, targetDataBinding);
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
//调用之前的onload
|
|
595
|
+
onLoad?.call(this);
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* 绑定点击事件
|
|
601
|
+
* @param {string | function } handler 处理点击事件的方法名称或者方法
|
|
602
|
+
* @param {any} tag 用户自定义数据
|
|
603
|
+
* @returns
|
|
604
|
+
*/
|
|
605
|
+
export function vclick(handler: any, tag?: any) {
|
|
606
|
+
return (target: any, propertyKey: string) => {
|
|
607
|
+
let targetDataBinding = dataBindingContainer.get(target) || {};
|
|
608
|
+
let propertys = targetDataBinding["vclick"] || [];
|
|
609
|
+
propertys.push({ tag: tag, name: propertyKey, handler: handler });
|
|
610
|
+
targetDataBinding["vclick"] = propertys;
|
|
611
|
+
dataBindingContainer.set(target, targetDataBinding);
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* 显示节点
|
|
617
|
+
* @param {string | function } handler function类型返回boolean值为结果
|
|
618
|
+
* @returns
|
|
619
|
+
*/
|
|
620
|
+
export function vshow(handler: any) {
|
|
621
|
+
return (target: any, propertyKey: string) => {
|
|
622
|
+
let targetDataBinding = dataBindingContainer.get(target) || {};
|
|
623
|
+
let property = targetDataBinding["property"] || [];
|
|
624
|
+
property.push({
|
|
625
|
+
type: PropertyType.V_SHOW,
|
|
626
|
+
propertyKey: propertyKey,
|
|
627
|
+
handler: handler,
|
|
628
|
+
});
|
|
629
|
+
targetDataBinding["property"] = property;
|
|
630
|
+
dataBindingContainer.set(target, targetDataBinding);
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
*循环添加预制件到容器中,一般是ScrollView Layout ToggleGrop
|
|
637
|
+
|
|
638
|
+
*@example
|
|
639
|
+
* @vfor({ prefab: "itemPrefab", component: Item, data: "goodsList" })
|
|
640
|
+
* @property(Node)
|
|
641
|
+
* content: Node = null;
|
|
642
|
+
*
|
|
643
|
+
* @param {string} handler.path 预制体名称
|
|
644
|
+
* @param {Component} handler.component 预制体脚本名称
|
|
645
|
+
* @param {string} handler.viewModel 预制体数据数组
|
|
646
|
+
* @returns
|
|
647
|
+
*/
|
|
648
|
+
export function vfor(handler: vforType) {
|
|
649
|
+
return (target: any, propertyKey: string) => {
|
|
650
|
+
let targetDataBinding = dataBindingContainer.get(target) || {};
|
|
651
|
+
let property = targetDataBinding["property"] || [];
|
|
652
|
+
property.push({
|
|
653
|
+
type: PropertyType.V_FOR,
|
|
654
|
+
propertyKey: propertyKey,
|
|
655
|
+
handler: handler,
|
|
656
|
+
});
|
|
657
|
+
targetDataBinding["property"] = property;
|
|
658
|
+
dataBindingContainer.set(target, targetDataBinding);
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
/**
|
|
663
|
+
* 绑定数据
|
|
664
|
+
* @example
|
|
665
|
+
* 绑定string
|
|
666
|
+
*
|
|
667
|
+
* @vbind('tt.aa')
|
|
668
|
+
* @property(Label)
|
|
669
|
+
* aaa: Label = null;
|
|
670
|
+
*
|
|
671
|
+
* @vbind({string:"tt.aa"})
|
|
672
|
+
* @property(Label)
|
|
673
|
+
* aaa: Label = null;
|
|
674
|
+
*
|
|
675
|
+
* @vbind((t) => (t.viewModel.myGoods.count > 2 ? `${t.viewModel.myGoods.name}物品` : `卖完了`))
|
|
676
|
+
* @property(Label)
|
|
677
|
+
* lable5: Label = null;
|
|
678
|
+
*
|
|
679
|
+
* @vbind({
|
|
680
|
+
* 'LabelOutline.color':'mydata2.color2',
|
|
681
|
+
* string: "我有物品${myGoods.name}:${myGoods.count}个",
|
|
682
|
+
* color: "mydata2.color",
|
|
683
|
+
* fontSize: "${mydata2.fontSize}",
|
|
684
|
+
* })
|
|
685
|
+
* @property(Label)
|
|
686
|
+
* lable6: Label = null;
|
|
687
|
+
*
|
|
688
|
+
* 绑定精灵图片
|
|
689
|
+
* @vbind({spriteFrame:"tt.aa"})
|
|
690
|
+
* @property(Sprite)
|
|
691
|
+
* aaa: Sprite = null;
|
|
692
|
+
*
|
|
693
|
+
* @vbind('tt.aa')
|
|
694
|
+
* @property(Sprite)
|
|
695
|
+
* aaa: Sprite = null;
|
|
696
|
+
*
|
|
697
|
+
* @vbind({
|
|
698
|
+
* spriteFrame: "myGoods2?.icon",
|
|
699
|
+
* 'UITransform.contentSize': 'mydata2.contentSize',
|
|
700
|
+
* 'UIOpacity.opacity': 'mydata2.opacity',
|
|
701
|
+
* angle: 'mydata2.angle',
|
|
702
|
+
* scale: 'mydata2.scale',
|
|
703
|
+
* })
|
|
704
|
+
* @property(Sprite)
|
|
705
|
+
* sprite2: Sprite = null;
|
|
706
|
+
*
|
|
707
|
+
* 绑定处理器
|
|
708
|
+
*
|
|
709
|
+
*
|
|
710
|
+
* @param {string | function | object} handler string类型,直接绑定数据; function类型,返回结果;object,绑定多个属性
|
|
711
|
+
* @returns
|
|
712
|
+
*/
|
|
713
|
+
export function vbind(handler: any) {
|
|
714
|
+
return (target: any, propertyKey: string) => {
|
|
715
|
+
|
|
716
|
+
let targetDataBinding = dataBindingContainer.get(target) || {};
|
|
717
|
+
let property = targetDataBinding["property"] || [];
|
|
718
|
+
property.push({
|
|
719
|
+
type: PropertyType.V_BIND,
|
|
720
|
+
propertyKey: propertyKey,
|
|
721
|
+
handler: handler,
|
|
722
|
+
});
|
|
723
|
+
targetDataBinding["property"] = property;
|
|
724
|
+
dataBindingContainer.set(target, targetDataBinding);
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
/**
|
|
729
|
+
* 字符串处理
|
|
730
|
+
* @param target
|
|
731
|
+
* @param data
|
|
732
|
+
* @returns
|
|
733
|
+
*/
|
|
734
|
+
function stringHandler(target: any, data: string): Promise<string> {
|
|
735
|
+
let split = function (handlerStr) {
|
|
736
|
+
let propertyArrString = [];
|
|
737
|
+
let stack = [];
|
|
738
|
+
for (let i = 0; i < handlerStr.length; i++) {
|
|
739
|
+
const e = handlerStr[i];
|
|
740
|
+
if ("{" == e) {
|
|
741
|
+
stack.push(i + 1);
|
|
742
|
+
} else if ("}" == e) {
|
|
743
|
+
let startPos = stack.pop();
|
|
744
|
+
let length = i - startPos;
|
|
745
|
+
let propertyStr = handlerStr.substr(startPos, length);
|
|
746
|
+
propertyArrString.push(propertyStr);
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
return propertyArrString;
|
|
750
|
+
};
|
|
751
|
+
|
|
752
|
+
let replase = function (oldString, keyArr, valueArr) {
|
|
753
|
+
let newString = new String(oldString);
|
|
754
|
+
for (let i = 0; i < keyArr.length; i++) {
|
|
755
|
+
const key = keyArr[i];
|
|
756
|
+
const value = valueArr[i];
|
|
757
|
+
newString = newString.replace(`\$\{${key}\}`, value);
|
|
758
|
+
}
|
|
759
|
+
return newString;
|
|
760
|
+
};
|
|
761
|
+
|
|
762
|
+
return new Promise((res, rej) => {
|
|
763
|
+
try {
|
|
764
|
+
let keyArr = split(data);
|
|
765
|
+
if (keyArr.length == 0) {
|
|
766
|
+
res(getValue(target.viewModel, [data])[0]);
|
|
767
|
+
} else if (keyArr.length == 1 && `\$\{${keyArr[0]}\}` == data) {
|
|
768
|
+
res(getValue(target.viewModel, keyArr)[0]);
|
|
769
|
+
} else {
|
|
770
|
+
let valueArr = getValue(target.viewModel, keyArr);
|
|
771
|
+
let newString = replase(data, keyArr, valueArr);
|
|
772
|
+
res(newString.valueOf());
|
|
773
|
+
}
|
|
774
|
+
} catch (e) {
|
|
775
|
+
rej("失败");
|
|
776
|
+
}
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
/**
|
|
781
|
+
* 图片处理
|
|
782
|
+
* @param target
|
|
783
|
+
* @param data
|
|
784
|
+
* @returns
|
|
785
|
+
*/
|
|
786
|
+
function spriteFrameHandler(target: any, data: string) {
|
|
787
|
+
return new Promise(async (res, rej) => {
|
|
788
|
+
let url = await stringHandler(target, data);
|
|
789
|
+
if (url.startsWith("http")) {
|
|
790
|
+
assetManager.loadRemote(url, { ext: ".png" }, (error: Error, data: ImageAsset) => {
|
|
791
|
+
if (!!error) {
|
|
792
|
+
rej(`${url}加载失败!`);
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
const spriteFrame = new SpriteFrame();
|
|
797
|
+
spriteFrame.packable = true;
|
|
798
|
+
const texture = new Texture2D();
|
|
799
|
+
texture.image = data;
|
|
800
|
+
spriteFrame.texture = texture;
|
|
801
|
+
res(spriteFrame);
|
|
802
|
+
});
|
|
803
|
+
} else {
|
|
804
|
+
resources.load(url + "/spriteFrame", SpriteFrame, (e: Error, spriteFrame: SpriteFrame) => {
|
|
805
|
+
if (!!e) {
|
|
806
|
+
rej(`${url}加载失败!`);
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
res(spriteFrame);
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
/**
|
|
816
|
+
*
|
|
817
|
+
* @param target
|
|
818
|
+
* @param data
|
|
819
|
+
* @returns
|
|
820
|
+
*/
|
|
821
|
+
function commonHandler(target: any, data: string): Promise<any> {
|
|
822
|
+
return stringHandler(target, data);
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
/**
|
|
826
|
+
*
|
|
827
|
+
* @param target
|
|
828
|
+
* @param property
|
|
829
|
+
* @param handle
|
|
830
|
+
* @returns
|
|
831
|
+
*/
|
|
832
|
+
function vshowHandler(target: any, property: string, handle: any) {
|
|
833
|
+
return new Promise(async (res, rej) => {
|
|
834
|
+
try {
|
|
835
|
+
let propertyIns = target[property];
|
|
836
|
+
let node = propertyIns instanceof Node ? propertyIns : propertyIns.node;
|
|
837
|
+
if ("string" == typeof handle) {
|
|
838
|
+
commonHandler(target, handle)
|
|
839
|
+
.then((value) => {
|
|
840
|
+
node.active = value;
|
|
841
|
+
})
|
|
842
|
+
.catch((e) => {
|
|
843
|
+
log(e);
|
|
844
|
+
});
|
|
845
|
+
} else if ("function" == typeof handle) {
|
|
846
|
+
node.active = handle.call(target, target);
|
|
847
|
+
} else {
|
|
848
|
+
node.active = handle;
|
|
849
|
+
}
|
|
850
|
+
res(1);
|
|
851
|
+
} catch (e) {
|
|
852
|
+
rej(e);
|
|
853
|
+
}
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
/**
|
|
858
|
+
*
|
|
859
|
+
* @param target
|
|
860
|
+
* @param property
|
|
861
|
+
* @param handle
|
|
862
|
+
* @returns
|
|
863
|
+
*/
|
|
864
|
+
function vforHandler(target: any, property: string, handle: vforType) {
|
|
865
|
+
return new Promise(async (res, rej) => {
|
|
866
|
+
try {
|
|
867
|
+
let { component, prefab, data } = handle;
|
|
868
|
+
|
|
869
|
+
let dataIns: any[] = await commonHandler(target, data);
|
|
870
|
+
let propertyIns: Node = target[property];
|
|
871
|
+
|
|
872
|
+
propertyIns.removeAllChildren();
|
|
873
|
+
for (let i = 0, length = dataIns.length; i < length; i++) {
|
|
874
|
+
const element = dataIns[i];
|
|
875
|
+
let inc = instantiate(target[prefab]);
|
|
876
|
+
let compScript = inc.getComponent(component);
|
|
877
|
+
let func_onload = compScript.onLoad;
|
|
878
|
+
compScript.onLoad = function () {
|
|
879
|
+
func_onload?.call(compScript);
|
|
880
|
+
compScript.setData(element);
|
|
881
|
+
};
|
|
882
|
+
|
|
883
|
+
propertyIns.addChild(inc);
|
|
884
|
+
}
|
|
885
|
+
res(1);
|
|
886
|
+
} catch (e) {
|
|
887
|
+
rej(e);
|
|
888
|
+
}
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
function vsearchHandler(parent: any, map: Map<string, Node>) {
|
|
893
|
+
map.set(parent.name, parent);
|
|
894
|
+
let children = parent.children;
|
|
895
|
+
for (const key in children) {
|
|
896
|
+
if (!isValid(children[key])) continue;
|
|
897
|
+
vsearchHandler(children[key], map);
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
const funcList = {
|
|
902
|
+
common: commonHandler,
|
|
903
|
+
string: stringHandler,
|
|
904
|
+
spriteFrame: spriteFrameHandler,
|
|
905
|
+
};
|