@quenty/humanoidspeed 1.8.0 → 2.0.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,22 @@
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.0.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/humanoidspeed@1.8.0...@quenty/humanoidspeed@2.0.0) (2022-03-06)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * Linting ([86f4a16](https://github.com/Quenty/NevermoreEngine/commit/86f4a1664de613b1bcdd146b6833d9cf3202546f))
12
+
13
+
14
+ ### Features
15
+
16
+ * Add additive speed modifier too ([9520629](https://github.com/Quenty/NevermoreEngine/commit/9520629eeec9f1a21e64bb92a0a469f0f56933b6))
17
+
18
+
19
+
20
+
21
+
6
22
  # [1.8.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/humanoidspeed@1.7.1...@quenty/humanoidspeed@1.8.0) (2022-01-17)
7
23
 
8
24
  **Note:** Version bump only for package @quenty/humanoidspeed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/humanoidspeed",
3
- "version": "1.8.0",
3
+ "version": "2.0.0",
4
4
  "description": "Handles humanoid speed in a centralized location",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -27,15 +27,15 @@
27
27
  "Quenty"
28
28
  ],
29
29
  "dependencies": {
30
- "@quenty/baseobject": "^3.5.0",
31
- "@quenty/binder": "^4.8.0",
32
- "@quenty/characterutils": "^3.6.0",
33
- "@quenty/loader": "^3.4.0",
34
- "@quenty/promise": "^3.6.0",
30
+ "@quenty/baseobject": "^4.0.0",
31
+ "@quenty/binder": "^5.0.0",
32
+ "@quenty/characterutils": "^4.0.0",
33
+ "@quenty/loader": "^4.0.0",
34
+ "@quenty/promise": "^4.0.0",
35
35
  "@quenty/table": "^2.1.1"
36
36
  },
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
- "gitHead": "c094ba8f4e128cdff08919d89de226d3d65247ce"
40
+ "gitHead": "dd428cab58282c975a4c082957dc8f58e3186905"
41
41
  }
@@ -32,6 +32,7 @@ function HumanoidSpeed.new(humanoid)
32
32
  self._speedValue.Parent = humanoid
33
33
 
34
34
  self._multipliers = {} -- Multiplicitive, [key] = mult, takes product of this list
35
+ self._adders = {} -- [key] = added
35
36
 
36
37
  self._maid:GiveTask(self._speedValue.Changed:Connect(function()
37
38
  self:_update()
@@ -71,11 +72,38 @@ function HumanoidSpeed:ApplySpeedMultiplier(multiplier)
71
72
  end
72
73
  end
73
74
 
75
+ --[=[
76
+ Applies a speed additive to the player's speed
77
+ @param amount number
78
+ @return function -- Cleanup function
79
+ ]=]
80
+ function HumanoidSpeed:ApplySpeedAdditive(amount)
81
+ assert(type(amount) == "number", "Bad amount")
82
+
83
+ local key = HttpService:GenerateGUID(false)
84
+ self._adders[key] = amount
85
+
86
+ self:_update()
87
+
88
+ return function()
89
+ if self.Destroy then
90
+ self:_removeSpeedAdder(key)
91
+ end
92
+ end
93
+ end
94
+
74
95
  function HumanoidSpeed:_removeSpeedMultiplier(key)
75
96
  self._multipliers[key] = nil
76
97
  self:_update()
77
98
  end
78
99
 
100
+
101
+ function HumanoidSpeed:_removeSpeedAdder(key)
102
+ self._adders[key] = nil
103
+ self:_update()
104
+ end
105
+
106
+
79
107
  function HumanoidSpeed:_getMultiplier()
80
108
  local mult = 1
81
109
  for _, item in pairs(self._multipliers) do
@@ -84,9 +112,17 @@ function HumanoidSpeed:_getMultiplier()
84
112
  return mult
85
113
  end
86
114
 
115
+ function HumanoidSpeed:_getBaseSpeed()
116
+ local current = self._defaultSpeed
117
+ for _, item in pairs(self._adders) do
118
+ current = current + item
119
+ end
120
+ return current
121
+ end
122
+
87
123
  function HumanoidSpeed:_update()
88
124
  local mult = self:_getMultiplier()
89
- self._speedValue.Value = mult*self._defaultSpeed
125
+ self._speedValue.Value = mult*self:_getBaseSpeed()
90
126
  self._obj.WalkSpeed = self._speedValue.Value
91
127
  end
92
128