@quenty/acceltween 2.5.0 → 2.5.1
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/CHANGELOG.md +11 -0
- package/package.json +2 -2
- package/src/Shared/AccelTween.lua +78 -57
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [2.5.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/acceltween@2.5.0...@quenty/acceltween@2.5.1) (2025-04-05)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* Add types to packages ([2374fb2](https://github.com/Quenty/NevermoreEngine/commit/2374fb2b043cfbe0e9b507b3316eec46a4e353a0))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [2.5.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/acceltween@2.4.0...@quenty/acceltween@2.5.0) (2024-09-12)
|
|
7
18
|
|
|
8
19
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/acceltween",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.1",
|
|
4
4
|
"description": "AccelTween implementation for Roblox",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "78c3ac0ab08dd18085b6e6e6e4f745e76ed99f68"
|
|
32
32
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
--!strict
|
|
1
2
|
--[=[
|
|
2
3
|
Provides a means to, with both a continuous position and velocity,
|
|
3
4
|
accelerate from its current position to a target position in minimum time
|
|
@@ -9,6 +10,63 @@
|
|
|
9
10
|
|
|
10
11
|
local AccelTween = {}
|
|
11
12
|
|
|
13
|
+
export type AccelTween = typeof(setmetatable(
|
|
14
|
+
{} :: {
|
|
15
|
+
--[=[
|
|
16
|
+
Gets and sets the current position of the AccelTween
|
|
17
|
+
@prop p number
|
|
18
|
+
@within AccelTween
|
|
19
|
+
]=]
|
|
20
|
+
p: number,
|
|
21
|
+
|
|
22
|
+
--[=[
|
|
23
|
+
Gets and sets the current velocity of the AccelTween
|
|
24
|
+
@prop v number
|
|
25
|
+
@within AccelTween
|
|
26
|
+
]=]
|
|
27
|
+
v: number,
|
|
28
|
+
|
|
29
|
+
--[=[
|
|
30
|
+
Gets and sets the maximum acceleration.
|
|
31
|
+
@prop a number
|
|
32
|
+
@within AccelTween
|
|
33
|
+
]=]
|
|
34
|
+
a: number,
|
|
35
|
+
|
|
36
|
+
--[=[
|
|
37
|
+
Gets and sets the target position.
|
|
38
|
+
@prop t number
|
|
39
|
+
@within AccelTween
|
|
40
|
+
]=]
|
|
41
|
+
t: number,
|
|
42
|
+
|
|
43
|
+
--[=[
|
|
44
|
+
Returns the remaining time before the AccelTween attains the target.
|
|
45
|
+
@readonly
|
|
46
|
+
@prop rtime number
|
|
47
|
+
@within AccelTween
|
|
48
|
+
]=]
|
|
49
|
+
rtime: number,
|
|
50
|
+
|
|
51
|
+
--[=[
|
|
52
|
+
Sets the current and target position, and sets the velocity to 0.
|
|
53
|
+
@prop pt number
|
|
54
|
+
@within AccelTween
|
|
55
|
+
]=]
|
|
56
|
+
pt: number,
|
|
57
|
+
|
|
58
|
+
-- Internal
|
|
59
|
+
_accel: number,
|
|
60
|
+
_t0: number,
|
|
61
|
+
_y0: number,
|
|
62
|
+
_a0: number,
|
|
63
|
+
_t1: number,
|
|
64
|
+
_y1: number,
|
|
65
|
+
_a1: number,
|
|
66
|
+
},
|
|
67
|
+
{ __index = AccelTween }
|
|
68
|
+
))
|
|
69
|
+
|
|
12
70
|
--[=[
|
|
13
71
|
Constructs a new AccelTween.
|
|
14
72
|
|
|
@@ -27,57 +85,20 @@ local AccelTween = {}
|
|
|
27
85
|
@param maxaccel number? -- The maximum acceleration applied to reach its target. Defaults to 1
|
|
28
86
|
@return AccelTween
|
|
29
87
|
]=]
|
|
30
|
-
function AccelTween.new(maxaccel)
|
|
88
|
+
function AccelTween.new(maxaccel: number?): AccelTween
|
|
31
89
|
local self = setmetatable({
|
|
32
|
-
_accel = maxaccel or 1
|
|
33
|
-
_t0 = 0
|
|
34
|
-
_y0 = 0
|
|
35
|
-
_a0 = 0
|
|
36
|
-
_t1 = 0
|
|
37
|
-
_y1 = 0
|
|
38
|
-
_a1 = 0
|
|
90
|
+
_accel = maxaccel or 1,
|
|
91
|
+
_t0 = 0,
|
|
92
|
+
_y0 = 0,
|
|
93
|
+
_a0 = 0,
|
|
94
|
+
_t1 = 0,
|
|
95
|
+
_y1 = 0,
|
|
96
|
+
_a1 = 0,
|
|
39
97
|
}, AccelTween)
|
|
40
98
|
|
|
41
|
-
return self
|
|
99
|
+
return self :: any
|
|
42
100
|
end
|
|
43
101
|
|
|
44
|
-
--[=[
|
|
45
|
-
Gets and sets the current position of the AccelTween
|
|
46
|
-
@prop p number
|
|
47
|
-
@within AccelTween
|
|
48
|
-
]=]
|
|
49
|
-
|
|
50
|
-
--[=[
|
|
51
|
-
Gets and sets the current velocity of the AccelTween
|
|
52
|
-
@prop v number
|
|
53
|
-
@within AccelTween
|
|
54
|
-
]=]
|
|
55
|
-
|
|
56
|
-
--[=[
|
|
57
|
-
Gets and sets the maximum acceleration.
|
|
58
|
-
@prop a number
|
|
59
|
-
@within AccelTween
|
|
60
|
-
]=]
|
|
61
|
-
|
|
62
|
-
--[=[
|
|
63
|
-
Gets and sets the target position.
|
|
64
|
-
@prop t number
|
|
65
|
-
@within AccelTween
|
|
66
|
-
]=]
|
|
67
|
-
|
|
68
|
-
--[=[
|
|
69
|
-
Returns the remaining time before the AccelTween attains the target.
|
|
70
|
-
@readonly
|
|
71
|
-
@prop rtime number
|
|
72
|
-
@within AccelTween
|
|
73
|
-
]=]
|
|
74
|
-
|
|
75
|
-
--[=[
|
|
76
|
-
Sets the current and target position, and sets the velocity to 0.
|
|
77
|
-
@prop pt number
|
|
78
|
-
@within AccelTween
|
|
79
|
-
]=]
|
|
80
|
-
|
|
81
102
|
function AccelTween:__index(index)
|
|
82
103
|
if AccelTween[index] then
|
|
83
104
|
return AccelTween[index]
|
|
@@ -116,12 +137,12 @@ function AccelTween:__newindex(index, value)
|
|
|
116
137
|
end
|
|
117
138
|
|
|
118
139
|
function AccelTween:_getstate(time)
|
|
119
|
-
if time < (self._t0 + self._t1)/2 then
|
|
140
|
+
if time < (self._t0 + self._t1) / 2 then
|
|
120
141
|
local t = time - self._t0
|
|
121
|
-
return self._y0 + t*t/2*self._a0, t*self._a0
|
|
142
|
+
return self._y0 + t * t / 2 * self._a0, t * self._a0
|
|
122
143
|
elseif time < self._t1 then
|
|
123
144
|
local t = time - self._t1
|
|
124
|
-
return self._y1 + t*t/2*self._a1, t*self._a1
|
|
145
|
+
return self._y1 + t * t / 2 * self._a1, t * self._a1
|
|
125
146
|
else
|
|
126
147
|
return self._y1, 0
|
|
127
148
|
end
|
|
@@ -135,26 +156,26 @@ function AccelTween:_setstate(newpos, newvel, newaccel, newtarg)
|
|
|
135
156
|
self._accel = newaccel or self._accel
|
|
136
157
|
local targ = newtarg or self._y1
|
|
137
158
|
|
|
138
|
-
if self._accel*self._accel < 1e-8 then
|
|
159
|
+
if self._accel * self._accel < 1e-8 then
|
|
139
160
|
self._t0, self._y0, self._a0 = 0, pos, 0
|
|
140
161
|
self._t1, self._y1, self._a1 = math.huge, targ, 0
|
|
141
162
|
else
|
|
142
163
|
local conda = targ < pos
|
|
143
164
|
local condb = vel < 0
|
|
144
|
-
local condc = pos - vel*vel/(2*self._accel) < targ
|
|
145
|
-
local condd = pos + vel*vel/(2*self._accel) < targ
|
|
165
|
+
local condc = pos - vel * vel / (2 * self._accel) < targ
|
|
166
|
+
local condd = pos + vel * vel / (2 * self._accel) < targ
|
|
146
167
|
if conda and condb and condc or not conda and (condb or not condb and condd) then
|
|
147
168
|
self._a0 = self._accel
|
|
148
|
-
self._t1 = time + ((2*vel*vel + 4*self._accel*(targ - pos))^0.5 - vel)/self._accel
|
|
169
|
+
self._t1 = time + ((2 * vel * vel + 4 * self._accel * (targ - pos)) ^ 0.5 - vel) / self._accel
|
|
149
170
|
else
|
|
150
171
|
self._a0 = -self._accel
|
|
151
|
-
self._t1 = time + ((2*vel*vel - 4*self._accel*(targ - pos))^0.5 + vel)/self._accel
|
|
172
|
+
self._t1 = time + ((2 * vel * vel - 4 * self._accel * (targ - pos)) ^ 0.5 + vel) / self._accel
|
|
152
173
|
end
|
|
153
|
-
self._t0 = time - vel/self._a0
|
|
154
|
-
self._y0 = pos - vel*vel/(2*self._a0)
|
|
174
|
+
self._t0 = time - vel / self._a0
|
|
175
|
+
self._y0 = pos - vel * vel / (2 * self._a0)
|
|
155
176
|
self._y1 = targ
|
|
156
177
|
self._a1 = -self._a0
|
|
157
178
|
end
|
|
158
179
|
end
|
|
159
180
|
|
|
160
|
-
return AccelTween
|
|
181
|
+
return AccelTween
|