@rbxts/sound-manager 2.2.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 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>
@@ -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
- }) => Map<string, SoundHandle> | undefined;
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
- for _, sound in categoryFolder:GetChildren() do
67
- if not sound:IsA("Sound") then
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 handle = createSpatialHandle(sound.SoundId, spatial.emitters, sound.Volume)
72
- local _name = sound.Name
73
- spatialHandles[_name] = handle
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
- sound:Play()
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 config = definitions[name]
89
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
90
- local soundsFolder = ReplicatedStorage:FindFirstChild("Sounds")
91
- if not soundsFolder then
92
- return nil
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 categoryFolder = soundsFolder:FindFirstChild(config.category)
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 sound in pairs(config.sounds) do
99
- local _sound = categoryFolder:FindFirstChild(sound)
100
- if not _sound then
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) => void;
30
+ onEnd: (sound: keyof T, callback: () => void, spatial?: {
31
+ emitters: BasePart[];
32
+ }) => void;
31
33
  isPlaying: (sound: keyof T) => boolean;
32
34
  };
@@ -311,12 +311,21 @@ local function createSoundRegistry(definitions)
311
311
  * @param callback Callback
312
312
 
313
313
  ]]
314
- local function onEnd(sound, callback)
315
- local _sound = folder:WaitForChild(sound)
316
- if not _sound then
317
- return nil
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)
318
328
  end
319
- _sound.Ended:Connect(callback)
320
329
  end
321
330
  --[[
322
331
  *
@@ -335,7 +344,7 @@ local function createSoundRegistry(definitions)
335
344
 
336
345
  ]]
337
346
  local function isPlaying(sound)
338
- local _sound = folder:WaitForChild(sound)
347
+ local _sound = folder:FindFirstChild(sound)
339
348
  if _sound.IsPlaying == true then
340
349
  return true
341
350
  else
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @returns the current playing legacy sounds and spatial sounds
3
+ */
4
+ export declare function currentPlayingSounds(): Array<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,4 @@
1
+ /**
2
+ * @returns Total count of legacy sounds and spatial sounds
3
+ */
4
+ export declare function TotalSoundCount(): number;
@@ -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.2.0",
3
+ "version": "2.3.0",
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": "ISC",
14
+ "license": "MIT",
15
15
  "type": "commonjs",
16
16
  "types": "out/index.d.ts",
17
17
  "files": [