@shijiu/jsview-vue 0.9.254 → 0.9.267
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/dom/bin/package.json +11 -11
- package/dom/browser-root-style.css +21 -21
- package/loader/jsview-main.js +41 -41
- package/loader/jsview.config.default.js +37 -37
- package/loader/jsview.default.config.js +37 -37
- package/package.json +1 -5
- package/samples/AdvanceMetroWidget/App.vue +122 -122
- package/samples/AdvanceMetroWidget/Frame.vue +100 -100
- package/samples/AdvanceMetroWidget/Item.vue +57 -57
- package/samples/AdvanceMetroWidget/data.js +136 -136
- package/samples/AnimPicture/App.vue +223 -223
- package/samples/Basic/App.vue +128 -128
- package/samples/Basic/components/TitleBar.vue +28 -28
- package/samples/Basic/components/anim/AnimGroup.vue +67 -67
- package/samples/Basic/components/anim/AnimKeyframeBasic.vue +101 -101
- package/samples/Basic/components/anim/AnimKeyframeComposite.vue +52 -52
- package/samples/Basic/components/anim/AnimTransition.vue +116 -116
- package/samples/Basic/components/div/DivBackground.vue +14 -14
- package/samples/Basic/components/div/DivClip.vue +80 -80
- package/samples/Basic/components/div/DivCssScoped.vue +26 -26
- package/samples/Basic/components/div/DivCssVar.vue +49 -49
- package/samples/Basic/components/div/DivGroup1.vue +32 -32
- package/samples/Basic/components/div/DivGroup2.vue +40 -40
- package/samples/Basic/components/div/DivLayout.vue +11 -11
- package/samples/Basic/components/div/DivRadius.vue +46 -46
- package/samples/Basic/components/text/TextAlign.vue +47 -47
- package/samples/Basic/components/text/TextFontStyle.vue +57 -57
- package/samples/Basic/components/text/TextGroup.vue +31 -31
- package/samples/Basic/components/text/TextOverflow.vue +77 -77
- package/samples/BasicFocusControl/App.vue +124 -124
- package/samples/BasicFocusControl/components/BaseBlock.vue +50 -50
- package/samples/BasicFocusControl/components/MainArea.vue +97 -97
- package/samples/BasicFocusControl/components/MainAreaLeftBlock.vue +20 -20
- package/samples/BasicFocusControl/components/MainAreaRightBlock.vue +29 -29
- package/samples/BasicFocusControl/components/SideBar.vue +72 -72
- package/samples/BasicFocusControl/components/SideBarBlock.vue +29 -29
- package/samples/ClassNameDemo/App.vue +119 -119
- package/samples/ClassNameDemo/components/ContentItem.vue +252 -252
- package/samples/ClassNameDemo/components/LoadingView.vue +43 -43
- package/samples/ClassNameDemo/components/TitleView.vue +24 -24
- package/samples/ClassNameDemo/data.js +24 -24
- package/samples/ColorSpace/App.vue +134 -134
- package/samples/DemoHomepage/App.vue +31 -31
- package/samples/DemoHomepage/components/BodyFrame.vue +81 -81
- package/samples/DemoHomepage/components/Dialog.vue +93 -93
- package/samples/DemoHomepage/components/Item.vue +76 -76
- package/samples/DemoHomepage/components/TabFrame.vue +86 -86
- package/samples/DemoHomepage/router.js +132 -132
- package/samples/DemoHomepage/views/Homepage.vue +186 -186
- package/samples/FlipCard/App.vue +80 -80
- package/samples/FlipCard/FlipCard.vue +123 -123
- package/samples/FlipCard/data.js +12 -12
- package/samples/FlowMultiWidget/App.vue +90 -90
- package/samples/FlowMultiWidget/components/Block.vue +106 -106
- package/samples/FlowMultiWidget/components/FlowPage.vue +59 -59
- package/samples/FlowMultiWidget/components/Item.vue +102 -102
- package/samples/FlowMultiWidget/components/MenuItem.vue +71 -71
- package/samples/FlowMultiWidget/components/MyMenu.vue +89 -89
- package/samples/FlowMultiWidget/data.js +446 -446
- package/samples/HashHistory/App.vue +124 -124
- package/samples/HashHistory/components/HorizontalButtonList.vue +113 -113
- package/samples/HashHistory/components/Item.vue +73 -73
- package/samples/HashHistory/router.js +29 -29
- package/samples/HashHistory/views/BasePage.vue +18 -18
- package/samples/HashHistory/views/MainPage.vue +67 -67
- package/samples/HashHistory/views/SubPage.vue +78 -78
- package/samples/HashHistory/views/SubPageFirst.vue +9 -9
- package/samples/HashHistory/views/SubPageSecond.vue +9 -9
- package/samples/LongImage/App.vue +96 -96
- package/samples/LongImage/Button.vue +153 -153
- package/samples/LongImage/LongImageScroll.vue +126 -126
- package/samples/LongImage/Scroll.vue +15 -15
- package/samples/LongText/App.vue +111 -111
- package/samples/LongText/Button.vue +153 -153
- package/samples/LongText/LongTextScroll.vue +224 -224
- package/samples/LongText/Scroll.vue +15 -15
- package/samples/Preload/App.vue +145 -145
- package/samples/Preload/data.js +22 -22
- package/samples/Preload/preloadItem.vue +21 -21
- package/samples/QrcodeDemo/App.vue +72 -72
- package/samples/SimpleWidgetDemo/App.vue +203 -203
- package/samples/SimpleWidgetDemo/Item.vue +82 -82
- package/samples/SimpleWidgetDemo/components/ContentItem.vue +411 -411
- package/samples/SimpleWidgetDemo/components/MyTab.vue +116 -116
- package/samples/SimpleWidgetDemo/data.js +110 -110
- package/samples/SprayView/App.vue +269 -269
- package/samples/SpriteImage/App.vue +174 -174
- package/samples/SpriteImage/images/egg_break.json +116 -116
- package/samples/TextBox/App.vue +178 -178
- package/samples/TextBox/RenderCenter.vue +108 -108
- package/samples/TextBox/RenderLeft.vue +108 -108
- package/samples/TextBox/RenderOneLine.vue +119 -119
- package/samples/TextBox/RenderRight.vue +106 -106
- package/samples/TextShadowDemo/App.vue +97 -97
- package/samples/TextureSize/App.vue +141 -141
- package/samples/ThrowMoveDemo/AccelerateDemo.vue +117 -117
- package/samples/ThrowMoveDemo/App.vue +113 -113
- package/samples/ThrowMoveDemo/LRParabolicDemo.vue +115 -115
- package/samples/ThrowMoveDemo/TargetDemo.vue +116 -116
- package/samples/ThrowMoveDemo/UDParabolicDemo.vue +121 -121
- package/samples/TransitPage/App.vue +40 -40
- package/samples/VideoDemo/App.vue +137 -137
- package/samples/VideoDemo/components/Button.vue +68 -68
- package/samples/VideoDemo/components/Controllor.vue +195 -195
- package/samples/VideoDemo/components/VideoFrame.vue +152 -152
- package/scripts/common.js +57 -115
- package/scripts/jsview-install-local-packages.js +73 -73
- package/scripts/jsview-post-build.js +127 -127
- package/scripts/jsview-post-install.js +78 -78
- package/scripts/jsview-run-android.js +64 -64
- package/utils/JsViewEngineWidget/bin/index.js +1 -1
- package/utils/JsViewEngineWidget/bin/package.json +11 -11
- package/utils/JsViewVueTools/JsvHashHistory.js +111 -111
- package/utils/JsViewVueTools/JsvRuntimeBridge.js +417 -417
- package/utils/JsViewVueWidget/BrowserDebugWidget/BrowserPreload.vue +80 -80
- package/utils/JsViewVueWidget/BrowserDebugWidget/BrowserQrcode.vue +147 -147
- package/utils/JsViewVueWidget/BrowserDebugWidget/BrowserSpray.vue +54 -54
- package/utils/JsViewVueWidget/BrowserDebugWidget/JsvApic/ApicDataBase.js +28 -28
- package/utils/JsViewVueWidget/BrowserDebugWidget/JsvApic/BrowserApic.vue +123 -123
- package/utils/JsViewVueWidget/BrowserDebugWidget/JsvApic/GifData.js +83 -83
- package/utils/JsViewVueWidget/BrowserDebugWidget/JsvApic/LoopToolBase.js +25 -25
- package/utils/JsViewVueWidget/BrowserDebugWidget/JsvApic/NormalLoopTool.js +61 -61
- package/utils/JsViewVueWidget/BrowserDebugWidget/JsvApic/PartLoopTool.js +119 -119
- package/utils/JsViewVueWidget/BrowserDebugWidget/JsvApic/Viewer.js +106 -106
- package/utils/JsViewVueWidget/BrowserDebugWidget/JsvApic/WebpData.js +141 -141
- package/utils/JsViewVueWidget/BrowserDebugWidget/WidgetLoader.js +20 -20
- package/utils/JsViewVueWidget/JsvActorMove/ActorControlBase.js +204 -204
- package/utils/JsViewVueWidget/JsvActorMove/JsvActorMove.vue +63 -63
- package/utils/JsViewVueWidget/JsvActorMove/JsvActorMoveControl.js +426 -426
- package/utils/JsViewVueWidget/JsvActorMove/index.js +12 -12
- package/utils/JsViewVueWidget/JsvApic/JsvApic.vue +178 -178
- package/utils/JsViewVueWidget/JsvApic/index.js +17 -17
- package/utils/JsViewVueWidget/JsvMarquee.vue +196 -196
- package/utils/JsViewVueWidget/JsvNinePatch.vue +76 -76
- package/utils/JsViewVueWidget/JsvPreload/JsvPreload.vue +350 -350
- package/utils/JsViewVueWidget/JsvPreload/index.js +21 -21
- package/utils/JsViewVueWidget/JsvQrcode/JsvQrcode.vue +140 -140
- package/utils/JsViewVueWidget/JsvQrcode/index.js +18 -18
- package/utils/JsViewVueWidget/JsvSpray/JsvSpray.vue +139 -139
- package/utils/JsViewVueWidget/JsvSpray/index.js +14 -14
- package/utils/JsViewVueWidget/JsvSpriteAnim/JsvSpriteAnim.vue +447 -447
- package/utils/JsViewVueWidget/JsvSpriteAnim/SpriteController.js +56 -56
- package/utils/JsViewVueWidget/JsvSpriteAnim/index.js +6 -6
- package/utils/JsViewVueWidget/JsvSwiper/Indicator.vue +34 -34
- package/utils/JsViewVueWidget/JsvSwiper/JsvSwiper.vue +494 -494
- package/utils/JsViewVueWidget/JsvSwiper/index.js +9 -9
- package/utils/JsViewVueWidget/JsvSwiper3D/Indicator.vue +34 -34
- package/utils/JsViewVueWidget/JsvSwiper3D/JsvSwiper.vue +403 -403
- package/utils/JsViewVueWidget/JsvSwiper3D/index.js +9 -9
- package/utils/JsViewVueWidget/JsvTextBox.vue +110 -110
- package/utils/JsViewVueWidget/JsvVideo.vue +35 -35
- package/patches/node_modules/@babel/preset-env/lib/available-plugins.js +0 -219
- package/patches/node_modules/@vue/cli-plugin-typescript/index.js +0 -100
- package/patches/node_modules/@vue/cli-service/lib/commands/serve.js +0 -395
- package/patches/node_modules/@vue/cli-service/lib/config/app.js +0 -272
- package/patches/node_modules/@vue/cli-service/lib/config/assets.js +0 -70
- package/patches/node_modules/@vue/cli-service/lib/config/base.js +0 -212
- package/patches/node_modules/@vue/compiler-sfc/dist/compiler-sfc.cjs.js +0 -2566
- package/patches/node_modules/@vue/compiler-sfc/dist/jsview-css-to-js.js +0 -274
- package/patches/node_modules/@vue/runtime-dom/dist/runtime-dom.esm-bundler.js +0 -1596
- package/patches/node_modules/postcss-js/objectifier.js +0 -90
- package/patches/node_modules/vue-loader/dist/resolveScript.js +0 -70
- package/scripts/deploy-fast-pack.js +0 -17
- package/scripts/deploy-fast-publish.js +0 -44
- package/scripts/deploy-git-commit-empty.js +0 -21
- package/scripts/deploy-prepare.js +0 -56
- package/scripts/make-js.sh +0 -181
- package/vetur.config.js +0 -5
|
@@ -1,427 +1,427 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Author: ChenChanghua
|
|
3
|
-
* @Date: 2021-10-20 17:04:26
|
|
4
|
-
* @LastEditors: ChenChanghua
|
|
5
|
-
* @LastEditTime: 2021-10-21 13:17:05
|
|
6
|
-
* @Description: file content
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { Forge } from "../../../dom/jsv-forge-define";
|
|
10
|
-
import ActorControlBase from "./ActorControlBase";
|
|
11
|
-
|
|
12
|
-
const CONST_MOVE_TYPE_ACC = 1; // 抛物变速运动
|
|
13
|
-
const CONST_MOVE_TYPE_UNIFORM = 2; // 匀速运动
|
|
14
|
-
const CONST_MOVE_TYPE_JUMP = 3; // 无动画,直接调整坐标到目标位置
|
|
15
|
-
|
|
16
|
-
// 单向运动控制模块,单方向指的是只能进行一个方向的运动,要不是x,要不是y
|
|
17
|
-
class JsvActorMoveControl extends ActorControlBase {
|
|
18
|
-
constructor() {
|
|
19
|
-
// 0: X位置,
|
|
20
|
-
// 1: Y位置,
|
|
21
|
-
super(2);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/*
|
|
25
|
-
* moveToX 参数说明:
|
|
26
|
-
* paused_callback (Function(x,y)) 运动暂停完成后的回调,回报当前JsvActorMove的相对x,y
|
|
27
|
-
*/
|
|
28
|
-
pause(paused_callback) {
|
|
29
|
-
super.pause(paused_callback);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/*
|
|
33
|
-
* moveToX 参数说明:
|
|
34
|
-
* target_x (int) 带符号整数,标识运动的目标位置,相对于JsvActorMove当前位置
|
|
35
|
-
* speed (int) 带符号整数,符号表示方向,标识运动的运行速度,单位(pixel/s)
|
|
36
|
-
* end_callback (Function(x,y)) 运动到目标位置后的回调函数,回报当前JsvActorMove的相对x,y
|
|
37
|
-
*/
|
|
38
|
-
moveToX(target_x, speed, end_callback) {
|
|
39
|
-
this._UniformMove(0, target_x, NaN, speed, null, end_callback);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/*
|
|
43
|
-
* moveToY 参数说明:
|
|
44
|
-
* target_y (int) 带符号整数,标识运动的目标位置,相对于JsvActorMove当前位置
|
|
45
|
-
* speed (int) 带符号整数,符号表示方向,标识运动的运行速度,单位(pixel/s)
|
|
46
|
-
* end_callback (Function(x,y)) 运动到目标位置后的回调函数,回报当前JsvActorMove的相对x,y
|
|
47
|
-
*/
|
|
48
|
-
moveToY(target_y, speed, end_callback) {
|
|
49
|
-
this._UniformMove(1, NaN, target_y, speed, null, end_callback);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/*
|
|
53
|
-
* repeatMoveAlongX 参数说明:
|
|
54
|
-
* target_x (int) 带符号整数,标识运动的目标位置,相对于JsvActorMove当前位置
|
|
55
|
-
* speed (int) 带符号整数,符号表示方向,标识运动的运行速度,单位(pixel/s)
|
|
56
|
-
* repeat_start (int) 带符号整数,标识往复运动的起始点,使用时注意,JsvActorMove的当前位置必须在
|
|
57
|
-
* repeat_start和target_x之间
|
|
58
|
-
* repeat_callback (Function(times)) 完整一个运动周期后的回调,返回当前运动的周期数times
|
|
59
|
-
*/
|
|
60
|
-
repeatMoveAlongX(target_x, speed, repeat_start, repeat_callback) {
|
|
61
|
-
this._UniformMove(0,
|
|
62
|
-
target_x, NaN, speed,
|
|
63
|
-
{
|
|
64
|
-
start: repeat_start,
|
|
65
|
-
repeatCallback: repeat_callback,
|
|
66
|
-
},
|
|
67
|
-
null);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/*
|
|
71
|
-
* repeatMoveAlongY 参数说明:
|
|
72
|
-
* target_y (int) 带符号整数,标识运动的目标位置,相对于JsvActorMove当前位置
|
|
73
|
-
* speed (int) 带符号整数,符号表示方向,标识运动的运行速度,单位(pixel/s)
|
|
74
|
-
* repeat_start (int) 带符号整数,标识往复运动的起始点,使用时注意,JsvActorMove的当前位置必须在
|
|
75
|
-
* repeat_start和target_y之间
|
|
76
|
-
* repeat_callback (Function(times)) 完整一个运动周期后的回调,返回当前运动的周期数times
|
|
77
|
-
*/
|
|
78
|
-
repeatMoveAlongY(target_y, speed, repeat_start, repeat_callback) {
|
|
79
|
-
this._UniformMove(1,
|
|
80
|
-
NaN, target_y, speed,
|
|
81
|
-
{
|
|
82
|
-
start: repeat_start,
|
|
83
|
-
repeatCallback: repeat_callback,
|
|
84
|
-
},
|
|
85
|
-
null);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
_UniformMove(x_or_y, target_x, target_y, speed, repeat_set, end_callback) {
|
|
89
|
-
const start_params = {
|
|
90
|
-
type: CONST_MOVE_TYPE_UNIFORM,
|
|
91
|
-
xOrY: x_or_y,
|
|
92
|
-
speed,
|
|
93
|
-
repeatSet: repeat_set,
|
|
94
|
-
};
|
|
95
|
-
this._Target[0] = target_x;
|
|
96
|
-
this._Target[1] = target_y;
|
|
97
|
-
super.start(start_params, end_callback);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/*
|
|
101
|
-
* throwAlongX 参数说明:
|
|
102
|
-
* init_v (int) 带符号整形,描素运动初速度,单位(pixel/s)
|
|
103
|
-
* acc (int) 带符号整形,描素运动的加速度,单位(pixel/(s*s))
|
|
104
|
-
* end_condition (Object) 动画结束的条件设定
|
|
105
|
-
* 格式{type:"catch", position:xxx, offset:xxx, direction: 1 or -1}
|
|
106
|
-
* 例如:
|
|
107
|
-
* 1. X轴方向运动,在相对于起始点右方30px位置,接住向上运动的物体时,
|
|
108
|
-
* 设置 direction = -1, offset = -30
|
|
109
|
-
* 2. X轴方向运动,在相对于起始点左方30px位置,接住运动到右边界后回旋向左的运动的物体时,
|
|
110
|
-
* 设置 direction = 1, offset = 30
|
|
111
|
-
* position为相对于元素0点位置的绝对坐标,和offset的设定二选一
|
|
112
|
-
* end_callback (Function(x,y)) 运动到目标位置后的回调函数,回报当前JsvActorMove的相对x,y
|
|
113
|
-
* pole_callback (Function(void)) 动画运行到拐点时的回调
|
|
114
|
-
*/
|
|
115
|
-
throwAlongX(init_v, acc, end_condition, end_callback, pole_callback) {
|
|
116
|
-
this._Throw(0, init_v, acc, end_condition, end_callback, pole_callback);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/*
|
|
120
|
-
* throwAlongY 参数说明:
|
|
121
|
-
* init_v (int) 带符号整形,描素运动初速度,单位(pixel/s)
|
|
122
|
-
* acc (int) 带符号整形,描素运动的加速度,单位(pixel/(s*s))
|
|
123
|
-
* end_condition (Object) 动画结束的条件设定
|
|
124
|
-
* 格式{type:"catch", position:xxx, offset:xxx, direction: 1 or -1}
|
|
125
|
-
* 例如:
|
|
126
|
-
* 1. Y轴方向运动,在相对于起始点上方30px位置,接住向上运动的物体时,
|
|
127
|
-
* 设置 direction = -1, offset = -30
|
|
128
|
-
* 2. Y轴方向运动,在相对于起始点下方30px位置,接住运动到高点后跌落下来的运动的物体时,
|
|
129
|
-
* 设置 direction = 1, offset = 30
|
|
130
|
-
* position为相对于元素0点位置的绝对坐标,和offset的设定二选一
|
|
131
|
-
* end_callback (Function(x,y)) 运动到目标位置后的回调函数,回报当前JsvActorMove的相对x,y
|
|
132
|
-
* pole_callback (Function(void)) 动画运行到拐点时的回调
|
|
133
|
-
*/
|
|
134
|
-
throwAlongY(init_v, acc, end_condition, end_callback, pole_callback) {
|
|
135
|
-
this._Throw(1, init_v, acc, end_condition, end_callback, pole_callback);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
_Throw(x_or_y, init_v, acc, end_condition, end_callback, pole_callback) {
|
|
139
|
-
// 需要先进行动画停止,以确定本次动画的起始点(this._Current)
|
|
140
|
-
let super_start = super.start.bind(this);
|
|
141
|
-
super.pause(() => {
|
|
142
|
-
const start_params = this._CalculateTerminalStatus(x_or_y, init_v, acc, end_condition, pole_callback);
|
|
143
|
-
if (start_params !== null) {
|
|
144
|
-
super_start(start_params, end_callback);
|
|
145
|
-
} else {
|
|
146
|
-
// 无法确定终止点,动画无法启动
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/*
|
|
152
|
-
* jumpTo 参数说明:
|
|
153
|
-
* new_x (int) 带符号整数,标识目标位置,数值相对于JsvActorMove在render中的起始位置
|
|
154
|
-
* new_y (int) 带符号整数,标识目标位置,数值相对于JsvActorMove在render中的起始位置
|
|
155
|
-
*/
|
|
156
|
-
jumpTo(new_x, new_y) {
|
|
157
|
-
this._Target[0] = new_x;
|
|
158
|
-
this._Target[1] = new_y;
|
|
159
|
-
|
|
160
|
-
const start_params = {
|
|
161
|
-
type: CONST_MOVE_TYPE_JUMP,
|
|
162
|
-
};
|
|
163
|
-
super.start(start_params, null);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
_CalculateTerminalStatus(x_or_y, init_v, acc, end_condition, pole_callback) {
|
|
167
|
-
const start_params = {
|
|
168
|
-
type: CONST_MOVE_TYPE_ACC,
|
|
169
|
-
xOrY: x_or_y,
|
|
170
|
-
initV: init_v,
|
|
171
|
-
acc,
|
|
172
|
-
hasPole: false,
|
|
173
|
-
polePosition: 0,
|
|
174
|
-
poleCallback: pole_callback,
|
|
175
|
-
isPositiveMove: (init_v > 0 || (init_v === 0 && acc > 0))
|
|
176
|
-
};
|
|
177
|
-
let start_pos = (x_or_y === 0 ? this._Current[0] : this._Current[1]);
|
|
178
|
-
|
|
179
|
-
if (acc === 0) {
|
|
180
|
-
console.error("Error: Acceleration is not inited!");
|
|
181
|
-
return null;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
let direction_revert = false;
|
|
185
|
-
let catch_direction = end_condition.direction;
|
|
186
|
-
let catch_pos = Object.prototype.hasOwnProperty.call(end_condition, "position") ?
|
|
187
|
-
end_condition.position
|
|
188
|
-
: (end_condition.offset + start_pos);
|
|
189
|
-
let move_pole_pos = 0; // 减速运动的顶点位置
|
|
190
|
-
let trace_include_pole = false; // 运动轨迹包含拐点
|
|
191
|
-
|
|
192
|
-
// 为了方便设计计算思路,根据初速度进行坐标系归一化(同归为向正方向进行计算)
|
|
193
|
-
if (init_v < 0 || (init_v === 0 && acc < 0)) {
|
|
194
|
-
// 启动坐标系反转
|
|
195
|
-
direction_revert = true;
|
|
196
|
-
init_v = -init_v;
|
|
197
|
-
acc = -acc;
|
|
198
|
-
start_pos = -start_pos;
|
|
199
|
-
catch_direction = -catch_direction;
|
|
200
|
-
catch_pos = -catch_pos;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
if (acc * init_v < 0) {
|
|
204
|
-
// 初速度与加速度反向
|
|
205
|
-
|
|
206
|
-
// 计算减速运动最终位移
|
|
207
|
-
move_pole_pos = start_pos + init_v * init_v / 2 / (-acc);
|
|
208
|
-
|
|
209
|
-
if (init_v * catch_direction < 0) {
|
|
210
|
-
// 准备在返回轨道中进行捕获
|
|
211
|
-
if (catch_pos > move_pole_pos) {
|
|
212
|
-
console.error(`Error: can not catch, range(<${move_pole_pos}), but catch=${catch_pos}`);
|
|
213
|
-
return null;
|
|
214
|
-
}
|
|
215
|
-
trace_include_pole = true;
|
|
216
|
-
} else {
|
|
217
|
-
// 准备在前进轨道中捕获
|
|
218
|
-
if (catch_pos > move_pole_pos || catch_pos < start_pos) {
|
|
219
|
-
console.error(`Error: can not catch, range(${start_pos}-${move_pole_pos}), but catch=${catch_pos}`);
|
|
220
|
-
return null;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
} else {
|
|
224
|
-
// 初速度与加速度方向相同,包含初速度为0的场景
|
|
225
|
-
if (acc * catch_direction < 0) {
|
|
226
|
-
// 准备在返回轨道中进行捕获,但速度与加速度同向,无返回轨道,无法捕捉
|
|
227
|
-
console.error("Error: can not catch, direction incorrect");
|
|
228
|
-
return null;
|
|
229
|
-
}
|
|
230
|
-
// 准备在前进轨道中捕获
|
|
231
|
-
if (catch_pos < start_pos) {
|
|
232
|
-
console.error(`Error: can not catch, range(>${start_pos}), but catch=${catch_pos}`);
|
|
233
|
-
return null;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// 方向恢复
|
|
238
|
-
if (direction_revert) {
|
|
239
|
-
catch_pos = -catch_pos;
|
|
240
|
-
move_pole_pos = -move_pole_pos;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// 记录拐点信息
|
|
244
|
-
start_params.hasPole = trace_include_pole;
|
|
245
|
-
start_params.polePosition = move_pole_pos;
|
|
246
|
-
|
|
247
|
-
// 刷新Target信息
|
|
248
|
-
if (x_or_y === 0) {
|
|
249
|
-
// X轴方向运动
|
|
250
|
-
this._Target[0] = catch_pos;
|
|
251
|
-
this._Target[1] = this._Current[1];
|
|
252
|
-
} else {
|
|
253
|
-
// Y轴方向运动
|
|
254
|
-
this._Target[0] = this._Current[0];
|
|
255
|
-
this._Target[1] = catch_pos;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
return start_params;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
_BuildAccelAnimation(current_array, tos_array, start_params) {
|
|
262
|
-
const anim = new Forge.ThrowAnimation(
|
|
263
|
-
current_array[0],
|
|
264
|
-
current_array[1],
|
|
265
|
-
start_params.xOrY,
|
|
266
|
-
start_params.initV,
|
|
267
|
-
start_params.acc,
|
|
268
|
-
(start_params.xOrY === 0 ? tos_array[0] : tos_array[1]),
|
|
269
|
-
start_params.hasPole,
|
|
270
|
-
start_params.polePosition
|
|
271
|
-
);
|
|
272
|
-
anim.SetPoleCallback(start_params.poleCallback);
|
|
273
|
-
return anim;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
_BuildUniformMoveAnimation(current_array, tos_array, start_params) {
|
|
277
|
-
const affect_x = (start_params.xOrY === 0);
|
|
278
|
-
const from_pos = (affect_x ? current_array[0] : current_array[1]);
|
|
279
|
-
const to_pos = (affect_x ? tos_array[0] : tos_array[1]);
|
|
280
|
-
let anim = null;
|
|
281
|
-
|
|
282
|
-
if (start_params.repeatSet !== null) {
|
|
283
|
-
// 进行Repeat处理
|
|
284
|
-
const repeat_set = start_params.repeatSet;
|
|
285
|
-
|
|
286
|
-
// Repeat动画中,循环运动区域为repeatSet.start 到 to_pos,
|
|
287
|
-
// 但首次动画从from_pos开始运行,首次运动完成后,第二次运行再从repeatSet.start开始
|
|
288
|
-
const start_percent = (from_pos - repeat_set.start) / (to_pos - repeat_set.start);
|
|
289
|
-
if (start_percent > 1 || start_percent < 0) {
|
|
290
|
-
console.error(`Error: current=${from_pos} out of repeat range[${repeat_set.start}-${to_pos}]`);
|
|
291
|
-
return null;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
anim = new Forge.TranslateFrameAnimation(
|
|
295
|
-
repeat_set.start, to_pos,
|
|
296
|
-
start_params.speed, affect_x,
|
|
297
|
-
current_array[0], current_array[1]
|
|
298
|
-
);
|
|
299
|
-
anim.SetStartPos(start_percent);
|
|
300
|
-
anim.EnableInfinite();
|
|
301
|
-
} else {
|
|
302
|
-
// 单次动画,无repeat
|
|
303
|
-
anim = new Forge.TranslateFrameAnimation(
|
|
304
|
-
from_pos, to_pos,
|
|
305
|
-
start_params.speed, affect_x,
|
|
306
|
-
current_array[0], current_array[1]
|
|
307
|
-
);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
return anim;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
_BuildJumpAnimation(current_array, tos_array) {
|
|
314
|
-
// 使用时长为0的Translate动画来完成jump动作
|
|
315
|
-
const anim = new Forge.TranslateAnimation(
|
|
316
|
-
tos_array[0], tos_array[0],
|
|
317
|
-
tos_array[1], tos_array[1],
|
|
318
|
-
1, null);
|
|
319
|
-
return anim;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
_ReCalculateAccelCurrent(froms, tos, progress, start_params) {
|
|
323
|
-
const position = { x: { value: froms[0] }, y: { value: froms[1] } };
|
|
324
|
-
let from = (start_params.xOrY === 0 ? position.x.value : position.y.value);
|
|
325
|
-
let to = (start_params.xOrY === 0 ? tos[0] : tos[1]);
|
|
326
|
-
const result_position_ref = (start_params.xOrY === 0 ? position.x : position.y);
|
|
327
|
-
let result_pos_value = 0;
|
|
328
|
-
|
|
329
|
-
// 转换坐标系,使运动始终向正方向以简化计算处理
|
|
330
|
-
from = (start_params.isPositiveMove ? from : -from);
|
|
331
|
-
to = (start_params.isPositiveMove ? to : -to);
|
|
332
|
-
const pole_position = (start_params.isPositiveMove ? start_params.polePosition : -start_params.polePosition);
|
|
333
|
-
|
|
334
|
-
if (start_params.hasPole) {
|
|
335
|
-
const moved = (pole_position * 2 - from - to) * progress;
|
|
336
|
-
if (moved > (pole_position - from)) {
|
|
337
|
-
// 运动了超过了拐点的距离
|
|
338
|
-
result_pos_value = pole_position - (moved - (pole_position - from));
|
|
339
|
-
} else {
|
|
340
|
-
// 未到达拐点
|
|
341
|
-
result_pos_value = from + moved;
|
|
342
|
-
}
|
|
343
|
-
} else {
|
|
344
|
-
result_pos_value = from + (to - from) * progress;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
// 恢复坐标系
|
|
348
|
-
result_position_ref.value = Math.floor(start_params.isPositiveMove ? result_pos_value : -result_pos_value);
|
|
349
|
-
|
|
350
|
-
// 记录Current
|
|
351
|
-
this._Current[0] = position.x.value;
|
|
352
|
-
this._Current[1] = position.y.value;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
_ReCalculateUMoveCurrent(froms, tos, progress, start_params) {
|
|
357
|
-
if (start_params.xOrY === 0) {
|
|
358
|
-
const value = (tos[0] - froms[0]) * progress + froms[0];
|
|
359
|
-
const direction = value >= 0 ? 1 : -1;
|
|
360
|
-
this._Current[0] = direction * Math.floor(Math.abs(value));
|
|
361
|
-
} else {
|
|
362
|
-
const value = (tos[1] - froms[1]) * progress + froms[1];
|
|
363
|
-
const direction = value >= 0 ? 1 : -1;
|
|
364
|
-
this._Current[1] = direction * Math.floor(Math.abs(value));
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
_ReCalculateJumpCurrent(froms, tos) {
|
|
369
|
-
this._Current[0] = tos[0];
|
|
370
|
-
this._Current[1] = tos[1];
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
// 异常内部函数
|
|
374
|
-
start() { }
|
|
375
|
-
|
|
376
|
-
// Override
|
|
377
|
-
_WrapBuildAnimation(current_array, tos_array, start_params) {
|
|
378
|
-
if (start_params.type === CONST_MOVE_TYPE_ACC) {
|
|
379
|
-
// 加速运动
|
|
380
|
-
return this._BuildAccelAnimation(current_array, tos_array, start_params);
|
|
381
|
-
} if (start_params.type === CONST_MOVE_TYPE_UNIFORM) {
|
|
382
|
-
// 匀速运动
|
|
383
|
-
return this._BuildUniformMoveAnimation(current_array, tos_array, start_params);
|
|
384
|
-
} if (start_params.type === CONST_MOVE_TYPE_JUMP) {
|
|
385
|
-
// 位置调整
|
|
386
|
-
return this._BuildJumpAnimation(current_array, tos_array);
|
|
387
|
-
}
|
|
388
|
-
console.error("Error:Undefined yet");
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
// Override
|
|
392
|
-
_WrapAddExtraListener(listener, start_params) {
|
|
393
|
-
if (start_params.type === CONST_MOVE_TYPE_UNIFORM) {
|
|
394
|
-
// 重复运动时,需要设定repeat回调
|
|
395
|
-
if (start_params.repeatSet !== null && start_params.repeatSet.repeatCallback) {
|
|
396
|
-
const repeat_callback = start_params.repeatSet.repeatCallback;
|
|
397
|
-
listener.OnRepeat((times) => {
|
|
398
|
-
repeat_callback(times);
|
|
399
|
-
});
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
// Override
|
|
405
|
-
_WrapCallback(currents, callback, start_params) {
|
|
406
|
-
if (callback) {
|
|
407
|
-
callback(currents[0], currents[1], start_params);
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
// Override
|
|
412
|
-
_WrapReCalculateCurrent(froms, tos, progress, start_params) {
|
|
413
|
-
if (start_params.type === CONST_MOVE_TYPE_ACC) {
|
|
414
|
-
this._ReCalculateAccelCurrent(froms, tos, progress, start_params);
|
|
415
|
-
} else if (start_params.type === CONST_MOVE_TYPE_UNIFORM) {
|
|
416
|
-
// 匀速运动
|
|
417
|
-
return this._ReCalculateUMoveCurrent(froms, tos, progress, start_params);
|
|
418
|
-
} else if (start_params.type === CONST_MOVE_TYPE_JUMP) {
|
|
419
|
-
// 位置调整
|
|
420
|
-
return this._ReCalculateJumpCurrent(froms, tos);
|
|
421
|
-
} else {
|
|
422
|
-
console.error("Error:Undefined yet");
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
|
|
1
|
+
/*
|
|
2
|
+
* @Author: ChenChanghua
|
|
3
|
+
* @Date: 2021-10-20 17:04:26
|
|
4
|
+
* @LastEditors: ChenChanghua
|
|
5
|
+
* @LastEditTime: 2021-10-21 13:17:05
|
|
6
|
+
* @Description: file content
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { Forge } from "../../../dom/jsv-forge-define";
|
|
10
|
+
import ActorControlBase from "./ActorControlBase";
|
|
11
|
+
|
|
12
|
+
const CONST_MOVE_TYPE_ACC = 1; // 抛物变速运动
|
|
13
|
+
const CONST_MOVE_TYPE_UNIFORM = 2; // 匀速运动
|
|
14
|
+
const CONST_MOVE_TYPE_JUMP = 3; // 无动画,直接调整坐标到目标位置
|
|
15
|
+
|
|
16
|
+
// 单向运动控制模块,单方向指的是只能进行一个方向的运动,要不是x,要不是y
|
|
17
|
+
class JsvActorMoveControl extends ActorControlBase {
|
|
18
|
+
constructor() {
|
|
19
|
+
// 0: X位置,
|
|
20
|
+
// 1: Y位置,
|
|
21
|
+
super(2);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/*
|
|
25
|
+
* moveToX 参数说明:
|
|
26
|
+
* paused_callback (Function(x,y)) 运动暂停完成后的回调,回报当前JsvActorMove的相对x,y
|
|
27
|
+
*/
|
|
28
|
+
pause(paused_callback) {
|
|
29
|
+
super.pause(paused_callback);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/*
|
|
33
|
+
* moveToX 参数说明:
|
|
34
|
+
* target_x (int) 带符号整数,标识运动的目标位置,相对于JsvActorMove当前位置
|
|
35
|
+
* speed (int) 带符号整数,符号表示方向,标识运动的运行速度,单位(pixel/s)
|
|
36
|
+
* end_callback (Function(x,y)) 运动到目标位置后的回调函数,回报当前JsvActorMove的相对x,y
|
|
37
|
+
*/
|
|
38
|
+
moveToX(target_x, speed, end_callback) {
|
|
39
|
+
this._UniformMove(0, target_x, NaN, speed, null, end_callback);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/*
|
|
43
|
+
* moveToY 参数说明:
|
|
44
|
+
* target_y (int) 带符号整数,标识运动的目标位置,相对于JsvActorMove当前位置
|
|
45
|
+
* speed (int) 带符号整数,符号表示方向,标识运动的运行速度,单位(pixel/s)
|
|
46
|
+
* end_callback (Function(x,y)) 运动到目标位置后的回调函数,回报当前JsvActorMove的相对x,y
|
|
47
|
+
*/
|
|
48
|
+
moveToY(target_y, speed, end_callback) {
|
|
49
|
+
this._UniformMove(1, NaN, target_y, speed, null, end_callback);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/*
|
|
53
|
+
* repeatMoveAlongX 参数说明:
|
|
54
|
+
* target_x (int) 带符号整数,标识运动的目标位置,相对于JsvActorMove当前位置
|
|
55
|
+
* speed (int) 带符号整数,符号表示方向,标识运动的运行速度,单位(pixel/s)
|
|
56
|
+
* repeat_start (int) 带符号整数,标识往复运动的起始点,使用时注意,JsvActorMove的当前位置必须在
|
|
57
|
+
* repeat_start和target_x之间
|
|
58
|
+
* repeat_callback (Function(times)) 完整一个运动周期后的回调,返回当前运动的周期数times
|
|
59
|
+
*/
|
|
60
|
+
repeatMoveAlongX(target_x, speed, repeat_start, repeat_callback) {
|
|
61
|
+
this._UniformMove(0,
|
|
62
|
+
target_x, NaN, speed,
|
|
63
|
+
{
|
|
64
|
+
start: repeat_start,
|
|
65
|
+
repeatCallback: repeat_callback,
|
|
66
|
+
},
|
|
67
|
+
null);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/*
|
|
71
|
+
* repeatMoveAlongY 参数说明:
|
|
72
|
+
* target_y (int) 带符号整数,标识运动的目标位置,相对于JsvActorMove当前位置
|
|
73
|
+
* speed (int) 带符号整数,符号表示方向,标识运动的运行速度,单位(pixel/s)
|
|
74
|
+
* repeat_start (int) 带符号整数,标识往复运动的起始点,使用时注意,JsvActorMove的当前位置必须在
|
|
75
|
+
* repeat_start和target_y之间
|
|
76
|
+
* repeat_callback (Function(times)) 完整一个运动周期后的回调,返回当前运动的周期数times
|
|
77
|
+
*/
|
|
78
|
+
repeatMoveAlongY(target_y, speed, repeat_start, repeat_callback) {
|
|
79
|
+
this._UniformMove(1,
|
|
80
|
+
NaN, target_y, speed,
|
|
81
|
+
{
|
|
82
|
+
start: repeat_start,
|
|
83
|
+
repeatCallback: repeat_callback,
|
|
84
|
+
},
|
|
85
|
+
null);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
_UniformMove(x_or_y, target_x, target_y, speed, repeat_set, end_callback) {
|
|
89
|
+
const start_params = {
|
|
90
|
+
type: CONST_MOVE_TYPE_UNIFORM,
|
|
91
|
+
xOrY: x_or_y,
|
|
92
|
+
speed,
|
|
93
|
+
repeatSet: repeat_set,
|
|
94
|
+
};
|
|
95
|
+
this._Target[0] = target_x;
|
|
96
|
+
this._Target[1] = target_y;
|
|
97
|
+
super.start(start_params, end_callback);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/*
|
|
101
|
+
* throwAlongX 参数说明:
|
|
102
|
+
* init_v (int) 带符号整形,描素运动初速度,单位(pixel/s)
|
|
103
|
+
* acc (int) 带符号整形,描素运动的加速度,单位(pixel/(s*s))
|
|
104
|
+
* end_condition (Object) 动画结束的条件设定
|
|
105
|
+
* 格式{type:"catch", position:xxx, offset:xxx, direction: 1 or -1}
|
|
106
|
+
* 例如:
|
|
107
|
+
* 1. X轴方向运动,在相对于起始点右方30px位置,接住向上运动的物体时,
|
|
108
|
+
* 设置 direction = -1, offset = -30
|
|
109
|
+
* 2. X轴方向运动,在相对于起始点左方30px位置,接住运动到右边界后回旋向左的运动的物体时,
|
|
110
|
+
* 设置 direction = 1, offset = 30
|
|
111
|
+
* position为相对于元素0点位置的绝对坐标,和offset的设定二选一
|
|
112
|
+
* end_callback (Function(x,y)) 运动到目标位置后的回调函数,回报当前JsvActorMove的相对x,y
|
|
113
|
+
* pole_callback (Function(void)) 动画运行到拐点时的回调
|
|
114
|
+
*/
|
|
115
|
+
throwAlongX(init_v, acc, end_condition, end_callback, pole_callback) {
|
|
116
|
+
this._Throw(0, init_v, acc, end_condition, end_callback, pole_callback);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/*
|
|
120
|
+
* throwAlongY 参数说明:
|
|
121
|
+
* init_v (int) 带符号整形,描素运动初速度,单位(pixel/s)
|
|
122
|
+
* acc (int) 带符号整形,描素运动的加速度,单位(pixel/(s*s))
|
|
123
|
+
* end_condition (Object) 动画结束的条件设定
|
|
124
|
+
* 格式{type:"catch", position:xxx, offset:xxx, direction: 1 or -1}
|
|
125
|
+
* 例如:
|
|
126
|
+
* 1. Y轴方向运动,在相对于起始点上方30px位置,接住向上运动的物体时,
|
|
127
|
+
* 设置 direction = -1, offset = -30
|
|
128
|
+
* 2. Y轴方向运动,在相对于起始点下方30px位置,接住运动到高点后跌落下来的运动的物体时,
|
|
129
|
+
* 设置 direction = 1, offset = 30
|
|
130
|
+
* position为相对于元素0点位置的绝对坐标,和offset的设定二选一
|
|
131
|
+
* end_callback (Function(x,y)) 运动到目标位置后的回调函数,回报当前JsvActorMove的相对x,y
|
|
132
|
+
* pole_callback (Function(void)) 动画运行到拐点时的回调
|
|
133
|
+
*/
|
|
134
|
+
throwAlongY(init_v, acc, end_condition, end_callback, pole_callback) {
|
|
135
|
+
this._Throw(1, init_v, acc, end_condition, end_callback, pole_callback);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
_Throw(x_or_y, init_v, acc, end_condition, end_callback, pole_callback) {
|
|
139
|
+
// 需要先进行动画停止,以确定本次动画的起始点(this._Current)
|
|
140
|
+
let super_start = super.start.bind(this);
|
|
141
|
+
super.pause(() => {
|
|
142
|
+
const start_params = this._CalculateTerminalStatus(x_or_y, init_v, acc, end_condition, pole_callback);
|
|
143
|
+
if (start_params !== null) {
|
|
144
|
+
super_start(start_params, end_callback);
|
|
145
|
+
} else {
|
|
146
|
+
// 无法确定终止点,动画无法启动
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/*
|
|
152
|
+
* jumpTo 参数说明:
|
|
153
|
+
* new_x (int) 带符号整数,标识目标位置,数值相对于JsvActorMove在render中的起始位置
|
|
154
|
+
* new_y (int) 带符号整数,标识目标位置,数值相对于JsvActorMove在render中的起始位置
|
|
155
|
+
*/
|
|
156
|
+
jumpTo(new_x, new_y) {
|
|
157
|
+
this._Target[0] = new_x;
|
|
158
|
+
this._Target[1] = new_y;
|
|
159
|
+
|
|
160
|
+
const start_params = {
|
|
161
|
+
type: CONST_MOVE_TYPE_JUMP,
|
|
162
|
+
};
|
|
163
|
+
super.start(start_params, null);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
_CalculateTerminalStatus(x_or_y, init_v, acc, end_condition, pole_callback) {
|
|
167
|
+
const start_params = {
|
|
168
|
+
type: CONST_MOVE_TYPE_ACC,
|
|
169
|
+
xOrY: x_or_y,
|
|
170
|
+
initV: init_v,
|
|
171
|
+
acc,
|
|
172
|
+
hasPole: false,
|
|
173
|
+
polePosition: 0,
|
|
174
|
+
poleCallback: pole_callback,
|
|
175
|
+
isPositiveMove: (init_v > 0 || (init_v === 0 && acc > 0))
|
|
176
|
+
};
|
|
177
|
+
let start_pos = (x_or_y === 0 ? this._Current[0] : this._Current[1]);
|
|
178
|
+
|
|
179
|
+
if (acc === 0) {
|
|
180
|
+
console.error("Error: Acceleration is not inited!");
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
let direction_revert = false;
|
|
185
|
+
let catch_direction = end_condition.direction;
|
|
186
|
+
let catch_pos = Object.prototype.hasOwnProperty.call(end_condition, "position") ?
|
|
187
|
+
end_condition.position
|
|
188
|
+
: (end_condition.offset + start_pos);
|
|
189
|
+
let move_pole_pos = 0; // 减速运动的顶点位置
|
|
190
|
+
let trace_include_pole = false; // 运动轨迹包含拐点
|
|
191
|
+
|
|
192
|
+
// 为了方便设计计算思路,根据初速度进行坐标系归一化(同归为向正方向进行计算)
|
|
193
|
+
if (init_v < 0 || (init_v === 0 && acc < 0)) {
|
|
194
|
+
// 启动坐标系反转
|
|
195
|
+
direction_revert = true;
|
|
196
|
+
init_v = -init_v;
|
|
197
|
+
acc = -acc;
|
|
198
|
+
start_pos = -start_pos;
|
|
199
|
+
catch_direction = -catch_direction;
|
|
200
|
+
catch_pos = -catch_pos;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (acc * init_v < 0) {
|
|
204
|
+
// 初速度与加速度反向
|
|
205
|
+
|
|
206
|
+
// 计算减速运动最终位移
|
|
207
|
+
move_pole_pos = start_pos + init_v * init_v / 2 / (-acc);
|
|
208
|
+
|
|
209
|
+
if (init_v * catch_direction < 0) {
|
|
210
|
+
// 准备在返回轨道中进行捕获
|
|
211
|
+
if (catch_pos > move_pole_pos) {
|
|
212
|
+
console.error(`Error: can not catch, range(<${move_pole_pos}), but catch=${catch_pos}`);
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
trace_include_pole = true;
|
|
216
|
+
} else {
|
|
217
|
+
// 准备在前进轨道中捕获
|
|
218
|
+
if (catch_pos > move_pole_pos || catch_pos < start_pos) {
|
|
219
|
+
console.error(`Error: can not catch, range(${start_pos}-${move_pole_pos}), but catch=${catch_pos}`);
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
} else {
|
|
224
|
+
// 初速度与加速度方向相同,包含初速度为0的场景
|
|
225
|
+
if (acc * catch_direction < 0) {
|
|
226
|
+
// 准备在返回轨道中进行捕获,但速度与加速度同向,无返回轨道,无法捕捉
|
|
227
|
+
console.error("Error: can not catch, direction incorrect");
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
// 准备在前进轨道中捕获
|
|
231
|
+
if (catch_pos < start_pos) {
|
|
232
|
+
console.error(`Error: can not catch, range(>${start_pos}), but catch=${catch_pos}`);
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// 方向恢复
|
|
238
|
+
if (direction_revert) {
|
|
239
|
+
catch_pos = -catch_pos;
|
|
240
|
+
move_pole_pos = -move_pole_pos;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// 记录拐点信息
|
|
244
|
+
start_params.hasPole = trace_include_pole;
|
|
245
|
+
start_params.polePosition = move_pole_pos;
|
|
246
|
+
|
|
247
|
+
// 刷新Target信息
|
|
248
|
+
if (x_or_y === 0) {
|
|
249
|
+
// X轴方向运动
|
|
250
|
+
this._Target[0] = catch_pos;
|
|
251
|
+
this._Target[1] = this._Current[1];
|
|
252
|
+
} else {
|
|
253
|
+
// Y轴方向运动
|
|
254
|
+
this._Target[0] = this._Current[0];
|
|
255
|
+
this._Target[1] = catch_pos;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return start_params;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
_BuildAccelAnimation(current_array, tos_array, start_params) {
|
|
262
|
+
const anim = new Forge.ThrowAnimation(
|
|
263
|
+
current_array[0],
|
|
264
|
+
current_array[1],
|
|
265
|
+
start_params.xOrY,
|
|
266
|
+
start_params.initV,
|
|
267
|
+
start_params.acc,
|
|
268
|
+
(start_params.xOrY === 0 ? tos_array[0] : tos_array[1]),
|
|
269
|
+
start_params.hasPole,
|
|
270
|
+
start_params.polePosition
|
|
271
|
+
);
|
|
272
|
+
anim.SetPoleCallback(start_params.poleCallback);
|
|
273
|
+
return anim;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
_BuildUniformMoveAnimation(current_array, tos_array, start_params) {
|
|
277
|
+
const affect_x = (start_params.xOrY === 0);
|
|
278
|
+
const from_pos = (affect_x ? current_array[0] : current_array[1]);
|
|
279
|
+
const to_pos = (affect_x ? tos_array[0] : tos_array[1]);
|
|
280
|
+
let anim = null;
|
|
281
|
+
|
|
282
|
+
if (start_params.repeatSet !== null) {
|
|
283
|
+
// 进行Repeat处理
|
|
284
|
+
const repeat_set = start_params.repeatSet;
|
|
285
|
+
|
|
286
|
+
// Repeat动画中,循环运动区域为repeatSet.start 到 to_pos,
|
|
287
|
+
// 但首次动画从from_pos开始运行,首次运动完成后,第二次运行再从repeatSet.start开始
|
|
288
|
+
const start_percent = (from_pos - repeat_set.start) / (to_pos - repeat_set.start);
|
|
289
|
+
if (start_percent > 1 || start_percent < 0) {
|
|
290
|
+
console.error(`Error: current=${from_pos} out of repeat range[${repeat_set.start}-${to_pos}]`);
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
anim = new Forge.TranslateFrameAnimation(
|
|
295
|
+
repeat_set.start, to_pos,
|
|
296
|
+
start_params.speed, affect_x,
|
|
297
|
+
current_array[0], current_array[1]
|
|
298
|
+
);
|
|
299
|
+
anim.SetStartPos(start_percent);
|
|
300
|
+
anim.EnableInfinite();
|
|
301
|
+
} else {
|
|
302
|
+
// 单次动画,无repeat
|
|
303
|
+
anim = new Forge.TranslateFrameAnimation(
|
|
304
|
+
from_pos, to_pos,
|
|
305
|
+
start_params.speed, affect_x,
|
|
306
|
+
current_array[0], current_array[1]
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return anim;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
_BuildJumpAnimation(current_array, tos_array) {
|
|
314
|
+
// 使用时长为0的Translate动画来完成jump动作
|
|
315
|
+
const anim = new Forge.TranslateAnimation(
|
|
316
|
+
tos_array[0], tos_array[0],
|
|
317
|
+
tos_array[1], tos_array[1],
|
|
318
|
+
1, null);
|
|
319
|
+
return anim;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
_ReCalculateAccelCurrent(froms, tos, progress, start_params) {
|
|
323
|
+
const position = { x: { value: froms[0] }, y: { value: froms[1] } };
|
|
324
|
+
let from = (start_params.xOrY === 0 ? position.x.value : position.y.value);
|
|
325
|
+
let to = (start_params.xOrY === 0 ? tos[0] : tos[1]);
|
|
326
|
+
const result_position_ref = (start_params.xOrY === 0 ? position.x : position.y);
|
|
327
|
+
let result_pos_value = 0;
|
|
328
|
+
|
|
329
|
+
// 转换坐标系,使运动始终向正方向以简化计算处理
|
|
330
|
+
from = (start_params.isPositiveMove ? from : -from);
|
|
331
|
+
to = (start_params.isPositiveMove ? to : -to);
|
|
332
|
+
const pole_position = (start_params.isPositiveMove ? start_params.polePosition : -start_params.polePosition);
|
|
333
|
+
|
|
334
|
+
if (start_params.hasPole) {
|
|
335
|
+
const moved = (pole_position * 2 - from - to) * progress;
|
|
336
|
+
if (moved > (pole_position - from)) {
|
|
337
|
+
// 运动了超过了拐点的距离
|
|
338
|
+
result_pos_value = pole_position - (moved - (pole_position - from));
|
|
339
|
+
} else {
|
|
340
|
+
// 未到达拐点
|
|
341
|
+
result_pos_value = from + moved;
|
|
342
|
+
}
|
|
343
|
+
} else {
|
|
344
|
+
result_pos_value = from + (to - from) * progress;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// 恢复坐标系
|
|
348
|
+
result_position_ref.value = Math.floor(start_params.isPositiveMove ? result_pos_value : -result_pos_value);
|
|
349
|
+
|
|
350
|
+
// 记录Current
|
|
351
|
+
this._Current[0] = position.x.value;
|
|
352
|
+
this._Current[1] = position.y.value;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
_ReCalculateUMoveCurrent(froms, tos, progress, start_params) {
|
|
357
|
+
if (start_params.xOrY === 0) {
|
|
358
|
+
const value = (tos[0] - froms[0]) * progress + froms[0];
|
|
359
|
+
const direction = value >= 0 ? 1 : -1;
|
|
360
|
+
this._Current[0] = direction * Math.floor(Math.abs(value));
|
|
361
|
+
} else {
|
|
362
|
+
const value = (tos[1] - froms[1]) * progress + froms[1];
|
|
363
|
+
const direction = value >= 0 ? 1 : -1;
|
|
364
|
+
this._Current[1] = direction * Math.floor(Math.abs(value));
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
_ReCalculateJumpCurrent(froms, tos) {
|
|
369
|
+
this._Current[0] = tos[0];
|
|
370
|
+
this._Current[1] = tos[1];
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// 异常内部函数
|
|
374
|
+
start() { }
|
|
375
|
+
|
|
376
|
+
// Override
|
|
377
|
+
_WrapBuildAnimation(current_array, tos_array, start_params) {
|
|
378
|
+
if (start_params.type === CONST_MOVE_TYPE_ACC) {
|
|
379
|
+
// 加速运动
|
|
380
|
+
return this._BuildAccelAnimation(current_array, tos_array, start_params);
|
|
381
|
+
} if (start_params.type === CONST_MOVE_TYPE_UNIFORM) {
|
|
382
|
+
// 匀速运动
|
|
383
|
+
return this._BuildUniformMoveAnimation(current_array, tos_array, start_params);
|
|
384
|
+
} if (start_params.type === CONST_MOVE_TYPE_JUMP) {
|
|
385
|
+
// 位置调整
|
|
386
|
+
return this._BuildJumpAnimation(current_array, tos_array);
|
|
387
|
+
}
|
|
388
|
+
console.error("Error:Undefined yet");
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// Override
|
|
392
|
+
_WrapAddExtraListener(listener, start_params) {
|
|
393
|
+
if (start_params.type === CONST_MOVE_TYPE_UNIFORM) {
|
|
394
|
+
// 重复运动时,需要设定repeat回调
|
|
395
|
+
if (start_params.repeatSet !== null && start_params.repeatSet.repeatCallback) {
|
|
396
|
+
const repeat_callback = start_params.repeatSet.repeatCallback;
|
|
397
|
+
listener.OnRepeat((times) => {
|
|
398
|
+
repeat_callback(times);
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// Override
|
|
405
|
+
_WrapCallback(currents, callback, start_params) {
|
|
406
|
+
if (callback) {
|
|
407
|
+
callback(currents[0], currents[1], start_params);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// Override
|
|
412
|
+
_WrapReCalculateCurrent(froms, tos, progress, start_params) {
|
|
413
|
+
if (start_params.type === CONST_MOVE_TYPE_ACC) {
|
|
414
|
+
this._ReCalculateAccelCurrent(froms, tos, progress, start_params);
|
|
415
|
+
} else if (start_params.type === CONST_MOVE_TYPE_UNIFORM) {
|
|
416
|
+
// 匀速运动
|
|
417
|
+
return this._ReCalculateUMoveCurrent(froms, tos, progress, start_params);
|
|
418
|
+
} else if (start_params.type === CONST_MOVE_TYPE_JUMP) {
|
|
419
|
+
// 位置调整
|
|
420
|
+
return this._ReCalculateJumpCurrent(froms, tos);
|
|
421
|
+
} else {
|
|
422
|
+
console.error("Error:Undefined yet");
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
427
|
export default JsvActorMoveControl;
|