@quenty/sounds 4.1.0-canary.252.9753dcc.0 → 4.2.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 +12 -1
- package/package.json +4 -4
- package/src/Shared/SoundUtils.lua +54 -9
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +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
|
-
# [4.
|
|
6
|
+
# [4.2.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/sounds@4.1.0...@quenty/sounds@4.2.0) (2022-03-20)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* Allow way to play a sound in a parent ([8ba20b1](https://github.com/Quenty/NevermoreEngine/commit/8ba20b1813a06697018504f40f862088956a2017))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [4.1.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/sounds@4.0.0...@quenty/sounds@4.1.0) (2022-03-10)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @quenty/sounds
|
|
9
20
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/sounds",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Utility functions involving sounds and their state",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
"Quenty"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@quenty/loader": "4.0.0",
|
|
30
|
-
"@quenty/promise": "4.1.0
|
|
29
|
+
"@quenty/loader": "^4.0.0",
|
|
30
|
+
"@quenty/promise": "^4.1.0"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "126c7a7e01245332b3e7622600b3528c5e0e97ae"
|
|
36
36
|
}
|
|
@@ -8,9 +8,13 @@
|
|
|
8
8
|
@class SoundUtils
|
|
9
9
|
]=]
|
|
10
10
|
|
|
11
|
+
local require = require(script.Parent.loader).load(script)
|
|
12
|
+
|
|
11
13
|
local SoundService = game:GetService("SoundService")
|
|
12
14
|
local RunService = game:GetService("RunService")
|
|
13
15
|
|
|
16
|
+
local SoundPromiseUtils = require("SoundPromiseUtils")
|
|
17
|
+
|
|
14
18
|
local SoundUtils = {}
|
|
15
19
|
|
|
16
20
|
--[=[
|
|
@@ -43,13 +47,58 @@ function SoundUtils.playFromId(id)
|
|
|
43
47
|
sound:Play()
|
|
44
48
|
end
|
|
45
49
|
|
|
46
|
-
|
|
47
|
-
sound:Destroy()
|
|
48
|
-
end)
|
|
50
|
+
SoundUtils.removeAfterTimeLength(sound)
|
|
49
51
|
|
|
50
52
|
return sound
|
|
51
53
|
end
|
|
52
54
|
|
|
55
|
+
--[=[
|
|
56
|
+
Plays back a template given asset id in the parent
|
|
57
|
+
|
|
58
|
+
@param id string | number
|
|
59
|
+
@param parent Instance
|
|
60
|
+
@return Sound
|
|
61
|
+
]=]
|
|
62
|
+
function SoundUtils.playFromIdInParent(id, parent)
|
|
63
|
+
assert(typeof(parent) == "Instance", "Bad parent")
|
|
64
|
+
|
|
65
|
+
local soundId = SoundUtils.toRbxAssetId(id)
|
|
66
|
+
assert(type(soundId) == "string", "Bad id")
|
|
67
|
+
|
|
68
|
+
local sound = Instance.new("Sound")
|
|
69
|
+
sound.Name = ("Sound_%s"):format(soundId)
|
|
70
|
+
sound.SoundId = soundId
|
|
71
|
+
sound.Volume = 0.25
|
|
72
|
+
sound.Archivable = false
|
|
73
|
+
sound.Parent = parent
|
|
74
|
+
|
|
75
|
+
if not RunService:IsRunning() then
|
|
76
|
+
SoundService:PlayLocalSound(sound)
|
|
77
|
+
else
|
|
78
|
+
sound:Play()
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
SoundUtils.removeAfterTimeLength(sound)
|
|
82
|
+
|
|
83
|
+
return sound
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
--[=[
|
|
87
|
+
Loads the sound and then cleans up the sound after load.
|
|
88
|
+
|
|
89
|
+
@param sound Sound
|
|
90
|
+
]=]
|
|
91
|
+
function SoundUtils.removeAfterTimeLength(sound)
|
|
92
|
+
-- TODO: clean up on destroying
|
|
93
|
+
SoundPromiseUtils.promiseLoaded(sound):Then(function()
|
|
94
|
+
task.delay(sound.TimeLength + 0.05, function()
|
|
95
|
+
sound:Destroy()
|
|
96
|
+
end)
|
|
97
|
+
end, function()
|
|
98
|
+
sound:Destroy()
|
|
99
|
+
end)
|
|
100
|
+
end
|
|
101
|
+
|
|
53
102
|
--[=[
|
|
54
103
|
Plays back a template given the templateName.
|
|
55
104
|
|
|
@@ -70,9 +119,7 @@ function SoundUtils.playTemplate(templates, templateName)
|
|
|
70
119
|
|
|
71
120
|
SoundService:PlayLocalSound(sound)
|
|
72
121
|
|
|
73
|
-
|
|
74
|
-
sound:Destroy()
|
|
75
|
-
end)
|
|
122
|
+
SoundUtils.removeAfterTimeLength(sound)
|
|
76
123
|
|
|
77
124
|
return sound
|
|
78
125
|
end
|
|
@@ -109,9 +156,7 @@ function SoundUtils.playTemplateInParent(templates, templateName, parent)
|
|
|
109
156
|
|
|
110
157
|
sound:Play()
|
|
111
158
|
|
|
112
|
-
|
|
113
|
-
sound:Destroy()
|
|
114
|
-
end)
|
|
159
|
+
SoundUtils.removeAfterTimeLength(sound)
|
|
115
160
|
|
|
116
161
|
return sound
|
|
117
162
|
end
|