@rbxts/sound-manager 1.0.0 → 2.0.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/LICENSE +21 -0
- package/README.md +29 -17
- package/out/core/createSoundCategoryRegistry.d.ts +9 -0
- package/out/core/createSoundCategoryRegistry.luau +85 -0
- package/out/core/createSoundRegistry.d.ts +21 -0
- package/out/core/createSoundRegistry.luau +265 -0
- package/out/core/options.d.ts +11 -0
- package/out/index.d.ts +2 -7
- package/out/init.luau +8 -53
- package/package.json +2 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Lukas
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,17 +1,29 @@
|
|
|
1
|
-
# Sound Manager
|
|
2
|
-
|
|
3
|
-
A Roblox sound management library built with Roblox-TS
|
|
4
|
-
|
|
5
|
-
## Getting Started
|
|
6
|
-
To use the Sound Manager library in your Roblox-TS project install it via npm:
|
|
7
|
-
```bash
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Example usage:
|
|
12
|
-
```typescript
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
Sounds
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
# Sound Manager
|
|
2
|
+
|
|
3
|
+
A Roblox sound management library built with Roblox-TS
|
|
4
|
+
|
|
5
|
+
## Getting Started
|
|
6
|
+
To use the Sound Manager library in your Roblox-TS project, install it via npm:
|
|
7
|
+
```bash
|
|
8
|
+
npm install @rbxts/sound-manager
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Example usage:
|
|
12
|
+
```typescript
|
|
13
|
+
import { createSoundRegistry } from "@rbxts/sound-manager";
|
|
14
|
+
|
|
15
|
+
const Sounds = createSoundRegistry({
|
|
16
|
+
SCP096: {
|
|
17
|
+
id: "rbxassetid://4714389545",
|
|
18
|
+
volume: 1,
|
|
19
|
+
loop: false,
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
Sounds.preloadAll();
|
|
24
|
+
|
|
25
|
+
Sounds.play("SCP096");
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
For more Details:
|
|
29
|
+
https://dev-lukas0.github.io/Sound-Manager-Docs/
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CategoryOptions } from "./options";
|
|
2
|
+
/**
|
|
3
|
+
* Create a sound category Registry
|
|
4
|
+
* @param definitions Define the Categorys
|
|
5
|
+
*/
|
|
6
|
+
export declare function createSoundCategoryRegistry<T extends Record<string, CategoryOptions>>(definitions: T): {
|
|
7
|
+
loadCategory: (name: keyof T) => void;
|
|
8
|
+
playCategory: <C extends keyof T>(name: C) => void;
|
|
9
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
--[[
|
|
3
|
+
*
|
|
4
|
+
* Create a sound category Registry
|
|
5
|
+
* @param definitions Define the Categorys
|
|
6
|
+
|
|
7
|
+
]]
|
|
8
|
+
local function createSoundCategoryRegistry(definitions)
|
|
9
|
+
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
|
10
|
+
local folder = ReplicatedStorage:FindFirstChild("Sounds")
|
|
11
|
+
if not folder then
|
|
12
|
+
folder = Instance.new("Folder")
|
|
13
|
+
folder.Name = "Sounds"
|
|
14
|
+
folder.Parent = ReplicatedStorage
|
|
15
|
+
end
|
|
16
|
+
--[[
|
|
17
|
+
*
|
|
18
|
+
* Loads a Category
|
|
19
|
+
* @param name Define which Sound Category should be loaded
|
|
20
|
+
|
|
21
|
+
]]
|
|
22
|
+
local function loadCategory(name)
|
|
23
|
+
if folder:FindFirstChild(name) then
|
|
24
|
+
return nil
|
|
25
|
+
end
|
|
26
|
+
local config = definitions[name]
|
|
27
|
+
local category = folder:FindFirstChild(config.category)
|
|
28
|
+
if not category then
|
|
29
|
+
category = Instance.new("Folder")
|
|
30
|
+
category.Name = config.category
|
|
31
|
+
category.Parent = folder
|
|
32
|
+
end
|
|
33
|
+
for sound, soundConfig in pairs(config.sounds) do
|
|
34
|
+
if category:FindFirstChild(sound) then
|
|
35
|
+
continue
|
|
36
|
+
end
|
|
37
|
+
local newSound = Instance.new("Sound")
|
|
38
|
+
newSound.Name = sound
|
|
39
|
+
newSound.SoundId = soundConfig.id
|
|
40
|
+
local _condition = soundConfig.volume
|
|
41
|
+
if _condition == nil then
|
|
42
|
+
_condition = 1
|
|
43
|
+
end
|
|
44
|
+
newSound.Volume = _condition
|
|
45
|
+
local _condition_1 = soundConfig.loop
|
|
46
|
+
if _condition_1 == nil then
|
|
47
|
+
_condition_1 = false
|
|
48
|
+
end
|
|
49
|
+
newSound.Looped = _condition_1
|
|
50
|
+
newSound.Parent = category
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
--[[
|
|
54
|
+
*
|
|
55
|
+
* Play every Sound from a Sound Category
|
|
56
|
+
* @param name Sound Category
|
|
57
|
+
|
|
58
|
+
]]
|
|
59
|
+
local function playCategory(name)
|
|
60
|
+
loadCategory(name)
|
|
61
|
+
local config = definitions[name]
|
|
62
|
+
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
|
63
|
+
local folder = ReplicatedStorage:FindFirstChild(config.category)
|
|
64
|
+
for sound in pairs(config.sounds) do
|
|
65
|
+
local _sound = folder:FindFirstChild(sound)
|
|
66
|
+
if not _sound then
|
|
67
|
+
continue
|
|
68
|
+
end
|
|
69
|
+
local _result = _sound
|
|
70
|
+
if _result ~= nil then
|
|
71
|
+
_result = _result:IsA("Sound")
|
|
72
|
+
end
|
|
73
|
+
if _result then
|
|
74
|
+
_sound:Play()
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
return {
|
|
79
|
+
loadCategory = loadCategory,
|
|
80
|
+
playCategory = playCategory,
|
|
81
|
+
}
|
|
82
|
+
end
|
|
83
|
+
return {
|
|
84
|
+
createSoundCategoryRegistry = createSoundCategoryRegistry,
|
|
85
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SoundOptions } from "./options";
|
|
2
|
+
/**
|
|
3
|
+
* Create a sound Registry
|
|
4
|
+
* @param definitions Define the Sounds
|
|
5
|
+
*/
|
|
6
|
+
export declare function createSoundRegistry<T extends Record<string, SoundOptions>>(definitions: T): {
|
|
7
|
+
play: (name: keyof T) => void;
|
|
8
|
+
stop: (name: keyof T) => void;
|
|
9
|
+
preloadAll: () => void;
|
|
10
|
+
load: (name: keyof T) => void;
|
|
11
|
+
fadeIn: (soundName: keyof T, duration: number, volume: number) => void;
|
|
12
|
+
fadeOut: (soundName: keyof T, duration: number, targetVolume?: number) => void;
|
|
13
|
+
reset: (sound: keyof T) => void;
|
|
14
|
+
setTimePosition: (sound: keyof T, timePosition: number) => void;
|
|
15
|
+
stopAll: (reset?: true) => void;
|
|
16
|
+
preload: (sound: keyof T) => void;
|
|
17
|
+
setGlobalVolume: (volume: number) => void;
|
|
18
|
+
setVolume: (sound: keyof T, volume: number) => void;
|
|
19
|
+
resetAll: (sound: keyof T) => void;
|
|
20
|
+
onEnd: (sound: keyof T, callback: () => void) => void;
|
|
21
|
+
};
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
--[[
|
|
3
|
+
*
|
|
4
|
+
* Create a sound Registry
|
|
5
|
+
* @param definitions Define the Sounds
|
|
6
|
+
|
|
7
|
+
]]
|
|
8
|
+
local function createSoundRegistry(definitions)
|
|
9
|
+
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
|
10
|
+
local folder = ReplicatedStorage:FindFirstChild("Sounds")
|
|
11
|
+
if not folder then
|
|
12
|
+
folder = Instance.new("Folder")
|
|
13
|
+
folder.Name = "Sounds"
|
|
14
|
+
folder.Parent = ReplicatedStorage
|
|
15
|
+
end
|
|
16
|
+
--[[
|
|
17
|
+
*
|
|
18
|
+
* Loads a Sound
|
|
19
|
+
* @param name Define which Sound should be loaded
|
|
20
|
+
|
|
21
|
+
]]
|
|
22
|
+
local function load(name)
|
|
23
|
+
if folder:FindFirstChild(name) then
|
|
24
|
+
return nil
|
|
25
|
+
end
|
|
26
|
+
local config = definitions[name]
|
|
27
|
+
local sound = Instance.new("Sound")
|
|
28
|
+
sound.Name = name
|
|
29
|
+
sound.SoundId = config.id
|
|
30
|
+
local _condition = config.volume
|
|
31
|
+
if _condition == nil then
|
|
32
|
+
_condition = 1
|
|
33
|
+
end
|
|
34
|
+
sound.Volume = _condition
|
|
35
|
+
local _condition_1 = config.loop
|
|
36
|
+
if _condition_1 == nil then
|
|
37
|
+
_condition_1 = false
|
|
38
|
+
end
|
|
39
|
+
sound.Looped = _condition_1
|
|
40
|
+
sound.Parent = folder
|
|
41
|
+
end
|
|
42
|
+
--[[
|
|
43
|
+
*
|
|
44
|
+
* Plays a Sound
|
|
45
|
+
* @param name Define which Sound should be played
|
|
46
|
+
|
|
47
|
+
]]
|
|
48
|
+
local function play(name)
|
|
49
|
+
load(name)
|
|
50
|
+
local sound = folder:FindFirstChild(name)
|
|
51
|
+
local _result = sound
|
|
52
|
+
if _result ~= nil then
|
|
53
|
+
_result:Play()
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
--[[
|
|
57
|
+
*
|
|
58
|
+
* Stops a Sound
|
|
59
|
+
* @param name Define which Sound should be stopped
|
|
60
|
+
|
|
61
|
+
]]
|
|
62
|
+
local function stop(name)
|
|
63
|
+
local sound = folder:FindFirstChild(name)
|
|
64
|
+
local _result = sound
|
|
65
|
+
if _result ~= nil then
|
|
66
|
+
_result:Stop()
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
--[[
|
|
70
|
+
*
|
|
71
|
+
* Loads every Sound
|
|
72
|
+
|
|
73
|
+
]]
|
|
74
|
+
local function preloadAll()
|
|
75
|
+
for name in pairs(definitions) do
|
|
76
|
+
load(name)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
--[[
|
|
80
|
+
*
|
|
81
|
+
* Smoothly fad in a sound
|
|
82
|
+
* @param soundName Sound Instance
|
|
83
|
+
* @param duration Time in Seconds
|
|
84
|
+
* @param volume Volume
|
|
85
|
+
|
|
86
|
+
]]
|
|
87
|
+
local function fadeIn(soundName, duration, volume)
|
|
88
|
+
local sound = folder:FindFirstChild(soundName)
|
|
89
|
+
sound.Volume = 0
|
|
90
|
+
sound:Play()
|
|
91
|
+
local step = 0.05
|
|
92
|
+
local interval = duration * step
|
|
93
|
+
task.spawn(function()
|
|
94
|
+
local vol = 0
|
|
95
|
+
while vol < volume do
|
|
96
|
+
vol += step
|
|
97
|
+
sound.Volume = math.clamp(vol, 0, volume)
|
|
98
|
+
task.wait(interval)
|
|
99
|
+
end
|
|
100
|
+
end)
|
|
101
|
+
end
|
|
102
|
+
--[[
|
|
103
|
+
*
|
|
104
|
+
* Smoothly fade out a sound
|
|
105
|
+
* @param soundName Sound name from Registry
|
|
106
|
+
* @param duration Time in seconds
|
|
107
|
+
* @param targetVolume Optional target volume (default 0)
|
|
108
|
+
|
|
109
|
+
]]
|
|
110
|
+
local function fadeOut(soundName, duration, targetVolume)
|
|
111
|
+
local sound = folder:FindFirstChild(soundName)
|
|
112
|
+
if not sound then
|
|
113
|
+
return nil
|
|
114
|
+
end
|
|
115
|
+
local startVolume = sound.Volume
|
|
116
|
+
local _condition = targetVolume
|
|
117
|
+
if _condition == nil then
|
|
118
|
+
_condition = 0
|
|
119
|
+
end
|
|
120
|
+
local endVolume = _condition
|
|
121
|
+
local step = 0.05
|
|
122
|
+
local interval = duration * step
|
|
123
|
+
task.spawn(function()
|
|
124
|
+
local vol = startVolume
|
|
125
|
+
while vol > endVolume do
|
|
126
|
+
vol = math.clamp(vol - step, endVolume, startVolume)
|
|
127
|
+
sound.Volume = vol
|
|
128
|
+
task.wait(interval)
|
|
129
|
+
end
|
|
130
|
+
sound.Volume = endVolume
|
|
131
|
+
if endVolume == 0 then
|
|
132
|
+
sound:Stop()
|
|
133
|
+
end
|
|
134
|
+
end)
|
|
135
|
+
end
|
|
136
|
+
--[[
|
|
137
|
+
*
|
|
138
|
+
* Reset a Sound
|
|
139
|
+
* @param sound Sound Instance
|
|
140
|
+
|
|
141
|
+
]]
|
|
142
|
+
local function reset(sound)
|
|
143
|
+
local _sound = folder:FindFirstChild(sound)
|
|
144
|
+
if not (sound ~= 0 and sound == sound and sound ~= "" and sound) then
|
|
145
|
+
return nil
|
|
146
|
+
end
|
|
147
|
+
_sound.TimePosition = 0
|
|
148
|
+
end
|
|
149
|
+
--[[
|
|
150
|
+
*
|
|
151
|
+
* Reset every Sound
|
|
152
|
+
* @param sound Sound Instance
|
|
153
|
+
|
|
154
|
+
]]
|
|
155
|
+
local function resetAll(sound)
|
|
156
|
+
for _, sound in folder:GetChildren() do
|
|
157
|
+
if sound:IsA("Sound") then
|
|
158
|
+
sound.TimePosition = 0
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
--[[
|
|
163
|
+
*
|
|
164
|
+
* Set Time Position
|
|
165
|
+
* @param sound Sound Instance
|
|
166
|
+
* @param timePosition Time Position
|
|
167
|
+
|
|
168
|
+
]]
|
|
169
|
+
local function setTimePosition(sound, timePosition)
|
|
170
|
+
local _sound = folder:FindFirstChild(sound)
|
|
171
|
+
if not (sound ~= 0 and sound == sound and sound ~= "" and sound) then
|
|
172
|
+
return nil
|
|
173
|
+
end
|
|
174
|
+
_sound.TimePosition = timePosition
|
|
175
|
+
end
|
|
176
|
+
--[[
|
|
177
|
+
*
|
|
178
|
+
* Stop every Sound
|
|
179
|
+
* @param reset Define whether every Sound should also be reset?
|
|
180
|
+
|
|
181
|
+
]]
|
|
182
|
+
local function stopAll(reset)
|
|
183
|
+
for _, instance in folder:GetChildren() do
|
|
184
|
+
if not instance:IsA("Sound") then
|
|
185
|
+
continue
|
|
186
|
+
end
|
|
187
|
+
instance:Stop()
|
|
188
|
+
if reset then
|
|
189
|
+
instance.TimePosition = 0
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
--[[
|
|
194
|
+
*
|
|
195
|
+
* Set Sound Volume
|
|
196
|
+
* @param sound Sound Instance
|
|
197
|
+
* @param volume Sound Volume
|
|
198
|
+
|
|
199
|
+
]]
|
|
200
|
+
local function setVolume(sound, volume)
|
|
201
|
+
local _sound = folder:FindFirstChild(sound)
|
|
202
|
+
if not (sound ~= 0 and sound == sound and sound ~= "" and sound) then
|
|
203
|
+
return nil
|
|
204
|
+
end
|
|
205
|
+
_sound.Volume = volume
|
|
206
|
+
end
|
|
207
|
+
--[[
|
|
208
|
+
*
|
|
209
|
+
* Set the global Sound Volume
|
|
210
|
+
* @param volume Sound Volume
|
|
211
|
+
|
|
212
|
+
]]
|
|
213
|
+
local function setGlobalVolume(volume)
|
|
214
|
+
for _, instance in folder:GetChildren() do
|
|
215
|
+
if not instance:IsA("Sound") then
|
|
216
|
+
continue
|
|
217
|
+
end
|
|
218
|
+
if instance:IsA("Sound") then
|
|
219
|
+
instance.Volume = volume
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
--[[
|
|
224
|
+
*
|
|
225
|
+
* Plays Sound on Event Callback
|
|
226
|
+
* @param name Sound Name
|
|
227
|
+
* @param callback Callback
|
|
228
|
+
|
|
229
|
+
]]
|
|
230
|
+
local function onEnd(sound, callback)
|
|
231
|
+
local _sound = folder:WaitForChild(sound)
|
|
232
|
+
if not _sound then
|
|
233
|
+
return nil
|
|
234
|
+
end
|
|
235
|
+
_sound.Ended:Connect(callback)
|
|
236
|
+
end
|
|
237
|
+
--[[
|
|
238
|
+
*
|
|
239
|
+
* Preloads a Sound
|
|
240
|
+
* @param sound Sound Instance
|
|
241
|
+
|
|
242
|
+
]]
|
|
243
|
+
local function preload(sound)
|
|
244
|
+
load(sound)
|
|
245
|
+
end
|
|
246
|
+
return {
|
|
247
|
+
play = play,
|
|
248
|
+
stop = stop,
|
|
249
|
+
preloadAll = preloadAll,
|
|
250
|
+
load = load,
|
|
251
|
+
fadeIn = fadeIn,
|
|
252
|
+
fadeOut = fadeOut,
|
|
253
|
+
reset = reset,
|
|
254
|
+
setTimePosition = setTimePosition,
|
|
255
|
+
stopAll = stopAll,
|
|
256
|
+
preload = preload,
|
|
257
|
+
setGlobalVolume = setGlobalVolume,
|
|
258
|
+
setVolume = setVolume,
|
|
259
|
+
resetAll = resetAll,
|
|
260
|
+
onEnd = onEnd,
|
|
261
|
+
}
|
|
262
|
+
end
|
|
263
|
+
return {
|
|
264
|
+
createSoundRegistry = createSoundRegistry,
|
|
265
|
+
}
|
package/out/core/options.d.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
export interface SoundOptions {
|
|
2
2
|
volume?: number;
|
|
3
3
|
loop?: boolean;
|
|
4
|
+
id: string;
|
|
4
5
|
}
|
|
6
|
+
interface SoundDefinition {
|
|
7
|
+
id: string;
|
|
8
|
+
volume?: number;
|
|
9
|
+
loop?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface CategoryOptions {
|
|
12
|
+
category: string;
|
|
13
|
+
sounds: Record<string, SoundDefinition>;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
package/out/index.d.ts
CHANGED
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
/** * * @param sound Define the Sound to play */
|
|
4
|
-
function play(soundName: string): void;
|
|
5
|
-
/** * * @param soundname Define the name of the Sound * @param soundid Define the SoundID of the Sound * @param options Define the options for the Sound (e.g. volume) */
|
|
6
|
-
function load(soundName: string, soundId: string, options?: SoundOptions): void;
|
|
7
|
-
}
|
|
1
|
+
export * from "./core/createSoundRegistry";
|
|
2
|
+
export * from "./core/createSoundCategoryRegistry";
|
package/out/init.luau
CHANGED
|
@@ -1,55 +1,10 @@
|
|
|
1
1
|
-- Compiled with roblox-ts v3.0.0
|
|
2
|
-
local
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
local function play(soundName)
|
|
7
|
-
local soundFolder = game:GetService("ReplicatedStorage"):FindFirstChild("Sounds")
|
|
8
|
-
if not soundFolder then
|
|
9
|
-
warn("Sound folder not found in ReplicatedStorage.")
|
|
10
|
-
return nil
|
|
11
|
-
end
|
|
12
|
-
local _sound = soundFolder:FindFirstChild(soundName)
|
|
13
|
-
if _sound then
|
|
14
|
-
_sound:Play()
|
|
15
|
-
else
|
|
16
|
-
warn(`Sound: {soundName} not found! Make sure to load it first.`)
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
_container.play = play
|
|
20
|
-
--* * * @param soundname Define the name of the Sound * @param soundid Define the SoundID of the Sound * @param options Define the options for the Sound (e.g. volume)
|
|
21
|
-
local function load(soundName, soundId, options)
|
|
22
|
-
local soundFolder = game:GetService("ReplicatedStorage"):FindFirstChild("Sounds")
|
|
23
|
-
if not soundFolder then
|
|
24
|
-
soundFolder = Instance.new("Folder")
|
|
25
|
-
soundFolder.Name = "Sounds"
|
|
26
|
-
soundFolder.Parent = game:GetService("ReplicatedStorage")
|
|
27
|
-
end
|
|
28
|
-
if soundFolder:FindFirstChild(soundName) then
|
|
29
|
-
warn(`Sound: {soundName} already exists.`)
|
|
30
|
-
return nil
|
|
31
|
-
end
|
|
32
|
-
local newSound = Instance.new("Sound")
|
|
33
|
-
newSound.Name = soundName
|
|
34
|
-
newSound.SoundId = soundId
|
|
35
|
-
newSound.Parent = soundFolder
|
|
36
|
-
local _result = options
|
|
37
|
-
if _result ~= nil then
|
|
38
|
-
_result = _result.volume
|
|
39
|
-
end
|
|
40
|
-
if _result ~= nil then
|
|
41
|
-
newSound.Volume = options.volume
|
|
42
|
-
end
|
|
43
|
-
local _result_1 = options
|
|
44
|
-
if _result_1 ~= nil then
|
|
45
|
-
_result_1 = _result_1.loop
|
|
46
|
-
end
|
|
47
|
-
if _result_1 ~= nil then
|
|
48
|
-
newSound.Looped = options.loop
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
_container.load = load
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local exports = {}
|
|
4
|
+
for _k, _v in TS.import(script, script, "core", "createSoundRegistry") or {} do
|
|
5
|
+
exports[_k] = _v
|
|
52
6
|
end
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
7
|
+
for _k, _v in TS.import(script, script, "core", "createSoundCategoryRegistry") or {} do
|
|
8
|
+
exports[_k] = _v
|
|
9
|
+
end
|
|
10
|
+
return exports
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rbxts/sound-manager",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "A sound manager for Roblox-Typescript projects.",
|
|
5
5
|
"main": "out/init.lua",
|
|
6
6
|
"scripts": {
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"typescript": "^5.9.3"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
+
"@rbxts/sound-manager": "file:rbxts-sound-manager-1.2.0.tgz",
|
|
37
38
|
"@rbxts/testez": "^0.4.2-ts.0"
|
|
38
39
|
}
|
|
39
40
|
}
|