melonjs 14.0.2 → 14.1.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.
Files changed (214) hide show
  1. package/README.md +2 -0
  2. package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +10 -0
  3. package/dist/melonjs.mjs/_virtual/arraymultimap.js +10 -0
  4. package/dist/melonjs.mjs/_virtual/earcut.js +10 -0
  5. package/dist/melonjs.mjs/_virtual/howler.js +10 -0
  6. package/dist/melonjs.mjs/_virtual/index.js +10 -0
  7. package/dist/melonjs.mjs/_virtual/index2.js +10 -0
  8. package/dist/melonjs.mjs/_virtual/multimap.js +10 -0
  9. package/dist/melonjs.mjs/_virtual/setmultimap.js +10 -0
  10. package/dist/melonjs.mjs/application/application.js +240 -0
  11. package/dist/melonjs.mjs/audio/audio.js +536 -0
  12. package/dist/melonjs.mjs/camera/camera2d.js +732 -0
  13. package/dist/melonjs.mjs/entity/entity.js +248 -0
  14. package/dist/melonjs.mjs/game.js +29 -0
  15. package/dist/melonjs.mjs/geometries/ellipse.js +275 -0
  16. package/dist/melonjs.mjs/geometries/line.js +116 -0
  17. package/dist/melonjs.mjs/geometries/path2d.js +319 -0
  18. package/dist/melonjs.mjs/geometries/point.js +89 -0
  19. package/dist/melonjs.mjs/geometries/poly.js +500 -0
  20. package/dist/melonjs.mjs/geometries/rectangle.js +375 -0
  21. package/dist/melonjs.mjs/geometries/roundrect.js +168 -0
  22. package/dist/melonjs.mjs/index.js +248 -0
  23. package/dist/melonjs.mjs/input/gamepad.js +501 -0
  24. package/dist/melonjs.mjs/input/input.js +26 -0
  25. package/dist/melonjs.mjs/input/keyboard.js +470 -0
  26. package/dist/melonjs.mjs/input/pointer.js +393 -0
  27. package/dist/melonjs.mjs/input/pointerevent.js +818 -0
  28. package/dist/melonjs.mjs/lang/deprecated.js +157 -0
  29. package/dist/melonjs.mjs/level/level.js +297 -0
  30. package/dist/melonjs.mjs/level/tiled/TMXGroup.js +141 -0
  31. package/dist/melonjs.mjs/level/tiled/TMXLayer.js +448 -0
  32. package/dist/melonjs.mjs/level/tiled/TMXObject.js +355 -0
  33. package/dist/melonjs.mjs/level/tiled/TMXTile.js +194 -0
  34. package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +639 -0
  35. package/dist/melonjs.mjs/level/tiled/TMXTileset.js +311 -0
  36. package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +83 -0
  37. package/dist/melonjs.mjs/level/tiled/TMXUtils.js +367 -0
  38. package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +506 -0
  39. package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +220 -0
  40. package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +157 -0
  41. package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +125 -0
  42. package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +109 -0
  43. package/dist/melonjs.mjs/loader/loader.js +801 -0
  44. package/dist/melonjs.mjs/loader/loadingscreen.js +120 -0
  45. package/dist/melonjs.mjs/loader/melonjs_logo.png.js +11 -0
  46. package/dist/melonjs.mjs/math/color.js +618 -0
  47. package/dist/melonjs.mjs/math/math.js +218 -0
  48. package/dist/melonjs.mjs/math/matrix2.js +503 -0
  49. package/dist/melonjs.mjs/math/matrix3.js +681 -0
  50. package/dist/melonjs.mjs/math/observable_vector2.js +471 -0
  51. package/dist/melonjs.mjs/math/observable_vector3.js +561 -0
  52. package/dist/melonjs.mjs/math/vector2.js +528 -0
  53. package/dist/melonjs.mjs/math/vector3.js +569 -0
  54. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +73 -0
  55. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +21 -0
  56. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +324 -0
  57. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +69 -0
  58. package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +691 -0
  59. package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +350 -0
  60. package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +3241 -0
  61. package/dist/melonjs.mjs/particles/emitter.js +267 -0
  62. package/dist/melonjs.mjs/particles/particle.js +188 -0
  63. package/dist/melonjs.mjs/particles/settings.js +319 -0
  64. package/dist/melonjs.mjs/physics/body.js +704 -0
  65. package/dist/melonjs.mjs/physics/bounds.js +460 -0
  66. package/dist/melonjs.mjs/physics/collision.js +132 -0
  67. package/dist/melonjs.mjs/physics/detector.js +194 -0
  68. package/dist/melonjs.mjs/physics/quadtree.js +391 -0
  69. package/dist/melonjs.mjs/physics/response.js +57 -0
  70. package/dist/melonjs.mjs/physics/sat.js +483 -0
  71. package/dist/melonjs.mjs/physics/world.js +221 -0
  72. package/dist/melonjs.mjs/plugin/plugin.js +141 -0
  73. package/dist/melonjs.mjs/renderable/collectable.js +62 -0
  74. package/dist/melonjs.mjs/renderable/colorlayer.js +80 -0
  75. package/dist/melonjs.mjs/renderable/container.js +1018 -0
  76. package/dist/melonjs.mjs/renderable/dragndrop.js +224 -0
  77. package/dist/melonjs.mjs/renderable/imagelayer.js +306 -0
  78. package/dist/melonjs.mjs/renderable/light2d.js +156 -0
  79. package/dist/melonjs.mjs/renderable/nineslicesprite.js +247 -0
  80. package/dist/melonjs.mjs/renderable/renderable.js +783 -0
  81. package/dist/melonjs.mjs/renderable/sprite.js +654 -0
  82. package/dist/melonjs.mjs/renderable/trigger.js +157 -0
  83. package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +213 -0
  84. package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +226 -0
  85. package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +128 -0
  86. package/dist/melonjs.mjs/state/stage.js +237 -0
  87. package/dist/melonjs.mjs/state/state.js +596 -0
  88. package/dist/melonjs.mjs/system/device.js +909 -0
  89. package/dist/melonjs.mjs/system/dom.js +78 -0
  90. package/dist/melonjs.mjs/system/event.js +537 -0
  91. package/dist/melonjs.mjs/system/platform.js +41 -0
  92. package/dist/melonjs.mjs/system/pooling.js +209 -0
  93. package/dist/melonjs.mjs/system/save.js +157 -0
  94. package/dist/melonjs.mjs/system/timer.js +286 -0
  95. package/dist/melonjs.mjs/text/bitmaptext.js +364 -0
  96. package/dist/melonjs.mjs/text/bitmaptextdata.js +199 -0
  97. package/dist/melonjs.mjs/text/glyph.js +66 -0
  98. package/dist/melonjs.mjs/text/text.js +453 -0
  99. package/dist/melonjs.mjs/text/textmetrics.js +176 -0
  100. package/dist/melonjs.mjs/text/textstyle.js +23 -0
  101. package/dist/melonjs.mjs/tweens/easing.js +336 -0
  102. package/dist/melonjs.mjs/tweens/interpolation.js +112 -0
  103. package/dist/melonjs.mjs/tweens/tween.js +480 -0
  104. package/dist/melonjs.mjs/utils/agent.js +76 -0
  105. package/dist/melonjs.mjs/utils/array.js +63 -0
  106. package/dist/melonjs.mjs/utils/file.js +42 -0
  107. package/dist/melonjs.mjs/utils/function.js +70 -0
  108. package/dist/melonjs.mjs/utils/string.js +82 -0
  109. package/dist/melonjs.mjs/utils/utils.js +173 -0
  110. package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +807 -0
  111. package/dist/melonjs.mjs/video/renderer.js +411 -0
  112. package/dist/melonjs.mjs/video/texture/atlas.js +519 -0
  113. package/dist/melonjs.mjs/video/texture/cache.js +143 -0
  114. package/dist/melonjs.mjs/video/texture/canvas_texture.js +144 -0
  115. package/dist/melonjs.mjs/video/video.js +462 -0
  116. package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +143 -0
  117. package/dist/melonjs.mjs/video/webgl/glshader.js +168 -0
  118. package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +10 -0
  119. package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +10 -0
  120. package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +10 -0
  121. package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +10 -0
  122. package/dist/melonjs.mjs/video/webgl/utils/attributes.js +25 -0
  123. package/dist/melonjs.mjs/video/webgl/utils/precision.js +20 -0
  124. package/dist/melonjs.mjs/video/webgl/utils/program.js +67 -0
  125. package/dist/melonjs.mjs/video/webgl/utils/string.js +25 -0
  126. package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +92 -0
  127. package/dist/melonjs.mjs/video/webgl/webgl_compositor.js +495 -0
  128. package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +1036 -0
  129. package/dist/melonjs.module.d.ts +1163 -1163
  130. package/dist/melonjs.module.js +1903 -3274
  131. package/package.json +22 -17
  132. package/src/application/application.js +3 -3
  133. package/src/audio/audio.js +32 -32
  134. package/src/camera/camera2d.js +31 -31
  135. package/src/entity/entity.js +17 -17
  136. package/src/geometries/ellipse.js +16 -16
  137. package/src/geometries/line.js +5 -5
  138. package/src/geometries/path2d.js +32 -32
  139. package/src/geometries/poly.js +15 -15
  140. package/src/geometries/rectangle.js +18 -18
  141. package/src/geometries/roundrect.js +8 -8
  142. package/src/input/gamepad.js +15 -15
  143. package/src/input/keyboard.js +12 -12
  144. package/src/input/pointer.js +6 -6
  145. package/src/input/pointerevent.js +12 -12
  146. package/src/lang/deprecated.js +12 -12
  147. package/src/level/level.js +25 -25
  148. package/src/level/tiled/TMXLayer.js +22 -22
  149. package/src/level/tiled/TMXTile.js +5 -5
  150. package/src/level/tiled/TMXTileMap.js +6 -6
  151. package/src/level/tiled/TMXTileset.js +2 -2
  152. package/src/level/tiled/TMXUtils.js +5 -5
  153. package/src/level/tiled/renderer/TMXHexagonalRenderer.js +2 -2
  154. package/src/level/tiled/renderer/TMXIsometricRenderer.js +2 -2
  155. package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
  156. package/src/level/tiled/renderer/TMXRenderer.js +19 -19
  157. package/src/loader/loader.js +20 -20
  158. package/src/math/color.js +20 -20
  159. package/src/math/math.js +16 -16
  160. package/src/math/matrix2.js +16 -16
  161. package/src/math/matrix3.js +25 -25
  162. package/src/math/observable_vector2.js +14 -14
  163. package/src/math/observable_vector3.js +16 -16
  164. package/src/math/vector2.js +9 -9
  165. package/src/math/vector3.js +10 -10
  166. package/src/particles/emitter.js +6 -6
  167. package/src/particles/particle.js +2 -2
  168. package/src/physics/body.js +28 -28
  169. package/src/physics/bounds.js +8 -8
  170. package/src/physics/collision.js +2 -2
  171. package/src/physics/detector.js +6 -6
  172. package/src/physics/quadtree.js +11 -11
  173. package/src/physics/sat.js +31 -31
  174. package/src/physics/world.js +5 -5
  175. package/src/plugin/plugin.js +5 -5
  176. package/src/renderable/collectable.js +3 -3
  177. package/src/renderable/colorlayer.js +5 -5
  178. package/src/renderable/container.js +21 -21
  179. package/src/renderable/dragndrop.js +14 -14
  180. package/src/renderable/imagelayer.js +13 -13
  181. package/src/renderable/light2d.js +3 -3
  182. package/src/renderable/nineslicesprite.js +16 -16
  183. package/src/renderable/renderable.js +23 -23
  184. package/src/renderable/sprite.js +28 -28
  185. package/src/renderable/trigger.js +15 -15
  186. package/src/renderable/ui/uibaseelement.js +7 -7
  187. package/src/renderable/ui/uispriteelement.js +6 -6
  188. package/src/renderable/ui/uitextbutton.js +13 -13
  189. package/src/state/stage.js +7 -7
  190. package/src/state/state.js +17 -17
  191. package/src/system/device.js +11 -11
  192. package/src/system/event.js +10 -10
  193. package/src/system/pooling.js +9 -9
  194. package/src/system/save.js +2 -2
  195. package/src/system/timer.js +10 -10
  196. package/src/text/bitmaptext.js +18 -18
  197. package/src/text/bitmaptextdata.js +2 -2
  198. package/src/text/text.js +23 -23
  199. package/src/text/textmetrics.js +8 -8
  200. package/src/tweens/tween.js +19 -19
  201. package/src/utils/agent.js +5 -5
  202. package/src/utils/array.js +4 -4
  203. package/src/utils/file.js +2 -2
  204. package/src/utils/function.js +6 -6
  205. package/src/utils/string.js +5 -5
  206. package/src/utils/utils.js +4 -4
  207. package/src/video/canvas/canvas_renderer.js +70 -70
  208. package/src/video/renderer.js +26 -26
  209. package/src/video/texture/atlas.js +22 -22
  210. package/src/video/texture/canvas_texture.js +9 -9
  211. package/src/video/video.js +17 -17
  212. package/src/video/webgl/glshader.js +10 -10
  213. package/src/video/webgl/webgl_compositor.js +41 -41
  214. package/src/video/webgl/webgl_renderer.js +75 -75
@@ -0,0 +1,536 @@
1
+ /*!
2
+ * melonJS Game Engine - v14.1.0
3
+ * http://www.melonjs.org
4
+ * melonjs is licensed under the MIT License.
5
+ * http://www.opensource.org/licenses/mit-license
6
+ * @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
7
+ */
8
+ import '../node_modules/howler/dist/howler.js';
9
+ import { clamp } from '../math/math.js';
10
+ import loader from '../loader/loader.js';
11
+ import { isDataUrl } from '../utils/string.js';
12
+ import { __exports as howler } from '../_virtual/howler.js';
13
+
14
+ // external import
15
+
16
+ /**
17
+ * @namespace audio
18
+ */
19
+
20
+ /**
21
+ * audio channel list
22
+ * @ignore
23
+ */
24
+ let audioTracks = {};
25
+
26
+ /**
27
+ * current active track
28
+ * @ignore
29
+ */
30
+ let current_track_id = null;
31
+
32
+ /**
33
+ * error retry counter
34
+ * @ignore
35
+ */
36
+ let retry_counter = 0;
37
+
38
+ /**
39
+ * list of active audio formats
40
+ * @ignore
41
+ */
42
+ let audioExts = [];
43
+
44
+ /**
45
+ * event listener callback on load error
46
+ * @ignore
47
+ */
48
+ let soundLoadError = function (sound_name, onerror_cb) {
49
+ // check the retry counter
50
+ if (retry_counter++ > 3) {
51
+ // something went wrong
52
+ var errmsg = "melonJS: failed loading " + sound_name;
53
+ {
54
+ // throw an exception and stop everything !
55
+ throw new Error(errmsg);
56
+ }
57
+ // else try loading again !
58
+ }
59
+ else {
60
+ audioTracks[sound_name].load();
61
+ }
62
+ };
63
+
64
+ /**
65
+ * Specify either to stop on audio loading error or not<br>
66
+ * if true, melonJS will throw an exception and stop loading<br>
67
+ * if false, melonJS will disable sounds and output a warning message
68
+ * in the console<br>
69
+ * @name stopOnAudioError
70
+ * @type {boolean}
71
+ * @default true
72
+ * @memberof audio
73
+ */
74
+ let stopOnAudioError = true;
75
+
76
+ /**
77
+ * Initialize and configure the audio support.<br>
78
+ * melonJS supports a wide array of audio codecs that have varying browser support :
79
+ * <i> ("mp3", "mpeg", opus", "ogg", "oga", "wav", "aac", "caf", "m4a", "m4b", "mp4", "weba", "webm", "dolby", "flac")</i>.<br>
80
+ * For a maximum browser coverage the recommendation is to use at least two of them,
81
+ * typically default to webm and then fallback to mp3 for the best balance of small filesize and high quality,
82
+ * webm has nearly full browser coverage with a great combination of compression and quality, and mp3 will fallback gracefully for other browsers.
83
+ * It is important to remember that melonJS selects the first compatible sound based on the list of extensions and given order passed here.
84
+ * So if you want webm to be used before mp3, you need to put the audio format in that order.
85
+ * @function audio.init
86
+ * @param {string} [format="mp3"] - audio format to prioritize
87
+ * @returns {boolean} Indicates whether audio initialization was successful
88
+ * @example
89
+ * // initialize the "sound engine", giving "webm" as default desired audio format, and "mp3" as a fallback
90
+ * if (!me.audio.init("webm,mp3")) {
91
+ * alert("Sorry but your browser does not support html 5 audio !");
92
+ * return;
93
+ * }
94
+ */
95
+ function init(format = "mp3") {
96
+ // convert it into an array
97
+ audioExts = format.split(",");
98
+
99
+ return !howler.Howler.noAudio;
100
+ }
101
+
102
+ /**
103
+ * check if the given audio format is supported
104
+ * @function audio.hasFormat
105
+ * @param {string} codec - audio format : "mp3", "mpeg", opus", "ogg", "oga", "wav", "aac", "caf", "m4a", "m4b", "mp4", "weba", "webm", "dolby", "flac"
106
+ * @returns {boolean} return true if the given audio format is supported
107
+ */
108
+ function hasFormat(codec) {
109
+ return hasAudio() && howler.Howler.codecs(codec);
110
+ }
111
+
112
+ /**
113
+ * check if audio (HTML5 or WebAudio) is supported
114
+ * @function audio.hasAudio
115
+ * @returns {boolean} return true if audio (HTML5 or WebAudio) is supported
116
+ */
117
+ function hasAudio() {
118
+ return !howler.Howler.noAudio;
119
+ }
120
+
121
+ /**
122
+ * enable audio output <br>
123
+ * only useful if audio supported and previously disabled through
124
+ * @function audio.enable
125
+ * @see audio#disable
126
+ */
127
+ function enable() {
128
+ unmuteAll();
129
+ }
130
+
131
+ /**
132
+ * disable audio output
133
+ * @function audio.disable
134
+ */
135
+ function disable() {
136
+ muteAll();
137
+ }
138
+
139
+ /**
140
+ * Load an audio file.<br>
141
+ * <br>
142
+ * sound item must contain the following fields :<br>
143
+ * - name : name of the sound<br>
144
+ * - src : source path<br>
145
+ * @ignore
146
+ */
147
+ function load(sound, html5, onload_cb, onerror_cb) {
148
+ var urls = [];
149
+ if (audioExts.length === 0) {
150
+ throw new Error("target audio extension(s) should be set through me.audio.init() before calling the preloader.");
151
+ }
152
+ if (isDataUrl(sound.src) === true) {
153
+ urls.push(sound.src);
154
+ } else {
155
+ for (var i = 0; i < audioExts.length; i++) {
156
+ urls.push(sound.src + sound.name + "." + audioExts[i] + loader.nocache);
157
+ }
158
+ }
159
+
160
+ audioTracks[sound.name] = new howler.Howl({
161
+ src : urls,
162
+ volume : howler.Howler.volume(),
163
+ html5 : html5 === true,
164
+ xhrWithCredentials : loader.withCredentials,
165
+ /**
166
+ * @ignore
167
+ */
168
+ onloaderror() {
169
+ soundLoadError.call(this, sound.name, onerror_cb);
170
+ },
171
+ /**
172
+ * @ignore
173
+ */
174
+ onload() {
175
+ retry_counter = 0;
176
+ if (onload_cb) {
177
+ onload_cb();
178
+ }
179
+ }
180
+ });
181
+
182
+ return 1;
183
+ }
184
+
185
+ /**
186
+ * play the specified sound
187
+ * @function audio.play
188
+ * @param {string} sound_name - audio clip name - case sensitive
189
+ * @param {boolean} [loop=false] - loop audio
190
+ * @param {Function} [onend] - Function to call when sound instance ends playing.
191
+ * @param {number} [volume=default] - Float specifying volume (0.0 - 1.0 values accepted).
192
+ * @returns {number} the sound instance ID.
193
+ * @example
194
+ * // play the "cling" audio clip
195
+ * me.audio.play("cling");
196
+ * // play & repeat the "engine" audio clip
197
+ * me.audio.play("engine", true);
198
+ * // play the "gameover_sfx" audio clip and call myFunc when finished
199
+ * me.audio.play("gameover_sfx", false, myFunc);
200
+ * // play the "gameover_sfx" audio clip with a lower volume level
201
+ * me.audio.play("gameover_sfx", false, null, 0.5);
202
+ */
203
+ function play(sound_name, loop = false, onend, volume) {
204
+ var sound = audioTracks[sound_name];
205
+ if (sound && typeof sound !== "undefined") {
206
+ var id = sound.play();
207
+ if (typeof loop === "boolean") {
208
+ // arg[0] can take different types in howler 2.0
209
+ sound.loop(loop, id);
210
+ }
211
+ sound.volume(typeof(volume) === "number" ? clamp(volume, 0.0, 1.0) : howler.Howler.volume(), id);
212
+ if (typeof(onend) === "function") {
213
+ if (loop === true) {
214
+ sound.on("end", onend, id);
215
+ }
216
+ else {
217
+ sound.once("end", onend, id);
218
+ }
219
+ }
220
+ return id;
221
+ } else {
222
+ throw new Error("audio clip " + sound_name + " does not exist");
223
+ }
224
+ }
225
+
226
+ /**
227
+ * Fade a currently playing sound between two volumee.
228
+ * @function audio.fade
229
+ * @param {string} sound_name - audio clip name - case sensitive
230
+ * @param {number} from - Volume to fade from (0.0 to 1.0).
231
+ * @param {number} to - Volume to fade to (0.0 to 1.0).
232
+ * @param {number} duration - Time in milliseconds to fade.
233
+ * @param {number} [id] - the sound instance ID. If none is passed, all sounds in group will fade.
234
+ */
235
+ function fade(sound_name, from, to, duration, id) {
236
+ var sound = audioTracks[sound_name];
237
+ if (sound && typeof sound !== "undefined") {
238
+ sound.fade(from, to, duration, id);
239
+ } else {
240
+ throw new Error("audio clip " + sound_name + " does not exist");
241
+ }
242
+ }
243
+
244
+ /**
245
+ * get/set the position of playback for a sound.
246
+ * @function audio.seek
247
+ * @param {string} sound_name - audio clip name - case sensitive
248
+ * @param {number} [seek] - the position to move current playback to (in seconds).
249
+ * @param {number} [id] - the sound instance ID. If none is passed, all sounds in group will changed.
250
+ * @returns {number} return the current seek position (if no extra parameters were given)
251
+ * @example
252
+ * // return the current position of the background music
253
+ * var current_pos = me.audio.seek("dst-gameforest");
254
+ * // set back the position of the background music to the beginning
255
+ * me.audio.seek("dst-gameforest", 0);
256
+ */
257
+ function seek(sound_name, ...args) {
258
+ var sound = audioTracks[sound_name];
259
+ if (sound && typeof sound !== "undefined") {
260
+ return sound.seek(...args);
261
+ } else {
262
+ throw new Error("audio clip " + sound_name + " does not exist");
263
+ }
264
+ }
265
+
266
+ /**
267
+ * get or set the rate of playback for a sound.
268
+ * @function audio.rate
269
+ * @param {string} sound_name - audio clip name - case sensitive
270
+ * @param {number} [rate] - playback rate : 0.5 to 4.0, with 1.0 being normal speed.
271
+ * @param {number} [id] - the sound instance ID. If none is passed, all sounds in group will be changed.
272
+ * @returns {number} return the current playback rate (if no extra parameters were given)
273
+ * @example
274
+ * // get the playback rate of the background music
275
+ * var rate = me.audio.rate("dst-gameforest");
276
+ * // speed up the playback of the background music
277
+ * me.audio.rate("dst-gameforest", 2.0);
278
+ */
279
+ function rate(sound_name, ...args) {
280
+ var sound = audioTracks[sound_name];
281
+ if (sound && typeof sound !== "undefined") {
282
+ return sound.rate(...args);
283
+ } else {
284
+ throw new Error("audio clip " + sound_name + " does not exist");
285
+ }
286
+ }
287
+
288
+ /**
289
+ * stop the specified sound on all channels
290
+ * @function audio.stop
291
+ * @param {string} [sound_name] - audio clip name (case sensitive). If none is passed, all sounds are stopped.
292
+ * @param {number} [id] - the sound instance ID. If none is passed, all sounds in group will stop.
293
+ * @example
294
+ * me.audio.stop("cling");
295
+ */
296
+ function stop(sound_name, id) {
297
+ if (typeof sound_name !== "undefined") {
298
+ var sound = audioTracks[sound_name];
299
+ if (sound && typeof sound !== "undefined") {
300
+ sound.stop(id);
301
+ // remove the defined onend callback (if any defined)
302
+ sound.off("end", undefined, id);
303
+ } else {
304
+ throw new Error("audio clip " + sound_name + " does not exist");
305
+ }
306
+ } else {
307
+ howler.Howler.stop();
308
+ }
309
+ }
310
+
311
+ /**
312
+ * pause the specified sound on all channels<br>
313
+ * this function does not reset the currentTime property
314
+ * @function audio.pause
315
+ * @param {string} sound_name - audio clip name - case sensitive
316
+ * @param {number} [id] - the sound instance ID. If none is passed, all sounds in group will pause.
317
+ * @example
318
+ * me.audio.pause("cling");
319
+ */
320
+ function pause(sound_name, id) {
321
+ var sound = audioTracks[sound_name];
322
+ if (sound && typeof sound !== "undefined") {
323
+ sound.pause(id);
324
+ } else {
325
+ throw new Error("audio clip " + sound_name + " does not exist");
326
+ }
327
+ }
328
+
329
+ /**
330
+ * resume the specified sound on all channels<br>
331
+ * @function audio.resume
332
+ * @param {string} sound_name - audio clip name - case sensitive
333
+ * @param {number} [id] - the sound instance ID. If none is passed, all sounds in group will resume.
334
+ * @example
335
+ * // play a audio clip
336
+ * var id = me.audio.play("myClip");
337
+ * ...
338
+ * // pause it
339
+ * me.audio.pause("myClip", id);
340
+ * ...
341
+ * // resume
342
+ * me.audio.resume("myClip", id);
343
+ */
344
+ function resume(sound_name, id) {
345
+ var sound = audioTracks[sound_name];
346
+ if (sound && typeof sound !== "undefined") {
347
+ sound.play(id);
348
+ } else {
349
+ throw new Error("audio clip " + sound_name + " does not exist");
350
+ }
351
+ }
352
+
353
+ /**
354
+ * play the specified audio track<br>
355
+ * this function automatically set the loop property to true<br>
356
+ * and keep track of the current sound being played.
357
+ * @function audio.playTrack
358
+ * @param {string} sound_name - audio track name - case sensitive
359
+ * @param {number} [volume=default] - Float specifying volume (0.0 - 1.0 values accepted).
360
+ * @returns {number} the sound instance ID.
361
+ * @example
362
+ * me.audio.playTrack("awesome_music");
363
+ */
364
+ function playTrack(sound_name, volume) {
365
+ current_track_id = sound_name;
366
+ return play(
367
+ current_track_id,
368
+ true,
369
+ null,
370
+ volume
371
+ );
372
+ }
373
+
374
+ /**
375
+ * stop the current audio track
376
+ * @function audio.stopTrack
377
+ * @see audio#playTrack
378
+ * @example
379
+ * // play a awesome music
380
+ * me.audio.playTrack("awesome_music");
381
+ * // stop the current music
382
+ * me.audio.stopTrack();
383
+ */
384
+ function stopTrack() {
385
+ if (current_track_id !== null) {
386
+ audioTracks[current_track_id].stop();
387
+ current_track_id = null;
388
+ }
389
+ }
390
+
391
+ /**
392
+ * pause the current audio track
393
+ * @function audio.pauseTrack
394
+ * @example
395
+ * me.audio.pauseTrack();
396
+ */
397
+ function pauseTrack() {
398
+ if (current_track_id !== null) {
399
+ audioTracks[current_track_id].pause();
400
+ }
401
+ }
402
+
403
+ /**
404
+ * resume the previously paused audio track
405
+ * @function audio.resumeTrack
406
+ * @example
407
+ * // play an awesome music
408
+ * me.audio.playTrack("awesome_music");
409
+ * // pause the audio track
410
+ * me.audio.pauseTrack();
411
+ * // resume the music
412
+ * me.audio.resumeTrack();
413
+ */
414
+ function resumeTrack() {
415
+ if (current_track_id !== null) {
416
+ audioTracks[current_track_id].play();
417
+ }
418
+ }
419
+
420
+ /**
421
+ * returns the current track Id
422
+ * @function audio.getCurrentTrack
423
+ * @returns {string} audio track name
424
+ */
425
+ function getCurrentTrack() {
426
+ return current_track_id;
427
+ }
428
+
429
+ /**
430
+ * set the default global volume
431
+ * @function audio.setVolume
432
+ * @param {number} volume - Float specifying volume (0.0 - 1.0 values accepted).
433
+ */
434
+ function setVolume(volume) {
435
+ howler.Howler.volume(volume);
436
+ }
437
+
438
+ /**
439
+ * get the default global volume
440
+ * @function audio.getVolume
441
+ * @returns {number} current volume value in Float [0.0 - 1.0] .
442
+ */
443
+ function getVolume() {
444
+ return howler.Howler.volume();
445
+ }
446
+
447
+ /**
448
+ * mute or unmute the specified sound, but does not pause the playback.
449
+ * @function audio.mute
450
+ * @param {string} sound_name - audio clip name - case sensitive
451
+ * @param {number} [id] - the sound instance ID. If none is passed, all sounds in group will mute.
452
+ * @param {boolean} [mute=true] - True to mute and false to unmute
453
+ * @example
454
+ * // mute the background music
455
+ * me.audio.mute("awesome_music");
456
+ */
457
+ function mute(sound_name, id, mute) {
458
+ // if not defined : true
459
+ mute = (typeof(mute) === "undefined" ? true : !!mute);
460
+ var sound = audioTracks[sound_name];
461
+ if (sound && typeof(sound) !== "undefined") {
462
+ sound.mute(mute, id);
463
+ } else {
464
+ throw new Error("audio clip " + sound_name + " does not exist");
465
+ }
466
+ }
467
+
468
+ /**
469
+ * unmute the specified sound
470
+ * @function audio.unmute
471
+ * @param {string} sound_name - audio clip name
472
+ * @param {number} [id] - the sound instance ID. If none is passed, all sounds in group will unmute.
473
+ */
474
+ function unmute(sound_name, id) {
475
+ mute(sound_name, id, false);
476
+ }
477
+
478
+ /**
479
+ * mute all audio
480
+ * @function audio.muteAll
481
+ */
482
+ function muteAll() {
483
+ howler.Howler.mute(true);
484
+ }
485
+
486
+ /**
487
+ * unmute all audio
488
+ * @function audio.unmuteAll
489
+ */
490
+ function unmuteAll() {
491
+ howler.Howler.mute(false);
492
+ }
493
+
494
+ /**
495
+ * Returns true if audio is muted globally.
496
+ * @function audio.muted
497
+ * @returns {boolean} true if audio is muted globally
498
+ */
499
+ function muted() {
500
+ return howler.Howler._muted;
501
+ }
502
+
503
+ /**
504
+ * unload specified audio track to free memory
505
+ * @function audio.unload
506
+ * @param {string} sound_name - audio track name - case sensitive
507
+ * @returns {boolean} true if unloaded
508
+ * @example
509
+ * me.audio.unload("awesome_music");
510
+ */
511
+ function unload(sound_name) {
512
+ if (!(sound_name in audioTracks)) {
513
+ return false;
514
+ }
515
+
516
+ // destroy the Howl object
517
+ audioTracks[sound_name].unload();
518
+ delete audioTracks[sound_name];
519
+ return true;
520
+ }
521
+
522
+ /**
523
+ * unload all audio to free memory
524
+ * @function audio.unloadAll
525
+ * @example
526
+ * me.audio.unloadAll();
527
+ */
528
+ function unloadAll() {
529
+ for (var sound_name in audioTracks) {
530
+ if (audioTracks.hasOwnProperty(sound_name)) {
531
+ unload(sound_name);
532
+ }
533
+ }
534
+ }
535
+
536
+ export { disable, enable, fade, getCurrentTrack, getVolume, hasAudio, hasFormat, init, load, mute, muteAll, muted, pause, pauseTrack, play, playTrack, rate, resume, resumeTrack, seek, setVolume, stop, stopOnAudioError, stopTrack, unload, unloadAll, unmute, unmuteAll };