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,48 +1,61 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.3.0
2
+ * melonJS Game Engine - v14.5.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
- * @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
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,748 +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
- result = JSON.parse(xmlhttp.responseText);
209
- break;
210
-
211
- default:
212
- throw new Error("TMX file format " + format + "not supported !");
213
- }
214
-
215
- //set the TMX content
216
- addToTMXList(result);
217
-
218
- // fire the callback
219
- if (typeof onload === "function") {
220
- onload();
221
- }
222
- }
223
- else if (typeof onerror === "function") {
224
- onerror(tmxData.name);
225
- }
226
- }
227
- };
228
- // send the request
229
- xmlhttp.send();
160
+ // check load status
161
+ checkLoadStatus(onload);
230
162
  }
231
163
 
232
164
  /**
233
- * preload JSON files
234
- * @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
+ * });
235
190
  */
236
- function preloadJSON(data, onload, onerror) {
237
- var xmlhttp = new XMLHttpRequest();
238
-
239
- if (xmlhttp.overrideMimeType) {
240
- 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);
241
231
  }
242
-
243
- xmlhttp.open("GET", data.src + loader.nocache, true);
244
- xmlhttp.withCredentials = loader.withCredentials;
245
-
246
- // set the callbacks
247
- xmlhttp.ontimeout = onerror;
248
- xmlhttp.onreadystatechange = function () {
249
- if (xmlhttp.readyState === 4) {
250
- // status = 0 when file protocol is used, or cross-domain origin,
251
- // (With Chrome use "--allow-file-access-from-files --disable-web-security")
252
- if ((xmlhttp.status === 200) || ((xmlhttp.status === 0) && xmlhttp.responseText)) {
253
- // get the Texture Packer Atlas content
254
- jsonList[data.name] = JSON.parse(xmlhttp.responseText);
255
- if (typeof onload === "function") {
256
- // fire the callback
257
- onload();
258
- }
259
- }
260
- else if (typeof onerror === "function") {
261
- onerror(data.name);
262
- }
263
- }
264
- };
265
- // send the request
266
- xmlhttp.send();
267
232
  }
268
233
 
269
234
  /**
270
- * preload Binary files
271
- * @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"});
272
244
  */
273
- function preloadBinary(data, onload, onerror) {
274
- var httpReq = new XMLHttpRequest();
275
-
276
- // load our file
277
- httpReq.open("GET", data.src + loader.nocache, true);
278
- httpReq.withCredentials = loader.withCredentials;
279
- httpReq.responseType = "arraybuffer";
280
- httpReq.onerror = onerror;
281
- httpReq.onload = function () {
282
- var arrayBuffer = httpReq.response;
283
- if (arrayBuffer) {
284
- var byteArray = new Uint8Array(arrayBuffer);
285
- var buffer = [];
286
- for (var i = 0; i < byteArray.byteLength; i++) {
287
- 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;
288
250
  }
289
- binList[data.name] = buffer.join("");
290
- if (typeof onload === "function") {
291
- // callback
292
- onload();
251
+
252
+ delete binList[res.name];
253
+ return true;
254
+
255
+ case "image":
256
+ if (!(res.name in imgList)) {
257
+ return false;
293
258
  }
259
+ delete imgList[res.name];
260
+ return true;
294
261
 
295
- }
296
- };
297
- httpReq.send();
298
- }
262
+ case "json":
263
+ if (!(res.name in jsonList)) {
264
+ return false;
265
+ }
299
266
 
300
- /**
301
- * preload Binary files
302
- * @ignore
303
- */
304
- function preloadJavascript(data, onload, onerror) {
305
- var script = document.createElement("script");
267
+ delete jsonList[res.name];
268
+ return true;
306
269
 
307
- script.src = data.src;
308
- script.type = "text/javascript";
309
- if (typeof (loader.crossOrigin) === "string") {
310
- script.crossOrigin = loader.crossOrigin;
311
- }
312
- script.defer = true;
270
+ case "js":
271
+ // ??
272
+ return true;
313
273
 
314
- if (typeof onload === "function") {
315
- script.onload = () => {
316
- // callback
317
- onload();
318
- };
319
- }
274
+ case "fontface":
275
+ // ??
276
+ return true;
320
277
 
321
- if (typeof onerror === "function") {
322
- script.onerror = () => {
323
- // callback
324
- onerror(data.name);
325
- };
326
- }
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;
327
286
 
328
- 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
+ }
329
293
  }
330
294
 
331
295
  /**
332
- * a small class to manage loading of stuff and manage resources
333
- * @namespace loader
296
+ * unload all resources to free memory
297
+ * @name unloadAll
298
+ * @memberof loader
299
+ * @public
300
+ * @example me.loader.unloadAll();
334
301
  */
335
- var loader = {
336
-
337
- /**
338
- * to enable/disable caching
339
- * @ignore
340
- */
341
- nocache : "",
342
-
343
- /*
344
- * PUBLIC STUFF
345
- */
346
-
347
- /**
348
- * onload callback
349
- * @public
350
- * @name onload
351
- * @memberof loader
352
- * @example
353
- * // set a callback when everything is loaded
354
- * me.loader.onload = this.loaded.bind(this);
355
- */
356
- onload : undefined,
357
-
358
- /**
359
- * onProgress callback<br>
360
- * each time a resource is loaded, the loader will fire the specified function,
361
- * giving the actual progress [0 ... 1], as argument, and an object describing the resource loaded
362
- * @public
363
- * @name onProgress
364
- * @memberof loader
365
- * @example
366
- * // set a callback for progress notification
367
- * me.loader.onProgress = this.updateProgress.bind(this);
368
- */
369
- onProgress : undefined,
370
-
371
- /**
372
- * crossOrigin attribute to configure the CORS requests for Image data element.
373
- * By default (that is, when the attribute is not specified), CORS is not used at all.
374
- * The "anonymous" keyword means that there will be no exchange of user credentials via cookies,
375
- * client-side SSL certificates or HTTP authentication as described in the Terminology section of the CORS specification.<br>
376
- * @public
377
- * @type {string}
378
- * @name crossOrigin
379
- * @default undefined
380
- * @memberof loader
381
- * @see https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes
382
- * @example
383
- * // allow for cross-origin texture loading in WebGL
384
- * me.loader.crossOrigin = "anonymous";
385
- *
386
- * // set all ressources to be loaded
387
- * me.loader.preload(game.resources, this.loaded.bind(this));
388
- */
389
- crossOrigin : undefined,
390
-
391
- /**
392
- * indicates whether or not cross-site Access-Control requests should be made using credentials such as cookies,
393
- * authorization headers or TLS client certificates. Setting withCredentials has no effect on same-site requests.
394
- * @public
395
- * @type {boolean}
396
- * @name withCredentials
397
- * @default false
398
- * @memberof loader
399
- * @see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials
400
- * @example
401
- * // enable withCredentials
402
- * me.loader.withCredentials = true;
403
- *
404
- * // set all ressources to be loaded
405
- * me.loader.preload(game.resources, this.loaded.bind(this));
406
- */
407
- withCredentials : false,
408
-
409
- /**
410
- * just increment the number of already loaded resources
411
- * @ignore
412
- */
413
- onResourceLoaded(res) {
414
- // increment the loading counter
415
- loadCount++;
416
-
417
- // currrent progress
418
- var progress = loadCount / resourceCount;
419
-
420
- // call callback if defined
421
- if (this.onProgress) {
422
- // pass the load progress in percent, as parameter
423
- this.onProgress(progress, res);
424
- }
425
- emit(LOADER_PROGRESS, progress, res);
426
- },
427
-
428
- /**
429
- * on error callback for image loading
430
- * @ignore
431
- */
432
- onLoadingError(res) {
433
- throw new Error("Failed loading resource " + res.src);
434
- },
435
-
436
- /**
437
- * enable the nocache mechanism
438
- * @ignore
439
- */
440
- setNocache(enable) {
441
- this.nocache = enable ? "?" + ~~(Math.random() * 10000000) : "";
442
- },
443
-
444
- /**
445
- * change the default baseURL for the given asset type.<br>
446
- * (this will prepend the asset URL and must finish with a '/')
447
- * @name setBaseURL
448
- * @memberof loader
449
- * @public
450
- * @param {string} type - "*", "audio", binary", "image", "json", "js", "tmx", "tsx"
451
- * @param {string} [url="./"] - default base URL
452
- * @example
453
- * // change the base URL relative address for audio assets
454
- * me.loader.setBaseURL("audio", "data/audio/");
455
- * // change the base URL absolute address for all object types
456
- * me.loader.setBaseURL("*", "http://myurl.com/")
457
- */
458
- setBaseURL(type, url) {
459
- if (type !== "*") {
460
- baseURL[type] = url;
461
- } else {
462
- // "wildcards"
463
- baseURL["audio"] = url;
464
- baseURL["binary"] = url;
465
- baseURL["image"] = url;
466
- baseURL["json"] = url;
467
- baseURL["js"] = url;
468
- baseURL["tmx"] = url;
469
- baseURL["tsx"] = url;
470
- // XXX ?
471
- //baseURL["fontface"] = url;
472
- }
473
- },
474
-
475
- /**
476
- * set all the specified game resources to be preloaded.
477
- * @name preload
478
- * @memberof loader
479
- * @public
480
- * @param {object[]} res
481
- * @param {string} res.name - internal name of the resource
482
- * @param {string} res.type - "audio", binary", "image", "json","js", "tmx", "tsx", "fontface"
483
- * @param {string} res.src - path and/or file name of the resource (for audio assets only the path is required)
484
- * @param {boolean} [res.stream] - Set to true to force HTML5 Audio, which allows not to wait for large file to be downloaded before playing.
485
- * @param {Function} [onload=loader.onload] - function to be called when all resources are loaded
486
- * @param {boolean} [switchToLoadState=true] - automatically switch to the loading screen
487
- * @example
488
- * game_resources = [
489
- * // PNG tileset
490
- * {name: "tileset-platformer", type: "image", src: "data/map/tileset.png"},
491
- * // PNG packed texture
492
- * {name: "texture", type:"image", src: "data/gfx/texture.png"}
493
- * // PNG base64 encoded image
494
- * {name: "texture", type:"image", src: "data:image/png;base64,iVBORw0KAAAQAAAAEACA..."}
495
- * // TSX file
496
- * {name: "meta_tiles", type: "tsx", src: "data/map/meta_tiles.tsx"},
497
- * // TMX level (XML & JSON)
498
- * {name: "map1", type: "tmx", src: "data/map/map1.json"},
499
- * {name: "map2", type: "tmx", src: "data/map/map2.tmx"},
500
- * {name: "map3", type: "tmx", format: "json", data: {"height":15,"layers":[...],"tilewidth":32,"version":1,"width":20}},
501
- * {name: "map4", type: "tmx", format: "xml", data: {xml representation of tmx}},
502
- * // audio resources
503
- * {name: "bgmusic", type: "audio", src: "data/audio/"},
504
- * {name: "cling", type: "audio", src: "data/audio/"},
505
- * // base64 encoded audio resources
506
- * {name: "band", type: "audio", src: "data:audio/wav;base64,..."},
507
- * // binary file
508
- * {name: "ymTrack", type: "binary", src: "data/audio/main.ym"},
509
- * // JSON file (used for texturePacker)
510
- * {name: "texture", type: "json", src: "data/gfx/texture.json"},
511
- * // JavaScript file
512
- * {name: "plugin", type: "js", src: "data/js/plugin.js"},
513
- * // Font Face
514
- * { name: "'kenpixel'", type: "fontface", src: "url('data/font/kenvector_future.woff2')" }
515
- * ];
516
- * ...
517
- * // set all resources to be loaded
518
- * me.loader.preload(game.resources, this.loaded.bind(this));
519
- */
520
- preload(res, onload, switchToLoadState = true) {
521
- // parse the resources
522
- for (var i = 0; i < res.length; i++) {
523
- resourceCount += this.load(
524
- res[i],
525
- this.onResourceLoaded.bind(this, res[i]),
526
- this.onLoadingError.bind(this, res[i])
527
- );
528
- }
529
- // set the onload callback if defined
530
- if (typeof(onload) !== "undefined") {
531
- 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
+ });
532
312
  }
313
+ }
533
314
 
534
- if (switchToLoadState === true) {
535
- // swith to the loading screen
536
- 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
+ });
537
322
  }
323
+ }
538
324
 
539
- // check load status
540
- checkLoadStatus(onload);
541
- },
542
-
543
- /**
544
- * Load a single resource (to be used if you need to load additional resource during the game)
545
- * @name load
546
- * @memberof loader
547
- * @public
548
- * @param {object} res
549
- * @param {string} res.name - internal name of the resource
550
- * @param {string} res.type - "audio", binary", "image", "json", "tmx", "tsx"
551
- * @param {string} res.src - path and/or file name of the resource (for audio assets only the path is required)
552
- * @param {boolean} [res.stream] - Set to true to force HTML5 Audio, which allows not to wait for large file to be downloaded before playing.
553
- * @param {Function} [onload] - function to be called when the resource is loaded
554
- * @param {Function} [onerror] - function to be called in case of error
555
- * @returns {number} the amount of corresponding resource to be preloaded
556
- * @example
557
- * // load an image asset
558
- * me.loader.load({name: "avatar", type:"image", src: "data/avatar.png"}, this.onload.bind(this), this.onerror.bind(this));
559
- * // load a base64 image asset
560
- * me.loader.load({name: "avatar", type:"image", src: "data:image/png;base64,iVBORw0KAAAQAAAAEACA..."};
561
- * // start loading music
562
- * me.loader.load({
563
- * name : "bgmusic",
564
- * type : "audio",
565
- * src : "data/audio/"
566
- * }, function () {
567
- * me.audio.play("bgmusic");
568
- * });
569
- */
570
- load(res, onload, onerror) {
571
- // transform the url if necessary
572
- if (typeof (baseURL[res.type]) !== "undefined") {
573
- res.src = baseURL[res.type] + res.src;
574
- }
575
- // check ressource type
576
- switch (res.type) {
577
- case "binary":
578
- // reuse the preloadImage fn
579
- preloadBinary.call(this, res, onload, onerror);
580
- return 1;
581
-
582
- case "image":
583
- // reuse the preloadImage fn
584
- preloadImage.call(this, res, onload, onerror);
585
- return 1;
586
-
587
- case "json":
588
- preloadJSON.call(this, res, onload, onerror);
589
- return 1;
590
-
591
- case "js":
592
- preloadJavascript.call(this, res, onload, onerror);
593
- return 1;
594
-
595
- case "tmx":
596
- case "tsx":
597
- preloadTMX.call(this, res, onload, onerror);
598
- return 1;
599
-
600
- case "audio":
601
- load(res, !!res.stream, onload, onerror);
602
- return 1;
603
-
604
- case "fontface":
605
- preloadFontFace.call(this, res, onload, onerror);
606
- return 1;
607
-
608
- default:
609
- throw new Error("load : unknown or invalid resource type : " + res.type);
610
- }
611
- },
612
-
613
- /**
614
- * unload specified resource to free memory
615
- * @name unload
616
- * @memberof loader
617
- * @public
618
- * @param {object} res
619
- * @param {string} res.name - internal name of the resource
620
- * @param {string} res.type - "audio", binary", "image", "json", "tmx", "tsx"
621
- * @returns {boolean} true if unloaded
622
- * @example me.loader.unload({name: "avatar", type:"image"});
623
- */
624
- unload(res) {
625
- switch (res.type) {
626
- case "binary":
627
- if (!(res.name in binList)) {
628
- return false;
629
- }
630
-
631
- delete binList[res.name];
632
- return true;
633
-
634
- case "image":
635
- if (!(res.name in imgList)) {
636
- return false;
637
- }
638
- delete imgList[res.name];
639
- return true;
640
-
641
- case "json":
642
- if (!(res.name in jsonList)) {
643
- return false;
644
- }
645
-
646
- delete jsonList[res.name];
647
- return true;
648
-
649
- case "js":
650
- // ??
651
- return true;
652
-
653
- case "fontface":
654
- // ??
655
- return true;
656
-
657
- case "tmx":
658
- case "tsx":
659
- if (!(res.name in tmxList)) {
660
- return false;
661
- }
662
-
663
- delete tmxList[res.name];
664
- return true;
665
-
666
- case "audio":
667
- return unload(res.name);
668
-
669
- default:
670
- throw new Error("unload : unknown or invalid resource type : " + res.type);
671
- }
672
- },
673
-
674
- /**
675
- * unload all resources to free memory
676
- * @name unloadAll
677
- * @memberof loader
678
- * @public
679
- * @example me.loader.unloadAll();
680
- */
681
- unloadAll() {
682
- var name;
683
-
684
- // unload all binary resources
685
- for (name in binList) {
686
- if (binList.hasOwnProperty(name)) {
687
- this.unload({
688
- "name" : name,
689
- "type" : "binary"
690
- });
691
- }
325
+ // unload all tmx resources
326
+ for (name in tmxList) {
327
+ if (tmxList.hasOwnProperty(name)) {
328
+ unload({
329
+ "name" : name,
330
+ "type" : "tmx"
331
+ });
692
332
  }
333
+ }
693
334
 
694
- // unload all image resources
695
- for (name in imgList) {
696
- if (imgList.hasOwnProperty(name)) {
697
- this.unload({
698
- "name" : name,
699
- "type" : "image"
700
- });
701
- }
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
+ });
702
342
  }
343
+ }
703
344
 
704
- // unload all tmx resources
705
- for (name in tmxList) {
706
- if (tmxList.hasOwnProperty(name)) {
707
- this.unload({
708
- "name" : name,
709
- "type" : "tmx"
710
- });
711
- }
712
- }
345
+ // unload all audio resources
346
+ unloadAll$1();
347
+ }
713
348
 
714
- // unload all in json resources
715
- for (name in jsonList) {
716
- if (jsonList.hasOwnProperty(name)) {
717
- this.unload({
718
- "name" : name,
719
- "type" : "json"
720
- });
721
- }
722
- }
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
+ }
723
365
 
724
- // unload all audio resources
725
- unloadAll();
726
- },
727
-
728
- /**
729
- * return the specified TMX/TSX object
730
- * @name getTMX
731
- * @memberof loader
732
- * @public
733
- * @param {string} elt - name of the tmx/tsx element ("map1");
734
- * @returns {object} requested element or null if not found
735
- */
736
- getTMX(elt) {
737
- // force as string
738
- elt = "" + elt;
739
- if (elt in tmxList) {
740
- return tmxList[elt];
741
- }
742
- return null;
743
- },
744
-
745
- /**
746
- * return the specified Binary object
747
- * @name getBinary
748
- * @memberof loader
749
- * @public
750
- * @param {string} elt - name of the binary object ("ymTrack");
751
- * @returns {object} requested element or null if not found
752
- */
753
- getBinary(elt) {
754
- // force as string
755
- elt = "" + elt;
756
- if (elt in binList) {
757
- return binList[elt];
758
- }
759
- return null;
760
- },
761
-
762
- /**
763
- * return the specified Image Object
764
- * @name getImage
765
- * @memberof loader
766
- * @public
767
- * @param {string} image - name of the Image element ("tileset-platformer");
768
- * @returns {HTMLImageElement} requested element or null if not found
769
- */
770
- getImage(image) {
771
- // force as string and extract the base name
772
- image = getBasename("" + image);
773
- if (image in imgList) {
774
- // return the corresponding Image object
775
- return imgList[image];
776
- }
777
- return null;
778
- },
779
-
780
- /**
781
- * return the specified JSON Object
782
- * @name getJSON
783
- * @memberof loader
784
- * @public
785
- * @param {string} elt - name of the json file to load
786
- * @returns {object}
787
- */
788
- getJSON(elt) {
789
- // force as string
790
- elt = "" + elt;
791
- if (elt in jsonList) {
792
- return jsonList[elt];
793
- }
794
- 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];
795
379
  }
380
+ return null;
381
+ }
796
382
 
797
- };
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
+ }
798
400
 
799
- 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
+ }
800
417
 
801
- export { loader$1 as default };
418
+ export { baseURL, getBinary, getImage, getJSON, getTMX, load, onProgress, onload, preload, unload, unloadAll };