@quenty/sounds 4.1.0 → 4.2.1-canary.256.3cf0683.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,29 @@
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.2.1-canary.256.3cf0683.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/sounds@4.2.0...@quenty/sounds@4.2.1-canary.256.3cf0683.0) (2022-03-27)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * Add initial package-locks to packages without them ([4ff9578](https://github.com/Quenty/NevermoreEngine/commit/4ff9578522d02d38d71a1c58d865a203a1c214f5))
12
+ * Sounds can be played back from parents, and we can create sounds without playing them ([49e8863](https://github.com/Quenty/NevermoreEngine/commit/49e8863450ff5fc23333ae23a8c25bc93954ecbd))
13
+
14
+
15
+
16
+
17
+
18
+ # [4.2.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/sounds@4.1.0...@quenty/sounds@4.2.0) (2022-03-20)
19
+
20
+
21
+ ### Bug Fixes
22
+
23
+ * Allow way to play a sound in a parent ([8ba20b1](https://github.com/Quenty/NevermoreEngine/commit/8ba20b1813a06697018504f40f862088956a2017))
24
+
25
+
26
+
27
+
28
+
6
29
  # [4.1.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/sounds@4.0.0...@quenty/sounds@4.1.0) (2022-03-10)
7
30
 
8
31
  **Note:** Version bump only for package @quenty/sounds
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/sounds",
3
- "version": "4.1.0",
3
+ "version": "4.2.1-canary.256.3cf0683.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.1-canary.256.3cf0683.0",
30
+ "@quenty/promise": "4.1.1-canary.256.3cf0683.0"
31
31
  },
32
32
  "publishConfig": {
33
33
  "access": "public"
34
34
  },
35
- "gitHead": "0797de955876b050fb24875de0423453e268b2ce"
35
+ "gitHead": "3cf06830affe1e6a6ca452a87969520cd941ccaa"
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
  --[=[
@@ -27,7 +31,27 @@ local SoundUtils = {}
27
31
  @param id string | number
28
32
  @return Sound
29
33
  ]=]
30
- function SoundUtils.playFromId(id)
34
+ function SoundUtils.playFromId(id: string | number): Sound
35
+ local soundId = SoundUtils.toRbxAssetId(id)
36
+ assert(type(soundId) == "string", "Bad id")
37
+
38
+ local sound = SoundUtils.createSoundFromId(id)
39
+
40
+ if RunService:IsClient() then
41
+ SoundService:PlayLocalSound(sound)
42
+ else
43
+ sound:Play()
44
+ end
45
+
46
+ SoundUtils.removeAfterTimeLength(sound)
47
+
48
+ return sound
49
+ end
50
+
51
+ --[=[
52
+ Creates a new sound object from the given id
53
+ ]=]
54
+ function SoundUtils.createSoundFromId(id: string | number): Sound
31
55
  local soundId = SoundUtils.toRbxAssetId(id)
32
56
  assert(type(soundId) == "string", "Bad id")
33
57
 
@@ -37,19 +61,45 @@ function SoundUtils.playFromId(id)
37
61
  sound.Volume = 0.25
38
62
  sound.Archivable = false
39
63
 
40
- if RunService:IsClient() then
64
+ return sound
65
+ end
66
+
67
+ --[=[
68
+ Plays back a template given asset id in the parent
69
+ ]=]
70
+ function SoundUtils.playFromIdInParent(id: string | number, parent: Instance): Sound
71
+ assert(typeof(parent) == "Instance", "Bad parent")
72
+
73
+ local sound = SoundUtils.createSoundFromId(id)
74
+ sound.Parent = parent
75
+
76
+ if not RunService:IsRunning() then
41
77
  SoundService:PlayLocalSound(sound)
42
78
  else
43
79
  sound:Play()
44
80
  end
45
81
 
46
- task.delay(sound.TimeLength + 0.05, function()
47
- sound:Destroy()
48
- end)
82
+ SoundUtils.removeAfterTimeLength(sound)
49
83
 
50
84
  return sound
51
85
  end
52
86
 
87
+ --[=[
88
+ Loads the sound and then cleans up the sound after load.
89
+
90
+ @param sound Sound
91
+ ]=]
92
+ function SoundUtils.removeAfterTimeLength(sound: Sound)
93
+ -- TODO: clean up on destroying
94
+ SoundPromiseUtils.promiseLoaded(sound):Then(function()
95
+ task.delay(sound.TimeLength + 0.05, function()
96
+ sound:Destroy()
97
+ end)
98
+ end, function()
99
+ sound:Destroy()
100
+ end)
101
+ end
102
+
53
103
  --[=[
54
104
  Plays back a template given the templateName.
55
105
 
@@ -61,7 +111,7 @@ end
61
111
  @param templateName string
62
112
  @return Sound
63
113
  ]=]
64
- function SoundUtils.playTemplate(templates, templateName)
114
+ function SoundUtils.playTemplate(templates, templateName: string)
65
115
  assert(type(templates) == "table", "Bad templates")
66
116
  assert(type(templateName) == "string", "Bad templateName")
67
117
 
@@ -70,19 +120,17 @@ function SoundUtils.playTemplate(templates, templateName)
70
120
 
71
121
  SoundService:PlayLocalSound(sound)
72
122
 
73
- task.delay(sound.TimeLength + 0.05, function()
74
- sound:Destroy()
75
- end)
123
+ SoundUtils.removeAfterTimeLength(sound)
76
124
 
77
125
  return sound
78
126
  end
79
127
 
80
128
  --[=[
81
129
  Converts a string or number to a string for playback.
82
- @param id string | number
83
- @return string
130
+ @param id string? | number
131
+ @return string?
84
132
  ]=]
85
- function SoundUtils.toRbxAssetId(id)
133
+ function SoundUtils.toRbxAssetId(id: string? | number): string
86
134
  if type(id) == "number" then
87
135
  return ("rbxassetid://%d"):format(id)
88
136
  else
@@ -102,16 +150,14 @@ end
102
150
  @param parent Instance
103
151
  @return Sound
104
152
  ]=]
105
- function SoundUtils.playTemplateInParent(templates, templateName, parent)
153
+ function SoundUtils.playTemplateInParent(templates, templateName: string, parent: Instance)
106
154
  local sound = templates:Clone(templateName)
107
155
  sound.Archivable = false
108
156
  sound.Parent = parent
109
157
 
110
158
  sound:Play()
111
159
 
112
- task.delay(sound.TimeLength + 0.05, function()
113
- sound:Destroy()
114
- end)
160
+ SoundUtils.removeAfterTimeLength(sound)
115
161
 
116
162
  return sound
117
163
  end