@quenty/sounds 6.9.1-canary.402.40f9a1f.0 → 6.9.1-canary.402.a911cda.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 +11 -2
- package/package.json +7 -5
- package/src/Shared/SoundPromiseUtils.lua +28 -4
- package/src/Shared/SoundUtils.lua +44 -18
package/CHANGELOG.md
CHANGED
|
@@ -3,9 +3,18 @@
|
|
|
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.9.1-canary.402.
|
|
6
|
+
## [6.9.1-canary.402.a911cda.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/sounds@6.9.0...@quenty/sounds@6.9.1-canary.402.a911cda.0) (2023-08-23)
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* Add missing dependencies ([324e3db](https://github.com/Quenty/NevermoreEngine/commit/324e3dbcd7ed260542eebe24889cbc6cd968d380))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* Sound plays using :Play() always since PlayLocalSound no longer works in Hoarcekat ([58eeb15](https://github.com/Quenty/NevermoreEngine/commit/58eeb15e832c5d13a4a602c87656b233862d8392))
|
|
17
|
+
* Sounds can play back tables ([d33bbee](https://github.com/Quenty/NevermoreEngine/commit/d33bbeed98016b04b0958ce27df5a82f7c9cbf4e))
|
|
9
18
|
|
|
10
19
|
|
|
11
20
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/sounds",
|
|
3
|
-
"version": "6.9.1-canary.402.
|
|
3
|
+
"version": "6.9.1-canary.402.a911cda.0",
|
|
4
4
|
"description": "Utility functions involving sounds and their state",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -26,12 +26,14 @@
|
|
|
26
26
|
"Quenty"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@quenty/loader": "6.2.2-canary.402.
|
|
30
|
-
"@quenty/
|
|
31
|
-
"@quenty/
|
|
29
|
+
"@quenty/loader": "6.2.2-canary.402.a911cda.0",
|
|
30
|
+
"@quenty/maid": "2.5.1-canary.402.a911cda.0",
|
|
31
|
+
"@quenty/promise": "6.7.1-canary.402.a911cda.0",
|
|
32
|
+
"@quenty/promisemaid": "1.2.1-canary.402.a911cda.0",
|
|
33
|
+
"@quenty/rbxasset": "1.1.1-canary.402.a911cda.0"
|
|
32
34
|
},
|
|
33
35
|
"publishConfig": {
|
|
34
36
|
"access": "public"
|
|
35
37
|
},
|
|
36
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "a911cdaf4f1039b599528cec17b027f4660e4fd8"
|
|
37
39
|
}
|
|
@@ -7,6 +7,8 @@ local require = require(script.Parent.loader).load(script)
|
|
|
7
7
|
|
|
8
8
|
local Promise = require("Promise")
|
|
9
9
|
local PromiseUtils = require("PromiseUtils")
|
|
10
|
+
local PromiseMaidUtils = require("PromiseMaidUtils")
|
|
11
|
+
local Maid = require("Maid")
|
|
10
12
|
|
|
11
13
|
local SoundPromiseUtils = {}
|
|
12
14
|
|
|
@@ -21,22 +23,44 @@ function SoundPromiseUtils.promiseLoaded(sound)
|
|
|
21
23
|
end
|
|
22
24
|
|
|
23
25
|
local promise = Promise.new()
|
|
26
|
+
local maid = Maid.new()
|
|
24
27
|
|
|
25
|
-
|
|
28
|
+
maid:GiveTask(sound:GetPropertyChangedSignal("IsLoaded"):Connect(function()
|
|
29
|
+
if sound.IsLoaded then
|
|
30
|
+
promise:Resolve()
|
|
31
|
+
end
|
|
32
|
+
end))
|
|
26
33
|
|
|
27
|
-
|
|
34
|
+
maid:GiveTask(sound.Loaded:Connect(function()
|
|
28
35
|
if sound.IsLoaded then
|
|
29
36
|
promise:Resolve()
|
|
30
37
|
end
|
|
31
|
-
end)
|
|
38
|
+
end))
|
|
32
39
|
|
|
33
40
|
promise:Finally(function()
|
|
34
|
-
|
|
41
|
+
maid:DoCleaning()
|
|
35
42
|
end)
|
|
36
43
|
|
|
37
44
|
return promise
|
|
38
45
|
end
|
|
39
46
|
|
|
47
|
+
function SoundPromiseUtils.promisePlayed(sound)
|
|
48
|
+
return SoundPromiseUtils.promiseLoaded(sound):Then(function()
|
|
49
|
+
return PromiseUtils.delayed(sound.TimeLength)
|
|
50
|
+
end)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
function SoundPromiseUtils.promiseLooped(sound)
|
|
54
|
+
local promise = Promise.new()
|
|
55
|
+
|
|
56
|
+
PromiseMaidUtils.whilePromise(promise, function(maid)
|
|
57
|
+
maid:GiveTask(sound.DidLoop:Connect(function()
|
|
58
|
+
promise:Resolve()
|
|
59
|
+
end))
|
|
60
|
+
end)
|
|
61
|
+
|
|
62
|
+
return promise
|
|
63
|
+
end
|
|
40
64
|
--[=[
|
|
41
65
|
Promises that all sounds are loaded
|
|
42
66
|
@param sounds { Sound }
|
|
@@ -29,13 +29,9 @@ local SoundUtils = {}
|
|
|
29
29
|
The sound will be automatically cleaned up after the sound is played.
|
|
30
30
|
:::
|
|
31
31
|
|
|
32
|
-
@param id string | number
|
|
33
32
|
@return Sound
|
|
34
33
|
]=]
|
|
35
|
-
function SoundUtils.playFromId(id: string | number): Sound
|
|
36
|
-
local soundId = RbxAssetUtils.toRbxAssetId(id)
|
|
37
|
-
assert(type(soundId) == "string", "Bad id")
|
|
38
|
-
|
|
34
|
+
function SoundUtils.playFromId(id: string | number | table): Sound
|
|
39
35
|
local sound = SoundUtils.createSoundFromId(id)
|
|
40
36
|
|
|
41
37
|
if RunService:IsClient() then
|
|
@@ -52,34 +48,52 @@ end
|
|
|
52
48
|
--[=[
|
|
53
49
|
Creates a new sound object from the given id
|
|
54
50
|
]=]
|
|
55
|
-
function SoundUtils.createSoundFromId(id: string | number): Sound
|
|
56
|
-
local soundId =
|
|
51
|
+
function SoundUtils.createSoundFromId(id: string | number | table): Sound
|
|
52
|
+
local soundId = SoundUtils.toRbxAssetId(id)
|
|
57
53
|
assert(type(soundId) == "string", "Bad id")
|
|
58
54
|
|
|
59
55
|
local sound = Instance.new("Sound")
|
|
56
|
+
sound.Archivable = false
|
|
57
|
+
|
|
58
|
+
SoundUtils.applyPropertiesFromId(sound, id)
|
|
59
|
+
|
|
60
|
+
return sound
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
function SoundUtils.applyPropertiesFromId(sound, id)
|
|
64
|
+
local soundId = SoundUtils.toRbxAssetId(id)
|
|
60
65
|
sound.Name = ("Sound_%s"):format(soundId)
|
|
61
66
|
sound.SoundId = soundId
|
|
62
67
|
sound.RollOffMode = Enum.RollOffMode.InverseTapered
|
|
63
68
|
sound.Volume = 0.25
|
|
64
|
-
sound.Archivable = false
|
|
65
69
|
|
|
66
|
-
|
|
70
|
+
if type(id) == "table" then
|
|
71
|
+
for property, value in pairs(id) do
|
|
72
|
+
if property ~= "Parent" and property ~= "RollOffMinDistance" then
|
|
73
|
+
sound[property] = value
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
if id.RollOffMinDistance then
|
|
78
|
+
sound.RollOffMinDistance = id.RollOffMinDistance
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
if id.Parent then
|
|
82
|
+
sound.Parent = id.Parent
|
|
83
|
+
end
|
|
84
|
+
end
|
|
67
85
|
end
|
|
68
86
|
|
|
69
87
|
--[=[
|
|
70
88
|
Plays back a template given asset id in the parent
|
|
71
89
|
]=]
|
|
72
|
-
function SoundUtils.playFromIdInParent(id: string | number, parent: Instance): Sound
|
|
90
|
+
function SoundUtils.playFromIdInParent(id: string | number | table, parent: Instance): Sound
|
|
73
91
|
assert(typeof(parent) == "Instance", "Bad parent")
|
|
74
92
|
|
|
75
93
|
local sound = SoundUtils.createSoundFromId(id)
|
|
76
94
|
sound.Parent = parent
|
|
77
95
|
|
|
78
|
-
|
|
79
|
-
SoundService:PlayLocalSound(sound)
|
|
80
|
-
else
|
|
81
|
-
sound:Play()
|
|
82
|
-
end
|
|
96
|
+
sound:Play()
|
|
83
97
|
|
|
84
98
|
SoundUtils.removeAfterTimeLength(sound)
|
|
85
99
|
|
|
@@ -130,14 +144,26 @@ end
|
|
|
130
144
|
--[=[
|
|
131
145
|
Converts a string or number to a string for playback.
|
|
132
146
|
|
|
133
|
-
Alias of [RbxAssetUtils.toRbxAssetId] for backwards compatibility.
|
|
134
|
-
|
|
135
147
|
@function toRbxAssetId
|
|
136
148
|
@param id string? | number
|
|
137
149
|
@return string?
|
|
138
150
|
@within SoundUtils
|
|
139
151
|
]=]
|
|
140
|
-
SoundUtils.toRbxAssetId
|
|
152
|
+
function SoundUtils.toRbxAssetId(soundId)
|
|
153
|
+
if type(soundId) == "table" then
|
|
154
|
+
return RbxAssetUtils.toRbxAssetId(soundId.SoundId)
|
|
155
|
+
else
|
|
156
|
+
return RbxAssetUtils.toRbxAssetId(soundId)
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
function SoundUtils.isConvertableToRbxAsset(soundId)
|
|
161
|
+
if type(soundId) == "table" then
|
|
162
|
+
return RbxAssetUtils.isConvertableToRbxAsset(soundId.SoundId)
|
|
163
|
+
else
|
|
164
|
+
return RbxAssetUtils.isConvertableToRbxAsset(soundId)
|
|
165
|
+
end
|
|
166
|
+
end
|
|
141
167
|
|
|
142
168
|
--[=[
|
|
143
169
|
Plays back a sound template in a specific parent.
|