@shijiu/jsview-vue 2.1.25 → 2.1.200

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.
Files changed (80) hide show
  1. package/package.json +1 -1
  2. package/utils/JsViewEngineWidget/JsvFocusBlock.vue +1 -1
  3. package/utils/JsViewEngineWidget/JsvFocusHub.ts +123 -0
  4. package/utils/JsViewEngineWidget/JsvFocusManager.js +4 -3
  5. package/utils/JsViewEngineWidget/MetroWidget/AnimationManager.ts +145 -51
  6. package/utils/JsViewEngineWidget/MetroWidget/ListWidget.vue +51 -64
  7. package/utils/JsViewEngineWidget/MetroWidget/MetroWidget.vue +62 -71
  8. package/utils/JsViewEngineWidget/MetroWidget/MetroWidgetSetup.js +308 -613
  9. package/utils/JsViewEngineWidget/TemplateParser/CommonMetroTemplate.ts +127 -247
  10. package/utils/JsViewEngineWidget/TemplateParser/ListMetroTemplate.ts +1 -0
  11. package/utils/JsViewEngineWidget/TemplateParser/MetroTemplate.ts +36 -2
  12. package/utils/JsViewEngineWidget/WidgetCommon.ts +25 -6
  13. package/utils/JsViewPlugin/JsvAudio/{JsvAudioBrowser.vue → BrowserAudio/BrowserAudio.vue} +1 -1
  14. package/utils/JsViewPlugin/JsvAudio/index.js +1 -1
  15. package/utils/JsViewPlugin/JsvLatex/BrowserDomBuilder.js +37 -0
  16. package/utils/JsViewPlugin/JsvLatex/Color.ts +43 -0
  17. package/utils/JsViewPlugin/JsvLatex/JsvLatex.vue +159 -0
  18. package/utils/JsViewPlugin/JsvLatex/JsvLatexBridgeProxy.js +16 -0
  19. package/utils/JsViewPlugin/JsvLatex/JsvLatexBrowser.vue +59 -0
  20. package/utils/JsViewPlugin/JsvLatex/PluginLoader.js +171 -0
  21. package/utils/JsViewPlugin/JsvLatex/index.js +28 -0
  22. package/utils/JsViewPlugin/JsvLatex/mathjax-tex-svg.txt +1 -0
  23. package/utils/JsViewPlugin/JsvLatex/version.js +24 -0
  24. package/utils/JsViewPlugin/JsvLatex/version.mjs +24 -0
  25. package/utils/JsViewPlugin/index.js +2 -1
  26. package/utils/JsViewVueTools/JsvDynamicCssStyle.js +2 -52
  27. package/utils/JsViewVueTools/JsvPerformance.ts +11 -0
  28. package/utils/JsViewVueTools/JsvPreDownloader.ts +55 -11
  29. package/utils/JsViewVueTools/JsvStyleSheetsDeclarer.js +40 -0
  30. package/utils/JsViewVueTools/JsvTextureStore/CanvasTexture/CanvasTexture.ts +143 -0
  31. package/utils/JsViewVueTools/JsvTextureStore/CanvasTexture/CommandList.ts +24 -0
  32. package/utils/JsViewVueTools/JsvTextureStore/CanvasTexture/Path.ts +198 -0
  33. package/utils/JsViewVueTools/JsvTextureStore/JsvTextureStore.ts +31 -0
  34. package/utils/JsViewVueTools/JsvTextureStore/Store.ts +32 -0
  35. package/utils/JsViewVueTools/JsvTextureStore/Texture.ts +38 -0
  36. package/utils/JsViewVueTools/index.js +3 -0
  37. package/utils/JsViewVueWidget/JsvEnableRenderBreak.vue +17 -0
  38. package/utils/JsViewVueWidget/JsvFreeMoveActor/ActionRefObject.ts +6 -0
  39. package/utils/JsViewVueWidget/JsvFreeMoveActor/ActorControl.ts +144 -0
  40. package/utils/JsViewVueWidget/JsvFreeMoveActor/ActorState.ts +6 -0
  41. package/utils/JsViewVueWidget/JsvFreeMoveActor/{CallbackManager.js → CallbackManager.ts} +19 -10
  42. package/utils/JsViewVueWidget/JsvFreeMoveActor/ForgeTypeDefine.ts +45 -0
  43. package/utils/JsViewVueWidget/JsvFreeMoveActor/FreeMoveActor.vue +1 -1
  44. package/utils/JsViewVueWidget/JsvFreeMoveActor/JsvEnvBlocker.vue +124 -0
  45. package/utils/JsViewVueWidget/JsvFreeMoveActor/KeepFlags.ts +6 -0
  46. package/utils/JsViewVueWidget/JsvFreeMoveActor/SetAction.ts +553 -0
  47. package/utils/JsViewVueWidget/JsvFreeMoveActor/SetCondition.ts +138 -0
  48. package/utils/JsViewVueWidget/JsvFreeMoveActor/SetState.ts +53 -0
  49. package/utils/JsViewVueWidget/JsvFreeMoveActor/index.js +11 -1
  50. package/utils/JsViewVueWidget/JsvHole.js +1 -1
  51. package/utils/JsViewVueWidget/JsvLine/JsvLine.vue +101 -0
  52. package/utils/JsViewVueWidget/JsvLine/LineManager.js +62 -0
  53. package/utils/JsViewVueWidget/JsvLine/index.js +3 -0
  54. package/utils/JsViewVueWidget/JsvMarquee.vue +316 -139
  55. package/utils/JsViewVueWidget/JsvMindMap/CommonType.ts +1 -0
  56. package/utils/JsViewVueWidget/JsvMindMap/Constant.ts +20 -0
  57. package/utils/JsViewVueWidget/JsvMindMap/DataTree.ts +394 -0
  58. package/utils/JsViewVueWidget/JsvMindMap/Geometry.ts +277 -0
  59. package/utils/JsViewVueWidget/JsvMindMap/JsvMindMap.vue +653 -0
  60. package/utils/JsViewVueWidget/JsvMindMap/index.js +1 -0
  61. package/utils/JsViewVueWidget/JsvMindMap/rtree.js +628 -0
  62. package/utils/JsViewVueWidget/JsvNinePatch.vue +2 -2
  63. package/utils/JsViewVueWidget/JsvPieChart.vue +124 -0
  64. package/utils/JsViewVueWidget/JsvPosterImage.vue +32 -9
  65. package/utils/JsViewVueWidget/JsvPreload/BrowserPreload.vue +135 -133
  66. package/utils/JsViewVueWidget/JsvPreload/JsvPreload.vue +273 -270
  67. package/utils/JsViewVueWidget/JsvSector.vue +107 -0
  68. package/utils/JsViewVueWidget/JsvTextBox.vue +14 -1
  69. package/utils/JsViewVueWidget/JsvTextureAnim/JsvTextureAnim.vue +28 -2
  70. package/utils/JsViewVueWidget/JsvVisibleSensor/JsvVisibleSensor.vue +122 -93
  71. package/utils/JsViewVueWidget/index.js +15 -7
  72. package/utils/JsViewVueWidget/JsvFreeMoveActor/ActorControl.js +0 -112
  73. package/utils/JsViewVueWidget/JsvFreeMoveActor/CommonTools.js +0 -18
  74. package/utils/JsViewVueWidget/JsvFreeMoveActor/SetAction.js +0 -216
  75. package/utils/JsViewVueWidget/JsvFreeMoveActor/SetCondition.js +0 -66
  76. package/utils/JsViewVueWidget/JsvFreeMoveActor/SetState.js +0 -38
  77. package/utils/JsViewVueWidget/JsvFreeMoveActor/TypeDefine.js +0 -12
  78. package/utils/JsViewVueWidget/JsvTouchContainer.vue +0 -183
  79. package/utils/JsViewVueWidget/JsvTransparentDiv.vue +0 -87
  80. /package/utils/{JsViewVueWidget → JsViewPlugin/JsvAudio/BrowserAudio}/JsvSystemAudio.vue +0 -0
@@ -0,0 +1,553 @@
1
+ /*
2
+ * @Author: donglin.lu@qcast.cn
3
+ * @Date: 2023-07-18 11:14:00
4
+ * @LastEditors: donglin.lu@qcast.cn
5
+ * @Description: file content
6
+ */
7
+
8
+ import { ConditionSetBuilder, StateCmdBuilder, CmdPackBuilder, ActionCmdBuilder } from "./ForgeTypeDefine"
9
+ import { ActEventDefine } from "./ForgeTypeDefine"
10
+ import { GroupType_ActionAssoc } from "./ForgeTypeDefine"
11
+ import CallbackManager from "./CallbackManager";
12
+ import ActionRefObject from "./ActionRefObject";
13
+ import ActorState from "./ActorState";
14
+
15
+ const ConditionCmdCreator = (
16
+ builderThis: ActorPackBuilder,
17
+ setCondFunc: Function, // 条件创建处理
18
+ acts: Array<Object> | null, // 条件达成后的命令列表
19
+ isFinal: boolean, // 用于进行结束时清理临时condition
20
+ callback: Function | null // 达到条件后的callback
21
+ ) => {
22
+ let commonInfo = ConditionSetBuilder.InitCommonInfo();
23
+ ConditionSetBuilder.UpdateCommonInfo(commonInfo, GroupType_ActionAssoc);
24
+
25
+ // 创建位置条件
26
+ let conditionSet: Object = setCondFunc(commonInfo);;
27
+
28
+ let conditionSubCmds: Array<Object> = acts ? acts : [];
29
+
30
+ // 设置达到条件后的callback
31
+ if (callback) {
32
+ // callback接受参数为({xPos, yPos, xSpd, ySpd, xAcc, yAcc})
33
+ conditionSubCmds.push(builderThis._CallbackManager.buildCallbackCmd(callback));
34
+ }
35
+
36
+ if (isFinal) {
37
+ // 结束时清理临时condition
38
+ conditionSubCmds.push(StateCmdBuilder.DelActionAssocCondition());
39
+ }
40
+
41
+ // 挂载设置好的Sub command list
42
+ if (conditionSubCmds.length > 0) {
43
+ ConditionSetBuilder.SetCmdList(conditionSet, conditionSubCmds);
44
+ }
45
+
46
+ return StateCmdBuilder.NewCondition(conditionSet);
47
+ }
48
+
49
+ const ActOnActEvent = (
50
+ builderThis: ActorPackBuilder,
51
+ jsRefToken: number,
52
+ eventType: number,
53
+ acts: Array<Object> | null,
54
+ isFinal: boolean,
55
+ callback: Function): Object => {
56
+ return ConditionCmdCreator(builderThis, (commonInfo: Object) => {
57
+ return ConditionSetBuilder.OnActEvent(jsRefToken, eventType, commonInfo);
58
+ }, acts, isFinal, callback)
59
+ }
60
+
61
+ const ActOnReachPosition = (
62
+ builderThis: ActorPackBuilder,
63
+ xPos: number | undefined,
64
+ yPos: number | undefined,
65
+ acts: Array<Object> | null,
66
+ isFinal: boolean,
67
+ callback: Function | null
68
+ ): Object => {
69
+ return ConditionCmdCreator(builderThis, (commonInfo: Object) => {
70
+ return ConditionSetBuilder.ReachPosition(xPos, yPos, commonInfo);
71
+ }, acts, isFinal, callback);
72
+ }
73
+
74
+ const ActOnGetToSpeed = (
75
+ builderThis: ActorPackBuilder,
76
+ xSpeed: number | undefined,
77
+ ySpeed: number | undefined,
78
+ acts: Array<Object> | null,
79
+ isFinal: boolean,
80
+ callback: Function | null
81
+ ): Object => {
82
+ return ConditionCmdCreator(builderThis, (commonInfo: Object): Object => {
83
+ return ConditionSetBuilder.ReachSpeed(xSpeed, ySpeed, commonInfo);
84
+ }, acts, isFinal, callback);
85
+ }
86
+
87
+ const ActOnGetAcrossSpeed = (
88
+ builderThis: ActorPackBuilder,
89
+ xSpeed: number | undefined,
90
+ ySpeed: number | undefined,
91
+ acts: Array<Object> | null,
92
+ isFinal: boolean,
93
+ callback: Function | null
94
+ ): Object => {
95
+ return ConditionCmdCreator(builderThis, (commonInfo: Object): Object => {
96
+ return ConditionSetBuilder.AcrossSpeed(xSpeed, ySpeed, commonInfo);
97
+ }, acts, isFinal, callback);
98
+ }
99
+
100
+ class ActorPackBuilder {
101
+ public _CallbackManager: CallbackManager;
102
+ private _ActionTokenGen: number;
103
+
104
+ private _SpeedKeeps: number;
105
+ private _AccKeeps: number;
106
+ private _RefObj: ActionRefObject | null;
107
+ private _CommonInfoValid: boolean;
108
+
109
+ constructor(callbackManager: CallbackManager) {
110
+ this._CallbackManager = callbackManager;
111
+
112
+ this._ActionTokenGen = 1; // 自累加的token分发器, 预留0作为无效值判断
113
+
114
+ // 下一个Act指令时所保留的状态
115
+ this._SpeedKeeps = 0;
116
+ this._AccKeeps = 0;
117
+ this._RefObj = null;
118
+ this._CommonInfoValid = false;
119
+ }
120
+
121
+ public updateCommonInfo(
122
+ xySpdEnables: number,
123
+ xyAccEnables: number,
124
+ actRefObj: ActionRefObject | null
125
+ ) {
126
+ this._SpeedKeeps = xySpdEnables;
127
+ this._AccKeeps = xyAccEnables;
128
+ this._RefObj = actRefObj;
129
+
130
+ // 如果有refobj,则分发token
131
+ this._InitActRefObj(this._RefObj);
132
+
133
+ this._CommonInfoValid = true;
134
+ }
135
+
136
+ private _InitActRefObj(refObj: ActionRefObject | null) {
137
+ if (refObj) {
138
+ if (refObj.used) {
139
+ console.warn("Warn: actRef be overrided, old token=" + refObj.token);
140
+ }
141
+ refObj.token = this._ActionTokenGen++;
142
+ refObj.used = false;
143
+ }
144
+ }
145
+
146
+ private _CheckCommonInfo(): boolean {
147
+ if (!this._CommonInfoValid) {
148
+ console.error("Error: must call from new action()");
149
+ return false;
150
+ }
151
+ return true;
152
+ }
153
+
154
+ /**
155
+ * teleportTo 将Actor在下一帧直接传送到目标位置
156
+ * 注意点: 此过程可以触发所有position的cross条件,但不会触发speed的相关判断,常用于拖拽 + 边界判断
157
+ *
158
+ * @param {int} targetX 带符号整数,标识运动的目标位置,相对于Actor当前位置, 如果设置为undefined, 则表示该轴不设目标
159
+ * @param {int} targetY 带符号整数,标识运动的目标位置,相对于Actor当前位置, 如果设置为undefined, 则表示该轴不设目标
160
+ * @return CommandPack(放入run或者then的CmdPackList队列)
161
+ */
162
+ public teleportTo(
163
+ targetX: number | undefined,
164
+ targetY: number | undefined,
165
+ ) {
166
+ if (!this._BasicPreProcess("teleportTo")) {
167
+ return;
168
+ }
169
+
170
+ return this._TeleportToInner(targetX, targetY, false);
171
+ }
172
+
173
+ /**
174
+ * teleportOffset 将Actor在下一帧直接传送到目标位置
175
+ * 注意点: 此过程可以触发所有position的cross条件,但不会触发speed的相关判断,常用于拖拽 + 边界判断
176
+ *
177
+ * @param {int} offsetX 带符号整数,标识运动的目标位置,相对于Actor当前位置, 如果设置为undefined, 则表示该轴不设目标
178
+ * @param {int} offsetY 带符号整数,标识运动的目标位置,相对于Actor当前位置, 如果设置为undefined, 则表示该轴不设目标
179
+ * @return CommandPack(放入run或者then的CmdPackList队列)
180
+ */
181
+ public teleportOffset(
182
+ offsetX: number | undefined,
183
+ offsetY: number | undefined,
184
+ ) {
185
+ if (!this._BasicPreProcess("teleportOffset")) {
186
+ return;
187
+ }
188
+
189
+ return this._TeleportToInner(offsetX, offsetY, true);
190
+ }
191
+
192
+ /**
193
+ * moveTo 以给定速度移动到目标位置
194
+ *
195
+ * @param {int} targetX 带符号整数,标识运动的目标位置,相对于Actor当前位置, 如果设置为undefined, 则表示该轴不设目标
196
+ * @param {int} targetY 带符号整数,标识运动的目标位置,相对于Actor当前位置, 如果设置为undefined, 则表示该轴不设目标
197
+ * @param {double} xSpeed 运行速度,使用时会自动取绝对值,单位(pixel/帧),
198
+ * undefined时,若targetX设置, 则以另一轴速度反推此速度, 否则不改变该轴速度
199
+ * @param {double} ySpeed 运行速度,使用时会自动取绝对值,单位(pixel/帧)
200
+ * undefined时,若targetY设置, 则以另一轴速度反推此速度, 否则不改变该轴速度
201
+ * @param {function} endCallback 参数(x, y) 运动到目标位置后的回调函数, x或者y达到后即回调,以先到为准,回报当前Actor的相对于原始位置的x,y
202
+ * @return CommandPack(放入run或者then的CmdPackList队列)
203
+ */
204
+ public moveTo(
205
+ targetX: number | undefined,
206
+ targetY: number | undefined,
207
+ xSpeed: number | undefined,
208
+ ySpeed: number | undefined,
209
+ endCallback: Function | null = null
210
+ ) {
211
+ if (!this._BasicPreProcess("moveTo")) {
212
+ return;
213
+ }
214
+
215
+ // x, y 都没有速度, 无内容
216
+ if (!xSpeed && !ySpeed) {
217
+ return null;
218
+ }
219
+
220
+ // 处理步骤备忘:
221
+ // 1. 构造 command list (cmdList), 加入通过 ActionCmdBuilder 构建的各种改变速度的行为
222
+ // 2. 构筑结束的条件处理(包含回调和 delActionAssocCondtion 动作), 通过 StateCmdBuilder.NewCondtion 创建并加入 cmdList
223
+ // 3. 通过 CmdPackBuilder.InitActCmdPack,送入 cmdList 和预设好的keep, 完成commandPack构建
224
+
225
+ let cmdList: Array<Object> = [];
226
+
227
+ // 设置运动速度
228
+ cmdList.push(ActionCmdBuilder.SetArrowSpeed(targetX, targetY, xSpeed, ySpeed));
229
+
230
+ // 设置达到目标位置的condition
231
+ cmdList.push(
232
+ ActOnReachPosition(
233
+ this,
234
+ targetX, targetY,
235
+ [ActionCmdBuilder.StopMovingExact(),
236
+ this._RefObj ? StateCmdBuilder.FireActEvent(ActEventDefine.ActFinish, this._RefObj.token) : null
237
+ ],
238
+ true,
239
+ endCallback ? (actorState: ActorState) => {
240
+ endCallback?.(actorState.xPos, actorState.yPos);
241
+ } : null
242
+ )
243
+ );
244
+
245
+ //return CmdPackBuilder.InitActCmdPack(this._SpeedKeeps, this._AccKeeps, cmdList);
246
+
247
+ let c = CmdPackBuilder.InitActCmdPack(this._SpeedKeeps, this._AccKeeps, this._RefObj?.token, cmdList);
248
+ return c;
249
+ }
250
+
251
+ /*
252
+ * altSpeed 调整速度,costTime不为0时为平滑过渡
253
+ * 参数说明:
254
+ * xSpeed (double) 带符号整数,符号表示方向,标识运动的运行速度,单位(pixel/帧), 可设undefined代表不改变该轴速度
255
+ * ySpeed (double) 带符号整数,符号表示方向,标识运动的运行速度,单位(pixel/帧), 可设undefined代表不改变该轴速度
256
+ * spreadFrame (int) 选填,正整数, 变速需要经历帧数, 若为立即变速,则设置为0,或者不再设置(undefined)
257
+ * finishCallback (Function(xSpeed, ySpeed)) 选填,达到目标速度后的回调,当costTime不为0时有效
258
+ */
259
+ altSpeed(
260
+ xSpeed: number | undefined,
261
+ ySpeed: number | undefined,
262
+ spreadFrame: number | undefined,
263
+ finishCallback: Function | null = null
264
+ ) {
265
+ if (!this._BasicPreProcess("altSpeed")) {
266
+ return;
267
+ }
268
+
269
+ // 处理步骤备忘:
270
+ // 1. 构造 command list (cmdList), 加入通过 ActionCmdBuilder 构建的各种改变速度的行为
271
+ // 2. 构筑结束的条件处理(包含回调和 delActionAssocCondtion 动作), 通过 StateCmdBuilder.NewCondtion 创建并加入 cmdList
272
+ // 3. 通过 CmdPackBuilder.InitActCmdPack,送入 cmdList 和预设好的keep, 完成commandPack构建
273
+
274
+ let cmdList: Array<Object> = [];
275
+
276
+ if (isNaN(spreadFrame as number) || spreadFrame == 0) {
277
+ // 经历的帧数为0, 即为立即变速
278
+ cmdList.push(ActionCmdBuilder.SetSpeed(xSpeed, ySpeed));
279
+ return CmdPackBuilder.InitActCmdPack(this._SpeedKeeps, this._AccKeeps, this._RefObj?.token, cmdList);
280
+ } else {
281
+ // 均匀变速逻辑
282
+ cmdList.push(ActionCmdBuilder.AltSpeed(xSpeed, ySpeed, spreadFrame));
283
+
284
+ // 创建结束ConditionSet
285
+ cmdList.push(
286
+ ActOnGetToSpeed(
287
+ this,
288
+ xSpeed, ySpeed,
289
+ [ActionCmdBuilder.ResetAcc(0, 0),
290
+ this._RefObj ? StateCmdBuilder.FireActEvent(ActEventDefine.ActFinish, this._RefObj.token) : null
291
+ ],
292
+ true, // isFinal
293
+ finishCallback ? (actorState: ActorState) => {
294
+ finishCallback(actorState.xSpd, actorState.ySpd);
295
+ } : null
296
+ )
297
+ )
298
+
299
+ return CmdPackBuilder.InitActCmdPack(this._SpeedKeeps, this._AccKeeps, this._RefObj?.token, cmdList);
300
+ }
301
+ }
302
+
303
+ /*
304
+ * brakeToPosition 以当前速度开始,减速并停止到目标位置
305
+ * 参数说明:
306
+ * targetX (int) 带符号整数,目标运动终点位置,如果设置为undefined,标识不以此轴为终点
307
+ * targetY (int) 带符号整数,目标运动终点位置,如果设置为undefined,标识不以此轴为终点
308
+ * finishCallback (Function(x,y)) 运动到目标位置后的回调函数, x或者y达到后即回调,以先到为准,回报当前Actor的相对于原始位置的x,y
309
+ * rejectedCallback (Function()) 当前速度无法达到target位置时,回调此函数,然后放弃改变任何速度和加速度
310
+ */
311
+ brakeToPosition(
312
+ targetX: number | undefined,
313
+ targetY: number | undefined,
314
+ finishCallback: Function | null = null,
315
+ rejectedCallback: Function | null = null
316
+ ) {
317
+ // brakeToPosition 的设计
318
+ // 1. 由native根据当前的速度值和目标位置,计算出正好能停止到目标点的减速度
319
+ // 2. 监控native发出的内部事件 ActFinish (所以需要 ActionRefObject 的token进行动作对齐)
320
+ // 3. 当收到 ActFinish, 回调callback,标识动作完成
321
+ // 特别注意: 存在有可能以当前speed无法到达target的情况,此时由native判断出,
322
+
323
+ if (!this._RefObj) {
324
+ // 此动作的结束由native来判断和决定
325
+ // 要跟踪native的 ActFinish 事件
326
+ this._RefObj = { token: 0, used: false };
327
+ this._InitActRefObj(this._RefObj);
328
+ }
329
+
330
+ if (!this._BasicPreProcess("brakeToPosition")) {
331
+ return;
332
+ }
333
+
334
+ // 处理步骤备忘:
335
+ // 1. 构造 command list (cmdList), 加入通过 ActionCmdBuilder 构建的各种改变速度的行为
336
+ // 2. 构筑结束的条件处理(包含回调和 delActionAssocCondtion 动作), 通过 StateCmdBuilder.NewCondtion 创建并加入 cmdList
337
+ // 3. 通过 CmdPackBuilder.InitActCmdPack,送入 cmdList 和预设好的keep, 完成commandPack构建
338
+
339
+ let cmdList: Array<Object> = [];
340
+
341
+ // 通过targetX和targetY以及内部当前的 xSpeed 和 ySpeed 状态,计算 xAcc 和 yAcc, 使运动接近目标位置时停止
342
+ cmdList.push(ActionCmdBuilder.BrakeToPos(targetX, targetY));
343
+
344
+ // 创建结束ConditionSet(ActFinish)
345
+ cmdList.push(
346
+ ActOnActEvent(
347
+ this,
348
+ this._RefObj.token,
349
+ ActEventDefine.ActFinish,
350
+ null,
351
+ true,
352
+ (actorState: ActorState) => {
353
+ finishCallback?.(actorState.xPos, actorState.yPos);
354
+ }
355
+ )
356
+ );
357
+
358
+ // 创建结束ConditionSet(ActReject)
359
+ cmdList.push(
360
+ ActOnActEvent(
361
+ this,
362
+ this._RefObj.token,
363
+ ActEventDefine.ActReject,
364
+ null,
365
+ true,
366
+ () => {
367
+ rejectedCallback?.();
368
+ }
369
+ )
370
+ );
371
+
372
+ return CmdPackBuilder.InitActCmdPack(this._SpeedKeeps, this._AccKeeps, this._RefObj?.token, cmdList);
373
+ }
374
+
375
+
376
+ /*
377
+ * setSpeed
378
+ * 调整运行速度,立刻生效
379
+ *
380
+ * 参数说明:
381
+ * spdX (double) x 速度有效值,可正可负, 每帧的posX移动量, 可以传入undefined来决定此值不设置
382
+ * spdY (double) y 速度有效值,可正可负, 每帧的posY移动量, 可以传入undefined来决定此值不设置
383
+ */
384
+ setSpeed(
385
+ spdX: number | undefined,
386
+ spdY: number | undefined,
387
+ ) {
388
+ if (!this._BasicPreProcess("setSpeed")) {
389
+ return;
390
+ }
391
+
392
+ let cmdList: Array<Object> = [];
393
+ cmdList.push(ActionCmdBuilder.SetSpeed(spdX, spdY));
394
+
395
+ return CmdPackBuilder.InitActCmdPack(this._SpeedKeeps, this._AccKeeps, this._RefObj?.token, cmdList);
396
+ }
397
+
398
+ /*
399
+ * setSpeed
400
+ * 调整运行速度,立刻生效
401
+ *
402
+ * 参数说明:
403
+ * spdX (double) x 速度有效值,可正可负, 每帧的posX移动量, 可以传入undefined来决定此值不设置
404
+ * spdY (double) y 速度有效值,可正可负, 每帧的posY移动量, 可以传入undefined来决定此值不设置
405
+ */
406
+ setAccel(
407
+ accelX: number | undefined,
408
+ accelY: number | undefined,
409
+ onRevertX: Function | null = null,
410
+ onRevertY: Function | null = null
411
+ ) {
412
+ if (!this._BasicPreProcess("setAccel")) {
413
+ return;
414
+ }
415
+
416
+ // 处理步骤备忘:
417
+ // 1. 构造 command list (cmdList), 加入通过 ActionCmdBuilder 构建的各种改变速度的行为
418
+ // 2. 构筑结束的条件处理(包含回调和 delActionAssocCondtion 动作), 通过 StateCmdBuilder.NewCondtion 创建并加入 cmdList
419
+ // 3. 通过 CmdPackBuilder.InitActCmdPack,送入 cmdList 和预设好的keep, 完成commandPack构建
420
+
421
+ let cmdList: Array<Object> = [];
422
+ cmdList.push(ActionCmdBuilder.SetAccel(accelX, accelY));
423
+
424
+ // 创建拐点的condition回调
425
+ this._BuildAccelOnPole(this, cmdList, this._RefObj, onRevertX, onRevertY);
426
+
427
+ return CmdPackBuilder.InitActCmdPack(this._SpeedKeeps, this._AccKeeps, this._RefObj?.token, cmdList);
428
+ }
429
+
430
+ /*
431
+ * setSpdAndAccel
432
+ * 同时设置速度和加速度,并提供拐点回调(用于抛物线处理)
433
+ *
434
+ * 参数说明:
435
+ * spdX (double) x 速度有效值,可正可负, 每帧的posX移动量, 可以传入undefined来决定此值不设置
436
+ * spdY (double) y 速度有效值,可正可负, 每帧的posY移动量, 可以传入undefined来决定此值不设置
437
+ * accelX (double) 加速度有效值,可正可负,每帧spdX的调整量,可以传入undefined来决定此值不设置
438
+ * accelY (double) 加速度有效值,可正可负,每帧spdY的调整量,可以传入undefined来决定此值不设置
439
+ * onRevertX (function) x速度开始反向运动时,进行回调(例如抛物到达顶点)
440
+ * onRevertY (function) y速度开始反向运动时,进行回调(例如抛物到达顶点)
441
+ */
442
+ setSpdAndAccel(
443
+ spdX: number | undefined,
444
+ spdY: number | undefined,
445
+ accelX: number | undefined,
446
+ accelY: number | undefined,
447
+ onRevertX: Function | null = null,
448
+ onRevertY: Function | null = null
449
+ ) {
450
+ if (!this._BasicPreProcess("setSpdAndAccel")) {
451
+ return;
452
+ }
453
+
454
+ // 处理步骤备忘:
455
+ // 1. 构造 command list (cmdList), 加入通过 ActionCmdBuilder 构建的各种改变速度的行为
456
+ // 2. 构筑结束的条件处理(包含回调和 delActionAssocCondtion 动作), 通过 StateCmdBuilder.NewCondtion 创建并加入 cmdList
457
+ // 3. 通过 CmdPackBuilder.InitActCmdPack,送入 cmdList 和预设好的keep, 完成commandPack构建
458
+
459
+ let cmdList: Array<Object> = [];
460
+
461
+ // 设置速度和加速度值
462
+ cmdList.push(ActionCmdBuilder.SetSpeed(spdX, spdY));
463
+ cmdList.push(ActionCmdBuilder.SetAccel(accelX, accelY));
464
+
465
+ // 创建拐点的condition回调
466
+ this._BuildAccelOnPole(this, cmdList, this._RefObj, onRevertX, onRevertY);
467
+
468
+ return CmdPackBuilder.InitActCmdPack(this._SpeedKeeps, this._AccKeeps, this._RefObj?.token, cmdList);
469
+ }
470
+
471
+ /*
472
+ * stopMoving
473
+ * 停止运动
474
+ * isExact (boolean) 设置为true时, 如果在positionCondition中会按照condition的位置进行精准停止
475
+ */
476
+ stopMoving(
477
+ isExact: boolean = true
478
+ ) {
479
+ if (!this._BasicPreProcess("stopMoving")) {
480
+ return;
481
+ }
482
+
483
+ let cmdList: Array<Object> = [];
484
+ cmdList.push(isExact ? ActionCmdBuilder.StopMovingExact() : ActionCmdBuilder.StopMoving());
485
+
486
+ return CmdPackBuilder.InitActCmdPack(this._SpeedKeeps, this._AccKeeps, this._RefObj?.token, cmdList);
487
+ }
488
+
489
+ _BuildAccelOnPole(
490
+ builderThis: ActorPackBuilder,
491
+ cmdList: Array<Object>,
492
+ actRefObj: ActionRefObject | null,
493
+ onRevertX: Function | null,
494
+ onRevertY: Function | null
495
+ ) {
496
+ if (actRefObj || onRevertX || onRevertY) {
497
+ // RefObj: 外界可能希望了解速度拐点的ActEvent
498
+ // onRevertX || onRevertY: 通过callback希望了解速度拐点信息
499
+
500
+ // X轴拐点检测 newCondition
501
+ cmdList.push(
502
+ ActOnGetAcrossSpeed(
503
+ builderThis,
504
+ 0, undefined,
505
+ [actRefObj ? StateCmdBuilder.FireActEvent(ActEventDefine.SpeedRevertX, actRefObj.token) : null],
506
+ false, // isFinal
507
+ onRevertX ? () => {
508
+ onRevertX();
509
+ } : null
510
+ )
511
+ )
512
+
513
+ // Y轴拐点检测 newCondition
514
+ cmdList.push(
515
+ ActOnGetAcrossSpeed(
516
+ builderThis,
517
+ undefined, 0,
518
+ [actRefObj ? StateCmdBuilder.FireActEvent(ActEventDefine.SpeedRevertY, actRefObj.token) : null],
519
+ false, // isFinal
520
+ onRevertY ? () => {
521
+ onRevertY();
522
+ } : null
523
+ )
524
+ )
525
+ }
526
+ }
527
+
528
+ _BasicPreProcess(procName: string) {
529
+ // CommonInfo 只能使用一次,规避多次使用问题
530
+ if (!this._CheckCommonInfo()) {
531
+ return false;
532
+ }
533
+ this._CommonInfoValid = false;
534
+
535
+ if (this._RefObj) {
536
+ this._RefObj.used = true;
537
+ }
538
+
539
+ return true;
540
+ }
541
+
542
+ private _TeleportToInner(x: number | undefined, y: number | undefined, isOffset: boolean = false) {
543
+ let cmdList: Array<Object> = [];
544
+
545
+ // 传送动作
546
+ cmdList.push(ActionCmdBuilder.TeleportTo(x, y, isOffset));
547
+
548
+ let c = CmdPackBuilder.InitActCmdPack(this._SpeedKeeps, this._AccKeeps, this._RefObj?.token, cmdList);
549
+ return c;
550
+ }
551
+ }
552
+
553
+ export default ActorPackBuilder;
@@ -0,0 +1,138 @@
1
+ /*
2
+ * @Author: donglin.lu@qcast.cn
3
+ * @Date: 2023-07-18 11:14:00
4
+ * @LastEditors: donglin.lu@qcast.cn
5
+ * @Description: file content
6
+ */
7
+
8
+ import ActionRefObject from "./ActionRefObject";
9
+ import CallbackManager from "./CallbackManager";
10
+ import { ConditionSetBuilder, StateCmdBuilder, CmdPackBuilder } from "./ForgeTypeDefine"
11
+
12
+ const setChildCommnadPackList = (conditionSet: Object, callbackManager: CallbackManager, cmdPackList: Array<Object>) => {
13
+ for (let i = 0; i < cmdPackList.length; i++) {
14
+ if (typeof cmdPackList[i] == "function") {
15
+ // 将回调函数更换为对应CommandPack, 内容为 FireEcho 的 stateCommand
16
+ cmdPackList[i] = CmdPackBuilder.InitStateCmdPack(callbackManager.buildCallbackCmd(cmdPackList[i] as Function));
17
+ }
18
+ }
19
+
20
+ // 将此cmdPackList设置给ConditionSet
21
+ ConditionSetBuilder.SetCmdPackList(conditionSet, cmdPackList);
22
+ }
23
+
24
+ class ConditionPackBuilder {
25
+ public _Callbacks: CallbackManager;
26
+ private _CommonInfo: Object;
27
+ private _CommonInfoValid: boolean;
28
+
29
+ constructor(callbackManager) {
30
+ this._Callbacks = callbackManager;
31
+ this._CommonInfo = ConditionSetBuilder.InitCommonInfo();
32
+ this._CommonInfoValid = false;
33
+ }
34
+
35
+ updateCommandInfo(group: number, multiTimes: boolean, specName: string | null) {
36
+ ConditionSetBuilder.UpdateCommonInfo(this._CommonInfo, group, multiTimes, specName);
37
+ this._CommonInfoValid = true;
38
+ }
39
+
40
+ /**
41
+ * reachPosition
42
+ * 获取 ReachPosition 的condition
43
+ * x或y已经处于,或者被越过时触发
44
+ *
45
+ * @param {double} xPosition 位置有效值,可以传入undefined来决定此值不设置
46
+ * @param {double} yPosition 位置有效值,可以传入undefined来决定此值不设置
47
+ */
48
+ reachPosition(xPosition: number | undefined, yPosition: number | undefined): Object | null {
49
+ // CommonInfo 只能使用一次,规避多次使用问题
50
+ if (!this._CheckCommonInfo()) {
51
+ return null;
52
+ }
53
+ this._CommonInfoValid = false;
54
+
55
+ return this._BuildPack(ConditionSetBuilder.ReachPosition(xPosition, yPosition, this._CommonInfo));
56
+ }
57
+
58
+ /**
59
+ * AcrossPosition
60
+ * 获取 AcrossPosition 的condition
61
+ * x或y被越过时触发
62
+ *
63
+ * @param {double} xPosition 位置有效值,可以传入undefined来决定此值不设置
64
+ * @param {double} yPosition 位置有效值,可以传入undefined来决定此值不设置
65
+ */
66
+ acrossPosition(xPosition: number | undefined, yPosition: number | undefined): Object | null {
67
+ // CommonInfo 只能使用一次,规避多次使用问题
68
+ if (!this._CheckCommonInfo()) {
69
+ return null;
70
+ }
71
+ this._CommonInfoValid = false;
72
+
73
+ return this._BuildPack(ConditionSetBuilder.AcrossPosition(xPosition, yPosition, this._CommonInfo));
74
+ }
75
+
76
+ /**
77
+ * OnActEvent
78
+ * 响应 actRef 关联的 action 所发出的内部状态信息
79
+ *
80
+ * @param {ActionRefObject} actRef 一个进行Action时传给action的空的{}, 内容被action内部填写
81
+ * @param {ActEventDefine} eventType 监听的事件类型
82
+ */
83
+ onActEvent(actRef: ActionRefObject, eventType: number): Object | null {
84
+ // CommonInfo 只能使用一次,规避多次使用问题
85
+ if (!this._CheckCommonInfo()) {
86
+ return null;
87
+ }
88
+ this._CommonInfoValid = false;
89
+
90
+ if (isNaN(actRef?.token) || isNaN(eventType)) {
91
+ // 类型不符合
92
+ console.error("onActEvent params error", actRef, eventType);
93
+ return null;
94
+ }
95
+
96
+ return this._BuildPack(ConditionSetBuilder.OnActEvent(actRef.token, eventType, this._CommonInfo));
97
+ }
98
+
99
+ /**
100
+ * OnHitBlock
101
+ * 监听Actor关联的LayoutView与blocker碰撞的状态
102
+ * 碰撞发生后,可以 State.revertWithHitBlock 将LayoutView返回到紧贴到碰撞点的状态
103
+ *
104
+ * @param {Number} blkGID 想监听的blocker集群的组ID, 例如所有的跳板横向碰撞面,或者所有的跳板边缘的纵向碰撞面, 0为无效值
105
+ */
106
+ OnHitBlock(blkGID: Number) {
107
+ // CommonInfo 只能使用一次,规避多次使用问题
108
+ if (!this._CheckCommonInfo()) {
109
+ return null;
110
+ }
111
+ this._CommonInfoValid = false;
112
+
113
+ return this._BuildPack(ConditionSetBuilder.OnHitBlock(blkGID, this._CommonInfo));
114
+ }
115
+
116
+ _CheckCommonInfo(): boolean {
117
+ if (!this._CommonInfoValid) {
118
+ console.error("Error: must call from new conditoin()");
119
+ return false;
120
+ }
121
+ return true;
122
+ }
123
+
124
+ _BuildPack(conditionSet: Object) {
125
+ let cmdPack = CmdPackBuilder.InitStateCmdPack(StateCmdBuilder.NewCondition(conditionSet));
126
+
127
+ // 追加then处理
128
+ let callbackManager = this._Callbacks;
129
+ cmdPack["then"] = (childCmdPackList: Array<Object>) => {
130
+ setChildCommnadPackList(conditionSet, callbackManager, childCmdPackList);
131
+ return cmdPack;
132
+ };
133
+
134
+ return cmdPack;
135
+ }
136
+ }
137
+
138
+ export default ConditionPackBuilder;