melonjs 14.4.0 → 14.5.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 (207) hide show
  1. package/README.md +11 -55
  2. package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +1 -1
  3. package/dist/melonjs.mjs/_virtual/arraymultimap.js +1 -1
  4. package/dist/melonjs.mjs/_virtual/earcut.js +1 -1
  5. package/dist/melonjs.mjs/_virtual/howler.js +1 -1
  6. package/dist/melonjs.mjs/_virtual/index.js +1 -1
  7. package/dist/melonjs.mjs/_virtual/index2.js +1 -1
  8. package/dist/melonjs.mjs/_virtual/multimap.js +1 -1
  9. package/dist/melonjs.mjs/_virtual/setmultimap.js +1 -1
  10. package/dist/melonjs.mjs/application/application.js +1 -1
  11. package/dist/melonjs.mjs/application/header.js +1 -1
  12. package/dist/melonjs.mjs/application/resize.js +1 -1
  13. package/dist/melonjs.mjs/application/settings.js +1 -1
  14. package/dist/melonjs.mjs/audio/audio.js +4 -4
  15. package/dist/melonjs.mjs/camera/camera2d.js +1 -1
  16. package/dist/melonjs.mjs/const.js +1 -1
  17. package/dist/melonjs.mjs/entity/entity.js +43 -9
  18. package/dist/melonjs.mjs/geometries/ellipse.js +2 -3
  19. package/dist/melonjs.mjs/geometries/line.js +1 -1
  20. package/dist/melonjs.mjs/geometries/path2d.js +18 -42
  21. package/dist/melonjs.mjs/geometries/point.js +1 -6
  22. package/dist/melonjs.mjs/geometries/poly.js +2 -5
  23. package/dist/melonjs.mjs/geometries/rectangle.js +13 -9
  24. package/dist/melonjs.mjs/geometries/roundrect.js +1 -1
  25. package/dist/melonjs.mjs/index.js +8 -6
  26. package/dist/melonjs.mjs/input/gamepad.js +10 -16
  27. package/dist/melonjs.mjs/input/input.js +1 -1
  28. package/dist/melonjs.mjs/input/keyboard.js +1 -1
  29. package/dist/melonjs.mjs/input/pointer.js +1 -1
  30. package/dist/melonjs.mjs/input/pointerevent.js +2 -16
  31. package/dist/melonjs.mjs/lang/console.js +1 -1
  32. package/dist/melonjs.mjs/lang/deprecated.js +1 -1
  33. package/dist/melonjs.mjs/level/level.js +3 -3
  34. package/dist/melonjs.mjs/level/tiled/TMXGroup.js +1 -1
  35. package/dist/melonjs.mjs/level/tiled/TMXLayer.js +1 -8
  36. package/dist/melonjs.mjs/level/tiled/TMXObject.js +1 -1
  37. package/dist/melonjs.mjs/level/tiled/TMXTile.js +1 -1
  38. package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +8 -4
  39. package/dist/melonjs.mjs/level/tiled/TMXTileset.js +5 -5
  40. package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +1 -1
  41. package/dist/melonjs.mjs/level/tiled/TMXUtils.js +1 -1
  42. package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
  43. package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
  44. package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
  45. package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
  46. package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +1 -1
  47. package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
  48. package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
  49. package/dist/melonjs.mjs/loader/cache.js +24 -0
  50. package/dist/melonjs.mjs/loader/loader.js +331 -716
  51. package/dist/melonjs.mjs/loader/loadingscreen.js +4 -4
  52. package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
  53. package/dist/melonjs.mjs/loader/parser.js +281 -0
  54. package/dist/melonjs.mjs/loader/settings.js +91 -0
  55. package/dist/melonjs.mjs/math/color.js +1 -1
  56. package/dist/melonjs.mjs/math/math.js +1 -1
  57. package/dist/melonjs.mjs/math/matrix2.js +7 -9
  58. package/dist/melonjs.mjs/math/matrix3.js +18 -21
  59. package/dist/melonjs.mjs/math/observable_vector2.js +3 -3
  60. package/dist/melonjs.mjs/math/observable_vector3.js +3 -4
  61. package/dist/melonjs.mjs/math/vector2.js +3 -3
  62. package/dist/melonjs.mjs/math/vector3.js +3 -4
  63. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +1 -1
  64. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +1 -1
  65. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +1 -1
  66. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +1 -1
  67. package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
  68. package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +1 -1
  69. package/dist/melonjs.mjs/node_modules/eventemitter3/index2.js +1 -1
  70. package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +1 -1
  71. package/dist/melonjs.mjs/particles/emitter.js +3 -3
  72. package/dist/melonjs.mjs/particles/particle.js +1 -1
  73. package/dist/melonjs.mjs/particles/settings.js +1 -1
  74. package/dist/melonjs.mjs/physics/body.js +18 -14
  75. package/dist/melonjs.mjs/physics/bounds.js +18 -70
  76. package/dist/melonjs.mjs/physics/collision.js +1 -1
  77. package/dist/melonjs.mjs/physics/detector.js +1 -1
  78. package/dist/melonjs.mjs/physics/quadtree.js +1 -1
  79. package/dist/melonjs.mjs/physics/response.js +1 -1
  80. package/dist/melonjs.mjs/physics/sat.js +1 -1
  81. package/dist/melonjs.mjs/physics/world.js +1 -1
  82. package/dist/melonjs.mjs/plugin/plugin.js +3 -3
  83. package/dist/melonjs.mjs/renderable/collectable.js +1 -1
  84. package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
  85. package/dist/melonjs.mjs/renderable/container.js +25 -19
  86. package/dist/melonjs.mjs/renderable/dragndrop.js +1 -1
  87. package/dist/melonjs.mjs/renderable/imagelayer.js +7 -1
  88. package/dist/melonjs.mjs/renderable/light2d.js +1 -1
  89. package/dist/melonjs.mjs/renderable/nineslicesprite.js +1 -1
  90. package/dist/melonjs.mjs/renderable/renderable.js +126 -105
  91. package/dist/melonjs.mjs/renderable/sprite.js +33 -54
  92. package/dist/melonjs.mjs/renderable/trigger.js +1 -1
  93. package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +1 -1
  94. package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +1 -1
  95. package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +1 -1
  96. package/dist/melonjs.mjs/state/stage.js +1 -1
  97. package/dist/melonjs.mjs/state/state.js +2 -2
  98. package/dist/melonjs.mjs/system/device.js +1 -1
  99. package/dist/melonjs.mjs/system/dom.js +1 -1
  100. package/dist/melonjs.mjs/system/event.js +1 -1
  101. package/dist/melonjs.mjs/system/platform.js +1 -1
  102. package/dist/melonjs.mjs/system/pooling.js +8 -18
  103. package/dist/melonjs.mjs/system/save.js +1 -1
  104. package/dist/melonjs.mjs/system/timer.js +1 -1
  105. package/dist/melonjs.mjs/text/bitmaptext.js +66 -8
  106. package/dist/melonjs.mjs/text/bitmaptextdata.js +1 -1
  107. package/dist/melonjs.mjs/text/glyph.js +1 -1
  108. package/dist/melonjs.mjs/text/text.js +1 -1
  109. package/dist/melonjs.mjs/text/textmetrics.js +1 -1
  110. package/dist/melonjs.mjs/text/textstyle.js +1 -1
  111. package/dist/melonjs.mjs/tweens/easing.js +1 -1
  112. package/dist/melonjs.mjs/tweens/interpolation.js +1 -1
  113. package/dist/melonjs.mjs/tweens/tween.js +1 -1
  114. package/dist/melonjs.mjs/utils/agent.js +1 -1
  115. package/dist/melonjs.mjs/utils/array.js +1 -1
  116. package/dist/melonjs.mjs/utils/file.js +1 -1
  117. package/dist/melonjs.mjs/utils/function.js +1 -1
  118. package/dist/melonjs.mjs/utils/string.js +2 -2
  119. package/dist/melonjs.mjs/utils/utils.js +2 -4
  120. package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +1 -1
  121. package/dist/melonjs.mjs/video/renderer.js +1 -1
  122. package/dist/melonjs.mjs/video/texture/atlas.js +10 -9
  123. package/dist/melonjs.mjs/video/texture/cache.js +3 -3
  124. package/dist/melonjs.mjs/video/texture/canvas_texture.js +1 -1
  125. package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
  126. package/dist/melonjs.mjs/video/video.js +2 -2
  127. package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +1 -1
  128. package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +235 -0
  129. package/{src/video/webgl → dist/melonjs.mjs/video/webgl/compositors}/webgl_compositor.js +28 -205
  130. package/dist/melonjs.mjs/video/webgl/glshader.js +1 -1
  131. package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
  132. package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +1 -1
  133. package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
  134. package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +1 -1
  135. package/dist/melonjs.mjs/video/webgl/utils/attributes.js +1 -1
  136. package/dist/melonjs.mjs/video/webgl/utils/precision.js +1 -1
  137. package/dist/melonjs.mjs/video/webgl/utils/program.js +1 -1
  138. package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
  139. package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +1 -1
  140. package/dist/melonjs.mjs/video/webgl/webgl_compositor.js +2 -2
  141. package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +2 -2
  142. package/dist/melonjs.module.js +17844 -17809
  143. package/dist/types/entity/entity.d.ts +2 -2
  144. package/dist/types/geometries/path2d.d.ts +5 -31
  145. package/dist/types/geometries/point.d.ts +2 -7
  146. package/dist/types/geometries/poly.d.ts +0 -1
  147. package/dist/types/index.d.ts +2 -2
  148. package/dist/types/loader/cache.d.ts +7 -0
  149. package/dist/types/loader/loader.d.ts +166 -181
  150. package/dist/types/loader/parser.d.ts +41 -0
  151. package/dist/types/loader/settings.d.ts +57 -0
  152. package/dist/types/particles/emitter.d.ts +4 -4
  153. package/dist/types/physics/bounds.d.ts +29 -84
  154. package/dist/types/renderable/container.d.ts +0 -11
  155. package/dist/types/renderable/renderable.d.ts +37 -31
  156. package/dist/types/renderable/sprite.d.ts +3 -3
  157. package/dist/types/state/state.d.ts +1 -1
  158. package/dist/types/system/pooling.d.ts +2 -2
  159. package/dist/types/video/renderer.d.ts +1 -1
  160. package/dist/types/video/webgl/compositors/compositor.d.ts +101 -0
  161. package/dist/types/video/webgl/compositors/webgl_compositor.d.ts +86 -0
  162. package/dist/types/video/webgl/webgl_compositor.d.ts +2 -3
  163. package/dist/types/video/webgl/webgl_renderer.d.ts +1 -1
  164. package/package.json +16 -15
  165. package/src/audio/audio.js +3 -3
  166. package/src/entity/entity.js +42 -8
  167. package/src/geometries/ellipse.js +1 -2
  168. package/src/geometries/path2d.js +17 -41
  169. package/src/geometries/point.js +0 -5
  170. package/src/geometries/poly.js +1 -4
  171. package/src/geometries/rectangle.js +12 -8
  172. package/src/index.js +2 -2
  173. package/src/input/gamepad.js +9 -15
  174. package/src/input/pointerevent.js +1 -15
  175. package/src/level/level.js +2 -2
  176. package/src/level/tiled/TMXLayer.js +0 -7
  177. package/src/level/tiled/TMXTileMap.js +7 -3
  178. package/src/level/tiled/TMXTileset.js +4 -4
  179. package/src/loader/cache.js +16 -0
  180. package/src/loader/loader.js +339 -711
  181. package/src/loader/loadingscreen.js +3 -3
  182. package/src/loader/parser.js +279 -0
  183. package/src/loader/settings.js +85 -0
  184. package/src/math/matrix2.js +6 -8
  185. package/src/math/matrix3.js +17 -20
  186. package/src/math/observable_vector2.js +2 -2
  187. package/src/math/observable_vector3.js +2 -3
  188. package/src/math/vector2.js +2 -2
  189. package/src/math/vector3.js +2 -3
  190. package/src/particles/emitter.js +2 -2
  191. package/src/physics/body.js +17 -13
  192. package/src/physics/bounds.js +17 -69
  193. package/src/renderable/container.js +24 -18
  194. package/src/renderable/imagelayer.js +6 -0
  195. package/src/renderable/renderable.js +125 -104
  196. package/src/renderable/sprite.js +32 -53
  197. package/src/state/state.js +1 -1
  198. package/src/system/pooling.js +7 -17
  199. package/src/text/bitmaptext.js +65 -7
  200. package/src/utils/string.js +1 -1
  201. package/src/utils/utils.js +1 -3
  202. package/src/video/texture/atlas.js +9 -8
  203. package/src/video/texture/cache.js +2 -2
  204. package/src/video/video.js +1 -1
  205. package/src/video/webgl/compositors/compositor.js +227 -0
  206. package/src/video/webgl/compositors/webgl_compositor.js +300 -0
  207. package/src/video/webgl/webgl_renderer.js +1 -1
@@ -1,42 +1,62 @@
1
1
  import * as fileUtil from "./../utils/file.js";
2
2
  import * as event from "./../system/event.js";
3
- import { ua } from "./../system/platform.js";
4
3
  import * as audio from "./../audio/audio.js";
5
4
  import state from "./../state/state.js";
6
- import level from "./../level/level.js";
7
- import * as TMXUtils from "./../level/tiled/TMXUtils.js";
8
- import { isDataUrl } from "./../utils/string.js";
9
-
10
-
11
- // contains all the images loaded
12
- var imgList = {};
13
- // contains all the TMX loaded
14
- var tmxList = {};
15
- // contains all the binary files loaded
16
- var binList = {};
17
- // contains all the JSON files
18
- var jsonList = {};
19
- // baseURL
20
- var baseURL = {};
5
+ import { imgList, tmxList, binList, jsonList } from "./cache.js";
6
+ import { preloadImage, preloadFontFace, preloadTMX, preloadJSON, preloadBinary, preloadJavascript } from "./parser.js";
7
+ import { baseURL } from "./settings.js";
8
+
9
+
10
+ /**
11
+ * a small class to manage loading of stuff and manage resources
12
+ * @namespace loader
13
+ */
14
+
15
+ // for backward compatibility
16
+ export * from "./settings.js";
17
+
18
+ /**
19
+ * onload callback
20
+ * @name onload
21
+ * @default undefined
22
+ * @memberof loader
23
+ * @example
24
+ * // set a callback when everything is loaded
25
+ * me.loader.onload = this.loaded.bind(this);
26
+ */
27
+ export let onload;
28
+
29
+ /**
30
+ * onProgress callback<br>
31
+ * each time a resource is loaded, the loader will fire the specified function,
32
+ * giving the actual progress [0 ... 1], as argument, and an object describing the resource loaded
33
+ * @name onProgress
34
+ * @default undefined
35
+ * @memberof loader
36
+ * @example
37
+ * // set a callback for progress notification
38
+ * me.loader.onProgress = this.updateProgress.bind(this);
39
+ */
40
+ export let onProgress;
21
41
 
22
42
  // flag to check loading status
23
- var resourceCount = 0;
24
- var loadCount = 0;
25
- var timerId = 0;
43
+ let resourceCount = 0;
44
+ let loadCount = 0;
45
+ let timerId = 0;
26
46
 
27
47
  /**
28
48
  * check the loading status
29
49
  * @ignore
30
50
  */
31
- function checkLoadStatus(onload) {
51
+ function checkLoadStatus(onloadcb) {
32
52
  if (loadCount === resourceCount) {
33
53
  // wait 1/2s and execute callback (cheap workaround to ensure everything is loaded)
34
- if (typeof onload === "function" || loader.onload) {
54
+ if (typeof onloadcb === "function" || onload) {
35
55
  // make sure we clear the timer
36
56
  clearTimeout(timerId);
37
57
  // trigger the onload callback
38
58
  // we call either the supplied callback (which takes precedence) or the global one
39
- var callback = onload || loader.onload;
59
+ var callback = onloadcb || onload;
40
60
  setTimeout(() => {
41
61
  callback();
42
62
  event.emit(event.LOADER_COMPLETE);
@@ -48,748 +68,356 @@ function checkLoadStatus(onload) {
48
68
  }
49
69
  else {
50
70
  timerId = setTimeout(() => {
51
- checkLoadStatus(onload);
71
+ checkLoadStatus(onloadcb);
52
72
  }, 100);
53
73
  }
54
74
  }
55
75
 
56
76
  /**
57
- * load Images
58
- * @example
59
- * preloadImages([
60
- * { name : 'image1', src : 'images/image1.png'},
61
- * { name : 'image2', src : 'images/image2.png'},
62
- * { name : 'image3', src : 'images/image3.png'},
63
- * { name : 'image4', src : 'images/image4.png'}
64
- * ]);
77
+ * just increment the number of already loaded resources
65
78
  * @ignore
66
79
  */
67
- function preloadImage(img, onload, onerror) {
68
- // create new Image object and add to list
69
- imgList[img.name] = new Image();
70
- if (typeof onload === "function") {
71
- imgList[img.name].onload = onload;
72
- }
73
- if (typeof onerror === "function") {
74
- imgList[img.name].onerror = onerror;
75
- }
76
- if (typeof (loader.crossOrigin) === "string") {
77
- imgList[img.name].crossOrigin = loader.crossOrigin;
80
+ function onResourceLoaded(res) {
81
+ // increment the loading counter
82
+ loadCount++;
83
+
84
+ // currrent progress
85
+ var progress = loadCount / resourceCount;
86
+
87
+ // call callback if defined
88
+ if (typeof onProgress === "function") {
89
+ // pass the load progress in percent, as parameter
90
+ onProgress(progress, res);
78
91
  }
79
- imgList[img.name].src = img.src + loader.nocache;
92
+ event.emit(event.LOADER_PROGRESS, progress, res);
80
93
  }
81
94
 
82
95
  /**
83
- * load a font face
84
- * @example
85
- * preloadFontFace(
86
- * name: "'kenpixel'", type: "fontface", src: "url('data/font/kenvector_future.woff2')"
87
- * ]);
96
+ * on error callback for image loading
88
97
  * @ignore
89
98
  */
90
- function preloadFontFace(data, onload, onerror) {
91
-
92
- if (isDataUrl(data.src) === true) {
93
- // make sure it in the `url(data:[<mediatype>][;base64],<data>)` format as expected by FontFace
94
- if (!data.src.startsWith("url(")) {
95
- data.src = "url(" + data.src + ")";
96
- }
97
- }
98
-
99
- var font = new FontFace(data.name, data.src);
100
-
101
- // loading promise
102
- font.load().then(() => {
103
- // apply the font after the font has finished downloading
104
- document.fonts.add(font);
105
- document.body.style.fontFamily = data.name;
106
- if (typeof onload === "function") {
107
- // onloaded callback
108
- onload();
109
- }
110
- }, () => {
111
- if (typeof onerror === "function") {
112
- // rejected
113
- onerror(data.name);
114
- }
115
- });
99
+ function onLoadingError(res) {
100
+ throw new Error("Failed loading resource " + res.src);
116
101
  }
117
102
 
118
103
  /**
119
- * preload TMX files
120
- * @ignore
104
+ * set all the specified game resources to be preloaded.
105
+ * @name preload
106
+ * @memberof loader
107
+ * @public
108
+ * @param {object[]} res
109
+ * @param {string} res.name - internal name of the resource
110
+ * @param {string} res.type - "audio", binary", "image", "json","js", "tmx", "tsx", "fontface"
111
+ * @param {string} res.src - path and/or file name of the resource (for audio assets only the path is required)
112
+ * @param {boolean} [res.stream] - Set to true to force HTML5 Audio, which allows not to wait for large file to be downloaded before playing.
113
+ * @param {Function} [onload=loader.onload] - function to be called when all resources are loaded
114
+ * @param {boolean} [switchToLoadState=true] - automatically switch to the loading screen
115
+ * @example
116
+ * game_resources = [
117
+ * // PNG tileset
118
+ * {name: "tileset-platformer", type: "image", src: "data/map/tileset.png"},
119
+ * // PNG packed texture
120
+ * {name: "texture", type:"image", src: "data/gfx/texture.png"}
121
+ * // PNG base64 encoded image
122
+ * {name: "texture", type:"image", src: "data:image/png;base64,iVBORw0KAAAQAAAAEACA..."}
123
+ * // TSX file
124
+ * {name: "meta_tiles", type: "tsx", src: "data/map/meta_tiles.tsx"},
125
+ * // TMX level (XML & JSON)
126
+ * {name: "map1", type: "tmx", src: "data/map/map1.json"},
127
+ * {name: "map2", type: "tmx", src: "data/map/map2.tmx"},
128
+ * {name: "map3", type: "tmx", format: "json", data: {"height":15,"layers":[...],"tilewidth":32,"version":1,"width":20}},
129
+ * {name: "map4", type: "tmx", format: "xml", data: {xml representation of tmx}},
130
+ * // audio resources
131
+ * {name: "bgmusic", type: "audio", src: "data/audio/"},
132
+ * {name: "cling", type: "audio", src: "data/audio/"},
133
+ * // base64 encoded audio resources
134
+ * {name: "band", type: "audio", src: "data:audio/wav;base64,..."},
135
+ * // binary file
136
+ * {name: "ymTrack", type: "binary", src: "data/audio/main.ym"},
137
+ * // JSON file (used for texturePacker)
138
+ * {name: "texture", type: "json", src: "data/gfx/texture.json"},
139
+ * // JavaScript file
140
+ * {name: "plugin", type: "js", src: "data/js/plugin.js"},
141
+ * // Font Face
142
+ * { name: "'kenpixel'", type: "fontface", src: "url('data/font/kenvector_future.woff2')" }
143
+ * ];
144
+ * ...
145
+ * // set all resources to be loaded
146
+ * me.loader.preload(game.resources, this.loaded.bind(this));
121
147
  */
122
- function preloadTMX(tmxData, onload, onerror) {
123
- /**
124
- * @ignore
125
- */
126
- function addToTMXList(data) {
127
- // set the TMX content
128
- tmxList[tmxData.name] = data;
129
-
130
- // add the tmx to the level manager
131
- if (tmxData.type === "tmx") {
132
- level.add(tmxData.type, tmxData.name);
133
- }
148
+ export function preload(res, onloadcb, switchToLoadState = true) {
149
+ // parse the resources
150
+ for (var i = 0; i < res.length; i++) {
151
+ resourceCount += load(
152
+ res[i],
153
+ onResourceLoaded.bind(this, res[i]),
154
+ onLoadingError.bind(this, res[i])
155
+ );
134
156
  }
135
-
136
-
137
- //if the data is in the tmxData object, don't get it via a XMLHTTPRequest
138
- if (tmxData.data) {
139
- addToTMXList(tmxData.data);
140
- if (typeof onload === "function") {
141
- onload();
142
- }
143
- return;
157
+ // set the onload callback if defined
158
+ if (typeof(onloadcb) !== "undefined") {
159
+ onload = onloadcb;
144
160
  }
145
161
 
146
- var xmlhttp = new XMLHttpRequest();
147
- // check the data format ('tmx', 'json')
148
- var format = fileUtil.getExtension(tmxData.src);
149
-
150
- if (xmlhttp.overrideMimeType) {
151
- if (format === "json") {
152
- xmlhttp.overrideMimeType("application/json");
153
- }
154
- else {
155
- xmlhttp.overrideMimeType("text/xml");
156
- }
162
+ if (switchToLoadState === true) {
163
+ // swith to the loading screen
164
+ state.change(state.LOADING);
157
165
  }
158
166
 
159
- xmlhttp.open("GET", tmxData.src + loader.nocache, true);
160
- xmlhttp.withCredentials = loader.withCredentials;
161
- // set the callbacks
162
- xmlhttp.ontimeout = onerror;
163
- xmlhttp.onreadystatechange = function () {
164
- if (xmlhttp.readyState === 4) {
165
- // status = 0 when file protocol is used, or cross-domain origin,
166
- // (With Chrome use "--allow-file-access-from-files --disable-web-security")
167
- if ((xmlhttp.status === 200) || ((xmlhttp.status === 0) && xmlhttp.responseText)) {
168
- var result = null;
169
-
170
- // parse response
171
- switch (format) {
172
- case "xml":
173
- case "tmx":
174
- case "tsx":
175
- // ie9 does not fully implement the responseXML
176
- if (ua.match(/msie/i) || !xmlhttp.responseXML) {
177
- if (globalThis.DOMParser) {
178
- // manually create the XML DOM
179
- result = (new DOMParser()).parseFromString(xmlhttp.responseText, "text/xml");
180
- } else {
181
- throw new Error("XML file format loading not supported, use the JSON file format instead");
182
- }
183
- }
184
- else {
185
- result = xmlhttp.responseXML;
186
- }
187
- // converts to a JS object
188
- var data = TMXUtils.parse(result);
189
- switch (format) {
190
- case "tmx":
191
- result = data.map;
192
- break;
193
-
194
- case "tsx":
195
- result = data.tilesets[0];
196
- break;
197
- }
198
-
199
- break;
200
-
201
- case "json":
202
- case "tmj":
203
- case "tsj":
204
- result = JSON.parse(xmlhttp.responseText);
205
- break;
206
-
207
- default:
208
- throw new Error("TMX file format " + format + " not supported !");
209
- }
210
-
211
- //set the TMX content
212
- addToTMXList(result);
213
-
214
- // fire the callback
215
- if (typeof onload === "function") {
216
- onload();
217
- }
218
- }
219
- else if (typeof onerror === "function") {
220
- onerror(tmxData.name);
221
- }
222
- }
223
- };
224
- // send the request
225
- xmlhttp.send();
167
+ // check load status
168
+ checkLoadStatus(onload);
226
169
  }
227
170
 
228
171
  /**
229
- * preload JSON files
230
- * @ignore
172
+ * Load a single resource (to be used if you need to load additional resource during the game)
173
+ * @name load
174
+ * @memberof loader
175
+ * @public
176
+ * @param {object} res
177
+ * @param {string} res.name - internal name of the resource
178
+ * @param {string} res.type - "audio", binary", "image", "json", "tmx", "tsx"
179
+ * @param {string} res.src - path and/or file name of the resource (for audio assets only the path is required)
180
+ * @param {boolean} [res.stream] - Set to true to force HTML5 Audio, which allows not to wait for large file to be downloaded before playing.
181
+ * @param {Function} [onload] - function to be called when the resource is loaded
182
+ * @param {Function} [onerror] - function to be called in case of error
183
+ * @returns {number} the amount of corresponding resource to be preloaded
184
+ * @example
185
+ * // load an image asset
186
+ * me.loader.load({name: "avatar", type:"image", src: "data/avatar.png"}, this.onload.bind(this), this.onerror.bind(this));
187
+ * // load a base64 image asset
188
+ * me.loader.load({name: "avatar", type:"image", src: "data:image/png;base64,iVBORw0KAAAQAAAAEACA..."};
189
+ * // start loading music
190
+ * me.loader.load({
191
+ * name : "bgmusic",
192
+ * type : "audio",
193
+ * src : "data/audio/"
194
+ * }, function () {
195
+ * me.audio.play("bgmusic");
196
+ * });
231
197
  */
232
- function preloadJSON(data, onload, onerror) {
233
- var xmlhttp = new XMLHttpRequest();
234
-
235
- if (xmlhttp.overrideMimeType) {
236
- xmlhttp.overrideMimeType("application/json");
198
+ export function load(res, onload, onerror) {
199
+ // transform the url if necessary
200
+ if (typeof (baseURL[res.type]) !== "undefined") {
201
+ res.src = baseURL[res.type] + res.src;
202
+ }
203
+ // check ressource type
204
+ switch (res.type) {
205
+ case "binary":
206
+ // reuse the preloadImage fn
207
+ preloadBinary.call(this, res, onload, onerror);
208
+ return 1;
209
+
210
+ case "image":
211
+ // reuse the preloadImage fn
212
+ preloadImage.call(this, res, onload, onerror);
213
+ return 1;
214
+
215
+ case "json":
216
+ preloadJSON.call(this, res, onload, onerror);
217
+ return 1;
218
+
219
+ case "js":
220
+ preloadJavascript.call(this, res, onload, onerror);
221
+ return 1;
222
+
223
+ case "tmx":
224
+ case "tsx":
225
+ preloadTMX.call(this, res, onload, onerror);
226
+ return 1;
227
+
228
+ case "audio":
229
+ audio.load(res, !!res.stream, onload, onerror);
230
+ return 1;
231
+
232
+ case "fontface":
233
+ preloadFontFace.call(this, res, onload, onerror);
234
+ return 1;
235
+
236
+ default:
237
+ throw new Error("load : unknown or invalid resource type : " + res.type);
237
238
  }
238
-
239
- xmlhttp.open("GET", data.src + loader.nocache, true);
240
- xmlhttp.withCredentials = loader.withCredentials;
241
-
242
- // set the callbacks
243
- xmlhttp.ontimeout = onerror;
244
- xmlhttp.onreadystatechange = function () {
245
- if (xmlhttp.readyState === 4) {
246
- // status = 0 when file protocol is used, or cross-domain origin,
247
- // (With Chrome use "--allow-file-access-from-files --disable-web-security")
248
- if ((xmlhttp.status === 200) || ((xmlhttp.status === 0) && xmlhttp.responseText)) {
249
- // get the Texture Packer Atlas content
250
- jsonList[data.name] = JSON.parse(xmlhttp.responseText);
251
- if (typeof onload === "function") {
252
- // fire the callback
253
- onload();
254
- }
255
- }
256
- else if (typeof onerror === "function") {
257
- onerror(data.name);
258
- }
259
- }
260
- };
261
- // send the request
262
- xmlhttp.send();
263
239
  }
264
240
 
265
241
  /**
266
- * preload Binary files
267
- * @ignore
242
+ * unload specified resource to free memory
243
+ * @name unload
244
+ * @memberof loader
245
+ * @public
246
+ * @param {object} res
247
+ * @param {string} res.name - internal name of the resource
248
+ * @param {string} res.type - "audio", binary", "image", "json", "tmx", "tsx"
249
+ * @returns {boolean} true if unloaded
250
+ * @example me.loader.unload({name: "avatar", type:"image"});
268
251
  */
269
- function preloadBinary(data, onload, onerror) {
270
- var httpReq = new XMLHttpRequest();
271
-
272
- // load our file
273
- httpReq.open("GET", data.src + loader.nocache, true);
274
- httpReq.withCredentials = loader.withCredentials;
275
- httpReq.responseType = "arraybuffer";
276
- httpReq.onerror = onerror;
277
- httpReq.onload = function () {
278
- var arrayBuffer = httpReq.response;
279
- if (arrayBuffer) {
280
- var byteArray = new Uint8Array(arrayBuffer);
281
- var buffer = [];
282
- for (var i = 0; i < byteArray.byteLength; i++) {
283
- buffer[i] = String.fromCharCode(byteArray[i]);
252
+ export function unload(res) {
253
+ switch (res.type) {
254
+ case "binary":
255
+ if (!(res.name in binList)) {
256
+ return false;
284
257
  }
285
- binList[data.name] = buffer.join("");
286
- if (typeof onload === "function") {
287
- // callback
288
- onload();
258
+
259
+ delete binList[res.name];
260
+ return true;
261
+
262
+ case "image":
263
+ if (!(res.name in imgList)) {
264
+ return false;
289
265
  }
266
+ delete imgList[res.name];
267
+ return true;
290
268
 
291
- }
292
- };
293
- httpReq.send();
294
- }
269
+ case "json":
270
+ if (!(res.name in jsonList)) {
271
+ return false;
272
+ }
295
273
 
296
- /**
297
- * preload Binary files
298
- * @ignore
299
- */
300
- function preloadJavascript(data, onload, onerror) {
301
- var script = document.createElement("script");
274
+ delete jsonList[res.name];
275
+ return true;
302
276
 
303
- script.src = data.src;
304
- script.type = "text/javascript";
305
- if (typeof (loader.crossOrigin) === "string") {
306
- script.crossOrigin = loader.crossOrigin;
307
- }
308
- script.defer = true;
277
+ case "js":
278
+ // ??
279
+ return true;
309
280
 
310
- if (typeof onload === "function") {
311
- script.onload = () => {
312
- // callback
313
- onload();
314
- };
315
- }
281
+ case "fontface":
282
+ // ??
283
+ return true;
316
284
 
317
- if (typeof onerror === "function") {
318
- script.onerror = () => {
319
- // callback
320
- onerror(data.name);
321
- };
322
- }
285
+ case "tmx":
286
+ case "tsx":
287
+ if (!(res.name in tmxList)) {
288
+ return false;
289
+ }
323
290
 
324
- document.getElementsByTagName("body")[0].appendChild(script);
291
+ delete tmxList[res.name];
292
+ return true;
293
+
294
+ case "audio":
295
+ return audio.unload(res.name);
296
+
297
+ default:
298
+ throw new Error("unload : unknown or invalid resource type : " + res.type);
299
+ }
325
300
  }
326
301
 
327
302
  /**
328
- * a small class to manage loading of stuff and manage resources
329
- * @namespace loader
303
+ * unload all resources to free memory
304
+ * @name unloadAll
305
+ * @memberof loader
306
+ * @public
307
+ * @example me.loader.unloadAll();
330
308
  */
331
- var loader = {
332
-
333
- /**
334
- * to enable/disable caching
335
- * @ignore
336
- */
337
- nocache : "",
338
-
339
- /*
340
- * PUBLIC STUFF
341
- */
342
-
343
- /**
344
- * onload callback
345
- * @public
346
- * @name onload
347
- * @memberof loader
348
- * @example
349
- * // set a callback when everything is loaded
350
- * me.loader.onload = this.loaded.bind(this);
351
- */
352
- onload : undefined,
353
-
354
- /**
355
- * onProgress callback<br>
356
- * each time a resource is loaded, the loader will fire the specified function,
357
- * giving the actual progress [0 ... 1], as argument, and an object describing the resource loaded
358
- * @public
359
- * @name onProgress
360
- * @memberof loader
361
- * @example
362
- * // set a callback for progress notification
363
- * me.loader.onProgress = this.updateProgress.bind(this);
364
- */
365
- onProgress : undefined,
366
-
367
- /**
368
- * crossOrigin attribute to configure the CORS requests for Image data element.
369
- * By default (that is, when the attribute is not specified), CORS is not used at all.
370
- * The "anonymous" keyword means that there will be no exchange of user credentials via cookies,
371
- * client-side SSL certificates or HTTP authentication as described in the Terminology section of the CORS specification.<br>
372
- * @public
373
- * @type {string}
374
- * @name crossOrigin
375
- * @default undefined
376
- * @memberof loader
377
- * @see https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes
378
- * @example
379
- * // allow for cross-origin texture loading in WebGL
380
- * me.loader.crossOrigin = "anonymous";
381
- *
382
- * // set all ressources to be loaded
383
- * me.loader.preload(game.resources, this.loaded.bind(this));
384
- */
385
- crossOrigin : undefined,
386
-
387
- /**
388
- * indicates whether or not cross-site Access-Control requests should be made using credentials such as cookies,
389
- * authorization headers or TLS client certificates. Setting withCredentials has no effect on same-site requests.
390
- * @public
391
- * @type {boolean}
392
- * @name withCredentials
393
- * @default false
394
- * @memberof loader
395
- * @see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials
396
- * @example
397
- * // enable withCredentials
398
- * me.loader.withCredentials = true;
399
- *
400
- * // set all ressources to be loaded
401
- * me.loader.preload(game.resources, this.loaded.bind(this));
402
- */
403
- withCredentials : false,
404
-
405
- /**
406
- * just increment the number of already loaded resources
407
- * @ignore
408
- */
409
- onResourceLoaded(res) {
410
- // increment the loading counter
411
- loadCount++;
412
-
413
- // currrent progress
414
- var progress = loadCount / resourceCount;
415
-
416
- // call callback if defined
417
- if (this.onProgress) {
418
- // pass the load progress in percent, as parameter
419
- this.onProgress(progress, res);
420
- }
421
- event.emit(event.LOADER_PROGRESS, progress, res);
422
- },
423
-
424
- /**
425
- * on error callback for image loading
426
- * @ignore
427
- */
428
- onLoadingError(res) {
429
- throw new Error("Failed loading resource " + res.src);
430
- },
431
-
432
- /**
433
- * enable the nocache mechanism
434
- * @ignore
435
- */
436
- setNocache(enable) {
437
- this.nocache = enable ? "?" + ~~(Math.random() * 10000000) : "";
438
- },
439
-
440
- /**
441
- * change the default baseURL for the given asset type.<br>
442
- * (this will prepend the asset URL and must finish with a '/')
443
- * @name setBaseURL
444
- * @memberof loader
445
- * @public
446
- * @param {string} type - "*", "audio", binary", "image", "json", "js", "tmx", "tsx"
447
- * @param {string} [url="./"] - default base URL
448
- * @example
449
- * // change the base URL relative address for audio assets
450
- * me.loader.setBaseURL("audio", "data/audio/");
451
- * // change the base URL absolute address for all object types
452
- * me.loader.setBaseURL("*", "http://myurl.com/")
453
- */
454
- setBaseURL(type, url) {
455
- if (type !== "*") {
456
- baseURL[type] = url;
457
- } else {
458
- // "wildcards"
459
- baseURL["audio"] = url;
460
- baseURL["binary"] = url;
461
- baseURL["image"] = url;
462
- baseURL["json"] = url;
463
- baseURL["js"] = url;
464
- baseURL["tmx"] = url;
465
- baseURL["tsx"] = url;
466
- // XXX ?
467
- //baseURL["fontface"] = url;
468
- }
469
- },
470
-
471
- /**
472
- * set all the specified game resources to be preloaded.
473
- * @name preload
474
- * @memberof loader
475
- * @public
476
- * @param {object[]} res
477
- * @param {string} res.name - internal name of the resource
478
- * @param {string} res.type - "audio", binary", "image", "json","js", "tmx", "tsx", "fontface"
479
- * @param {string} res.src - path and/or file name of the resource (for audio assets only the path is required)
480
- * @param {boolean} [res.stream] - Set to true to force HTML5 Audio, which allows not to wait for large file to be downloaded before playing.
481
- * @param {Function} [onload=loader.onload] - function to be called when all resources are loaded
482
- * @param {boolean} [switchToLoadState=true] - automatically switch to the loading screen
483
- * @example
484
- * game_resources = [
485
- * // PNG tileset
486
- * {name: "tileset-platformer", type: "image", src: "data/map/tileset.png"},
487
- * // PNG packed texture
488
- * {name: "texture", type:"image", src: "data/gfx/texture.png"}
489
- * // PNG base64 encoded image
490
- * {name: "texture", type:"image", src: "data:image/png;base64,iVBORw0KAAAQAAAAEACA..."}
491
- * // TSX file
492
- * {name: "meta_tiles", type: "tsx", src: "data/map/meta_tiles.tsx"},
493
- * // TMX level (XML & JSON)
494
- * {name: "map1", type: "tmx", src: "data/map/map1.json"},
495
- * {name: "map2", type: "tmx", src: "data/map/map2.tmx"},
496
- * {name: "map3", type: "tmx", format: "json", data: {"height":15,"layers":[...],"tilewidth":32,"version":1,"width":20}},
497
- * {name: "map4", type: "tmx", format: "xml", data: {xml representation of tmx}},
498
- * // audio resources
499
- * {name: "bgmusic", type: "audio", src: "data/audio/"},
500
- * {name: "cling", type: "audio", src: "data/audio/"},
501
- * // base64 encoded audio resources
502
- * {name: "band", type: "audio", src: "data:audio/wav;base64,..."},
503
- * // binary file
504
- * {name: "ymTrack", type: "binary", src: "data/audio/main.ym"},
505
- * // JSON file (used for texturePacker)
506
- * {name: "texture", type: "json", src: "data/gfx/texture.json"},
507
- * // JavaScript file
508
- * {name: "plugin", type: "js", src: "data/js/plugin.js"},
509
- * // Font Face
510
- * { name: "'kenpixel'", type: "fontface", src: "url('data/font/kenvector_future.woff2')" }
511
- * ];
512
- * ...
513
- * // set all resources to be loaded
514
- * me.loader.preload(game.resources, this.loaded.bind(this));
515
- */
516
- preload(res, onload, switchToLoadState = true) {
517
- // parse the resources
518
- for (var i = 0; i < res.length; i++) {
519
- resourceCount += this.load(
520
- res[i],
521
- this.onResourceLoaded.bind(this, res[i]),
522
- this.onLoadingError.bind(this, res[i])
523
- );
524
- }
525
- // set the onload callback if defined
526
- if (typeof(onload) !== "undefined") {
527
- this.onload = onload;
309
+ export function unloadAll() {
310
+ var name;
311
+
312
+ // unload all binary resources
313
+ for (name in binList) {
314
+ if (binList.hasOwnProperty(name)) {
315
+ unload({
316
+ "name" : name,
317
+ "type" : "binary"
318
+ });
528
319
  }
320
+ }
529
321
 
530
- if (switchToLoadState === true) {
531
- // swith to the loading screen
532
- state.change(state.LOADING);
322
+ // unload all image resources
323
+ for (name in imgList) {
324
+ if (imgList.hasOwnProperty(name)) {
325
+ unload({
326
+ "name" : name,
327
+ "type" : "image"
328
+ });
533
329
  }
330
+ }
534
331
 
535
- // check load status
536
- checkLoadStatus(onload);
537
- },
538
-
539
- /**
540
- * Load a single resource (to be used if you need to load additional resource during the game)
541
- * @name load
542
- * @memberof loader
543
- * @public
544
- * @param {object} res
545
- * @param {string} res.name - internal name of the resource
546
- * @param {string} res.type - "audio", binary", "image", "json", "tmx", "tsx"
547
- * @param {string} res.src - path and/or file name of the resource (for audio assets only the path is required)
548
- * @param {boolean} [res.stream] - Set to true to force HTML5 Audio, which allows not to wait for large file to be downloaded before playing.
549
- * @param {Function} [onload] - function to be called when the resource is loaded
550
- * @param {Function} [onerror] - function to be called in case of error
551
- * @returns {number} the amount of corresponding resource to be preloaded
552
- * @example
553
- * // load an image asset
554
- * me.loader.load({name: "avatar", type:"image", src: "data/avatar.png"}, this.onload.bind(this), this.onerror.bind(this));
555
- * // load a base64 image asset
556
- * me.loader.load({name: "avatar", type:"image", src: "data:image/png;base64,iVBORw0KAAAQAAAAEACA..."};
557
- * // start loading music
558
- * me.loader.load({
559
- * name : "bgmusic",
560
- * type : "audio",
561
- * src : "data/audio/"
562
- * }, function () {
563
- * me.audio.play("bgmusic");
564
- * });
565
- */
566
- load(res, onload, onerror) {
567
- // transform the url if necessary
568
- if (typeof (baseURL[res.type]) !== "undefined") {
569
- res.src = baseURL[res.type] + res.src;
570
- }
571
- // check ressource type
572
- switch (res.type) {
573
- case "binary":
574
- // reuse the preloadImage fn
575
- preloadBinary.call(this, res, onload, onerror);
576
- return 1;
577
-
578
- case "image":
579
- // reuse the preloadImage fn
580
- preloadImage.call(this, res, onload, onerror);
581
- return 1;
582
-
583
- case "json":
584
- preloadJSON.call(this, res, onload, onerror);
585
- return 1;
586
-
587
- case "js":
588
- preloadJavascript.call(this, res, onload, onerror);
589
- return 1;
590
-
591
- case "tmx":
592
- case "tsx":
593
- preloadTMX.call(this, res, onload, onerror);
594
- return 1;
595
-
596
- case "audio":
597
- audio.load(res, !!res.stream, onload, onerror);
598
- return 1;
599
-
600
- case "fontface":
601
- preloadFontFace.call(this, res, onload, onerror);
602
- return 1;
603
-
604
- default:
605
- throw new Error("load : unknown or invalid resource type : " + res.type);
606
- }
607
- },
608
-
609
- /**
610
- * unload specified resource to free memory
611
- * @name unload
612
- * @memberof loader
613
- * @public
614
- * @param {object} res
615
- * @param {string} res.name - internal name of the resource
616
- * @param {string} res.type - "audio", binary", "image", "json", "tmx", "tsx"
617
- * @returns {boolean} true if unloaded
618
- * @example me.loader.unload({name: "avatar", type:"image"});
619
- */
620
- unload(res) {
621
- switch (res.type) {
622
- case "binary":
623
- if (!(res.name in binList)) {
624
- return false;
625
- }
626
-
627
- delete binList[res.name];
628
- return true;
629
-
630
- case "image":
631
- if (!(res.name in imgList)) {
632
- return false;
633
- }
634
- delete imgList[res.name];
635
- return true;
636
-
637
- case "json":
638
- if (!(res.name in jsonList)) {
639
- return false;
640
- }
641
-
642
- delete jsonList[res.name];
643
- return true;
644
-
645
- case "js":
646
- // ??
647
- return true;
648
-
649
- case "fontface":
650
- // ??
651
- return true;
652
-
653
- case "tmx":
654
- case "tsx":
655
- if (!(res.name in tmxList)) {
656
- return false;
657
- }
658
-
659
- delete tmxList[res.name];
660
- return true;
661
-
662
- case "audio":
663
- return audio.unload(res.name);
664
-
665
- default:
666
- throw new Error("unload : unknown or invalid resource type : " + res.type);
667
- }
668
- },
669
-
670
- /**
671
- * unload all resources to free memory
672
- * @name unloadAll
673
- * @memberof loader
674
- * @public
675
- * @example me.loader.unloadAll();
676
- */
677
- unloadAll() {
678
- var name;
679
-
680
- // unload all binary resources
681
- for (name in binList) {
682
- if (binList.hasOwnProperty(name)) {
683
- this.unload({
684
- "name" : name,
685
- "type" : "binary"
686
- });
687
- }
332
+ // unload all tmx resources
333
+ for (name in tmxList) {
334
+ if (tmxList.hasOwnProperty(name)) {
335
+ unload({
336
+ "name" : name,
337
+ "type" : "tmx"
338
+ });
688
339
  }
340
+ }
689
341
 
690
- // unload all image resources
691
- for (name in imgList) {
692
- if (imgList.hasOwnProperty(name)) {
693
- this.unload({
694
- "name" : name,
695
- "type" : "image"
696
- });
697
- }
342
+ // unload all in json resources
343
+ for (name in jsonList) {
344
+ if (jsonList.hasOwnProperty(name)) {
345
+ unload({
346
+ "name" : name,
347
+ "type" : "json"
348
+ });
698
349
  }
350
+ }
699
351
 
700
- // unload all tmx resources
701
- for (name in tmxList) {
702
- if (tmxList.hasOwnProperty(name)) {
703
- this.unload({
704
- "name" : name,
705
- "type" : "tmx"
706
- });
707
- }
708
- }
352
+ // unload all audio resources
353
+ audio.unloadAll();
354
+ }
709
355
 
710
- // unload all in json resources
711
- for (name in jsonList) {
712
- if (jsonList.hasOwnProperty(name)) {
713
- this.unload({
714
- "name" : name,
715
- "type" : "json"
716
- });
717
- }
718
- }
356
+ /**
357
+ * return the specified TMX/TSX object
358
+ * @name getTMX
359
+ * @memberof loader
360
+ * @public
361
+ * @param {string} elt - name of the tmx/tsx element ("map1");
362
+ * @returns {object} requested element or null if not found
363
+ */
364
+ export function getTMX(elt) {
365
+ // force as string
366
+ elt = "" + elt;
367
+ if (elt in tmxList) {
368
+ return tmxList[elt];
369
+ }
370
+ return null;
371
+ }
719
372
 
720
- // unload all audio resources
721
- audio.unloadAll();
722
- },
723
-
724
- /**
725
- * return the specified TMX/TSX object
726
- * @name getTMX
727
- * @memberof loader
728
- * @public
729
- * @param {string} elt - name of the tmx/tsx element ("map1");
730
- * @returns {object} requested element or null if not found
731
- */
732
- getTMX(elt) {
733
- // force as string
734
- elt = "" + elt;
735
- if (elt in tmxList) {
736
- return tmxList[elt];
737
- }
738
- return null;
739
- },
740
-
741
- /**
742
- * return the specified Binary object
743
- * @name getBinary
744
- * @memberof loader
745
- * @public
746
- * @param {string} elt - name of the binary object ("ymTrack");
747
- * @returns {object} requested element or null if not found
748
- */
749
- getBinary(elt) {
750
- // force as string
751
- elt = "" + elt;
752
- if (elt in binList) {
753
- return binList[elt];
754
- }
755
- return null;
756
- },
757
-
758
- /**
759
- * return the specified Image Object
760
- * @name getImage
761
- * @memberof loader
762
- * @public
763
- * @param {string} image - name of the Image element ("tileset-platformer");
764
- * @returns {HTMLImageElement} requested element or null if not found
765
- */
766
- getImage(image) {
767
- // force as string and extract the base name
768
- image = fileUtil.getBasename("" + image);
769
- if (image in imgList) {
770
- // return the corresponding Image object
771
- return imgList[image];
772
- }
773
- return null;
774
- },
775
-
776
- /**
777
- * return the specified JSON Object
778
- * @name getJSON
779
- * @memberof loader
780
- * @public
781
- * @param {string} elt - name of the json file to load
782
- * @returns {object}
783
- */
784
- getJSON(elt) {
785
- // force as string
786
- elt = "" + elt;
787
- if (elt in jsonList) {
788
- return jsonList[elt];
789
- }
790
- return null;
373
+ /**
374
+ * return the specified Binary object
375
+ * @name getBinary
376
+ * @memberof loader
377
+ * @public
378
+ * @param {string} elt - name of the binary object ("ymTrack");
379
+ * @returns {object} requested element or null if not found
380
+ */
381
+ export function getBinary(elt) {
382
+ // force as string
383
+ elt = "" + elt;
384
+ if (elt in binList) {
385
+ return binList[elt];
791
386
  }
387
+ return null;
388
+ }
792
389
 
793
- };
390
+ /**
391
+ * return the specified Image Object
392
+ * @name getImage
393
+ * @memberof loader
394
+ * @public
395
+ * @param {string} image - name of the Image element ("tileset-platformer");
396
+ * @returns {HTMLImageElement} requested element or null if not found
397
+ */
398
+ export function getImage(image) {
399
+ // force as string and extract the base name
400
+ image = fileUtil.getBasename("" + image);
401
+ if (image in imgList) {
402
+ // return the corresponding Image object
403
+ return imgList[image];
404
+ }
405
+ return null;
406
+ }
794
407
 
795
- export default loader;
408
+ /**
409
+ * return the specified JSON Object
410
+ * @name getJSON
411
+ * @memberof loader
412
+ * @public
413
+ * @param {string} elt - name of the json file to load
414
+ * @returns {object}
415
+ */
416
+ export function getJSON(elt) {
417
+ // force as string
418
+ elt = "" + elt;
419
+ if (elt in jsonList) {
420
+ return jsonList[elt];
421
+ }
422
+ return null;
423
+ }