@quenty/blend 12.4.0 → 12.5.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,23 @@
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
+ # [12.5.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/blend@12.4.0...@quenty/blend@12.5.0) (2024-09-12)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * Blend spring uses a default spring object, fixing any errors ([d468636](https://github.com/Quenty/NevermoreEngine/commit/d468636dc58f951fbfc565d4a6b68c79483e379a))
12
+ * Fix some spring object stuff ([34e8ede](https://github.com/Quenty/NevermoreEngine/commit/34e8edee97fa93a0a5bd84442b85826082444f2a))
13
+
14
+
15
+ ### Features
16
+
17
+ * Update Blend.Spring to use SpringObject underneath ([b5d41f5](https://github.com/Quenty/NevermoreEngine/commit/b5d41f5b6955fc77bd37d9ec97b9704410c7c3f5))
18
+
19
+
20
+
21
+
22
+
6
23
  # [12.4.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/blend@12.3.0...@quenty/blend@12.4.0) (2024-08-09)
7
24
 
8
25
  **Note:** Version bump only for package @quenty/blend
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/blend",
3
- "version": "12.4.0",
3
+ "version": "12.5.0",
4
4
  "description": "Declarative UI system.",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -27,24 +27,24 @@
27
27
  "access": "public"
28
28
  },
29
29
  "dependencies": {
30
- "@quenty/acceltween": "^2.4.0",
31
- "@quenty/brio": "^14.4.0",
32
- "@quenty/ducktype": "^5.3.0",
33
- "@quenty/instanceutils": "^13.4.0",
34
- "@quenty/loader": "^10.3.0",
35
- "@quenty/maid": "^3.2.0",
36
- "@quenty/promise": "^10.3.0",
37
- "@quenty/rx": "^13.4.0",
38
- "@quenty/signal": "^7.3.0",
39
- "@quenty/spring": "^10.3.0",
30
+ "@quenty/acceltween": "^2.5.0",
31
+ "@quenty/brio": "^14.5.0",
32
+ "@quenty/ducktype": "^5.4.0",
33
+ "@quenty/instanceutils": "^13.5.0",
34
+ "@quenty/loader": "^10.4.0",
35
+ "@quenty/maid": "^3.3.0",
36
+ "@quenty/promise": "^10.4.0",
37
+ "@quenty/rx": "^13.5.0",
38
+ "@quenty/signal": "^7.4.0",
39
+ "@quenty/spring": "^10.4.0",
40
40
  "@quenty/steputils": "^3.4.0",
41
41
  "@quenty/string": "^3.2.0",
42
- "@quenty/valuebaseutils": "^13.4.0",
43
- "@quenty/valueobject": "^13.4.0"
42
+ "@quenty/valuebaseutils": "^13.5.0",
43
+ "@quenty/valueobject": "^13.5.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@quenty/contentproviderutils": "^12.4.0",
47
- "@quenty/playerthumbnailutils": "^10.3.0"
46
+ "@quenty/contentproviderutils": "^12.5.0",
47
+ "@quenty/playerthumbnailutils": "^10.4.0"
48
48
  },
49
- "gitHead": "ba466bdbc05c42fb607cf5e228c16339201d21d7"
49
+ "gitHead": "fb172906f3ee725269ec1e5f4daf9dca227e729d"
50
50
  }
@@ -17,13 +17,12 @@ local BrioUtils = require("BrioUtils")
17
17
  local RxInstanceUtils = require("RxInstanceUtils")
18
18
  local RxValueBaseUtils = require("RxValueBaseUtils")
19
19
  local Signal = require("Signal")
20
- local Spring = require("Spring")
21
- local SpringUtils = require("SpringUtils")
22
20
  local StepUtils = require("StepUtils")
23
21
  local ValueBaseUtils = require("ValueBaseUtils")
24
22
  local ValueObject = require("ValueObject")
25
23
  local ValueObjectUtils = require("ValueObjectUtils")
26
24
  local RxBrioUtils = require("RxBrioUtils")
25
+ local SpringObject
27
26
 
28
27
  local Blend = {}
29
28
 
@@ -410,53 +409,17 @@ end
410
409
  @return Observable?
411
410
  ]=]
412
411
  function Blend.Spring(source, speed, damper)
413
- local sourceObservable = Blend.toPropertyObservable(source) or Rx.of(source)
414
- local speedObservable = Blend.toNumberObservable(speed)
415
- local damperObservable = Blend.toNumberObservable(damper)
416
-
417
- local function createSpring(maid, initialValue)
418
- local spring = Spring.new(initialValue)
419
-
420
- if speedObservable then
421
- maid:GiveTask(speedObservable:Subscribe(function(value)
422
- assert(type(value) == "number", "Bad value")
423
- spring.Speed = value
424
- end))
425
- end
426
-
427
- if damperObservable then
428
- maid:GiveTask(damperObservable:Subscribe(function(value)
429
- assert(type(value) == "number", "Bad value")
430
-
431
- spring.Damper = value
432
- end))
433
- end
434
-
435
- return spring
412
+ if not SpringObject then
413
+ SpringObject = require("SpringObject")
436
414
  end
437
415
 
438
- -- TODO: Centralize and cache
439
416
  return Observable.new(function(sub)
440
- local spring
441
417
  local maid = Maid.new()
442
418
 
443
- local startAnimate, stopAnimate = StepUtils.bindToRenderStep(function()
444
- local animating, position = SpringUtils.animating(spring)
445
- sub:Fire(SpringUtils.fromLinearIfNeeded(position))
446
- return animating
447
- end)
419
+ local spring = maid:Add(SpringObject.new(source, speed, damper))
420
+ spring.Epsilon = 1e-3
448
421
 
449
- maid:GiveTask(stopAnimate)
450
- maid:GiveTask(sourceObservable:Subscribe(function(value)
451
- if value then
452
- local linearValue = SpringUtils.toLinearIfNeeded(value)
453
- spring = spring or createSpring(maid, linearValue)
454
- spring.t = SpringUtils.toLinearIfNeeded(value)
455
- startAnimate()
456
- else
457
- warn("Got nil value from emitted source")
458
- end
459
- end))
422
+ maid:GiveTask(spring:Observe():Subscribe(sub:GetFireFailComplete()))
460
423
 
461
424
  return maid
462
425
  end)
@@ -45,9 +45,7 @@ function SpringObject.new(target, speed, damper)
45
45
  self._maid:GiveTask(self.Changed)
46
46
 
47
47
  if target then
48
- self.Target = target
49
- else
50
- self:_getSpringForType(0)
48
+ self:SetTarget(target)
51
49
  end
52
50
 
53
51
  if speed then
@@ -287,8 +285,17 @@ function SpringObject:__index(index)
287
285
  return self._epsilon
288
286
  elseif SpringObject[index] then
289
287
  return SpringObject[index]
288
+ elseif index == "_currentSpring" then
289
+ local found = rawget(self, "_currentSpring")
290
+ if found then
291
+ return found
292
+ end
293
+
294
+ -- Note that sometimes the current spring isn't loaded yet as a type so
295
+ -- we use a number for this.
296
+ return self:_getSpringForType(0)
290
297
  else
291
- error(("%q is not a member of SpringObject"):format(tostring(index)))
298
+ error(string.format("%q is not a member of SpringObject", tostring(index)))
292
299
  end
293
300
  end
294
301
 
@@ -323,6 +330,7 @@ function SpringObject:__newindex(index, value)
323
330
  end)
324
331
  elseif index == "Speed" or index == "s" then
325
332
  local observable = assert(Blend.toNumberObservable(value), "Invalid speed")
333
+ assert(self._currentSpring, "No self._currentSpring")
326
334
 
327
335
  self._maid._speedSub = observable:Subscribe(function(unconverted)
328
336
  assert(type(unconverted) == "number", "Bad damper")
@@ -337,16 +345,19 @@ function SpringObject:__newindex(index, value)
337
345
  assert(type(value) == "function", "Bad clock value")
338
346
  self._currentSpring.Clock = value
339
347
  self.Changed:Fire()
348
+ elseif index == "_currentSpring" then
349
+ rawset(self, "_currentSpring", value)
340
350
  else
341
- error(("%q is not a member of SpringObject"):format(tostring(index)))
351
+ error(string.format("%q is not a member of SpringObject", tostring(index)))
342
352
  end
343
353
  end
344
354
 
345
355
  function SpringObject:_getSpringForType(converted)
346
356
  if rawget(self, "_currentSpring") == nil then
347
357
  -- only happens on init
348
- rawset(self, "_currentSpring", Spring.new(converted))
349
- return self._currentSpring
358
+ local created = Spring.new(converted)
359
+ rawset(self, "_currentSpring", created)
360
+ return created
350
361
  else
351
362
  local currentType = typeof(SpringUtils.fromLinearIfNeeded(self._currentSpring.Value))
352
363
  if currentType == typeof(SpringUtils.fromLinearIfNeeded(converted)) then
@@ -356,11 +367,12 @@ function SpringObject:_getSpringForType(converted)
356
367
  local oldSpeed = self._currentSpring.s
357
368
  local clock = self._currentSpring.Clock
358
369
 
359
- self._currentSpring = Spring.new(converted)
360
- self._currentSpring.Clock = clock
361
- self._currentSpring.Speed = oldSpeed
362
- self._currentSpring.Damper = oldDamper
363
- return self._currentSpring
370
+ local newSpring = Spring.new(converted)
371
+ newSpring.Clock = clock
372
+ newSpring.Speed = oldSpeed
373
+ newSpring.Damper = oldDamper
374
+ rawset(self, "_currentSpring", newSpring)
375
+ return newSpring
364
376
  end
365
377
  end
366
378
  end