@rbxts/sound-manager 2.1.0 → 2.3.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/README.md +62 -43
- package/out/core/createSoundCategoryRegistry.d.ts +3 -1
- package/out/core/createSoundCategoryRegistry.luau +48 -33
- package/out/core/createSoundRegistry.d.ts +19 -7
- package/out/core/createSoundRegistry.luau +151 -58
- package/out/core/createSpatialHandle.d.ts +7 -0
- package/out/core/createSpatialHandle.luau +59 -0
- package/out/core/options.d.ts +12 -0
- 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/out/utils/functions.d.ts +13 -0
- package/out/utils/functions.luau +47 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -1,15 +1,48 @@
|
|
|
1
|
-
|
|
1
|
+
<h1 align="center">
|
|
2
|
+
<a href="https://www.npmjs.com/package/@rbxts/sound-manager">
|
|
3
|
+
<img src="https://github.com/dev-lukas0/Sound-Manager/blob/master/public/logo.png?raw=true" alt="Sound-Manager" width="200" />
|
|
4
|
+
</a>
|
|
5
|
+
<br />
|
|
6
|
+
<b>Sound Manager</b>
|
|
7
|
+
|
|
8
|
+
</h1>
|
|
2
9
|
|
|
3
|
-
|
|
10
|
+
<div align="center">
|
|
11
|
+
|
|
12
|
+
  
|
|
13
|
+
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## 🔉 Sound Manager
|
|
22
|
+
|
|
23
|
+
**Sound Manager** is a roblox sound-management library built with Roblox-TS, designed to simplify sound handling in your roblox projects.
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
## 📦 Installation
|
|
4
28
|
|
|
5
|
-
## Getting Started
|
|
6
29
|
To use the Sound Manager library in your Roblox-TS project, install it via npm:
|
|
30
|
+
|
|
7
31
|
```bash
|
|
8
32
|
npm install @rbxts/sound-manager
|
|
9
33
|
```
|
|
10
34
|
|
|
11
|
-
|
|
12
|
-
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
## 🚀 Quick Start
|
|
38
|
+
|
|
39
|
+
[See the Documentation ->](https://dev-lukas0.github.io/Sound-Manager-Docs/)
|
|
40
|
+
|
|
41
|
+
### ⚡ Starting with Sound Manager
|
|
42
|
+
|
|
43
|
+
Sound-Manager uses [`createSoundRegistry`]() and [`createSoundCategoryRegistry`]() to create sounds and categories.
|
|
44
|
+
|
|
45
|
+
```ts
|
|
13
46
|
import { createSoundRegistry } from "@rbxts/sound-manager";
|
|
14
47
|
|
|
15
48
|
const Sounds = createSoundRegistry({
|
|
@@ -17,51 +50,37 @@ const Sounds = createSoundRegistry({
|
|
|
17
50
|
id: "rbxassetid://4714389545",
|
|
18
51
|
volume: 1,
|
|
19
52
|
loop: false,
|
|
20
|
-
}
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
Test: {
|
|
56
|
+
id: "rbxassetid://17771398985",
|
|
57
|
+
volume: 1,
|
|
58
|
+
loop: true,
|
|
59
|
+
}
|
|
21
60
|
});
|
|
61
|
+
```
|
|
22
62
|
|
|
23
|
-
Sounds
|
|
63
|
+
### 🎵 Playing Sounds
|
|
24
64
|
|
|
65
|
+
To play a sound, you can use the [`play`](https://dev-lukas0.github.io/Sound-Manager-Docs/docs/API/play) method on the sound registry:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
25
68
|
Sounds.play("SCP096");
|
|
26
69
|
```
|
|
27
70
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
- [x] onEnd
|
|
40
|
-
- [x] isPlaying
|
|
41
|
-
|
|
42
|
-
### Development Utilities
|
|
43
|
-
- [ ] Total Sound Count function
|
|
44
|
-
- [ ] Currently Playing Sounds function
|
|
45
|
-
- [ ] Sound Instance Getter function
|
|
46
|
-
- [ ] Sound Properties Getter function
|
|
47
|
-
|
|
48
|
-
### Category API
|
|
49
|
-
- [x] playCategory
|
|
50
|
-
- [x] stopCategory / stopAllCategories
|
|
51
|
-
- [x] setCategoryVolume / setGlobalCategoryVolume
|
|
52
|
-
- [x] fadeInCategory / fadeOutCategory
|
|
53
|
-
- [x] preloadCategory / preloadAllCategories
|
|
54
|
-
- [x] isCategoryPlaying
|
|
55
|
-
- [x] onCategoryEnd
|
|
56
|
-
- [x] resetCategory / resetAllCategories
|
|
57
|
-
- [x] playSoundFromCategory
|
|
58
|
-
|
|
59
|
-
### Features
|
|
60
|
-
- [x] Sound Autocompletion
|
|
61
|
-
- [ ] Sound Categories
|
|
62
|
-
- [ ] Sound Creation functions
|
|
63
|
-
- [ ] Sound Priority
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
## 🗺️ Roadmap
|
|
74
|
+
-------
|
|
75
|
+
See the [Roadmap](./Roadmap.md) for planned features and current progress.
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
## 📝 License
|
|
80
|
+
|
|
81
|
+
**Sound Manager** is licensed under the [MIT LICENSE](./LICENSE).
|
|
64
82
|
|
|
83
|
+
|
|
65
84
|
|
|
66
85
|
For more Details:
|
|
67
86
|
https://dev-lukas0.github.io/Sound-Manager-Docs/
|
|
@@ -5,7 +5,9 @@ import { CategoryOptions } from "./options";
|
|
|
5
5
|
*/
|
|
6
6
|
export declare function createSoundCategoryRegistry<T extends Record<string, CategoryOptions>>(definitions: T): {
|
|
7
7
|
loadCategory: (name: keyof T) => void;
|
|
8
|
-
playCategory: <C extends keyof T>(name: C
|
|
8
|
+
playCategory: <C extends keyof T>(name: C, spatial?: {
|
|
9
|
+
emitters: BasePart[];
|
|
10
|
+
}) => void;
|
|
9
11
|
stopCategory: <C extends keyof T>(name: C) => void;
|
|
10
12
|
stopAllCategories: () => void;
|
|
11
13
|
setCategoryVolume: <C extends keyof T>(category: C, volume: number) => void;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local createSpatialHandle = TS.import(script, script.Parent, "createSpatialHandle").createSpatialHandle
|
|
2
4
|
--[[
|
|
3
5
|
*
|
|
4
6
|
* Create a sound category Registry
|
|
@@ -6,6 +8,7 @@
|
|
|
6
8
|
|
|
7
9
|
]]
|
|
8
10
|
local function createSoundCategoryRegistry(definitions)
|
|
11
|
+
local spatialHandles = {}
|
|
9
12
|
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
|
10
13
|
local folder = ReplicatedStorage:FindFirstChild("Sounds")
|
|
11
14
|
if not folder then
|
|
@@ -53,29 +56,43 @@ local function createSoundCategoryRegistry(definitions)
|
|
|
53
56
|
* @param name Sound Category
|
|
54
57
|
|
|
55
58
|
]]
|
|
56
|
-
local function playCategory(name)
|
|
59
|
+
local function playCategory(name, spatial)
|
|
57
60
|
loadCategory(name)
|
|
58
61
|
local config = definitions[name]
|
|
59
|
-
local
|
|
60
|
-
local soundsFolder = ReplicatedStorage:FindFirstChild("Sounds")
|
|
61
|
-
if not soundsFolder then
|
|
62
|
-
return nil
|
|
63
|
-
end
|
|
64
|
-
local categoryFolder = soundsFolder:FindFirstChild(config.category)
|
|
62
|
+
local categoryFolder = folder:FindFirstChild(config.category)
|
|
65
63
|
if not categoryFolder then
|
|
66
64
|
return nil
|
|
67
65
|
end
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
|
72
75
|
end
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
end
|
|
77
|
+
for _, instance in categoryFolder:GetChildren() do
|
|
78
|
+
if not instance:IsA("Sound") then
|
|
79
|
+
continue
|
|
76
80
|
end
|
|
77
|
-
if
|
|
78
|
-
|
|
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
|
|
93
|
+
handle:play()
|
|
94
|
+
else
|
|
95
|
+
instance:Play()
|
|
79
96
|
end
|
|
80
97
|
end
|
|
81
98
|
end
|
|
@@ -86,27 +103,25 @@ local function createSoundCategoryRegistry(definitions)
|
|
|
86
103
|
|
|
87
104
|
]]
|
|
88
105
|
local function stopCategory(name)
|
|
89
|
-
local
|
|
90
|
-
local
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
|
94
116
|
end
|
|
95
|
-
local
|
|
117
|
+
local config = definitions[name]
|
|
118
|
+
local categoryFolder = folder:FindFirstChild(config.category)
|
|
96
119
|
if not categoryFolder then
|
|
97
120
|
return nil
|
|
98
121
|
end
|
|
99
|
-
for
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
continue
|
|
103
|
-
end
|
|
104
|
-
local _result = _sound
|
|
105
|
-
if _result ~= nil then
|
|
106
|
-
_result = _result:IsA("Sound")
|
|
107
|
-
end
|
|
108
|
-
if _result then
|
|
109
|
-
_sound:Stop()
|
|
122
|
+
for _, instance in categoryFolder:GetChildren() do
|
|
123
|
+
if instance:IsA("Sound") then
|
|
124
|
+
instance:Stop()
|
|
110
125
|
end
|
|
111
126
|
end
|
|
112
127
|
end
|
|
@@ -1,22 +1,34 @@
|
|
|
1
|
-
import { SoundOptions } from "./options";
|
|
1
|
+
import { SoundHandle, SoundOptions } from "./options";
|
|
2
2
|
/**
|
|
3
3
|
* Create a sound Registry
|
|
4
4
|
* @param definitions Define the Sounds
|
|
5
5
|
*/
|
|
6
6
|
export declare function createSoundRegistry<T extends Record<string, SoundOptions>>(definitions: T): {
|
|
7
|
-
play: (name: keyof T
|
|
8
|
-
|
|
7
|
+
play: (name: keyof T, spatial?: {
|
|
8
|
+
emitters: BasePart[];
|
|
9
|
+
}) => SoundHandle | undefined;
|
|
10
|
+
stop: (name: keyof T, spatial?: {
|
|
11
|
+
emitters: BasePart[];
|
|
12
|
+
}) => void;
|
|
9
13
|
preloadAll: () => void;
|
|
10
14
|
load: (name: keyof T) => void;
|
|
11
|
-
fadeIn: (soundName: keyof T, duration: number, volume: number
|
|
12
|
-
|
|
15
|
+
fadeIn: (soundName: keyof T, duration: number, volume: number, spatial?: {
|
|
16
|
+
emitters: BasePart[];
|
|
17
|
+
}) => void;
|
|
18
|
+
fadeOut: (soundName: keyof T, duration: number, targetVolume?: number, spatial?: {
|
|
19
|
+
emitters: BasePart[];
|
|
20
|
+
}) => void;
|
|
13
21
|
reset: (sound: keyof T) => void;
|
|
14
22
|
setTimePosition: (sound: keyof T, timePosition: number) => void;
|
|
15
23
|
stopAll: (reset?: true) => void;
|
|
16
24
|
preload: (sound: keyof T) => void;
|
|
17
25
|
setGlobalVolume: (volume: number) => void;
|
|
18
|
-
setVolume: (sound: keyof T, volume: number
|
|
26
|
+
setVolume: (sound: keyof T, volume: number, spatial?: {
|
|
27
|
+
emitters: BasePart[];
|
|
28
|
+
}) => void;
|
|
19
29
|
resetAll: (sound: keyof T) => void;
|
|
20
|
-
onEnd: (sound: keyof T, callback: () => void
|
|
30
|
+
onEnd: (sound: keyof T, callback: () => void, spatial?: {
|
|
31
|
+
emitters: BasePart[];
|
|
32
|
+
}) => void;
|
|
21
33
|
isPlaying: (sound: keyof T) => boolean;
|
|
22
34
|
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local createSpatialHandle = TS.import(script, script.Parent, "createSpatialHandle").createSpatialHandle
|
|
2
4
|
--[[
|
|
3
5
|
*
|
|
4
6
|
* Create a sound Registry
|
|
@@ -6,6 +8,7 @@
|
|
|
6
8
|
|
|
7
9
|
]]
|
|
8
10
|
local function createSoundRegistry(definitions)
|
|
11
|
+
local spatialHandles = {}
|
|
9
12
|
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
|
10
13
|
local folder = ReplicatedStorage:FindFirstChild("Sounds")
|
|
11
14
|
if not folder then
|
|
@@ -43,28 +46,58 @@ local function createSoundRegistry(definitions)
|
|
|
43
46
|
*
|
|
44
47
|
* Plays a Sound
|
|
45
48
|
* @param name Define which Sound should be played
|
|
49
|
+
* @param spatial Array of Baseparts
|
|
46
50
|
|
|
47
51
|
]]
|
|
48
|
-
local function play(name)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
_result
|
|
52
|
+
local function play(name, spatial)
|
|
53
|
+
local config = definitions[name]
|
|
54
|
+
if not spatial or not spatial.emitters then
|
|
55
|
+
load(name)
|
|
56
|
+
local sound = folder:FindFirstChild(name)
|
|
57
|
+
local _result = sound
|
|
58
|
+
if _result ~= nil then
|
|
59
|
+
_result:Play()
|
|
60
|
+
end
|
|
61
|
+
return nil
|
|
62
|
+
else
|
|
63
|
+
local emittersArray = spatial.emitters
|
|
64
|
+
local _exp = config.id
|
|
65
|
+
local _condition = config.volume
|
|
66
|
+
if _condition == nil then
|
|
67
|
+
_condition = 1
|
|
68
|
+
end
|
|
69
|
+
local handle = createSpatialHandle(_exp, emittersArray, _condition)
|
|
70
|
+
local _name = name
|
|
71
|
+
spatialHandles[_name] = handle
|
|
72
|
+
handle:play()
|
|
73
|
+
return handle
|
|
54
74
|
end
|
|
55
75
|
end
|
|
56
76
|
--[[
|
|
57
77
|
*
|
|
58
78
|
* Stops a Sound
|
|
59
79
|
* @param name Define which Sound should be stopped
|
|
80
|
+
* @param spatial Array of Baseparts
|
|
60
81
|
|
|
61
82
|
]]
|
|
62
|
-
local function stop(name)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
_result
|
|
83
|
+
local function stop(name, spatial)
|
|
84
|
+
if not spatial then
|
|
85
|
+
local sound = folder:FindFirstChild(name)
|
|
86
|
+
local _result = sound
|
|
87
|
+
if _result ~= nil then
|
|
88
|
+
_result:Stop()
|
|
89
|
+
end
|
|
90
|
+
return nil
|
|
67
91
|
end
|
|
92
|
+
local _name = name
|
|
93
|
+
local handle = spatialHandles[_name]
|
|
94
|
+
if not handle then
|
|
95
|
+
return nil
|
|
96
|
+
end
|
|
97
|
+
handle:stop()
|
|
98
|
+
handle:destroy()
|
|
99
|
+
local _name_1 = name
|
|
100
|
+
spatialHandles[_name_1] = nil
|
|
68
101
|
end
|
|
69
102
|
--[[
|
|
70
103
|
*
|
|
@@ -82,22 +115,44 @@ local function createSoundRegistry(definitions)
|
|
|
82
115
|
* @param soundName Sound Instance
|
|
83
116
|
* @param duration Time in Seconds
|
|
84
117
|
* @param volume Volume
|
|
118
|
+
* @param spatial Array of Baseparts
|
|
85
119
|
|
|
86
120
|
]]
|
|
87
|
-
local function fadeIn(soundName, duration, volume)
|
|
88
|
-
local
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
local
|
|
95
|
-
|
|
96
|
-
vol
|
|
97
|
-
|
|
98
|
-
|
|
121
|
+
local function fadeIn(soundName, duration, volume, spatial)
|
|
122
|
+
local config = definitions[soundName]
|
|
123
|
+
if not spatial or not spatial.emitters then
|
|
124
|
+
local sound = folder:FindFirstChild(soundName)
|
|
125
|
+
sound.Volume = 0
|
|
126
|
+
sound:Play()
|
|
127
|
+
local step = 0.05
|
|
128
|
+
local interval = duration * step
|
|
129
|
+
task.spawn(function()
|
|
130
|
+
local vol = 0
|
|
131
|
+
while vol < volume do
|
|
132
|
+
vol += step
|
|
133
|
+
sound.Volume = math.clamp(vol, 0, volume)
|
|
134
|
+
task.wait(interval)
|
|
135
|
+
end
|
|
136
|
+
end)
|
|
137
|
+
else
|
|
138
|
+
local emittersArray = spatial.emitters
|
|
139
|
+
local _exp = config.id
|
|
140
|
+
local _condition = config.volume
|
|
141
|
+
if _condition == nil then
|
|
142
|
+
_condition = 1
|
|
143
|
+
end
|
|
144
|
+
local handle = createSpatialHandle(_exp, emittersArray, _condition)
|
|
145
|
+
local _self = handle
|
|
146
|
+
local _result = _self.fadeIn
|
|
147
|
+
if _result ~= nil then
|
|
148
|
+
_result(_self, duration, volume)
|
|
149
|
+
end
|
|
150
|
+
if not config.loop == true then
|
|
151
|
+
handle:played(function()
|
|
152
|
+
handle:destroy()
|
|
153
|
+
end)
|
|
99
154
|
end
|
|
100
|
-
end
|
|
155
|
+
end
|
|
101
156
|
end
|
|
102
157
|
--[[
|
|
103
158
|
*
|
|
@@ -105,33 +160,55 @@ local function createSoundRegistry(definitions)
|
|
|
105
160
|
* @param soundName Sound name from Registry
|
|
106
161
|
* @param duration Time in seconds
|
|
107
162
|
* @param targetVolume Optional target volume (default 0)
|
|
163
|
+
* @param spatial Array of Baseparts
|
|
108
164
|
|
|
109
165
|
]]
|
|
110
|
-
local function fadeOut(soundName, duration, targetVolume)
|
|
111
|
-
local
|
|
112
|
-
if not
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
_condition =
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
local
|
|
125
|
-
|
|
126
|
-
vol =
|
|
127
|
-
|
|
128
|
-
|
|
166
|
+
local function fadeOut(soundName, duration, targetVolume, spatial)
|
|
167
|
+
local config = definitions[soundName]
|
|
168
|
+
if not spatial or not spatial.emitters then
|
|
169
|
+
local sound = folder:FindFirstChild(soundName)
|
|
170
|
+
if not sound then
|
|
171
|
+
return nil
|
|
172
|
+
end
|
|
173
|
+
local startVolume = sound.Volume
|
|
174
|
+
local _condition = targetVolume
|
|
175
|
+
if _condition == nil then
|
|
176
|
+
_condition = 0
|
|
177
|
+
end
|
|
178
|
+
local endVolume = _condition
|
|
179
|
+
local step = 0.05
|
|
180
|
+
local interval = duration * step
|
|
181
|
+
task.spawn(function()
|
|
182
|
+
local vol = startVolume
|
|
183
|
+
while vol > endVolume do
|
|
184
|
+
vol = math.clamp(vol - step, endVolume, startVolume)
|
|
185
|
+
sound.Volume = vol
|
|
186
|
+
task.wait(interval)
|
|
187
|
+
end
|
|
188
|
+
sound.Volume = endVolume
|
|
189
|
+
if endVolume == 0 then
|
|
190
|
+
sound:Stop()
|
|
191
|
+
end
|
|
192
|
+
end)
|
|
193
|
+
else
|
|
194
|
+
local emittersArray = spatial.emitters
|
|
195
|
+
local _exp = config.id
|
|
196
|
+
local _condition = config.volume
|
|
197
|
+
if _condition == nil then
|
|
198
|
+
_condition = 1
|
|
129
199
|
end
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
200
|
+
local handle = createSpatialHandle(_exp, emittersArray, _condition)
|
|
201
|
+
local _self = handle
|
|
202
|
+
local _result = _self.fadeOut
|
|
203
|
+
if _result ~= nil then
|
|
204
|
+
_result(_self, duration)
|
|
133
205
|
end
|
|
134
|
-
|
|
206
|
+
if not config.loop == true then
|
|
207
|
+
handle:played(function()
|
|
208
|
+
handle:destroy()
|
|
209
|
+
end)
|
|
210
|
+
end
|
|
211
|
+
end
|
|
135
212
|
end
|
|
136
213
|
--[[
|
|
137
214
|
*
|
|
@@ -195,14 +272,21 @@ local function createSoundRegistry(definitions)
|
|
|
195
272
|
* Set Sound Volume
|
|
196
273
|
* @param sound Sound Instance
|
|
197
274
|
* @param volume Sound Volume
|
|
275
|
+
* @param spatial Array of Baseparts
|
|
198
276
|
|
|
199
277
|
]]
|
|
200
|
-
local function setVolume(sound, volume)
|
|
201
|
-
local
|
|
202
|
-
if not
|
|
203
|
-
|
|
278
|
+
local function setVolume(sound, volume, spatial)
|
|
279
|
+
local config = definitions[sound]
|
|
280
|
+
if not spatial or spatial.emitters then
|
|
281
|
+
local _sound = folder:FindFirstChild(sound)
|
|
282
|
+
if not (sound ~= 0 and sound == sound and sound ~= "" and sound) then
|
|
283
|
+
return nil
|
|
284
|
+
end
|
|
285
|
+
_sound.Volume = volume
|
|
286
|
+
else
|
|
287
|
+
local emittersArray = spatial.emitters
|
|
288
|
+
local handle = createSpatialHandle(config.id, emittersArray, volume)
|
|
204
289
|
end
|
|
205
|
-
_sound.Volume = volume
|
|
206
290
|
end
|
|
207
291
|
--[[
|
|
208
292
|
*
|
|
@@ -227,12 +311,21 @@ local function createSoundRegistry(definitions)
|
|
|
227
311
|
* @param callback Callback
|
|
228
312
|
|
|
229
313
|
]]
|
|
230
|
-
local function onEnd(sound, callback)
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
314
|
+
local function onEnd(sound, callback, spatial)
|
|
315
|
+
if not spatial then
|
|
316
|
+
local _sound = folder:WaitForChild(sound)
|
|
317
|
+
if not _sound then
|
|
318
|
+
return nil
|
|
319
|
+
end
|
|
320
|
+
_sound.Ended:Connect(callback)
|
|
321
|
+
else
|
|
322
|
+
local _sound = sound
|
|
323
|
+
local handle = spatialHandles[_sound]
|
|
324
|
+
if not handle then
|
|
325
|
+
return nil
|
|
326
|
+
end
|
|
327
|
+
handle:played(callback)
|
|
234
328
|
end
|
|
235
|
-
_sound.Ended:Connect(callback)
|
|
236
329
|
end
|
|
237
330
|
--[[
|
|
238
331
|
*
|
|
@@ -251,7 +344,7 @@ local function createSoundRegistry(definitions)
|
|
|
251
344
|
|
|
252
345
|
]]
|
|
253
346
|
local function isPlaying(sound)
|
|
254
|
-
local _sound = folder:
|
|
347
|
+
local _sound = folder:FindFirstChild(sound)
|
|
255
348
|
if _sound.IsPlaying == true then
|
|
256
349
|
return true
|
|
257
350
|
else
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local _functions = TS.import(script, script.Parent.Parent, "utils", "functions")
|
|
4
|
+
local fadeIn = _functions.fadeIn
|
|
5
|
+
local fadeOut = _functions.fadeOut
|
|
6
|
+
--[[
|
|
7
|
+
*
|
|
8
|
+
* Create a Spatial Handle
|
|
9
|
+
* @param assetId Asset ID
|
|
10
|
+
* @param emitters Emitter
|
|
11
|
+
|
|
12
|
+
]]
|
|
13
|
+
local function createSpatialHandle(assetId, emitters, volume)
|
|
14
|
+
local player = Instance.new("AudioPlayer")
|
|
15
|
+
player.Asset = assetId
|
|
16
|
+
player.Volume = volume
|
|
17
|
+
player.Parent = game:GetService("ReplicatedStorage")
|
|
18
|
+
local emitterInstances = {}
|
|
19
|
+
for _, part in emitters do
|
|
20
|
+
local emitter = Instance.new("AudioEmitter")
|
|
21
|
+
emitter.Parent = part
|
|
22
|
+
local wire = Instance.new("Wire")
|
|
23
|
+
wire.SourceInstance = player
|
|
24
|
+
wire.TargetInstance = emitter
|
|
25
|
+
wire.Parent = emitter
|
|
26
|
+
table.insert(emitterInstances, emitter)
|
|
27
|
+
end
|
|
28
|
+
return {
|
|
29
|
+
play = function(self)
|
|
30
|
+
player:Play()
|
|
31
|
+
end,
|
|
32
|
+
stop = function(self)
|
|
33
|
+
player:Stop()
|
|
34
|
+
end,
|
|
35
|
+
fadeIn = function(self, duration, volume)
|
|
36
|
+
fadeIn(player, volume, duration)
|
|
37
|
+
end,
|
|
38
|
+
fadeOut = function(self, duration)
|
|
39
|
+
fadeOut(player, duration)
|
|
40
|
+
end,
|
|
41
|
+
destroy = function(self)
|
|
42
|
+
player:Destroy()
|
|
43
|
+
-- ▼ ReadonlyArray.forEach ▼
|
|
44
|
+
local _callback = function(e)
|
|
45
|
+
return e:Destroy()
|
|
46
|
+
end
|
|
47
|
+
for _k, _v in emitterInstances do
|
|
48
|
+
_callback(_v, _k - 1, emitterInstances)
|
|
49
|
+
end
|
|
50
|
+
-- ▲ ReadonlyArray.forEach ▲
|
|
51
|
+
end,
|
|
52
|
+
played = function(self, callback)
|
|
53
|
+
player.Ended:Connect(callback)
|
|
54
|
+
end,
|
|
55
|
+
}
|
|
56
|
+
end
|
|
57
|
+
return {
|
|
58
|
+
createSpatialHandle = createSpatialHandle,
|
|
59
|
+
}
|
package/out/core/options.d.ts
CHANGED
|
@@ -2,6 +2,18 @@ export interface SoundOptions {
|
|
|
2
2
|
volume?: number;
|
|
3
3
|
loop?: boolean;
|
|
4
4
|
id: string;
|
|
5
|
+
spatial?: {
|
|
6
|
+
attenuation?: number;
|
|
7
|
+
directional?: boolean;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export interface SoundHandle {
|
|
11
|
+
play(): void;
|
|
12
|
+
stop(): void;
|
|
13
|
+
fadeIn?(duration: number, volume: number): void;
|
|
14
|
+
fadeOut?(duration: number): void;
|
|
15
|
+
destroy(): void;
|
|
16
|
+
played(callback: () => void): void;
|
|
5
17
|
}
|
|
6
18
|
interface SoundDefinition {
|
|
7
19
|
id: string;
|
|
@@ -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
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fades in a Sound
|
|
3
|
+
* @param player AudioPlayer
|
|
4
|
+
* @param targetVolume Target volume
|
|
5
|
+
* @param duration Duration
|
|
6
|
+
*/
|
|
7
|
+
export declare function fadeIn(player: AudioPlayer, targetVolume: number, duration: number): void;
|
|
8
|
+
/**
|
|
9
|
+
* Smoothly fades out a Sound
|
|
10
|
+
* @param player AudioPlayer
|
|
11
|
+
* @param duration Duration
|
|
12
|
+
*/
|
|
13
|
+
export declare function fadeOut(player: AudioPlayer, duration: number): void;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
--[[
|
|
3
|
+
*
|
|
4
|
+
* Fades in a Sound
|
|
5
|
+
* @param player AudioPlayer
|
|
6
|
+
* @param targetVolume Target volume
|
|
7
|
+
* @param duration Duration
|
|
8
|
+
|
|
9
|
+
]]
|
|
10
|
+
local function fadeIn(player, targetVolume, duration)
|
|
11
|
+
player.Volume = 0
|
|
12
|
+
player:Play()
|
|
13
|
+
local steps = 20
|
|
14
|
+
task.spawn(function()
|
|
15
|
+
for i = 0, steps do
|
|
16
|
+
player.Volume = (i / steps) * targetVolume
|
|
17
|
+
task.wait(duration / steps)
|
|
18
|
+
end
|
|
19
|
+
end)
|
|
20
|
+
end
|
|
21
|
+
--[[
|
|
22
|
+
*
|
|
23
|
+
* Smoothly fades out a Sound
|
|
24
|
+
* @param player AudioPlayer
|
|
25
|
+
* @param duration Duration
|
|
26
|
+
|
|
27
|
+
]]
|
|
28
|
+
local function fadeOut(player, duration)
|
|
29
|
+
local _condition = player.Volume
|
|
30
|
+
if _condition == nil then
|
|
31
|
+
_condition = 1
|
|
32
|
+
end
|
|
33
|
+
local startVolume = _condition
|
|
34
|
+
local steps = 20
|
|
35
|
+
local interval = duration / steps
|
|
36
|
+
task.spawn(function()
|
|
37
|
+
for i = steps, 0, -1 do
|
|
38
|
+
player.Volume = (i / steps) * startVolume
|
|
39
|
+
task.wait(interval)
|
|
40
|
+
end
|
|
41
|
+
player:Stop()
|
|
42
|
+
end)
|
|
43
|
+
end
|
|
44
|
+
return {
|
|
45
|
+
fadeIn = fadeIn,
|
|
46
|
+
fadeOut = fadeOut,
|
|
47
|
+
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rbxts/sound-manager",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "A sound manager for Roblox-Typescript projects.",
|
|
5
5
|
"main": "out/init.lua",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "rbxtsc",
|
|
8
8
|
"watch": "rbxtsc -w",
|
|
9
|
-
"prepublishOnly": "npm run build"
|
|
9
|
+
"prepublishOnly": "npm run build",
|
|
10
|
+
"start": "npm pack && npm run watch"
|
|
10
11
|
},
|
|
11
12
|
"keywords": [],
|
|
12
13
|
"author": "Easy-Build-Studio",
|
|
13
|
-
"license": "
|
|
14
|
+
"license": "MIT",
|
|
14
15
|
"type": "commonjs",
|
|
15
16
|
"types": "out/index.d.ts",
|
|
16
17
|
"files": [
|