@quenty/blend 6.10.0 → 6.11.0

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 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
+ # [6.11.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/blend@6.10.0...@quenty/blend@6.11.0) (2023-03-06)
7
+
8
+
9
+ ### Features
10
+
11
+ * Add SetTarget() and Epsilon API to SpringObject ([5a60717](https://github.com/Quenty/NevermoreEngine/commit/5a607177b942a20e4679824661623a82ff296541))
12
+
13
+
14
+
15
+
16
+
6
17
  # [6.10.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/blend@6.9.0...@quenty/blend@6.10.0) (2023-03-05)
7
18
 
8
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/blend",
3
- "version": "6.10.0",
3
+ "version": "6.11.0",
4
4
  "description": "Declarative UI system.",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -42,8 +42,8 @@
42
42
  "@quenty/valueobject": "^7.7.0"
43
43
  },
44
44
  "devDependencies": {
45
- "@quenty/contentproviderutils": "^6.3.0",
45
+ "@quenty/contentproviderutils": "^6.4.0",
46
46
  "@quenty/playerthumbnailutils": "^6.3.0"
47
47
  },
48
- "gitHead": "e62b5eac2e5d9084ab9083f128452dd2d98b6f1a"
48
+ "gitHead": "ce54e6f72519719e6155643418f2496f30a55f8e"
49
49
  }
@@ -30,13 +30,14 @@ SpringObject.__index = SpringObject
30
30
  function SpringObject.new(target, speed, damper)
31
31
  local self = setmetatable({
32
32
  _maid = Maid.new();
33
+ _epsilon = 1e-6;
33
34
  Changed = Signal.new();
34
35
  }, SpringObject)
35
36
 
36
37
  --[=[
37
38
  Event fires when the spring value changes
38
39
  @prop Changed Signal<()> -- Fires whenever the spring initially changes state
39
- @within ValueObject
40
+ @within SpringObject
40
41
  ]=]
41
42
  self._maid:GiveTask(self.Changed)
42
43
 
@@ -94,7 +95,7 @@ function SpringObject:PromiseFinished(signal)
94
95
 
95
96
  -- TODO: Mathematical solution?
96
97
  local startAnimate, stopAnimate = StepUtils.bindToSignal(signal, function()
97
- local animating = SpringUtils.animating(self._currentSpring)
98
+ local animating = SpringUtils.animating(self._currentSpring, self._epsilon)
98
99
  if not animating then
99
100
  promise:Resolve(true)
100
101
  end
@@ -119,7 +120,7 @@ function SpringObject:ObserveVelocityOnSignal(signal)
119
120
  local maid = Maid.new()
120
121
 
121
122
  local startAnimate, stopAnimate = StepUtils.bindToSignal(signal, function()
122
- local animating = SpringUtils.animating(self._currentSpring)
123
+ local animating = SpringUtils.animating(self._currentSpring, self._epsilon)
123
124
  if animating then
124
125
  sub:Fire(SpringUtils.fromLinearIfNeeded(self._currentSpring.Velocity))
125
126
  else
@@ -146,7 +147,7 @@ function SpringObject:ObserveOnSignal(signal)
146
147
  local maid = Maid.new()
147
148
 
148
149
  local startAnimate, stopAnimate = StepUtils.bindToSignal(signal, function()
149
- local animating, position = SpringUtils.animating(self._currentSpring)
150
+ local animating, position = SpringUtils.animating(self._currentSpring, self._epsilon)
150
151
  sub:Fire(SpringUtils.fromLinearIfNeeded(position))
151
152
  return animating
152
153
  end)
@@ -164,7 +165,7 @@ end
164
165
  @return boolean -- True if animating
165
166
  ]=]
166
167
  function SpringObject:IsAnimating()
167
- return (SpringUtils.animating(self._currentSpring))
168
+ return (SpringUtils.animating(self._currentSpring, self._epsilon))
168
169
  end
169
170
 
170
171
  --[=[
@@ -179,6 +180,41 @@ function SpringObject:Impulse(velocity)
179
180
  self.Changed:Fire()
180
181
  end
181
182
 
183
+ --[=[
184
+ Sets the actual target. If doNotAnimate is set, then animation will be skipped.
185
+
186
+ @param value T -- The target to set
187
+ @param doNotAnimate boolean? -- Whether or not to animate
188
+ @return ()
189
+ ]=]
190
+ function SpringObject:SetTarget(value, doNotAnimate)
191
+ local observable = Blend.toPropertyObservable(value) or Rx.of(value)
192
+
193
+ if doNotAnimate then
194
+ local isFirst = true
195
+
196
+ self._maid._targetSub = observable:Subscribe(function(unconverted)
197
+ local converted = SpringUtils.toLinearIfNeeded(unconverted)
198
+ local spring = self:_getSpringForType(converted)
199
+ spring.Target = converted
200
+
201
+ if isFirst then
202
+ spring.Position = converted
203
+ spring.Velocity = 0*converted
204
+ end
205
+
206
+ self.Changed:Fire()
207
+ end)
208
+ else
209
+ self._maid._targetSub = observable:Subscribe(function(unconverted)
210
+ local converted = SpringUtils.toLinearIfNeeded(unconverted)
211
+ self:_getSpringForType(converted).Target = converted
212
+
213
+ self.Changed:Fire()
214
+ end)
215
+ end
216
+ end
217
+
182
218
  --[=[
183
219
  Instantly skips the spring forwards by that amount time
184
220
  @param delta number -- Time to skip forwards
@@ -204,6 +240,8 @@ function SpringObject:__index(index)
204
240
  return self._currentSpring.Speed
205
241
  elseif index == "Clock" then
206
242
  return self._currentSpring.Clock
243
+ elseif index == "Epsilon" then
244
+ return self._epsilon
207
245
  elseif SpringObject[index] then
208
246
  return SpringObject[index]
209
247
  else
@@ -230,14 +268,7 @@ function SpringObject:__newindex(index, value)
230
268
  self.Changed:Fire()
231
269
  end)
232
270
  elseif index == "Target" or index == "t" then
233
- local observable = Blend.toPropertyObservable(value) or Rx.of(value)
234
-
235
- self._maid._targetSub = observable:Subscribe(function(unconverted)
236
- local converted = SpringUtils.toLinearIfNeeded(unconverted)
237
- self:_getSpringForType(converted).Target = converted
238
-
239
- self.Changed:Fire()
240
- end)
271
+ self:SetTarget(value)
241
272
  elseif index == "Damper" or index == "d" then
242
273
  local observable = assert(Blend.toNumberObservable(value), "Invalid damper")
243
274
 
@@ -256,6 +287,9 @@ function SpringObject:__newindex(index, value)
256
287
  self._currentSpring.Speed = unconverted
257
288
  self.Changed:Fire()
258
289
  end)
290
+ elseif index == "Epsilon" then
291
+ assert(type(value) == "number", "Bad value")
292
+ rawset(self, "_epsilon", value)
259
293
  elseif index == "Clock" then
260
294
  assert(type(value) == "function", "Bad clock value")
261
295
  self._currentSpring.Clock = value