-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsound.lua
154 lines (135 loc) · 5.21 KB
/
sound.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
---@meta _
--- The `Sound` class is used to control and play pieces of audio.
---
--- For a full list of sounds added by the base game, see [this page](https://saturnyoshi.gitlab.io/RoRML-Docs/misc/vanillaSounds.html).
---
--- **Note**: Please keep in mind when using this class that audio playback is not synced to the game speed and
--- will not do anything if the volume level is at 0%. As such, the `isPlaying` method should not be used
--- to check the timing of events.
---
---@class Sound
---@field id Id The sound's GameMaker resource ID
---@field ID Id alias for `id`
---
---@overload fun(name: string, fname: string): Sound
Sound = {}
--[[
---- static functions
--]]
--- Executes a [namespace search](https://saturnyoshi.gitlab.io/RoRML-Docs/misc/contextSearch.html) to find an existing Item.
---
--- See the page on [namespace searching](https://saturnyoshi.gitlab.io/RoRML-Docs/misc/contextSearch.html#context-find) for more information.
---
---@param name string
---@param namespace? Namespace
---@return Sound
function Sound.find(name, namespace) end
--- Executes a [namespace search](https://saturnyoshi.gitlab.io/RoRML-Docs/misc/contextSearch.html) to find an existing Item.
---
--- See the page on [namespace searching](https://saturnyoshi.gitlab.io/RoRML-Docs/misc/contextSearch.html#context-find-all) for more information.
---
---@param namespace? Namespace
---@return Sound[]
function Sound.findAll(namespace) end
--- Loads a sound from the path `fname` relative to the mod's directory. Only `.wav` and `.ogg` files are supported.
---
--- If a name is not provided then the filename will be used.
---
--- # Examples
--- Load the file `glass.ogg` from the mod's `sounds` folder and assign it to the variable `smash`.
--- ```lua
--- local smash = Sound.load("Smash", "sounds/glass.ogg")
--- ```
---
--- Load the file `bang.ogg` from the mod's `sounds` folder.
--- As no name is provided, the sound will automatically be assigned the name `bang`.
--- ```lua
--- local bang = Sound.load("sounds/bang.ogg")
--- ```
---
---@param name string The name to give the sound within the current namespace
---@param fname string The path to the file, relative to the mod's base path. *file extension is optional*
---@return Sound
function Sound.load(name, fname) end
--- Returns the currently playing music as a Sound object.
---
---@return Sound? '' The currently playing music, nil if no music is playing
function Sound.getMusic() end
--- Sets the music.
---
---@param music Sound? The sound object to use as the new music. *if nil, music will be stopped*
function Sound.setMusic(music) end
--- Used to fetch a Sound object from its GameMaker resource ID.
---
--- Useful for getting sounds from instance variables which contain a sound ID.
---
---@param id number The GameMaker ID of the sound
---@return Sound? '' The Sound if found, otherwise nil
function Sound.fromID(id) end
--[[
---- methods
--]]
--- Plays the sound.
---
--- # Examples
--- This would play the `smash` sound at the default pitch and volume.
--- ```lua
--- smash:play()
--- ```
---
--- This would play the `smash` sound at 80% pitch and 150% volume.
--- ```lua
--- smash:play(0.8, 1.5)
--- ```
---
---@param pitch number? The pitch to play the sound at. A higher pitch means a higher and faster sound, a lower pitch means a lower and slower sound. *defaults to 1*
---@param volume number? The volume to play the sound at. *defaults to 1*
function Sound:play(pitch, volume) end
--- Stops all playing instances of the sound.
---
--- # Example
--- Stop any currently playing instanecs of the `smash` sound.
--- ```lua
--- smash:stop()
--- ```
---
function Sound:stop() end
--- Returns whether any instance of the sound is currently playing.
---
--- # Example
--- Check if the sound `smash` is currently playing, and if it is, execute some code.
--- ```lua
--- if smash:isPlaying() then
--- -- Some Code
--- end
--- ```
---
---@return boolean '' true if any instances of the sound are playing, otherwise false
function Sound:isPlaying() end
--- Loops the sound, playing it repeatedly until the [`Sound:stop()`](https://saturnyoshi.gitlab.io/RoRML-Docs/class/sound.html#sound-stop) method is called.
---
--- # Example
--- Play the `smash` sound on loop until `smash:stop()` is called.
--- ```lua
--- smash:loop()
--- ```
---
function Sound:loop() end
--- Used to effectively replace the sound when it is referenced by the base game.
---
--- **Note**: that this does not affect what sound plays when mods reference the sound.
---
---@param remap Sound? The sound to be replaced with. *if nil removes the remap*
function Sound:setRemap(remap) end
--- Used to check whether a sound has been remapped.
---
---@return '' Sound The remapped sound if applicable, otherwise nil
function Sound:getRemap() end
--- See the page on [namespace searching](https://saturnyoshi.gitlab.io/RoRML-Docs/misc/contextSearch.html#context-origin) for more information.
---
---@return Namespace '' The namespace containing the sound
function Sound:getOrigin() end
--- See the page on [namespace searching](https://saturnyoshi.gitlab.io/RoRML-Docs/misc/contextSearch.html#context-name) for more information.
---
---@return string '' The name of the sound
function Sound:getName() end