melonjs 14.4.0 → 14.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/README.md +11 -55
  2. package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +1 -1
  3. package/dist/melonjs.mjs/_virtual/arraymultimap.js +1 -1
  4. package/dist/melonjs.mjs/_virtual/earcut.js +1 -1
  5. package/dist/melonjs.mjs/_virtual/howler.js +1 -1
  6. package/dist/melonjs.mjs/_virtual/index.js +1 -1
  7. package/dist/melonjs.mjs/_virtual/index2.js +1 -1
  8. package/dist/melonjs.mjs/_virtual/multimap.js +1 -1
  9. package/dist/melonjs.mjs/_virtual/setmultimap.js +1 -1
  10. package/dist/melonjs.mjs/application/application.js +1 -1
  11. package/dist/melonjs.mjs/application/header.js +1 -1
  12. package/dist/melonjs.mjs/application/resize.js +1 -1
  13. package/dist/melonjs.mjs/application/settings.js +1 -1
  14. package/dist/melonjs.mjs/audio/audio.js +4 -4
  15. package/dist/melonjs.mjs/camera/camera2d.js +1 -1
  16. package/dist/melonjs.mjs/const.js +1 -1
  17. package/dist/melonjs.mjs/entity/entity.js +43 -9
  18. package/dist/melonjs.mjs/geometries/ellipse.js +2 -3
  19. package/dist/melonjs.mjs/geometries/line.js +1 -1
  20. package/dist/melonjs.mjs/geometries/path2d.js +18 -42
  21. package/dist/melonjs.mjs/geometries/point.js +1 -6
  22. package/dist/melonjs.mjs/geometries/poly.js +2 -5
  23. package/dist/melonjs.mjs/geometries/rectangle.js +13 -9
  24. package/dist/melonjs.mjs/geometries/roundrect.js +1 -1
  25. package/dist/melonjs.mjs/index.js +8 -6
  26. package/dist/melonjs.mjs/input/gamepad.js +10 -16
  27. package/dist/melonjs.mjs/input/input.js +1 -1
  28. package/dist/melonjs.mjs/input/keyboard.js +1 -1
  29. package/dist/melonjs.mjs/input/pointer.js +1 -1
  30. package/dist/melonjs.mjs/input/pointerevent.js +2 -16
  31. package/dist/melonjs.mjs/lang/console.js +1 -1
  32. package/dist/melonjs.mjs/lang/deprecated.js +1 -1
  33. package/dist/melonjs.mjs/level/level.js +3 -3
  34. package/dist/melonjs.mjs/level/tiled/TMXGroup.js +1 -1
  35. package/dist/melonjs.mjs/level/tiled/TMXLayer.js +1 -8
  36. package/dist/melonjs.mjs/level/tiled/TMXObject.js +1 -1
  37. package/dist/melonjs.mjs/level/tiled/TMXTile.js +1 -1
  38. package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +8 -4
  39. package/dist/melonjs.mjs/level/tiled/TMXTileset.js +5 -5
  40. package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +1 -1
  41. package/dist/melonjs.mjs/level/tiled/TMXUtils.js +1 -1
  42. package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
  43. package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
  44. package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
  45. package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
  46. package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +1 -1
  47. package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
  48. package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
  49. package/dist/melonjs.mjs/loader/cache.js +24 -0
  50. package/dist/melonjs.mjs/loader/loader.js +331 -716
  51. package/dist/melonjs.mjs/loader/loadingscreen.js +4 -4
  52. package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
  53. package/dist/melonjs.mjs/loader/parser.js +281 -0
  54. package/dist/melonjs.mjs/loader/settings.js +91 -0
  55. package/dist/melonjs.mjs/math/color.js +1 -1
  56. package/dist/melonjs.mjs/math/math.js +1 -1
  57. package/dist/melonjs.mjs/math/matrix2.js +7 -9
  58. package/dist/melonjs.mjs/math/matrix3.js +18 -21
  59. package/dist/melonjs.mjs/math/observable_vector2.js +3 -3
  60. package/dist/melonjs.mjs/math/observable_vector3.js +3 -4
  61. package/dist/melonjs.mjs/math/vector2.js +3 -3
  62. package/dist/melonjs.mjs/math/vector3.js +3 -4
  63. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +1 -1
  64. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +1 -1
  65. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +1 -1
  66. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +1 -1
  67. package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
  68. package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +1 -1
  69. package/dist/melonjs.mjs/node_modules/eventemitter3/index2.js +1 -1
  70. package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +1 -1
  71. package/dist/melonjs.mjs/particles/emitter.js +3 -3
  72. package/dist/melonjs.mjs/particles/particle.js +1 -1
  73. package/dist/melonjs.mjs/particles/settings.js +1 -1
  74. package/dist/melonjs.mjs/physics/body.js +18 -14
  75. package/dist/melonjs.mjs/physics/bounds.js +18 -70
  76. package/dist/melonjs.mjs/physics/collision.js +1 -1
  77. package/dist/melonjs.mjs/physics/detector.js +1 -1
  78. package/dist/melonjs.mjs/physics/quadtree.js +1 -1
  79. package/dist/melonjs.mjs/physics/response.js +1 -1
  80. package/dist/melonjs.mjs/physics/sat.js +1 -1
  81. package/dist/melonjs.mjs/physics/world.js +1 -1
  82. package/dist/melonjs.mjs/plugin/plugin.js +3 -3
  83. package/dist/melonjs.mjs/renderable/collectable.js +1 -1
  84. package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
  85. package/dist/melonjs.mjs/renderable/container.js +25 -19
  86. package/dist/melonjs.mjs/renderable/dragndrop.js +1 -1
  87. package/dist/melonjs.mjs/renderable/imagelayer.js +7 -1
  88. package/dist/melonjs.mjs/renderable/light2d.js +1 -1
  89. package/dist/melonjs.mjs/renderable/nineslicesprite.js +1 -1
  90. package/dist/melonjs.mjs/renderable/renderable.js +126 -105
  91. package/dist/melonjs.mjs/renderable/sprite.js +33 -54
  92. package/dist/melonjs.mjs/renderable/trigger.js +1 -1
  93. package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +1 -1
  94. package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +1 -1
  95. package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +1 -1
  96. package/dist/melonjs.mjs/state/stage.js +1 -1
  97. package/dist/melonjs.mjs/state/state.js +2 -2
  98. package/dist/melonjs.mjs/system/device.js +1 -1
  99. package/dist/melonjs.mjs/system/dom.js +1 -1
  100. package/dist/melonjs.mjs/system/event.js +1 -1
  101. package/dist/melonjs.mjs/system/platform.js +1 -1
  102. package/dist/melonjs.mjs/system/pooling.js +8 -18
  103. package/dist/melonjs.mjs/system/save.js +1 -1
  104. package/dist/melonjs.mjs/system/timer.js +1 -1
  105. package/dist/melonjs.mjs/text/bitmaptext.js +66 -8
  106. package/dist/melonjs.mjs/text/bitmaptextdata.js +1 -1
  107. package/dist/melonjs.mjs/text/glyph.js +1 -1
  108. package/dist/melonjs.mjs/text/text.js +1 -1
  109. package/dist/melonjs.mjs/text/textmetrics.js +1 -1
  110. package/dist/melonjs.mjs/text/textstyle.js +1 -1
  111. package/dist/melonjs.mjs/tweens/easing.js +1 -1
  112. package/dist/melonjs.mjs/tweens/interpolation.js +1 -1
  113. package/dist/melonjs.mjs/tweens/tween.js +1 -1
  114. package/dist/melonjs.mjs/utils/agent.js +1 -1
  115. package/dist/melonjs.mjs/utils/array.js +1 -1
  116. package/dist/melonjs.mjs/utils/file.js +1 -1
  117. package/dist/melonjs.mjs/utils/function.js +1 -1
  118. package/dist/melonjs.mjs/utils/string.js +2 -2
  119. package/dist/melonjs.mjs/utils/utils.js +2 -4
  120. package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +1 -1
  121. package/dist/melonjs.mjs/video/renderer.js +1 -1
  122. package/dist/melonjs.mjs/video/texture/atlas.js +10 -9
  123. package/dist/melonjs.mjs/video/texture/cache.js +3 -3
  124. package/dist/melonjs.mjs/video/texture/canvas_texture.js +1 -1
  125. package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
  126. package/dist/melonjs.mjs/video/video.js +2 -2
  127. package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +1 -1
  128. package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +235 -0
  129. package/{src/video/webgl → dist/melonjs.mjs/video/webgl/compositors}/webgl_compositor.js +28 -205
  130. package/dist/melonjs.mjs/video/webgl/glshader.js +1 -1
  131. package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
  132. package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +1 -1
  133. package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
  134. package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +1 -1
  135. package/dist/melonjs.mjs/video/webgl/utils/attributes.js +1 -1
  136. package/dist/melonjs.mjs/video/webgl/utils/precision.js +1 -1
  137. package/dist/melonjs.mjs/video/webgl/utils/program.js +1 -1
  138. package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
  139. package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +1 -1
  140. package/dist/melonjs.mjs/video/webgl/webgl_compositor.js +2 -2
  141. package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +2 -2
  142. package/dist/melonjs.module.js +17844 -17809
  143. package/dist/types/entity/entity.d.ts +2 -2
  144. package/dist/types/geometries/path2d.d.ts +5 -31
  145. package/dist/types/geometries/point.d.ts +2 -7
  146. package/dist/types/geometries/poly.d.ts +0 -1
  147. package/dist/types/index.d.ts +2 -2
  148. package/dist/types/loader/cache.d.ts +7 -0
  149. package/dist/types/loader/loader.d.ts +166 -181
  150. package/dist/types/loader/parser.d.ts +41 -0
  151. package/dist/types/loader/settings.d.ts +57 -0
  152. package/dist/types/particles/emitter.d.ts +4 -4
  153. package/dist/types/physics/bounds.d.ts +29 -84
  154. package/dist/types/renderable/container.d.ts +0 -11
  155. package/dist/types/renderable/renderable.d.ts +37 -31
  156. package/dist/types/renderable/sprite.d.ts +3 -3
  157. package/dist/types/state/state.d.ts +1 -1
  158. package/dist/types/system/pooling.d.ts +2 -2
  159. package/dist/types/video/renderer.d.ts +1 -1
  160. package/dist/types/video/webgl/compositors/compositor.d.ts +101 -0
  161. package/dist/types/video/webgl/compositors/webgl_compositor.d.ts +86 -0
  162. package/dist/types/video/webgl/webgl_compositor.d.ts +2 -3
  163. package/dist/types/video/webgl/webgl_renderer.d.ts +1 -1
  164. package/package.json +16 -15
  165. package/src/audio/audio.js +3 -3
  166. package/src/entity/entity.js +42 -8
  167. package/src/geometries/ellipse.js +1 -2
  168. package/src/geometries/path2d.js +17 -41
  169. package/src/geometries/point.js +0 -5
  170. package/src/geometries/poly.js +1 -4
  171. package/src/geometries/rectangle.js +12 -8
  172. package/src/index.js +2 -2
  173. package/src/input/gamepad.js +9 -15
  174. package/src/input/pointerevent.js +1 -15
  175. package/src/level/level.js +2 -2
  176. package/src/level/tiled/TMXLayer.js +0 -7
  177. package/src/level/tiled/TMXTileMap.js +7 -3
  178. package/src/level/tiled/TMXTileset.js +4 -4
  179. package/src/loader/cache.js +16 -0
  180. package/src/loader/loader.js +339 -711
  181. package/src/loader/loadingscreen.js +3 -3
  182. package/src/loader/parser.js +279 -0
  183. package/src/loader/settings.js +85 -0
  184. package/src/math/matrix2.js +6 -8
  185. package/src/math/matrix3.js +17 -20
  186. package/src/math/observable_vector2.js +2 -2
  187. package/src/math/observable_vector3.js +2 -3
  188. package/src/math/vector2.js +2 -2
  189. package/src/math/vector3.js +2 -3
  190. package/src/particles/emitter.js +2 -2
  191. package/src/physics/body.js +17 -13
  192. package/src/physics/bounds.js +17 -69
  193. package/src/renderable/container.js +24 -18
  194. package/src/renderable/imagelayer.js +6 -0
  195. package/src/renderable/renderable.js +125 -104
  196. package/src/renderable/sprite.js +32 -53
  197. package/src/state/state.js +1 -1
  198. package/src/system/pooling.js +7 -17
  199. package/src/text/bitmaptext.js +65 -7
  200. package/src/utils/string.js +1 -1
  201. package/src/utils/utils.js +1 -3
  202. package/src/video/texture/atlas.js +9 -8
  203. package/src/video/texture/cache.js +2 -2
  204. package/src/video/video.js +1 -1
  205. package/src/video/webgl/compositors/compositor.js +227 -0
  206. package/src/video/webgl/compositors/webgl_compositor.js +300 -0
  207. package/src/video/webgl/webgl_renderer.js +1 -1
@@ -4,7 +4,7 @@ import * as event from "./../system/event.js";
4
4
  import Sprite from "./../renderable/sprite.js";
5
5
  import Renderable from "./../renderable/renderable.js";
6
6
  import Stage from "./../state/stage.js";
7
- import loader from "./loader.js";
7
+ import { load, unload } from "./loader.js";
8
8
  import logo_url from "./melonjs_logo.png";
9
9
 
10
10
 
@@ -86,7 +86,7 @@ class DefaultLoadingScreen extends Stage {
86
86
  ), 1);
87
87
 
88
88
  // load the melonJS logo
89
- loader.load({name: "melonjs_logo", type: "image", src: logo_url}, () => {
89
+ load({name: "melonjs_logo", type: "image", src: logo_url}, () => {
90
90
  // melonJS logo
91
91
  game.world.addChild(new Sprite(
92
92
  renderer.getWidth() / 2,
@@ -105,7 +105,7 @@ class DefaultLoadingScreen extends Stage {
105
105
  */
106
106
  onDestroyEvent() {
107
107
  // cancel the callback
108
- loader.unload({name: "melonjs_logo", type:"image"});
108
+ unload({name: "melonjs_logo", type:"image"});
109
109
  }
110
110
  }
111
111
 
@@ -0,0 +1,279 @@
1
+ import * as fileUtil from "../utils/file.js";
2
+ import { ua } from "../system/platform.js";
3
+ import level from "../level/level.js";
4
+ import * as TMXUtils from "../level/tiled/TMXUtils.js";
5
+ import { isDataUrl } from "../utils/string.js";
6
+ import { imgList, tmxList, binList, jsonList } from "./cache.js";
7
+ import { crossOrigin, nocache, withCredentials } from "./settings.js";
8
+
9
+
10
+ /**
11
+ * load Images
12
+ * @example
13
+ * preloadImages([
14
+ * { name : 'image1', src : 'images/image1.png'},
15
+ * { name : 'image2', src : 'images/image2.png'},
16
+ * { name : 'image3', src : 'images/image3.png'},
17
+ * { name : 'image4', src : 'images/image4.png'}
18
+ * ]);
19
+ * @ignore
20
+ */
21
+ export function preloadImage(img, onload, onerror) {
22
+ // create new Image object and add to list
23
+ imgList[img.name] = new Image();
24
+ if (typeof onload === "function") {
25
+ imgList[img.name].onload = onload;
26
+ }
27
+ if (typeof onerror === "function") {
28
+ imgList[img.name].onerror = onerror;
29
+ }
30
+ if (typeof (crossOrigin) === "string") {
31
+ imgList[img.name].crossOrigin = crossOrigin;
32
+ }
33
+ imgList[img.name].src = img.src + nocache;
34
+ }
35
+
36
+ /**
37
+ * load a font face
38
+ * @example
39
+ * preloadFontFace(
40
+ * name: "'kenpixel'", type: "fontface", src: "url('data/font/kenvector_future.woff2')"
41
+ * ]);
42
+ * @ignore
43
+ */
44
+ export function preloadFontFace(data, onload, onerror) {
45
+
46
+ if (isDataUrl(data.src) === true) {
47
+ // make sure it in the `url(data:[<mediatype>][;base64],<data>)` format as expected by FontFace
48
+ if (!data.src.startsWith("url(")) {
49
+ data.src = "url(" + data.src + ")";
50
+ }
51
+ }
52
+
53
+ var font = new FontFace(data.name, data.src);
54
+
55
+ // loading promise
56
+ font.load().then(() => {
57
+ // apply the font after the font has finished downloading
58
+ document.fonts.add(font);
59
+ document.body.style.fontFamily = data.name;
60
+ if (typeof onload === "function") {
61
+ // onloaded callback
62
+ onload();
63
+ }
64
+ }, () => {
65
+ if (typeof onerror === "function") {
66
+ // rejected
67
+ onerror(data.name);
68
+ }
69
+ });
70
+ }
71
+
72
+ /**
73
+ * preload TMX files
74
+ * @ignore
75
+ */
76
+ export function preloadTMX(tmxData, onload, onerror) {
77
+ /**
78
+ * @ignore
79
+ */
80
+ function addToTMXList(data) {
81
+ // set the TMX content
82
+ tmxList[tmxData.name] = data;
83
+
84
+ // add the tmx to the level manager
85
+ if (tmxData.type === "tmx") {
86
+ level.add(tmxData.type, tmxData.name);
87
+ }
88
+ }
89
+
90
+
91
+ //if the data is in the tmxData object, don't get it via a XMLHTTPRequest
92
+ if (tmxData.data) {
93
+ addToTMXList(tmxData.data);
94
+ if (typeof onload === "function") {
95
+ onload();
96
+ }
97
+ return;
98
+ }
99
+
100
+ var xmlhttp = new XMLHttpRequest();
101
+ // check the data format ('tmx', 'json')
102
+ var format = fileUtil.getExtension(tmxData.src);
103
+
104
+ if (xmlhttp.overrideMimeType) {
105
+ if (format === "json") {
106
+ xmlhttp.overrideMimeType("application/json");
107
+ }
108
+ else {
109
+ xmlhttp.overrideMimeType("text/xml");
110
+ }
111
+ }
112
+
113
+ xmlhttp.open("GET", tmxData.src + nocache, true);
114
+ xmlhttp.withCredentials = withCredentials;
115
+ // set the callbacks
116
+ xmlhttp.ontimeout = onerror;
117
+ xmlhttp.onreadystatechange = function () {
118
+ if (xmlhttp.readyState === 4) {
119
+ // status = 0 when file protocol is used, or cross-domain origin,
120
+ // (With Chrome use "--allow-file-access-from-files --disable-web-security")
121
+ if ((xmlhttp.status === 200) || ((xmlhttp.status === 0) && xmlhttp.responseText)) {
122
+ var result = null;
123
+
124
+ // parse response
125
+ switch (format) {
126
+ case "xml":
127
+ case "tmx":
128
+ case "tsx":
129
+ // ie9 does not fully implement the responseXML
130
+ if (ua.match(/msie/i) || !xmlhttp.responseXML) {
131
+ if (globalThis.DOMParser) {
132
+ // manually create the XML DOM
133
+ result = (new DOMParser()).parseFromString(xmlhttp.responseText, "text/xml");
134
+ } else {
135
+ throw new Error("XML file format loading not supported, use the JSON file format instead");
136
+ }
137
+ }
138
+ else {
139
+ result = xmlhttp.responseXML;
140
+ }
141
+ // converts to a JS object
142
+ var data = TMXUtils.parse(result);
143
+ switch (format) {
144
+ case "tmx":
145
+ result = data.map;
146
+ break;
147
+
148
+ case "tsx":
149
+ result = data.tilesets[0];
150
+ break;
151
+ }
152
+
153
+ break;
154
+
155
+ case "json":
156
+ case "tmj":
157
+ case "tsj":
158
+ result = JSON.parse(xmlhttp.responseText);
159
+ break;
160
+
161
+ default:
162
+ throw new Error("TMX file format " + format + " not supported !");
163
+ }
164
+
165
+ //set the TMX content
166
+ addToTMXList(result);
167
+
168
+ // fire the callback
169
+ if (typeof onload === "function") {
170
+ onload();
171
+ }
172
+ }
173
+ else if (typeof onerror === "function") {
174
+ onerror(tmxData.name);
175
+ }
176
+ }
177
+ };
178
+ // send the request
179
+ xmlhttp.send();
180
+ }
181
+
182
+ /**
183
+ * preload JSON files
184
+ * @ignore
185
+ */
186
+ export function preloadJSON(data, onload, onerror) {
187
+ var xmlhttp = new XMLHttpRequest();
188
+
189
+ if (xmlhttp.overrideMimeType) {
190
+ xmlhttp.overrideMimeType("application/json");
191
+ }
192
+
193
+ xmlhttp.open("GET", data.src + nocache, true);
194
+ xmlhttp.withCredentials = withCredentials;
195
+
196
+ // set the callbacks
197
+ xmlhttp.ontimeout = onerror;
198
+ xmlhttp.onreadystatechange = function () {
199
+ if (xmlhttp.readyState === 4) {
200
+ // status = 0 when file protocol is used, or cross-domain origin,
201
+ // (With Chrome use "--allow-file-access-from-files --disable-web-security")
202
+ if ((xmlhttp.status === 200) || ((xmlhttp.status === 0) && xmlhttp.responseText)) {
203
+ // get the Texture Packer Atlas content
204
+ jsonList[data.name] = JSON.parse(xmlhttp.responseText);
205
+ if (typeof onload === "function") {
206
+ // fire the callback
207
+ onload();
208
+ }
209
+ }
210
+ else if (typeof onerror === "function") {
211
+ onerror(data.name);
212
+ }
213
+ }
214
+ };
215
+ // send the request
216
+ xmlhttp.send();
217
+ }
218
+
219
+ /**
220
+ * preload Binary files
221
+ * @ignore
222
+ */
223
+ export function preloadBinary(data, onload, onerror) {
224
+ var httpReq = new XMLHttpRequest();
225
+
226
+ // load our file
227
+ httpReq.open("GET", data.src + nocache, true);
228
+ httpReq.withCredentials = withCredentials;
229
+ httpReq.responseType = "arraybuffer";
230
+ httpReq.onerror = onerror;
231
+ httpReq.onload = function () {
232
+ var arrayBuffer = httpReq.response;
233
+ if (arrayBuffer) {
234
+ var byteArray = new Uint8Array(arrayBuffer);
235
+ var buffer = [];
236
+ for (var i = 0; i < byteArray.byteLength; i++) {
237
+ buffer[i] = String.fromCharCode(byteArray[i]);
238
+ }
239
+ binList[data.name] = buffer.join("");
240
+ if (typeof onload === "function") {
241
+ // callback
242
+ onload();
243
+ }
244
+
245
+ }
246
+ };
247
+ httpReq.send();
248
+ }
249
+
250
+ /**
251
+ * preload Binary files
252
+ * @ignore
253
+ */
254
+ export function preloadJavascript(data, onload, onerror) {
255
+ var script = document.createElement("script");
256
+
257
+ script.src = data.src;
258
+ script.type = "text/javascript";
259
+ if (typeof (crossOrigin) === "string") {
260
+ script.crossOrigin = crossOrigin;
261
+ }
262
+ script.defer = true;
263
+
264
+ if (typeof onload === "function") {
265
+ script.onload = () => {
266
+ // callback
267
+ onload();
268
+ };
269
+ }
270
+
271
+ if (typeof onerror === "function") {
272
+ script.onerror = () => {
273
+ // callback
274
+ onerror(data.name);
275
+ };
276
+ }
277
+
278
+ document.getElementsByTagName("body")[0].appendChild(script);
279
+ }
@@ -0,0 +1,85 @@
1
+
2
+ // to enable/disable caching
3
+ export let nocache = "";
4
+
5
+ // baseURL
6
+ export let baseURL = {};
7
+
8
+
9
+ /**
10
+ * crossOrigin attribute to configure the CORS requests for Image data element.
11
+ * By default (that is, when the attribute is not specified), CORS is not used at all.
12
+ * The "anonymous" keyword means that there will be no exchange of user credentials via cookies,
13
+ * client-side SSL certificates or HTTP authentication as described in the Terminology section of the CORS specification.<br>
14
+ * @type {string}
15
+ * @name crossOrigin
16
+ * @default undefined
17
+ * @memberof loader
18
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes
19
+ * @example
20
+ * // allow for cross-origin texture loading in WebGL
21
+ * me.loader.crossOrigin = "anonymous";
22
+ *
23
+ * // set all ressources to be loaded
24
+ * me.loader.preload(game.resources, this.loaded.bind(this));
25
+ */
26
+ export let crossOrigin;
27
+
28
+ /**
29
+ * indicates whether or not cross-site Access-Control requests should be made using credentials such as cookies,
30
+ * authorization headers or TLS client certificates. Setting withCredentials has no effect on same-site requests.
31
+ * @public
32
+ * @type {boolean}
33
+ * @name withCredentials
34
+ * @default false
35
+ * @memberof loader
36
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials
37
+ * @example
38
+ * // enable withCredentials
39
+ * me.loader.withCredentials = true;
40
+ *
41
+ * // set all ressources to be loaded
42
+ * me.loader.preload(game.resources, this.loaded.bind(this));
43
+ */
44
+ export let withCredentials = false;
45
+
46
+ /**
47
+ * enable the nocache mechanism
48
+ * @ignore
49
+ */
50
+ export function setNocache(enable = false) {
51
+ nocache = enable ? "?" + ~~(Math.random() * 10000000) : "";
52
+ }
53
+
54
+ /**
55
+ * change the default baseURL for the given asset type.<br>
56
+ * (this will prepend the asset URL and must finish with a '/')
57
+ * @name setBaseURL
58
+ * @memberof loader
59
+ * @public
60
+ * @param {string} type - "*", "audio", binary", "image", "json", "js", "tmx", "tsx"
61
+ * @param {string} [url="./"] - default base URL
62
+ * @example
63
+ * // change the base URL relative address for audio assets
64
+ * me.loader.setBaseURL("audio", "data/audio/");
65
+ * // change the base URL absolute address for all object types
66
+ * me.loader.setBaseURL("*", "http://myurl.com/")
67
+ */
68
+ export function setBaseURL(type, url) {
69
+ if (type !== "*") {
70
+ baseURL[type] = url;
71
+ } else {
72
+ // "wildcards"
73
+ baseURL["audio"] = url;
74
+ baseURL["binary"] = url;
75
+ baseURL["image"] = url;
76
+ baseURL["json"] = url;
77
+ baseURL["js"] = url;
78
+ baseURL["tmx"] = url;
79
+ baseURL["tsx"] = url;
80
+ // XXX ?
81
+ //baseURL["fontface"] = url;
82
+ }
83
+ }
84
+
85
+
@@ -296,15 +296,13 @@ import Matrix3d from "./matrix3.js";
296
296
  * @param {number} [y=x] - a number representing the ordinate of the scaling vector.
297
297
  * @returns {Matrix2d} Reference to this object for method chaining
298
298
  */
299
- scale(x, y) {
300
- var a = this.val,
301
- _x = x,
302
- _y = typeof(y) === "undefined" ? _x : y;
299
+ scale(x, y = x) {
300
+ var a = this.val;
303
301
 
304
- a[0] *= _x;
305
- a[1] *= _x;
306
- a[3] *= _y;
307
- a[4] *= _y;
302
+ a[0] *= x;
303
+ a[1] *= x;
304
+ a[3] *= y;
305
+ a[4] *= y;
308
306
 
309
307
  return this;
310
308
  }
@@ -394,26 +394,23 @@ import { EPSILON } from "./math.js";
394
394
  * @param {number} [z=0] - a number representing the depth vector
395
395
  * @returns {Matrix3d} Reference to this object for method chaining
396
396
  */
397
- scale(x, y, z) {
398
- var a = this.val,
399
- _x = x,
400
- _y = typeof(y) === "undefined" ? _x : y,
401
- _z = typeof(z) === "undefined" ? 0 : z;
402
-
403
- a[0] = a[0] * _x;
404
- a[1] = a[1] * _x;
405
- a[2] = a[2] * _x;
406
- a[3] = a[3] * _x;
407
-
408
- a[4] = a[4] * _y;
409
- a[5] = a[5] * _y;
410
- a[6] = a[6] * _y;
411
- a[7] = a[7] * _y;
412
-
413
- a[8] = a[8] * _z;
414
- a[9] = a[9] * _z;
415
- a[10] = a[10] * _z;
416
- a[11] = a[11] * _z;
397
+ scale(x, y = x, z = 0) {
398
+ var a = this.val;
399
+
400
+ a[0] = a[0] * x;
401
+ a[1] = a[1] * x;
402
+ a[2] = a[2] * x;
403
+ a[3] = a[3] * x;
404
+
405
+ a[4] = a[4] * y;
406
+ a[5] = a[5] * y;
407
+ a[6] = a[6] * y;
408
+ a[7] = a[7] * y;
409
+
410
+ a[8] = a[8] * z;
411
+ a[9] = a[9] * z;
412
+ a[10] = a[10] * z;
413
+ a[11] = a[11] * z;
417
414
 
418
415
  return this;
419
416
  }
@@ -156,8 +156,8 @@ import {clamp} from "./math.js";
156
156
  * @param {number} [y=x]
157
157
  * @returns {ObservableVector2d} Reference to this object for method chaining
158
158
  */
159
- scale(x, y) {
160
- return this._set(this._x * x, this._y * (typeof (y) !== "undefined" ? y : x));
159
+ scale(x, y = x) {
160
+ return this._set(this._x * x, this._y * y);
161
161
  }
162
162
 
163
163
  /**
@@ -186,9 +186,8 @@ import pool from "./../system/pooling.js";
186
186
  * @param {number} [z=1]
187
187
  * @returns {ObservableVector3d} Reference to this object for method chaining
188
188
  */
189
- scale(x, y, z) {
190
- y = (typeof (y) !== "undefined" ? y : x);
191
- return this._set(this._x * x, this._y * y, this._z * (z || 1));
189
+ scale(x, y = x, z = 1) {
190
+ return this._set(this._x * x, this._y * y, this._z * z);
192
191
  }
193
192
 
194
193
  /**
@@ -120,8 +120,8 @@ import pool from "./../system/pooling.js";
120
120
  * @param {number} [y=x]
121
121
  * @returns {Vector2d} Reference to this object for method chaining
122
122
  */
123
- scale(x, y) {
124
- return this._set(this.x * x, this.y * (typeof (y) !== "undefined" ? y : x));
123
+ scale(x, y = x) {
124
+ return this._set(this.x * x, this.y * y);
125
125
  }
126
126
 
127
127
  /**
@@ -134,9 +134,8 @@ import pool from "./../system/pooling.js";
134
134
  * @param {number} [z=1]
135
135
  * @returns {Vector3d} Reference to this object for method chaining
136
136
  */
137
- scale(x, y, z) {
138
- y = (typeof (y) !== "undefined" ? y : x);
139
- return this._set(this.x * x, this.y * y, this.z * (z || 1));
137
+ scale(x, y = x, z = 1) {
138
+ return this._set(this.x * x, this.y * y, this.z * z);
140
139
  }
141
140
 
142
141
  /**
@@ -161,7 +161,7 @@ function createDefaultParticleTexture(w = 8, h = 8) {
161
161
 
162
162
  /**
163
163
  * Launch particles from emitter constantly (e.g. for stream)
164
- * @param {number} duration - [optional] time that the emitter releases particles in ms
164
+ * @param {number} [duration] - time that the emitter releases particles in ms
165
165
  */
166
166
  streamParticles(duration) {
167
167
  this._enabled = true;
@@ -179,7 +179,7 @@ function createDefaultParticleTexture(w = 8, h = 8) {
179
179
 
180
180
  /**
181
181
  * Launch all particles from emitter and stop (e.g. for explosion)
182
- * @param {number} total - [optional] number of particles to launch
182
+ * @param {number} [total] - number of particles to launch
183
183
  */
184
184
  burstParticles(total) {
185
185
  this._enabled = true;
@@ -558,20 +558,24 @@ import Point from "../geometries/point.js";
558
558
  * @returns {Body} Reference to this object for method chaining
559
559
  */
560
560
  rotate(angle, v = this.getBounds().center) {
561
- this.bounds.clear();
562
- this.forEach((shape) => {
563
- shape.rotate(angle, v);
564
- this.bounds.addBounds(shape.getBounds());
565
- if (shape instanceof Ellipse) {
566
- // use bounds position as ellipse position is center
567
- this.bounds.translate(
568
- shape.getBounds().x,
569
- shape.getBounds().y
570
- );
571
- } else {
572
- this.bounds.translate(shape.pos);
561
+ if (angle !== 0) {
562
+ this.bounds.clear();
563
+ this.forEach((shape) => {
564
+ shape.rotate(angle, v);
565
+ this.bounds.addBounds(shape.getBounds());
566
+ /*
567
+ if (!(shape instanceof Ellipse)) {
568
+ // ellipse position is center
569
+ this.bounds.translate(shape.pos);
570
+ }
571
+ */
572
+ });
573
+ /*
574
+ if (typeof this.onBodyUpdate === "function") {
575
+ this.onBodyUpdate(this);
573
576
  }
574
- });
577
+ */
578
+ }
575
579
  return this;
576
580
  }
577
581