@ives_xxz/framework 2.1.7 → 2.1.9

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.
@@ -21,9 +21,13 @@ type ParamType = {
21
21
  };
22
22
 
23
23
  export function FWPropertyNode($opt?: ParamType): FW.PropertyDecorator {
24
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
25
24
  return ($target, $propertyKey: string, $descriptorOrInitializer) => {
26
- const cache: { propertyKey: string; childName: string }[] = ($target[KeyChild] ??= []);
25
+ if (!$target.hasOwnProperty(KeyChild)) {
26
+ $target[KeyChild] = [];
27
+ }
28
+
29
+ const cache: { propertyKey: string; childName: string }[] = $target[KeyChild];
30
+
27
31
  if (!cache.some(($vo) => $vo.propertyKey === $propertyKey)) {
28
32
  cache.push({
29
33
  propertyKey: $propertyKey,
@@ -32,6 +36,7 @@ export function FWPropertyNode($opt?: ParamType): FW.PropertyDecorator {
32
36
  } else {
33
37
  throw new Error(`child 装饰器重复绑定属性:${$propertyKey},class:${$target?.name}`);
34
38
  }
39
+
35
40
  if (cache.length === 1) {
36
41
  const oldOnLoad: () => void = $target.onLoad || undefined;
37
42
  $target.onLoad = function () {
@@ -42,22 +47,19 @@ export function FWPropertyNode($opt?: ParamType): FW.PropertyDecorator {
42
47
  };
43
48
  }
44
49
 
45
- const KeyChildMulti = CookDecoratorKey('child_cache_multi'); // 重新定义 Key,避免冲突
50
+ const KeyChildMulti = CookDecoratorKey('child_cache_multi');
46
51
 
47
52
  /** 查找多个节点,并存储为数组 */
48
53
  export function FWPropertyNodes(...paths: string[]): FW.PropertyDecorator {
49
54
  return ($target: any, $propertyKey: string) => {
50
- // 确保 $target[KeyChild] 是数组
51
- if (!$target[KeyChildMulti]) {
55
+ if (!$target.hasOwnProperty(KeyChildMulti)) {
52
56
  $target[KeyChildMulti] = [];
53
57
  }
54
58
 
55
59
  const cache: { propertyKey: string; childNames: string[] }[] = $target[KeyChildMulti];
56
60
 
57
- // 查找是否已经存在该属性的绑定
58
61
  const existingEntry = cache.find(($vo) => $vo.propertyKey === $propertyKey);
59
62
 
60
- // 如果没有找到绑定,则添加
61
63
  if (!existingEntry) {
62
64
  cache.push({
63
65
  propertyKey: $propertyKey,
@@ -69,7 +71,6 @@ export function FWPropertyNodes(...paths: string[]): FW.PropertyDecorator {
69
71
  );
70
72
  }
71
73
 
72
- // 确保只绑定一次 onLoad,防止重复调用
73
74
  if (cache.length === 1) {
74
75
  const oldOnLoad = $target.onLoad;
75
76
 
@@ -81,7 +82,6 @@ export function FWPropertyNodes(...paths: string[]): FW.PropertyDecorator {
81
82
  cache.forEach(($vo) => {
82
83
  const nodes: cc.Node[] = [];
83
84
 
84
- // 将所有路径对应的节点存入数组
85
85
  $vo.childNames.forEach((childName) => {
86
86
  const childNode = searchChild(this.node, childName);
87
87
  if (!childNode) {
@@ -91,11 +91,9 @@ export function FWPropertyNodes(...paths: string[]): FW.PropertyDecorator {
91
91
  }
92
92
  });
93
93
 
94
- // 将结果赋值为数组,保证拿到所有节点
95
94
  this[$vo.propertyKey] = nodes;
96
95
  });
97
96
 
98
- // 调用父类 onLoad 方法
99
97
  if (oldOnLoad) {
100
98
  oldOnLoad.apply(this);
101
99
  }
@@ -116,11 +114,15 @@ export function FWPropertyComponent(
116
114
  $mute = false,
117
115
  ): FW.PropertyDecorator {
118
116
  return ($target, $propertyKey: string, $descriptorOrInitializer) => {
117
+ if (!$target.hasOwnProperty(KeyComp)) {
118
+ $target[KeyComp] = [];
119
+ }
119
120
  const cache: {
120
121
  propertyKey: string;
121
122
  compClass: INewable<cc.Component>;
122
123
  childName: string;
123
- }[] = ($target[KeyComp] ??= []);
124
+ }[] = $target[KeyComp];
125
+
124
126
  if (!cache.some(($vo) => $vo.propertyKey === $propertyKey)) {
125
127
  cache.push({
126
128
  propertyKey: $propertyKey,
@@ -162,7 +164,7 @@ export function FWPropertyComponents(
162
164
  ): FW.PropertyDecorator {
163
165
  return ($target, $propertyKey: string, $descriptorOrInitializer) => {
164
166
  const componentName = $childName || $propertyKey;
165
- const oldOnLoad: () => void = $target.onLoad || undefined; //$target.onLoad也可以拿到父类的实现
167
+ const oldOnLoad: () => void = $target.onLoad || undefined;
166
168
  $target.onLoad = function () {
167
169
  const components = this.node.getComponentsInChildren($componentClass);
168
170
  if (components.length == 0) return;
@@ -192,7 +194,6 @@ export function isNull(message?: string) {
192
194
  value = newVal;
193
195
  };
194
196
 
195
- // 使用 defineProperty 来替换原来的属性
196
197
  Object.defineProperty(target, propertyKey, {
197
198
  get: getter,
198
199
  set: setter,
@@ -96,34 +96,37 @@ export default class FWAudioManager extends FWManager implements FW.AudioManager
96
96
  ): Promise<number>;
97
97
  async play(): Promise<number> {
98
98
  try {
99
- if (this.audioPool.size >= this.maxConcurrentAudio) {
100
- this.clearFinishedAudio();
99
+ return new Promise<number>(async (resolve, reject) => {
101
100
  if (this.audioPool.size >= this.maxConcurrentAudio) {
102
- FW.Log.warn('音频池已满,无法播放新音频');
103
- return -1;
101
+ this.clearFinishedAudio();
102
+ if (this.audioPool.size >= this.maxConcurrentAudio) {
103
+ FW.Log.warn('音频池已满,无法播放新音频');
104
+ return -1;
105
+ }
104
106
  }
105
- }
106
107
 
107
- const audioData = await this.processAudioArguments(
108
- arguments,
109
- FW.SystemDefine.FWAudioType.SOUND,
110
- );
111
- if (!audioData.clip) return -1;
108
+ const audioData = await this.processAudioArguments(
109
+ arguments,
110
+ FW.SystemDefine.FWAudioType.SOUND,
111
+ );
112
+ if (!audioData.clip) return -1;
112
113
 
113
- const volume = (audioData.volume ?? this.soundVolume) * this.effectsVolume;
114
- const loop = audioData.loop ?? false;
115
- const tag = audioData.tag;
114
+ const volume = (audioData.volume ?? this.soundVolume) * this.effectsVolume;
115
+ const loop = audioData.loop ?? false;
116
+ const tag = audioData.tag;
116
117
 
117
- const id = cc.audioEngine.play(audioData.clip, loop, volume);
118
+ const id = cc.audioEngine.play(audioData.clip, loop, volume);
118
119
 
119
- this.audioPool.set(id, new FWAudioPoolItem(id, Date.now(), tag));
120
+ this.audioPool.set(id, new FWAudioPoolItem(id, Date.now(), tag));
120
121
 
121
- cc.audioEngine.setFinishCallback(id, () => {
122
- audioData.cb?.(id);
123
- this.audioPool.delete(id);
124
- });
122
+ cc.audioEngine.setFinishCallback(id, () => {
123
+ audioData.cb?.(id);
124
+ resolve(id);
125
+ this.audioPool.delete(id);
126
+ });
125
127
 
126
- return id;
128
+ return id;
129
+ });
127
130
  } catch (e) {
128
131
  FW.Log.error('播放音效失败:', e);
129
132
  return -1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ives_xxz/framework",
3
- "version": "2.1.7",
3
+ "version": "2.1.9",
4
4
  "description": "cocoscreator 2.x mvc framework",
5
5
  "main": "index.js",
6
6
  "keywords": ["123456"],