@quenty/numbersequenceutils 3.1.0 → 3.1.1-canary.38bdfe3.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,14 @@
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
+ ## [3.1.1-canary.38bdfe3.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/numbersequenceutils@3.1.0...@quenty/numbersequenceutils@3.1.1-canary.38bdfe3.0) (2022-09-07)
7
+
8
+ **Note:** Version bump only for package @quenty/numbersequenceutils
9
+
10
+
11
+
12
+
13
+
6
14
  # [3.1.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/numbersequenceutils@3.0.0...@quenty/numbersequenceutils@3.1.0) (2022-03-27)
7
15
 
8
16
  **Note:** Version bump only for package @quenty/numbersequenceutils
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2014-2021 Quenty
3
+ Copyright (c) 2014-2022 Quenty
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/numbersequenceutils",
3
- "version": "3.1.0",
3
+ "version": "3.1.1-canary.38bdfe3.0",
4
4
  "description": "Utility functions involving NumberSequences on Roblox",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -27,5 +27,9 @@
27
27
  "publishConfig": {
28
28
  "access": "public"
29
29
  },
30
- "gitHead": "501844bd6c3d3f765fd3032b997d8030bc963a1f"
30
+ "dependencies": {
31
+ "@quenty/loader": "5.0.1",
32
+ "@quenty/math": "2.2.0"
33
+ },
34
+ "gitHead": "38bdfe3721bddf1d272628b1104b1d8e0abaf24f"
31
35
  }
@@ -3,10 +3,91 @@
3
3
  @class NumberSequenceUtils
4
4
  ]=]
5
5
 
6
+ local require = require(script.Parent.loader).load(script)
7
+
8
+ local Math = require("Math")
9
+
6
10
  local NumberSequenceUtils = {}
7
11
 
8
12
  local EPSILON = 1e-3
9
13
 
14
+ --[=[
15
+ Gets the current NumberSequence value for a given t
16
+
17
+ @param numberSequence NumberSequence
18
+ @return (number) -> number
19
+ ]=]
20
+ function NumberSequenceUtils.getValueGenerator(numberSequence: NumberSequence): number
21
+ assert(typeof(numberSequence) == "NumberSequence", "Bad numberSequence")
22
+
23
+ -- TODO: Binary search
24
+ local keypoints = numberSequence.Keypoints
25
+ if #keypoints == 1 then
26
+ local keypoint = keypoints[1]
27
+ if keypoint.Envelope == 0 then
28
+ return function(t)
29
+ assert(type(t) == "number", "Bad t")
30
+
31
+ return keypoint.Value
32
+ end
33
+ else
34
+ return function(t)
35
+ assert(type(t) == "number", "Bad t")
36
+
37
+ return keypoint.Value + (math.random()-0.5)*keypoint.Envelope
38
+ end
39
+ end
40
+ elseif #keypoints == 2 then
41
+ local first = keypoints[1]
42
+ local second = keypoints[2]
43
+
44
+ if first.Value == second.Value and first.Envelope == 0 and second.Envelope == 0 then
45
+ return function(t)
46
+ assert(type(t) == "number", "Bad t")
47
+
48
+ return first.Value
49
+ end
50
+ else
51
+ local firstValue = first.Value + (math.random() - 0.5)*first.Envelope
52
+ local secondValue = second.Value + (math.random() - 0.5)*second.Envelope
53
+ return function(t)
54
+ assert(type(t) == "number", "Bad t")
55
+ local scale = math.clamp(Math.map(t, first.Time, second.Time, 0, 1), 0, 1)
56
+ return Math.lerp(firstValue, secondValue, scale)
57
+ end
58
+ end
59
+ else
60
+ -- pregenerate
61
+ local values = {}
62
+ for i=1, #keypoints do
63
+ local point = keypoints[i]
64
+ values[i] = point.Value + (math.random()-0.5)*point.Envelope
65
+ end
66
+
67
+ return function(t)
68
+ assert(type(t) == "number", "Bad t")
69
+
70
+ if t <= keypoints[1].Time then
71
+ return values[1]
72
+ end
73
+
74
+ -- TODO: Binary search
75
+ for i=2, #keypoints do
76
+ local point = keypoints[i]
77
+ if point.Time < t then
78
+ continue
79
+ end
80
+
81
+ local prevPoint = keypoints[i-1]
82
+ local scale = math.clamp(Math.map(t, prevPoint.Time, point.Time, 0, 1), 0, 1)
83
+ return Math.lerp(values[i-1], values[i], scale)
84
+ end
85
+
86
+ return values[#keypoints]
87
+ end
88
+ end
89
+ end
90
+
10
91
  --[=[
11
92
  Scales a number sequence value by the set amount
12
93
  @param sequence NumberSequence
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "node_modules",
3
+ "globIgnorePaths": [ "**/.package-lock.json" ],
4
+ "tree": {
5
+ "$path": { "optional": "../node_modules" }
6
+ }
7
+ }