melonjs 14.5.0 → 15.1.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.
- package/LICENSE.md +1 -1
- package/README.md +6 -6
- package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +1 -1
- package/dist/melonjs.mjs/_virtual/arraymultimap.js +1 -1
- package/dist/melonjs.mjs/_virtual/earcut.js +1 -1
- package/dist/melonjs.mjs/_virtual/howler.js +1 -1
- package/dist/melonjs.mjs/_virtual/index.js +7 -3
- package/dist/melonjs.mjs/_virtual/index2.js +1 -1
- package/dist/melonjs.mjs/_virtual/multimap.js +1 -1
- package/dist/melonjs.mjs/_virtual/setmultimap.js +1 -1
- package/dist/melonjs.mjs/application/application.js +27 -17
- package/dist/melonjs.mjs/application/header.js +6 -5
- package/dist/melonjs.mjs/application/resize.js +20 -20
- package/dist/melonjs.mjs/application/settings.js +1 -1
- package/dist/melonjs.mjs/audio/audio.js +18 -20
- package/dist/melonjs.mjs/camera/camera2d.js +10 -10
- package/dist/melonjs.mjs/const.js +1 -1
- package/dist/melonjs.mjs/entity/entity.js +4 -4
- package/dist/melonjs.mjs/geometries/ellipse.js +6 -6
- package/dist/melonjs.mjs/geometries/line.js +9 -9
- package/dist/melonjs.mjs/geometries/path2d.js +56 -56
- package/dist/melonjs.mjs/geometries/point.js +2 -2
- package/dist/melonjs.mjs/geometries/poly.js +29 -29
- package/dist/melonjs.mjs/geometries/rectangle.js +8 -8
- package/dist/melonjs.mjs/geometries/roundrect.js +6 -6
- package/dist/melonjs.mjs/index.js +8 -6
- package/dist/melonjs.mjs/input/gamepad.js +30 -30
- package/dist/melonjs.mjs/input/input.js +2 -2
- package/dist/melonjs.mjs/input/keyboard.js +15 -15
- package/dist/melonjs.mjs/input/pointer.js +2 -2
- package/dist/melonjs.mjs/input/pointerevent.js +59 -59
- package/dist/melonjs.mjs/lang/console.js +3 -3
- package/dist/melonjs.mjs/lang/deprecated.js +2 -2
- package/dist/melonjs.mjs/level/level.js +9 -9
- package/dist/melonjs.mjs/level/tiled/TMXGroup.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXLayer.js +31 -31
- package/dist/melonjs.mjs/level/tiled/TMXObject.js +8 -8
- package/dist/melonjs.mjs/level/tiled/TMXTile.js +8 -8
- package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +19 -19
- package/dist/melonjs.mjs/level/tiled/TMXTileset.js +15 -15
- package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXUtils.js +46 -41
- package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +30 -30
- package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +21 -21
- package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +10 -10
- package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +2 -2
- package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +6 -6
- package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
- package/dist/melonjs.mjs/loader/cache.js +1 -1
- package/dist/melonjs.mjs/loader/loader.js +7 -7
- package/dist/melonjs.mjs/loader/loadingscreen.js +2 -2
- package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
- package/dist/melonjs.mjs/loader/parser.js +13 -13
- package/dist/melonjs.mjs/loader/settings.js +3 -3
- package/dist/melonjs.mjs/math/color.js +25 -24
- package/dist/melonjs.mjs/math/math.js +2 -2
- package/dist/melonjs.mjs/math/matrix2.js +22 -22
- package/dist/melonjs.mjs/math/matrix3.js +52 -52
- package/dist/melonjs.mjs/math/observable_vector2.js +12 -12
- package/dist/melonjs.mjs/math/observable_vector3.js +22 -22
- package/dist/melonjs.mjs/math/vector2.js +11 -11
- package/dist/melonjs.mjs/math/vector3.js +21 -21
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/arraymultimap.js +45 -0
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/multimap.js +130 -0
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
- package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +2 -2
- package/dist/melonjs.mjs/node_modules/eventemitter3/index2.js +1 -1
- package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +1 -1
- package/dist/melonjs.mjs/particles/emitter.js +5 -5
- package/dist/melonjs.mjs/particles/particle.js +8 -8
- package/dist/melonjs.mjs/particles/settings.js +3 -3
- package/dist/melonjs.mjs/physics/body.js +17 -17
- package/dist/melonjs.mjs/physics/bounds.js +12 -12
- package/dist/melonjs.mjs/physics/collision.js +3 -3
- package/dist/melonjs.mjs/physics/detector.js +14 -14
- package/dist/melonjs.mjs/physics/quadtree.js +19 -19
- package/dist/melonjs.mjs/physics/response.js +1 -1
- package/dist/melonjs.mjs/physics/sat.js +60 -60
- package/dist/melonjs.mjs/physics/world.js +4 -4
- package/dist/melonjs.mjs/plugin/plugin.js +11 -11
- package/dist/melonjs.mjs/renderable/collectable.js +2 -2
- package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
- package/dist/melonjs.mjs/renderable/container.js +77 -59
- package/dist/melonjs.mjs/renderable/dragndrop.js +5 -5
- package/dist/melonjs.mjs/renderable/imagelayer.js +7 -6
- package/dist/melonjs.mjs/renderable/light2d.js +6 -6
- package/dist/melonjs.mjs/renderable/nineslicesprite.js +12 -12
- package/dist/melonjs.mjs/renderable/renderable.js +35 -13
- package/dist/melonjs.mjs/renderable/sprite.js +25 -25
- package/dist/melonjs.mjs/renderable/trigger.js +11 -9
- package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +97 -27
- package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +25 -25
- package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +83 -65
- package/dist/melonjs.mjs/state/stage.js +7 -7
- package/dist/melonjs.mjs/state/state.js +15 -15
- package/dist/melonjs.mjs/system/device.js +3 -3
- package/dist/melonjs.mjs/system/dom.js +1 -1
- package/dist/melonjs.mjs/system/event.js +2 -2
- package/dist/melonjs.mjs/system/platform.js +1 -1
- package/dist/melonjs.mjs/system/pooling.js +9 -9
- package/dist/melonjs.mjs/system/save.js +6 -6
- package/dist/melonjs.mjs/system/timer.js +16 -12
- package/dist/melonjs.mjs/text/bitmaptext.js +20 -20
- package/dist/melonjs.mjs/text/bitmaptextdata.js +22 -22
- package/dist/melonjs.mjs/text/glyph.js +3 -3
- package/dist/melonjs.mjs/text/text.js +63 -92
- package/dist/melonjs.mjs/text/textmetrics.js +15 -15
- package/dist/melonjs.mjs/text/textstyle.js +4 -6
- package/dist/melonjs.mjs/tweens/easing.js +4 -4
- package/dist/melonjs.mjs/tweens/interpolation.js +8 -8
- package/dist/melonjs.mjs/tweens/tween.js +11 -11
- package/dist/melonjs.mjs/utils/agent.js +6 -6
- package/dist/melonjs.mjs/utils/array.js +4 -4
- package/dist/melonjs.mjs/utils/file.js +1 -1
- package/dist/melonjs.mjs/utils/function.js +5 -5
- package/dist/melonjs.mjs/utils/string.js +3 -3
- package/dist/melonjs.mjs/utils/utils.js +16 -16
- package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +41 -119
- package/dist/melonjs.mjs/video/renderer.js +70 -14
- package/dist/melonjs.mjs/video/texture/atlas.js +39 -45
- package/dist/melonjs.mjs/video/texture/cache.js +9 -10
- package/dist/melonjs.mjs/video/texture/canvas_texture.js +63 -3
- package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
- package/dist/melonjs.mjs/video/video.js +2 -2
- package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +23 -19
- package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +80 -80
- package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +77 -0
- package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +252 -0
- package/dist/melonjs.mjs/video/webgl/compositors/webgl_compositor.js +1 -1
- package/dist/melonjs.mjs/video/webgl/glshader.js +7 -7
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +2 -2
- package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +2 -2
- package/dist/melonjs.mjs/video/webgl/utils/attributes.js +2 -2
- package/dist/melonjs.mjs/video/webgl/utils/precision.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/program.js +7 -7
- package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +4 -4
- package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +188 -181
- package/dist/melonjs.module.js +25040 -25193
- package/dist/types/application/application.d.ts +11 -8
- package/dist/types/audio/audio.d.ts +3 -3
- package/dist/types/entity/entity.d.ts +1 -1
- package/dist/types/index.d.ts +7 -4
- package/dist/types/input/input.d.ts +1 -1
- package/dist/types/input/keyboard.d.ts +1 -1
- package/dist/types/input/pointerevent.d.ts +6 -6
- package/dist/types/level/level.d.ts +2 -2
- package/dist/types/level/tiled/TMXLayer.d.ts +4 -4
- package/dist/types/level/tiled/TMXTileMap.d.ts +2 -2
- package/dist/types/level/tiled/TMXUtils.d.ts +5 -4
- package/dist/types/loader/loader.d.ts +2 -2
- package/dist/types/loader/settings.d.ts +2 -2
- package/dist/types/particles/emitter.d.ts +1 -1
- package/dist/types/physics/collision.d.ts +1 -1
- package/dist/types/physics/detector.d.ts +1 -1
- package/dist/types/plugin/plugin.d.ts +2 -2
- package/dist/types/renderable/container.d.ts +21 -17
- package/dist/types/renderable/renderable.d.ts +6 -0
- package/dist/types/renderable/sprite.d.ts +11 -11
- package/dist/types/renderable/trigger.d.ts +1 -1
- package/dist/types/renderable/ui/uibaseelement.d.ts +28 -6
- package/dist/types/renderable/ui/uispriteelement.d.ts +12 -14
- package/dist/types/renderable/ui/uitextbutton.d.ts +52 -12
- package/dist/types/state/stage.d.ts +1 -1
- package/dist/types/system/device.d.ts +1 -1
- package/dist/types/system/pooling.d.ts +3 -3
- package/dist/types/system/timer.d.ts +5 -5
- package/dist/types/text/bitmaptext.d.ts +1 -1
- package/dist/types/text/text.d.ts +7 -21
- package/dist/types/text/textstyle.d.ts +1 -1
- package/dist/types/utils/array.d.ts +2 -2
- package/dist/types/video/canvas/canvas_renderer.d.ts +8 -81
- package/dist/types/video/renderer.d.ts +48 -4
- package/dist/types/video/texture/atlas.d.ts +3 -3
- package/dist/types/video/texture/canvas_texture.d.ts +40 -0
- package/dist/types/video/webgl/buffer/vertex.d.ts +3 -3
- package/dist/types/video/webgl/compositors/compositor.d.ts +38 -32
- package/dist/types/video/webgl/compositors/primitive_compositor.d.ts +22 -0
- package/dist/types/video/webgl/compositors/quad_compositor.d.ts +72 -0
- package/dist/types/video/webgl/glshader.d.ts +1 -1
- package/dist/types/video/webgl/webgl_renderer.d.ts +47 -37
- package/package.json +16 -17
- package/src/application/application.js +26 -16
- package/src/application/header.js +5 -4
- package/src/application/resize.js +19 -19
- package/src/audio/audio.js +17 -19
- package/src/camera/camera2d.js +9 -9
- package/src/entity/entity.js +3 -3
- package/src/geometries/ellipse.js +5 -5
- package/src/geometries/line.js +8 -8
- package/src/geometries/path2d.js +55 -55
- package/src/geometries/point.js +1 -1
- package/src/geometries/poly.js +28 -28
- package/src/geometries/rectangle.js +7 -7
- package/src/geometries/roundrect.js +5 -5
- package/src/index.js +9 -4
- package/src/input/gamepad.js +29 -29
- package/src/input/input.js +1 -1
- package/src/input/keyboard.js +14 -14
- package/src/input/pointer.js +1 -1
- package/src/input/pointerevent.js +52 -52
- package/src/lang/console.js +2 -2
- package/src/lang/deprecated.js +1 -1
- package/src/level/level.js +8 -8
- package/src/level/tiled/TMXGroup.js +2 -2
- package/src/level/tiled/TMXLayer.js +30 -30
- package/src/level/tiled/TMXObject.js +7 -7
- package/src/level/tiled/TMXTile.js +7 -7
- package/src/level/tiled/TMXTileMap.js +18 -18
- package/src/level/tiled/TMXTileset.js +14 -14
- package/src/level/tiled/TMXTilesetGroup.js +2 -2
- package/src/level/tiled/TMXUtils.js +45 -40
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +29 -29
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +20 -20
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +9 -9
- package/src/level/tiled/renderer/TMXRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +5 -5
- package/src/loader/loader.js +6 -6
- package/src/loader/loadingscreen.js +1 -1
- package/src/loader/parser.js +12 -12
- package/src/loader/settings.js +2 -2
- package/src/math/color.js +24 -23
- package/src/math/math.js +1 -1
- package/src/math/matrix2.js +21 -21
- package/src/math/matrix3.js +51 -51
- package/src/math/observable_vector2.js +11 -11
- package/src/math/observable_vector3.js +21 -21
- package/src/math/vector2.js +10 -10
- package/src/math/vector3.js +20 -20
- package/src/particles/emitter.js +4 -4
- package/src/particles/particle.js +7 -7
- package/src/particles/settings.js +2 -2
- package/src/physics/body.js +16 -16
- package/src/physics/bounds.js +11 -11
- package/src/physics/collision.js +2 -2
- package/src/physics/detector.js +13 -13
- package/src/physics/quadtree.js +18 -18
- package/src/physics/sat.js +59 -59
- package/src/physics/world.js +3 -3
- package/src/plugin/plugin.js +8 -8
- package/src/polyfill/index.js +0 -2
- package/src/renderable/collectable.js +1 -1
- package/src/renderable/container.js +76 -58
- package/src/renderable/dragndrop.js +4 -4
- package/src/renderable/imagelayer.js +6 -5
- package/src/renderable/light2d.js +5 -5
- package/src/renderable/nineslicesprite.js +11 -11
- package/src/renderable/renderable.js +34 -12
- package/src/renderable/sprite.js +24 -24
- package/src/renderable/trigger.js +10 -8
- package/src/renderable/ui/uibaseelement.js +96 -26
- package/src/renderable/ui/uispriteelement.js +24 -24
- package/src/renderable/ui/uitextbutton.js +85 -67
- package/src/state/stage.js +6 -6
- package/src/state/state.js +14 -14
- package/src/system/device.js +2 -2
- package/src/system/event.js +1 -1
- package/src/system/pooling.js +8 -8
- package/src/system/save.js +5 -5
- package/src/system/timer.js +15 -11
- package/src/text/bitmaptext.js +19 -19
- package/src/text/bitmaptextdata.js +21 -21
- package/src/text/glyph.js +2 -2
- package/src/text/text.js +62 -91
- package/src/text/textmetrics.js +14 -14
- package/src/text/textstyle.js +3 -5
- package/src/tweens/easing.js +3 -3
- package/src/tweens/interpolation.js +7 -7
- package/src/tweens/tween.js +10 -10
- package/src/utils/agent.js +5 -5
- package/src/utils/array.js +3 -3
- package/src/utils/function.js +4 -4
- package/src/utils/string.js +2 -2
- package/src/utils/utils.js +15 -15
- package/src/video/canvas/canvas_renderer.js +39 -117
- package/src/video/renderer.js +68 -12
- package/src/video/texture/atlas.js +38 -44
- package/src/video/texture/cache.js +6 -6
- package/src/video/texture/canvas_texture.js +62 -2
- package/src/video/video.js +1 -1
- package/src/video/webgl/buffer/vertex.js +22 -18
- package/src/video/webgl/compositors/compositor.js +79 -80
- package/src/video/webgl/compositors/primitive_compositor.js +68 -0
- package/src/video/webgl/compositors/{webgl_compositor.js → quad_compositor.js} +52 -109
- package/src/video/webgl/glshader.js +6 -6
- package/src/video/webgl/shaders/primitive.vert +2 -5
- package/src/video/webgl/shaders/quad.vert +3 -1
- package/src/video/webgl/utils/attributes.js +1 -1
- package/src/video/webgl/utils/program.js +6 -6
- package/src/video/webgl/utils/uniforms.js +3 -3
- package/src/video/webgl/webgl_renderer.js +186 -179
- package/dist/melonjs.mjs/_virtual/make-built-in.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-define-property.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-get-own-property-descriptor.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-get-own-property-names.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-get-own-property-symbols.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-property-is-enumerable.js +0 -10
- package/dist/melonjs.mjs/_virtual/shared.js +0 -10
- package/dist/melonjs.mjs/game.js +0 -29
- package/dist/melonjs.mjs/polyfill/console.js +0 -18
- package/dist/melonjs.mjs/polyfill/performance.js +0 -27
- package/dist/melonjs.mjs/polyfill/requestAnimationFrame.js +0 -46
- package/dist/melonjs.mjs/polyfill/roundrect.js +0 -242
- package/dist/melonjs.mjs/renderable/re_container.js +0 -1016
- package/dist/melonjs.mjs/video/utils/resize.js +0 -116
- package/dist/melonjs.mjs/video/webgl/webgl_compositor.js +0 -494
- package/src/polyfill/performance.js +0 -20
- package/src/polyfill/requestAnimationFrame.js +0 -39
|
@@ -191,7 +191,7 @@ export default class TMXObject {
|
|
|
191
191
|
*/
|
|
192
192
|
setTile(tilesets) {
|
|
193
193
|
// get the corresponding tileset
|
|
194
|
-
|
|
194
|
+
let tileset = tilesets.getTilesetByGid(this.gid);
|
|
195
195
|
|
|
196
196
|
if (tileset.isCollection === false) {
|
|
197
197
|
// set width and height equal to tile size
|
|
@@ -209,8 +209,8 @@ export default class TMXObject {
|
|
|
209
209
|
* @returns {Polygon[]|Line[]|Ellipse[]} an array of shape objects
|
|
210
210
|
*/
|
|
211
211
|
parseTMXShapes() {
|
|
212
|
-
|
|
213
|
-
|
|
212
|
+
let i = 0;
|
|
213
|
+
let shapes = [];
|
|
214
214
|
|
|
215
215
|
// add an ellipse shape
|
|
216
216
|
if (this.isEllipse === true) {
|
|
@@ -226,7 +226,7 @@ export default class TMXObject {
|
|
|
226
226
|
} else {
|
|
227
227
|
// add a polygon
|
|
228
228
|
if (this.isPolygon === true) {
|
|
229
|
-
|
|
229
|
+
let _polygon = pool.pull("Polygon", 0, 0, this.points);
|
|
230
230
|
// make sure it's a convex polygon
|
|
231
231
|
if (_polygon.isConvex() === false ) {
|
|
232
232
|
throw new Error("collision polygones in Tiled should be defined as Convex");
|
|
@@ -234,9 +234,9 @@ export default class TMXObject {
|
|
|
234
234
|
shapes.push(_polygon.rotate(this.rotation));
|
|
235
235
|
|
|
236
236
|
} else if (this.isPolyLine === true) {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
237
|
+
let p = this.points;
|
|
238
|
+
let p1, p2;
|
|
239
|
+
let segments = p.length - 1;
|
|
240
240
|
for (i = 0; i < segments; i++) {
|
|
241
241
|
// clone the value before, as [i + 1]
|
|
242
242
|
// is reused later by the next segment
|
|
@@ -16,14 +16,14 @@ import { TMX_FLIP_V, TMX_FLIP_H, TMX_FLIP_AD, TMX_CLEAR_BIT_MASK } from "./const
|
|
|
16
16
|
* @param {TMXTileset} tileset - the corresponding tileset object
|
|
17
17
|
*/
|
|
18
18
|
constructor(x, y, gid, tileset) {
|
|
19
|
-
|
|
19
|
+
let width, height;
|
|
20
20
|
|
|
21
21
|
// call the parent constructor
|
|
22
22
|
super();
|
|
23
23
|
|
|
24
24
|
// determine the tile size
|
|
25
25
|
if (tileset.isCollection) {
|
|
26
|
-
|
|
26
|
+
let image = tileset.getTileImage(gid & TMX_CLEAR_BIT_MASK);
|
|
27
27
|
width = image.width;
|
|
28
28
|
height = image.height;
|
|
29
29
|
} else {
|
|
@@ -120,12 +120,12 @@ import { TMX_FLIP_V, TMX_FLIP_H, TMX_FLIP_AD, TMX_CLEAR_BIT_MASK } from "./const
|
|
|
120
120
|
* @returns {Renderable} a me.Sprite object
|
|
121
121
|
*/
|
|
122
122
|
getRenderable(settings) {
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
let renderable;
|
|
124
|
+
let tileset = this.tileset;
|
|
125
125
|
|
|
126
126
|
if (tileset.animations.has(this.tileId)) {
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
let frames = [];
|
|
128
|
+
let frameId = [];
|
|
129
129
|
(tileset.animations.get(this.tileId).frames).forEach((frame) => {
|
|
130
130
|
frameId.push(frame.tileid);
|
|
131
131
|
frames.push({
|
|
@@ -139,7 +139,7 @@ import { TMX_FLIP_V, TMX_FLIP_H, TMX_FLIP_AD, TMX_CLEAR_BIT_MASK } from "./const
|
|
|
139
139
|
|
|
140
140
|
} else {
|
|
141
141
|
if (tileset.isCollection === true) {
|
|
142
|
-
|
|
142
|
+
let image = tileset.getTileImage(this.tileId);
|
|
143
143
|
renderable = new Sprite(0, 0,
|
|
144
144
|
Object.assign({
|
|
145
145
|
image: image
|
|
@@ -31,7 +31,7 @@ function readImageLayer(map, data, z) {
|
|
|
31
31
|
applyTMXProperties(data.properties, data);
|
|
32
32
|
|
|
33
33
|
// create the layer
|
|
34
|
-
|
|
34
|
+
let imageLayer = pool.pull("ImageLayer",
|
|
35
35
|
// x/y is deprecated since 0.15 and replace by offsetx/y
|
|
36
36
|
+data.offsetx || +data.x || 0,
|
|
37
37
|
+data.offsety || +data.y || 0,
|
|
@@ -47,7 +47,7 @@ function readImageLayer(map, data, z) {
|
|
|
47
47
|
|
|
48
48
|
|
|
49
49
|
// set some additional flags
|
|
50
|
-
|
|
50
|
+
let visible = typeof(data.visible) !== "undefined" ? data.visible : true;
|
|
51
51
|
imageLayer.setOpacity(visible ? +data.opacity : 0);
|
|
52
52
|
|
|
53
53
|
return imageLayer;
|
|
@@ -80,7 +80,7 @@ function readObjectGroup(map, data, z) {
|
|
|
80
80
|
* @param {object} data - TMX map in JSON format
|
|
81
81
|
* @example
|
|
82
82
|
* // create a new level object based on the TMX JSON object
|
|
83
|
-
*
|
|
83
|
+
* let level = new me.TMXTileMap(levelId, me.loader.getTMX(levelId));
|
|
84
84
|
* // add the level to the game world container
|
|
85
85
|
* level.addTo(me.game.world, true);
|
|
86
86
|
*/
|
|
@@ -242,7 +242,7 @@ function readObjectGroup(map, data, z) {
|
|
|
242
242
|
}
|
|
243
243
|
|
|
244
244
|
// to automatically increment z index
|
|
245
|
-
|
|
245
|
+
let zOrder = 0;
|
|
246
246
|
|
|
247
247
|
// Tileset information
|
|
248
248
|
if (!this.tilesets) {
|
|
@@ -252,7 +252,7 @@ function readObjectGroup(map, data, z) {
|
|
|
252
252
|
|
|
253
253
|
// parse all tileset objects
|
|
254
254
|
if (typeof (data.tilesets) !== "undefined") {
|
|
255
|
-
|
|
255
|
+
let tilesets = data.tilesets;
|
|
256
256
|
tilesets.forEach((tileset) => {
|
|
257
257
|
// add the new tileset
|
|
258
258
|
this.tilesets.add(readTileset(tileset));
|
|
@@ -309,15 +309,15 @@ function readObjectGroup(map, data, z) {
|
|
|
309
309
|
* @param {boolean} [setViewportBounds=false] - if true, set the viewport bounds to the map size, this should be set to true especially if adding a level to the game world container.
|
|
310
310
|
* @example
|
|
311
311
|
* // create a new level object based on the TMX JSON object
|
|
312
|
-
*
|
|
312
|
+
* let level = new me.TMXTileMap(levelId, me.loader.getTMX(levelId));
|
|
313
313
|
* // add the level to the game world container
|
|
314
314
|
* level.addTo(me.game.world, true, true);
|
|
315
315
|
*/
|
|
316
316
|
addTo(container, flatten, setViewportBounds) {
|
|
317
|
-
|
|
318
|
-
|
|
317
|
+
let _sort = container.autoSort;
|
|
318
|
+
let _depth = container.autoDepth;
|
|
319
319
|
|
|
320
|
-
|
|
320
|
+
let levelBounds = this.getBounds();
|
|
321
321
|
|
|
322
322
|
// disable auto-sort and auto-depth
|
|
323
323
|
container.autoSort = false;
|
|
@@ -383,15 +383,15 @@ function readObjectGroup(map, data, z) {
|
|
|
383
383
|
* @returns {Renderable[]} Array of Objects
|
|
384
384
|
*/
|
|
385
385
|
getObjects(flatten) {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
386
|
+
let objects = [];
|
|
387
|
+
let isCollisionGroup = false;
|
|
388
|
+
let targetContainer;
|
|
389
389
|
|
|
390
390
|
// parse the map for objects
|
|
391
391
|
this.readMapObjects(this.data);
|
|
392
392
|
|
|
393
|
-
for (
|
|
394
|
-
|
|
393
|
+
for (let g = 0; g < this.objectGroups.length; g++) {
|
|
394
|
+
let group = this.objectGroups[g];
|
|
395
395
|
|
|
396
396
|
// check if this is the collision shape group
|
|
397
397
|
isCollisionGroup = group.name.toLowerCase().includes(COLLISION_GROUP);
|
|
@@ -415,13 +415,13 @@ function readObjectGroup(map, data, z) {
|
|
|
415
415
|
|
|
416
416
|
// iterate through the group and add all object into their
|
|
417
417
|
// corresponding target Container
|
|
418
|
-
for (
|
|
418
|
+
for (let o = 0; o < group.objects.length; o++) {
|
|
419
419
|
// TMX object settings
|
|
420
|
-
|
|
420
|
+
let settings = group.objects[o];
|
|
421
421
|
// reference to the instantiated object
|
|
422
|
-
|
|
422
|
+
let obj;
|
|
423
423
|
// a reference to the default shape
|
|
424
|
-
|
|
424
|
+
let shape;
|
|
425
425
|
|
|
426
426
|
// Tiled uses 0,0 by default
|
|
427
427
|
if (typeof (settings.anchorPoint) === "undefined") {
|
|
@@ -13,7 +13,7 @@ import { getTMX, getImage } from "./../../loader/loader.js";
|
|
|
13
13
|
* @param {object} tileset - tileset data in JSON format ({@link http://docs.mapeditor.org/en/stable/reference/tmx-map-format/#tileset})
|
|
14
14
|
*/
|
|
15
15
|
constructor(tileset) {
|
|
16
|
-
|
|
16
|
+
let i = 0;
|
|
17
17
|
// first gid
|
|
18
18
|
|
|
19
19
|
// tile properties (collidable, etc..)
|
|
@@ -26,8 +26,8 @@ import { getTMX, getImage } from "./../../loader/loader.js";
|
|
|
26
26
|
|
|
27
27
|
// check if an external tileset is defined
|
|
28
28
|
if (typeof(tileset.source) !== "undefined") {
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
let src = tileset.source;
|
|
30
|
+
let ext = fileUtil.getExtension(src);
|
|
31
31
|
if (ext === "tsx" || ext === "json") {
|
|
32
32
|
// load the external tileset (TSX/JSON)
|
|
33
33
|
tileset = getTMX(fileUtil.getBasename(src));
|
|
@@ -76,7 +76,7 @@ import { getTMX, getImage } from "./../../loader/loader.js";
|
|
|
76
76
|
*/
|
|
77
77
|
this._lastUpdate = 0;
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
let tiles = tileset.tiles;
|
|
80
80
|
for (i in tiles) {
|
|
81
81
|
if (tiles.hasOwnProperty(i)) {
|
|
82
82
|
if ("animation" in tiles[i]) {
|
|
@@ -91,8 +91,8 @@ import { getTMX, getImage } from "./../../loader/loader.js";
|
|
|
91
91
|
// set tile properties, if any
|
|
92
92
|
if ("properties" in tiles[i]) {
|
|
93
93
|
if (Array.isArray(tiles[i].properties)) { // JSON (new format)
|
|
94
|
-
|
|
95
|
-
for (
|
|
94
|
+
let tileProperty = {};
|
|
95
|
+
for (let j in tiles[i].properties) {
|
|
96
96
|
tileProperty[tiles[i].properties[j].name] = tiles[i].properties[j].value;
|
|
97
97
|
}
|
|
98
98
|
this.setTileProperty(+tiles[i].id + this.firstgid, tileProperty);
|
|
@@ -101,7 +101,7 @@ import { getTMX, getImage } from "./../../loader/loader.js";
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
if ("image" in tiles[i]) {
|
|
104
|
-
|
|
104
|
+
let image = getImage(tiles[i].image);
|
|
105
105
|
if (!image) {
|
|
106
106
|
throw new Error("melonJS: '" + tiles[i].image + "' file for tile '" + (+i + this.firstgid) + "' not found!");
|
|
107
107
|
}
|
|
@@ -112,14 +112,14 @@ import { getTMX, getImage } from "./../../loader/loader.js";
|
|
|
112
112
|
|
|
113
113
|
this.isCollection = this.imageCollection.length > 0;
|
|
114
114
|
|
|
115
|
-
|
|
115
|
+
let offset = tileset.tileoffset;
|
|
116
116
|
if (offset) {
|
|
117
117
|
this.tileoffset.x = +offset.x;
|
|
118
118
|
this.tileoffset.y = +offset.y;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
// set tile properties, if any (JSON old format)
|
|
122
|
-
|
|
122
|
+
let tileInfo = tileset.tileproperties;
|
|
123
123
|
if (tileInfo) {
|
|
124
124
|
for (i in tileInfo) {
|
|
125
125
|
if (tileInfo.hasOwnProperty(i)) {
|
|
@@ -148,8 +148,8 @@ import { getTMX, getImage } from "./../../loader/loader.js";
|
|
|
148
148
|
this.atlas = this.texture.getAtlas();
|
|
149
149
|
|
|
150
150
|
// calculate the number of tiles per horizontal line
|
|
151
|
-
|
|
152
|
-
|
|
151
|
+
let hTileCount = +tileset.columns || Math.round(this.image.width / (this.tilewidth + this.spacing));
|
|
152
|
+
let vTileCount = Math.round(this.image.height / (this.tileheight + this.spacing));
|
|
153
153
|
if (tileset.tilecount % hTileCount > 0) {
|
|
154
154
|
++vTileCount;
|
|
155
155
|
}
|
|
@@ -198,7 +198,7 @@ import { getTMX, getImage } from "./../../loader/loader.js";
|
|
|
198
198
|
* @returns {number} View tile ID
|
|
199
199
|
*/
|
|
200
200
|
getViewTileId(gid) {
|
|
201
|
-
|
|
201
|
+
let localId = gid - this.firstgid;
|
|
202
202
|
|
|
203
203
|
if (this.animations.has(localId)) {
|
|
204
204
|
// return the current corresponding tile id if animated
|
|
@@ -219,7 +219,7 @@ import { getTMX, getImage } from "./../../loader/loader.js";
|
|
|
219
219
|
|
|
220
220
|
// update tile animations
|
|
221
221
|
update(dt) {
|
|
222
|
-
|
|
222
|
+
let duration = 0,
|
|
223
223
|
now = timer.getTime(),
|
|
224
224
|
result = false;
|
|
225
225
|
|
|
@@ -267,7 +267,7 @@ import { getTMX, getImage } from "./../../loader/loader.js";
|
|
|
267
267
|
);
|
|
268
268
|
} else {
|
|
269
269
|
// use the tileset texture
|
|
270
|
-
|
|
270
|
+
let offset = this.atlas[this.getViewTileId(tmxTile.tileId)].offset;
|
|
271
271
|
// draw the tile
|
|
272
272
|
renderer.drawImage(
|
|
273
273
|
this.image,
|
|
@@ -36,13 +36,13 @@ import { TMX_CLEAR_BIT_MASK } from "./constants";
|
|
|
36
36
|
* @returns {TMXTileset} corresponding tileset
|
|
37
37
|
*/
|
|
38
38
|
getTilesetByGid(gid) {
|
|
39
|
-
|
|
39
|
+
let invalidRange = -1;
|
|
40
40
|
|
|
41
41
|
// clear the gid of all flip/rotation flags
|
|
42
42
|
gid &= TMX_CLEAR_BIT_MASK;
|
|
43
43
|
|
|
44
44
|
// cycle through all tilesets
|
|
45
|
-
for (
|
|
45
|
+
for (let i = 0, len = this.tilesets.length; i < len; i++) {
|
|
46
46
|
// return the corresponding tileset if matching
|
|
47
47
|
if (this.tilesets[i].contains(gid)) {
|
|
48
48
|
return this.tilesets[i];
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import utils from "../../utils/utils.js";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* set and interpret a TMX property value
|
|
5
5
|
* @ignore
|
|
6
6
|
*/
|
|
7
7
|
function setTMXValue(name, type, value) {
|
|
8
|
-
|
|
8
|
+
let match;
|
|
9
9
|
|
|
10
10
|
if (typeof(value) !== "string") {
|
|
11
11
|
// Value is already normalized (e.g. with JSON maps)
|
|
@@ -25,11 +25,11 @@ function setTMXValue(name, type, value) {
|
|
|
25
25
|
|
|
26
26
|
default :
|
|
27
27
|
// try to parse it anyway
|
|
28
|
-
if (!value || isBoolean(value)) {
|
|
28
|
+
if (!value || utils.string.isBoolean(value)) {
|
|
29
29
|
// if value not defined or boolean
|
|
30
30
|
value = value ? (value === "true") : true;
|
|
31
31
|
}
|
|
32
|
-
else if (isNumeric(value)) {
|
|
32
|
+
else if (utils.string.isNumeric(value)) {
|
|
33
33
|
// check if numeric
|
|
34
34
|
value = Number(value);
|
|
35
35
|
}
|
|
@@ -82,8 +82,8 @@ function setTMXValue(name, type, value) {
|
|
|
82
82
|
function parseAttributes(obj, elt) {
|
|
83
83
|
// do attributes
|
|
84
84
|
if (elt.attributes && elt.attributes.length > 0) {
|
|
85
|
-
for (
|
|
86
|
-
|
|
85
|
+
for (let j = 0; j < elt.attributes.length; j++) {
|
|
86
|
+
let attribute = elt.attributes.item(j);
|
|
87
87
|
if (typeof(attribute.name) !== "undefined") {
|
|
88
88
|
// DOM4 (Attr no longer inherit from Node)
|
|
89
89
|
obj[attribute.name] = attribute.value;
|
|
@@ -96,14 +96,19 @@ function parseAttributes(obj, elt) {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
/**
|
|
99
|
-
* decompress zlib/gzip data
|
|
99
|
+
* decompress and decode zlib/gzip data
|
|
100
100
|
* @ignore
|
|
101
101
|
* @name decompress
|
|
102
|
-
* @param
|
|
103
|
-
* @param
|
|
102
|
+
* @param {string} input - Base64 encoded and compressed data
|
|
103
|
+
* @param {string} format - compressed data format ("gzip","zlib", "zstd")
|
|
104
|
+
* @returns {Uint32Array} Decoded and decompress data
|
|
104
105
|
*/
|
|
105
|
-
export function decompress() {
|
|
106
|
-
|
|
106
|
+
export function decompress(data, format) {
|
|
107
|
+
if (typeof utils.inflateb64 === "function") {
|
|
108
|
+
return utils.inflateb64(data, format);
|
|
109
|
+
} else {
|
|
110
|
+
throw new Error("GZIP/ZLIB compressed TMX Tile Map not supported!");
|
|
111
|
+
}
|
|
107
112
|
}
|
|
108
113
|
|
|
109
114
|
/**
|
|
@@ -114,10 +119,10 @@ export function decompress() {
|
|
|
114
119
|
* @returns {number[]} Decoded data
|
|
115
120
|
*/
|
|
116
121
|
export function decodeCSV(input) {
|
|
117
|
-
|
|
122
|
+
let entries = input.replace("\n", "").trim().split(",");
|
|
118
123
|
|
|
119
|
-
|
|
120
|
-
for (
|
|
124
|
+
let result = [];
|
|
125
|
+
for (let i = 0; i < entries.length; i++) {
|
|
121
126
|
result.push(+entries[i]);
|
|
122
127
|
}
|
|
123
128
|
return result;
|
|
@@ -134,9 +139,9 @@ export function decodeCSV(input) {
|
|
|
134
139
|
export function decodeBase64AsArray(input, bytes) {
|
|
135
140
|
bytes = bytes || 1;
|
|
136
141
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
142
|
+
let i, j, len;
|
|
143
|
+
let dec = globalThis.atob(input.replace(/[^A-Za-z0-9\+\/\=]/g, ""));
|
|
144
|
+
let ar = new Uint32Array(dec.length / bytes);
|
|
140
145
|
|
|
141
146
|
for (i = 0, len = dec.length / bytes; i < len; i++) {
|
|
142
147
|
ar[i] = 0;
|
|
@@ -160,12 +165,12 @@ export function decode(data, encoding, compression) {
|
|
|
160
165
|
return decodeCSV(data);
|
|
161
166
|
|
|
162
167
|
case "base64":
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
168
|
+
if (compression !== "none") {
|
|
169
|
+
data = decompress(data, compression);
|
|
170
|
+
} else {
|
|
171
|
+
data = decodeBase64AsArray(data, 4);
|
|
172
|
+
}
|
|
173
|
+
return data;
|
|
169
174
|
|
|
170
175
|
case "none":
|
|
171
176
|
return data;
|
|
@@ -183,11 +188,11 @@ export function decode(data, encoding, compression) {
|
|
|
183
188
|
* @ignore
|
|
184
189
|
*/
|
|
185
190
|
export function normalize(obj, item) {
|
|
186
|
-
|
|
191
|
+
let nodeName = item.nodeName;
|
|
187
192
|
|
|
188
193
|
switch (nodeName) {
|
|
189
194
|
case "data":
|
|
190
|
-
var data = parse(item);
|
|
195
|
+
var data = parse(item); // <= "Unexpected lexical declaration in case block" if using let
|
|
191
196
|
|
|
192
197
|
data.encoding = data.encoding || "xml";
|
|
193
198
|
|
|
@@ -225,7 +230,7 @@ export function normalize(obj, item) {
|
|
|
225
230
|
case "layer":
|
|
226
231
|
case "objectgroup":
|
|
227
232
|
case "group":
|
|
228
|
-
var layer = parse(item);
|
|
233
|
+
var layer = parse(item); // // <= "Unexpected lexical declaration in case block" if using let
|
|
229
234
|
layer.type = (nodeName === "layer" ? "tilelayer" : nodeName);
|
|
230
235
|
if (layer.image) {
|
|
231
236
|
layer.image = layer.image.source;
|
|
@@ -241,13 +246,13 @@ export function normalize(obj, item) {
|
|
|
241
246
|
|
|
242
247
|
case "frame":
|
|
243
248
|
case "object":
|
|
244
|
-
var name = nodeName + "s";
|
|
249
|
+
var name = nodeName + "s"; // <= "Unexpected lexical declaration in case block" if using let
|
|
245
250
|
obj[name] = obj[name] || [];
|
|
246
251
|
obj[name].push(parse(item));
|
|
247
252
|
break;
|
|
248
253
|
|
|
249
254
|
case "tile":
|
|
250
|
-
var tile = parse(item);
|
|
255
|
+
var tile = parse(item); // <= "Unexpected lexical declaration in case block" if using let
|
|
251
256
|
if (tile.image) {
|
|
252
257
|
tile.imagewidth = tile.image.width;
|
|
253
258
|
tile.imageheight = tile.image.height;
|
|
@@ -258,7 +263,7 @@ export function normalize(obj, item) {
|
|
|
258
263
|
break;
|
|
259
264
|
|
|
260
265
|
case "tileset":
|
|
261
|
-
var tileset = parse(item);
|
|
266
|
+
var tileset = parse(item); // <= "Unexpected lexical declaration in case block" if using let
|
|
262
267
|
if (tileset.image) {
|
|
263
268
|
tileset.imagewidth = tileset.image.width;
|
|
264
269
|
tileset.imageheight = tileset.image.height;
|
|
@@ -274,10 +279,10 @@ export function normalize(obj, item) {
|
|
|
274
279
|
obj[nodeName] = [];
|
|
275
280
|
|
|
276
281
|
// Get a point array
|
|
277
|
-
var points = parse(item).points.split(" ");
|
|
282
|
+
var points = parse(item).points.split(" "); // <= "Unexpected lexical declaration in case block" if using let
|
|
278
283
|
|
|
279
284
|
// And normalize them into an array of vectors
|
|
280
|
-
for (
|
|
285
|
+
for (let i = 0, v; i < points.length; i++) {
|
|
281
286
|
v = points[i].split(",");
|
|
282
287
|
obj[nodeName].push({
|
|
283
288
|
"x" : +v[0],
|
|
@@ -292,7 +297,7 @@ export function normalize(obj, item) {
|
|
|
292
297
|
break;
|
|
293
298
|
|
|
294
299
|
case "property":
|
|
295
|
-
var property = parse(item);
|
|
300
|
+
var property = parse(item); // <= "Unexpected lexical declaration in case block" if using let
|
|
296
301
|
// for custom properties, text is used
|
|
297
302
|
var value = (typeof property.value !== "undefined") ? property.value : property.text;
|
|
298
303
|
|
|
@@ -316,9 +321,9 @@ export function normalize(obj, item) {
|
|
|
316
321
|
*/
|
|
317
322
|
export function parse(xml) {
|
|
318
323
|
// Create the return object
|
|
319
|
-
|
|
324
|
+
let obj = {};
|
|
320
325
|
|
|
321
|
-
|
|
326
|
+
let text = "";
|
|
322
327
|
|
|
323
328
|
if (xml.nodeType === 1) {
|
|
324
329
|
// do attributes
|
|
@@ -353,14 +358,14 @@ export function parse(xml) {
|
|
|
353
358
|
* @ignore
|
|
354
359
|
*/
|
|
355
360
|
export function applyTMXProperties(obj, data) {
|
|
356
|
-
|
|
357
|
-
|
|
361
|
+
let properties = data.properties;
|
|
362
|
+
let types = data.propertytypes;
|
|
358
363
|
if (typeof(properties) !== "undefined") {
|
|
359
|
-
for (
|
|
364
|
+
for (let property in properties) {
|
|
360
365
|
if (properties.hasOwnProperty(property)) {
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
366
|
+
let type = "string";
|
|
367
|
+
let name = property;
|
|
368
|
+
let value = properties[property];
|
|
364
369
|
// proof-check for new and old JSON format
|
|
365
370
|
if (typeof properties[property].name !== "undefined") {
|
|
366
371
|
name = properties[property].name;
|