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