@rbxts/sound-manager 1.0.0 → 1.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/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,26 @@
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 { Sounds } from "@rbxts/sound-manager";
14
-
15
- Sounds.load("TestSound", "rbxassetid://4714389545", { volume: 1, loop: false });
16
- Sounds.play("TestSound")
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
+ ```
@@ -0,0 +1,12 @@
1
+ import { SoundOptions } from "./options";
2
+ /**
3
+ *
4
+ * @param definitions Define the Sounds
5
+ * @returns
6
+ */
7
+ export declare function createSoundRegistry<T extends Record<string, SoundOptions>>(definitions: T): {
8
+ play: (name: keyof T) => void;
9
+ stop: (name: keyof T) => void;
10
+ preloadAll: () => void;
11
+ load: (name: keyof T) => void;
12
+ };
@@ -0,0 +1,90 @@
1
+ -- Compiled with roblox-ts v3.0.0
2
+ --[[
3
+ *
4
+ *
5
+ * @param definitions Define the Sounds
6
+ * @returns
7
+
8
+ ]]
9
+ local function createSoundRegistry(definitions)
10
+ local ReplicatedStorage = game:GetService("ReplicatedStorage")
11
+ local folder = ReplicatedStorage:FindFirstChild("Sounds")
12
+ if not folder then
13
+ folder = Instance.new("Folder")
14
+ folder.Name = "Sounds"
15
+ folder.Parent = ReplicatedStorage
16
+ end
17
+ --[[
18
+ *
19
+ *
20
+ * @param name Define which Sound should be loaded
21
+ * @returns
22
+
23
+ ]]
24
+ local function load(name)
25
+ if folder:FindFirstChild(name) then
26
+ return nil
27
+ end
28
+ local config = definitions[name]
29
+ local sound = Instance.new("Sound")
30
+ sound.Name = name
31
+ sound.SoundId = config.id
32
+ local _condition = config.volume
33
+ if _condition == nil then
34
+ _condition = 1
35
+ end
36
+ sound.Volume = _condition
37
+ local _condition_1 = config.loop
38
+ if _condition_1 == nil then
39
+ _condition_1 = false
40
+ end
41
+ sound.Looped = _condition_1
42
+ sound.Parent = folder
43
+ end
44
+ --[[
45
+ *
46
+ *
47
+ * @param name Define which Sound should be played
48
+
49
+ ]]
50
+ local function play(name)
51
+ load(name)
52
+ local sound = folder:FindFirstChild(name)
53
+ local _result = sound
54
+ if _result ~= nil then
55
+ _result:Play()
56
+ end
57
+ end
58
+ --[[
59
+ *
60
+ *
61
+ * @param name Define which Sound should be stopped
62
+
63
+ ]]
64
+ local function stop(name)
65
+ local sound = folder:FindFirstChild(name)
66
+ local _result = sound
67
+ if _result ~= nil then
68
+ _result:Stop()
69
+ end
70
+ end
71
+ --[[
72
+ *
73
+ * Loads every Sound
74
+
75
+ ]]
76
+ local function preloadAll()
77
+ for name in pairs(definitions) do
78
+ load(name)
79
+ end
80
+ end
81
+ return {
82
+ play = play,
83
+ stop = stop,
84
+ preloadAll = preloadAll,
85
+ load = load,
86
+ }
87
+ end
88
+ return {
89
+ createSoundRegistry = createSoundRegistry,
90
+ }
@@ -1,4 +1,5 @@
1
1
  export interface SoundOptions {
2
2
  volume?: number;
3
3
  loop?: boolean;
4
+ id: string;
4
5
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ -- Compiled with roblox-ts v3.0.0
2
+ local TS = _G[script]
3
+ local createSoundRegistry = TS.import(script, script.Parent, "createSoundRegistry").createSoundRegistry
4
+ local Sounds = createSoundRegistry({
5
+ Exlposion = {
6
+ id = "rbxassetid://1",
7
+ volume = 0.5,
8
+ loop = false,
9
+ },
10
+ })
11
+ return nil
package/out/index.d.ts CHANGED
@@ -1,7 +1 @@
1
- import { SoundOptions } from "./core/options";
2
- export declare namespace Sounds {
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";
package/out/init.luau CHANGED
@@ -1,55 +1,7 @@
1
1
  -- Compiled with roblox-ts v3.0.0
2
- local Sounds = {}
3
- do
4
- local _container = Sounds
5
- --* * * @param sound Define the Sound to play
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
- return {
54
- Sounds = Sounds,
55
- }
7
+ return exports
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rbxts/sound-manager",
3
- "version": "1.0.0",
3
+ "version": "1.2.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
  }