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