@rbxts/sound-manager 2.2.0 → 2.3.1
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/README.md +2 -2
- package/out/core/createSoundCategoryRegistry.d.ts +1 -2
- package/out/core/createSoundCategoryRegistry.luau +41 -25
- package/out/core/createSoundRegistry.d.ts +3 -1
- package/out/core/createSoundRegistry.luau +34 -9
- package/out/developer-tools/currentPlayingSounds.d.ts +4 -0
- package/out/developer-tools/currentPlayingSounds.luau +34 -0
- package/out/developer-tools/soundProperties.d.ts +13 -0
- package/out/developer-tools/soundProperties.luau +32 -0
- package/out/developer-tools/totalSoundCount.d.ts +4 -0
- package/out/developer-tools/totalSoundCount.luau +32 -0
- package/out/index.d.ts +8 -0
- package/out/init.luau +14 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<h1 align="center">
|
|
2
2
|
<a href="https://www.npmjs.com/package/@rbxts/sound-manager">
|
|
3
|
-
<img src="public/logo.png" alt="Sound-Manager" width="200" />
|
|
3
|
+
<img src="https://github.com/dev-lukas0/Sound-Manager/blob/master/public/logo.png?raw=true" alt="Sound-Manager" width="200" />
|
|
4
4
|
</a>
|
|
5
5
|
<br />
|
|
6
6
|
<b>Sound Manager</b>
|
|
@@ -40,7 +40,7 @@ npm install @rbxts/sound-manager
|
|
|
40
40
|
|
|
41
41
|
### ⚡ Starting with Sound Manager
|
|
42
42
|
|
|
43
|
-
Sound-Manager uses [`createSoundRegistry`]() and [`createSoundCategoryRegistry`]() to create sounds and categories.
|
|
43
|
+
Sound-Manager uses [`createSoundRegistry`](https://dev-lukas0.github.io/Sound-Manager/docs/reference/create-sound-registry) and [`createSoundCategoryRegistry`](https://dev-lukas0.github.io/Sound-Manager/docs/reference/create-sound-category-registry) to create sounds and categories.
|
|
44
44
|
|
|
45
45
|
```ts
|
|
46
46
|
import { createSoundRegistry } from "@rbxts/sound-manager";
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { CategoryOptions } from "./options";
|
|
2
|
-
import { SoundHandle } from "./options";
|
|
3
2
|
/**
|
|
4
3
|
* Create a sound category Registry
|
|
5
4
|
* @param definitions Define the Categorys
|
|
@@ -8,7 +7,7 @@ export declare function createSoundCategoryRegistry<T extends Record<string, Cat
|
|
|
8
7
|
loadCategory: (name: keyof T) => void;
|
|
9
8
|
playCategory: <C extends keyof T>(name: C, spatial?: {
|
|
10
9
|
emitters: BasePart[];
|
|
11
|
-
}) =>
|
|
10
|
+
}) => void;
|
|
12
11
|
stopCategory: <C extends keyof T>(name: C) => void;
|
|
13
12
|
stopAllCategories: () => void;
|
|
14
13
|
setCategoryVolume: <C extends keyof T>(category: C, volume: number) => void;
|
|
@@ -63,20 +63,38 @@ local function createSoundCategoryRegistry(definitions)
|
|
|
63
63
|
if not categoryFolder then
|
|
64
64
|
return nil
|
|
65
65
|
end
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
local categoryHandles
|
|
67
|
+
if spatial and #spatial.emitters > 0 then
|
|
68
|
+
local _name = name
|
|
69
|
+
categoryHandles = spatialHandles[_name]
|
|
70
|
+
if not categoryHandles then
|
|
71
|
+
categoryHandles = {}
|
|
72
|
+
local _name_1 = name
|
|
73
|
+
local _categoryHandles = categoryHandles
|
|
74
|
+
spatialHandles[_name_1] = _categoryHandles
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
for _, instance in categoryFolder:GetChildren() do
|
|
78
|
+
if not instance:IsA("Sound") then
|
|
68
79
|
continue
|
|
69
80
|
end
|
|
70
|
-
if spatial and #spatial.emitters > 0 then
|
|
71
|
-
local
|
|
72
|
-
local _name =
|
|
73
|
-
|
|
81
|
+
if spatial and #spatial.emitters > 0 and categoryHandles then
|
|
82
|
+
local _categoryHandles = categoryHandles
|
|
83
|
+
local _name = instance.Name
|
|
84
|
+
local old = _categoryHandles[_name]
|
|
85
|
+
if old then
|
|
86
|
+
old:stop()
|
|
87
|
+
old:destroy()
|
|
88
|
+
end
|
|
89
|
+
local handle = createSpatialHandle(instance.SoundId, spatial.emitters, instance.Volume)
|
|
90
|
+
local _categoryHandles_1 = categoryHandles
|
|
91
|
+
local _name_1 = instance.Name
|
|
92
|
+
_categoryHandles_1[_name_1] = handle
|
|
74
93
|
handle:play()
|
|
75
94
|
else
|
|
76
|
-
|
|
95
|
+
instance:Play()
|
|
77
96
|
end
|
|
78
97
|
end
|
|
79
|
-
return spatialHandles
|
|
80
98
|
end
|
|
81
99
|
--[[
|
|
82
100
|
*
|
|
@@ -85,27 +103,25 @@ local function createSoundCategoryRegistry(definitions)
|
|
|
85
103
|
|
|
86
104
|
]]
|
|
87
105
|
local function stopCategory(name)
|
|
88
|
-
local
|
|
89
|
-
local
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
106
|
+
local _name = name
|
|
107
|
+
local categoryHandles = spatialHandles[_name]
|
|
108
|
+
if categoryHandles then
|
|
109
|
+
for _, handle in categoryHandles do
|
|
110
|
+
handle:stop()
|
|
111
|
+
handle:destroy()
|
|
112
|
+
end
|
|
113
|
+
table.clear(categoryHandles)
|
|
114
|
+
local _name_1 = name
|
|
115
|
+
spatialHandles[_name_1] = nil
|
|
93
116
|
end
|
|
94
|
-
local
|
|
117
|
+
local config = definitions[name]
|
|
118
|
+
local categoryFolder = folder:FindFirstChild(config.category)
|
|
95
119
|
if not categoryFolder then
|
|
96
120
|
return nil
|
|
97
121
|
end
|
|
98
|
-
for
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
continue
|
|
102
|
-
end
|
|
103
|
-
local _result = _sound
|
|
104
|
-
if _result ~= nil then
|
|
105
|
-
_result = _result:IsA("Sound")
|
|
106
|
-
end
|
|
107
|
-
if _result then
|
|
108
|
-
_sound:Stop()
|
|
122
|
+
for _, instance in categoryFolder:GetChildren() do
|
|
123
|
+
if instance:IsA("Sound") then
|
|
124
|
+
instance:Stop()
|
|
109
125
|
end
|
|
110
126
|
end
|
|
111
127
|
end
|
|
@@ -27,6 +27,8 @@ export declare function createSoundRegistry<T extends Record<string, SoundOption
|
|
|
27
27
|
emitters: BasePart[];
|
|
28
28
|
}) => void;
|
|
29
29
|
resetAll: (sound: keyof T) => void;
|
|
30
|
-
onEnd: (sound: keyof T, callback: () => void
|
|
30
|
+
onEnd: (sound: keyof T, callback: () => void, spatial?: {
|
|
31
|
+
emitters: BasePart[];
|
|
32
|
+
}) => void;
|
|
31
33
|
isPlaying: (sound: keyof T) => boolean;
|
|
32
34
|
};
|
|
@@ -83,6 +83,10 @@ local function createSoundRegistry(definitions)
|
|
|
83
83
|
local function stop(name, spatial)
|
|
84
84
|
if not spatial then
|
|
85
85
|
local sound = folder:FindFirstChild(name)
|
|
86
|
+
if not sound then
|
|
87
|
+
warn(`{name} not found! Tip: Preload the sound first before using it.`)
|
|
88
|
+
return nil
|
|
89
|
+
end
|
|
86
90
|
local _result = sound
|
|
87
91
|
if _result ~= nil then
|
|
88
92
|
_result:Stop()
|
|
@@ -122,6 +126,10 @@ local function createSoundRegistry(definitions)
|
|
|
122
126
|
local config = definitions[soundName]
|
|
123
127
|
if not spatial or not spatial.emitters then
|
|
124
128
|
local sound = folder:FindFirstChild(soundName)
|
|
129
|
+
if not sound then
|
|
130
|
+
warn(`{soundName} not found! Tip: Preload the sound first before using it.`)
|
|
131
|
+
return nil
|
|
132
|
+
end
|
|
125
133
|
sound.Volume = 0
|
|
126
134
|
sound:Play()
|
|
127
135
|
local step = 0.05
|
|
@@ -168,6 +176,7 @@ local function createSoundRegistry(definitions)
|
|
|
168
176
|
if not spatial or not spatial.emitters then
|
|
169
177
|
local sound = folder:FindFirstChild(soundName)
|
|
170
178
|
if not sound then
|
|
179
|
+
warn(`{soundName} not found! Tip: Preload the sound first before using it.`)
|
|
171
180
|
return nil
|
|
172
181
|
end
|
|
173
182
|
local startVolume = sound.Volume
|
|
@@ -218,7 +227,8 @@ local function createSoundRegistry(definitions)
|
|
|
218
227
|
]]
|
|
219
228
|
local function reset(sound)
|
|
220
229
|
local _sound = folder:FindFirstChild(sound)
|
|
221
|
-
if not
|
|
230
|
+
if not _sound then
|
|
231
|
+
warn(`{sound} not found! Tip: Preload the sound first before using it.`)
|
|
222
232
|
return nil
|
|
223
233
|
end
|
|
224
234
|
_sound.TimePosition = 0
|
|
@@ -245,7 +255,8 @@ local function createSoundRegistry(definitions)
|
|
|
245
255
|
]]
|
|
246
256
|
local function setTimePosition(sound, timePosition)
|
|
247
257
|
local _sound = folder:FindFirstChild(sound)
|
|
248
|
-
if not
|
|
258
|
+
if not _sound then
|
|
259
|
+
warn(`{sound} not found! Tip: Preload the sound first before using it.`)
|
|
249
260
|
return nil
|
|
250
261
|
end
|
|
251
262
|
_sound.TimePosition = timePosition
|
|
@@ -279,7 +290,8 @@ local function createSoundRegistry(definitions)
|
|
|
279
290
|
local config = definitions[sound]
|
|
280
291
|
if not spatial or spatial.emitters then
|
|
281
292
|
local _sound = folder:FindFirstChild(sound)
|
|
282
|
-
if not
|
|
293
|
+
if not _sound then
|
|
294
|
+
warn(`{sound} not found! Tip: Preload the sound first before using it.`)
|
|
283
295
|
return nil
|
|
284
296
|
end
|
|
285
297
|
_sound.Volume = volume
|
|
@@ -311,12 +323,22 @@ local function createSoundRegistry(definitions)
|
|
|
311
323
|
* @param callback Callback
|
|
312
324
|
|
|
313
325
|
]]
|
|
314
|
-
local function onEnd(sound, callback)
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
326
|
+
local function onEnd(sound, callback, spatial)
|
|
327
|
+
if not spatial then
|
|
328
|
+
local _sound = folder:WaitForChild(sound)
|
|
329
|
+
if not _sound then
|
|
330
|
+
warn(`{sound} not found! Tip: Preload the sound first before using it.`)
|
|
331
|
+
return nil
|
|
332
|
+
end
|
|
333
|
+
_sound.Ended:Connect(callback)
|
|
334
|
+
else
|
|
335
|
+
local _sound = sound
|
|
336
|
+
local handle = spatialHandles[_sound]
|
|
337
|
+
if not handle then
|
|
338
|
+
return nil
|
|
339
|
+
end
|
|
340
|
+
handle:played(callback)
|
|
318
341
|
end
|
|
319
|
-
_sound.Ended:Connect(callback)
|
|
320
342
|
end
|
|
321
343
|
--[[
|
|
322
344
|
*
|
|
@@ -335,7 +357,10 @@ local function createSoundRegistry(definitions)
|
|
|
335
357
|
|
|
336
358
|
]]
|
|
337
359
|
local function isPlaying(sound)
|
|
338
|
-
local _sound = folder:
|
|
360
|
+
local _sound = folder:FindFirstChild(sound)
|
|
361
|
+
if not _sound then
|
|
362
|
+
warn(`{sound} not found! Tip: Preload the sound first before using it.`)
|
|
363
|
+
end
|
|
339
364
|
if _sound.IsPlaying == true then
|
|
340
365
|
return true
|
|
341
366
|
else
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
--[[
|
|
3
|
+
*
|
|
4
|
+
* @returns the current playing legacy sounds and spatial sounds
|
|
5
|
+
|
|
6
|
+
]]
|
|
7
|
+
local function currentPlayingSounds()
|
|
8
|
+
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
|
9
|
+
local playingSounds = {}
|
|
10
|
+
local soundsFolder = ReplicatedStorage:FindFirstChild("Sounds")
|
|
11
|
+
if soundsFolder and soundsFolder:IsA("Folder") then
|
|
12
|
+
for _, category in soundsFolder:GetChildren() do
|
|
13
|
+
if not category:IsA("Folder") then
|
|
14
|
+
continue
|
|
15
|
+
end
|
|
16
|
+
for _1, instance in category:GetChildren() do
|
|
17
|
+
if instance:IsA("Sound") then
|
|
18
|
+
local _arg0 = `{instance.Name}`
|
|
19
|
+
table.insert(playingSounds, _arg0)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
for _, instance in ReplicatedStorage:GetChildren() do
|
|
25
|
+
if instance:IsA("AudioPlayer") then
|
|
26
|
+
local _arg0 = `{instance.Name}`
|
|
27
|
+
table.insert(playingSounds, _arg0)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
return playingSounds
|
|
31
|
+
end
|
|
32
|
+
return {
|
|
33
|
+
currentPlayingSounds = currentPlayingSounds,
|
|
34
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SoundOptions } from "../core/options";
|
|
2
|
+
/**
|
|
3
|
+
* @returns Properties of a sound
|
|
4
|
+
*/
|
|
5
|
+
export declare function soundProperties<T extends Record<string, SoundOptions>>(name: keyof T, definitions: T): {
|
|
6
|
+
id: string;
|
|
7
|
+
volume: number;
|
|
8
|
+
loop: boolean;
|
|
9
|
+
spatial: {
|
|
10
|
+
attenuation?: number;
|
|
11
|
+
directional?: boolean;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
--[[
|
|
3
|
+
*
|
|
4
|
+
* @returns Properties of a sound
|
|
5
|
+
|
|
6
|
+
]]
|
|
7
|
+
local function soundProperties(name, definitions)
|
|
8
|
+
local sound = definitions[name]
|
|
9
|
+
if not sound then
|
|
10
|
+
error(`Sound {tostring(name)} not found`)
|
|
11
|
+
end
|
|
12
|
+
local _object = {
|
|
13
|
+
id = sound.id,
|
|
14
|
+
}
|
|
15
|
+
local _left = "volume"
|
|
16
|
+
local _condition = sound.volume
|
|
17
|
+
if _condition == nil then
|
|
18
|
+
_condition = 1
|
|
19
|
+
end
|
|
20
|
+
_object[_left] = _condition
|
|
21
|
+
local _left_1 = "loop"
|
|
22
|
+
local _condition_1 = sound.loop
|
|
23
|
+
if _condition_1 == nil then
|
|
24
|
+
_condition_1 = false
|
|
25
|
+
end
|
|
26
|
+
_object[_left_1] = _condition_1
|
|
27
|
+
_object.spatial = sound.spatial or {}
|
|
28
|
+
return _object
|
|
29
|
+
end
|
|
30
|
+
return {
|
|
31
|
+
soundProperties = soundProperties,
|
|
32
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
--[[
|
|
3
|
+
*
|
|
4
|
+
* @returns Total count of legacy sounds and spatial sounds
|
|
5
|
+
|
|
6
|
+
]]
|
|
7
|
+
local function TotalSoundCount()
|
|
8
|
+
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
|
9
|
+
local count = 0
|
|
10
|
+
local soundsFolder = ReplicatedStorage:FindFirstChild("Sounds")
|
|
11
|
+
if soundsFolder and soundsFolder:IsA("Folder") then
|
|
12
|
+
for _, category in soundsFolder:GetChildren() do
|
|
13
|
+
if not category:IsA("Folder") then
|
|
14
|
+
continue
|
|
15
|
+
end
|
|
16
|
+
for _1, instance in category:GetChildren() do
|
|
17
|
+
if instance:IsA("Sound") then
|
|
18
|
+
count += 1
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
for _, instance in ReplicatedStorage:GetChildren() do
|
|
24
|
+
if instance:IsA("AudioPlayer") then
|
|
25
|
+
count += 1
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
return count
|
|
29
|
+
end
|
|
30
|
+
return {
|
|
31
|
+
TotalSoundCount = TotalSoundCount,
|
|
32
|
+
}
|
package/out/index.d.ts
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
|
+
import { TotalSoundCount } from "./developer-tools/totalSoundCount";
|
|
2
|
+
import { currentPlayingSounds } from "./developer-tools/currentPlayingSounds";
|
|
3
|
+
import { soundProperties } from "./developer-tools/soundProperties";
|
|
1
4
|
export * from "./core/createSoundRegistry";
|
|
2
5
|
export * from "./core/createSoundCategoryRegistry";
|
|
6
|
+
export declare namespace Developer_Tools {
|
|
7
|
+
const getTotalSoundCount: typeof TotalSoundCount;
|
|
8
|
+
const getCurrentPlayingSounds: typeof currentPlayingSounds;
|
|
9
|
+
const getSoundProperties: typeof soundProperties;
|
|
10
|
+
}
|
package/out/init.luau
CHANGED
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
-- Compiled with roblox-ts v3.0.0
|
|
2
2
|
local TS = _G[script]
|
|
3
3
|
local exports = {}
|
|
4
|
+
local TotalSoundCount = TS.import(script, script, "developer-tools", "totalSoundCount").TotalSoundCount
|
|
5
|
+
local currentPlayingSounds = TS.import(script, script, "developer-tools", "currentPlayingSounds").currentPlayingSounds
|
|
6
|
+
local soundProperties = TS.import(script, script, "developer-tools", "soundProperties").soundProperties
|
|
4
7
|
for _k, _v in TS.import(script, script, "core", "createSoundRegistry") or {} do
|
|
5
8
|
exports[_k] = _v
|
|
6
9
|
end
|
|
7
10
|
for _k, _v in TS.import(script, script, "core", "createSoundCategoryRegistry") or {} do
|
|
8
11
|
exports[_k] = _v
|
|
9
12
|
end
|
|
13
|
+
local Developer_Tools = {}
|
|
14
|
+
do
|
|
15
|
+
local _container = Developer_Tools
|
|
16
|
+
local getTotalSoundCount = TotalSoundCount
|
|
17
|
+
_container.getTotalSoundCount = getTotalSoundCount
|
|
18
|
+
local getCurrentPlayingSounds = currentPlayingSounds
|
|
19
|
+
_container.getCurrentPlayingSounds = getCurrentPlayingSounds
|
|
20
|
+
local getSoundProperties = soundProperties
|
|
21
|
+
_container.getSoundProperties = getSoundProperties
|
|
22
|
+
end
|
|
23
|
+
exports.Developer_Tools = Developer_Tools
|
|
10
24
|
return exports
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rbxts/sound-manager",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"description": "A sound manager for Roblox-Typescript projects.",
|
|
5
5
|
"main": "out/init.lua",
|
|
6
6
|
"scripts": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"keywords": [],
|
|
13
13
|
"author": "Easy-Build-Studio",
|
|
14
|
-
"license": "
|
|
14
|
+
"license": "MIT",
|
|
15
15
|
"type": "commonjs",
|
|
16
16
|
"types": "out/index.d.ts",
|
|
17
17
|
"files": [
|