melonjs 10.4.0 → 10.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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v10.4.0
2
+ * melonJS Game Engine - v10.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
@@ -14619,7 +14619,8 @@ var dummyObj = {
14619
14619
  function shouldCollide(a, b) {
14620
14620
  return (
14621
14621
  a.isKinematic !== true && b.isKinematic !== true &&
14622
- a.body && b.body &&
14622
+ typeof a.body === "object" && typeof b.body === "object" &&
14623
+ !(a.body.isStatic === true && b.body.isStatic === true) &&
14623
14624
  (a.body.collisionMask & b.body.collisionType) !== 0 &&
14624
14625
  (a.body.collisionType & b.body.collisionMask) !== 0
14625
14626
  );
@@ -14732,10 +14733,10 @@ function collisionCheck(objA, response = globalResponse) {
14732
14733
  response.indexShapeB = indexB;
14733
14734
 
14734
14735
  // execute the onCollision callback
14735
- if (objA.onCollision && objA.onCollision(response, objB) !== false) {
14736
+ if (objA.onCollision && objA.onCollision(response, objB) !== false && objA.body.isStatic === false) {
14736
14737
  objA.body.respondToCollision.call(objA.body, response);
14737
14738
  }
14738
- if (objB.onCollision && objB.onCollision(response, objA) !== false) {
14739
+ if (objB.onCollision && objB.onCollision(response, objA) !== false && objB.body.isStatic === false) {
14739
14740
  objB.body.respondToCollision.call(objB.body, response);
14740
14741
  }
14741
14742
  }
@@ -15099,7 +15100,8 @@ class Body {
15099
15100
 
15100
15101
 
15101
15102
  /**
15102
- * either this body is a static body or not
15103
+ * Either this body is a static body or not.
15104
+ * A static body is completely fixed and can never change position or angle.
15103
15105
  * @readonly
15104
15106
  * @public
15105
15107
  * @type {boolean}
@@ -19388,6 +19390,455 @@ function applyTMXProperties(obj, data) {
19388
19390
  }
19389
19391
  }
19390
19392
 
19393
+ var src = {};
19394
+
19395
+ var arraymultimap = {};
19396
+
19397
+ var multimap = {};
19398
+
19399
+ var __generator = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
19400
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
19401
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
19402
+ function verb(n) { return function (v) { return step([n, v]); }; }
19403
+ function step(op) {
19404
+ if (f) throw new TypeError("Generator is already executing.");
19405
+ while (_) try {
19406
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19407
+ if (y = 0, t) op = [op[0] & 2, t.value];
19408
+ switch (op[0]) {
19409
+ case 0: case 1: t = op; break;
19410
+ case 4: _.label++; return { value: op[1], done: false };
19411
+ case 5: _.label++; y = op[1]; op = [0]; continue;
19412
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
19413
+ default:
19414
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
19415
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
19416
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
19417
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
19418
+ if (t[2]) _.ops.pop();
19419
+ _.trys.pop(); continue;
19420
+ }
19421
+ op = body.call(thisArg, _);
19422
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
19423
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
19424
+ }
19425
+ };
19426
+ var __values = (commonjsGlobal && commonjsGlobal.__values) || function(o) {
19427
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
19428
+ if (m) return m.call(o);
19429
+ if (o && typeof o.length === "number") return {
19430
+ next: function () {
19431
+ if (o && i >= o.length) o = void 0;
19432
+ return { value: o && o[i++], done: !o };
19433
+ }
19434
+ };
19435
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
19436
+ };
19437
+ var __read = (commonjsGlobal && commonjsGlobal.__read) || function (o, n) {
19438
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
19439
+ if (!m) return o;
19440
+ var i = m.call(o), r, ar = [], e;
19441
+ try {
19442
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19443
+ }
19444
+ catch (error) { e = { error: error }; }
19445
+ finally {
19446
+ try {
19447
+ if (r && !r.done && (m = i["return"])) m.call(i);
19448
+ }
19449
+ finally { if (e) throw e.error; }
19450
+ }
19451
+ return ar;
19452
+ };
19453
+ Object.defineProperty(multimap, "__esModule", { value: true });
19454
+ multimap.Multimap = void 0;
19455
+ var Multimap = /** @class */ (function () {
19456
+ function Multimap(operator, iterable) {
19457
+ var e_1, _a;
19458
+ this.size_ = 0;
19459
+ this.map = new Map();
19460
+ this.operator = operator;
19461
+ if (iterable) {
19462
+ try {
19463
+ for (var iterable_1 = __values(iterable), iterable_1_1 = iterable_1.next(); !iterable_1_1.done; iterable_1_1 = iterable_1.next()) {
19464
+ var _b = __read(iterable_1_1.value, 2), key = _b[0], value = _b[1];
19465
+ this.put(key, value);
19466
+ }
19467
+ }
19468
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
19469
+ finally {
19470
+ try {
19471
+ if (iterable_1_1 && !iterable_1_1.done && (_a = iterable_1.return)) _a.call(iterable_1);
19472
+ }
19473
+ finally { if (e_1) throw e_1.error; }
19474
+ }
19475
+ }
19476
+ return this;
19477
+ }
19478
+ Object.defineProperty(Multimap.prototype, "size", {
19479
+ get: function () {
19480
+ return this.size_;
19481
+ },
19482
+ enumerable: false,
19483
+ configurable: true
19484
+ });
19485
+ Multimap.prototype.get = function (key) {
19486
+ var values = this.map.get(key);
19487
+ if (values) {
19488
+ return this.operator.clone(values);
19489
+ }
19490
+ else {
19491
+ return this.operator.create();
19492
+ }
19493
+ };
19494
+ Multimap.prototype.put = function (key, value) {
19495
+ var values = this.map.get(key);
19496
+ if (!values) {
19497
+ values = this.operator.create();
19498
+ }
19499
+ if (!this.operator.add(value, values)) {
19500
+ return false;
19501
+ }
19502
+ this.map.set(key, values);
19503
+ this.size_++;
19504
+ return true;
19505
+ };
19506
+ Multimap.prototype.putAll = function (arg1, arg2) {
19507
+ var e_2, _a, e_3, _b;
19508
+ var pushed = 0;
19509
+ if (arg2) {
19510
+ var key = arg1;
19511
+ var values = arg2;
19512
+ try {
19513
+ for (var values_1 = __values(values), values_1_1 = values_1.next(); !values_1_1.done; values_1_1 = values_1.next()) {
19514
+ var value = values_1_1.value;
19515
+ this.put(key, value);
19516
+ pushed++;
19517
+ }
19518
+ }
19519
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
19520
+ finally {
19521
+ try {
19522
+ if (values_1_1 && !values_1_1.done && (_a = values_1.return)) _a.call(values_1);
19523
+ }
19524
+ finally { if (e_2) throw e_2.error; }
19525
+ }
19526
+ }
19527
+ else if (arg1 instanceof Multimap) {
19528
+ try {
19529
+ for (var _c = __values(arg1.entries()), _d = _c.next(); !_d.done; _d = _c.next()) {
19530
+ var _e = __read(_d.value, 2), key = _e[0], value = _e[1];
19531
+ this.put(key, value);
19532
+ pushed++;
19533
+ }
19534
+ }
19535
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
19536
+ finally {
19537
+ try {
19538
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
19539
+ }
19540
+ finally { if (e_3) throw e_3.error; }
19541
+ }
19542
+ }
19543
+ else {
19544
+ throw new TypeError("unexpected arguments");
19545
+ }
19546
+ return pushed > 0;
19547
+ };
19548
+ Multimap.prototype.has = function (key) {
19549
+ return this.map.has(key);
19550
+ };
19551
+ Multimap.prototype.hasEntry = function (key, value) {
19552
+ return this.operator.has(value, this.get(key));
19553
+ };
19554
+ Multimap.prototype.delete = function (key) {
19555
+ this.size_ -= this.operator.size(this.get(key));
19556
+ return this.map.delete(key);
19557
+ };
19558
+ Multimap.prototype.deleteEntry = function (key, value) {
19559
+ var current = this.get(key);
19560
+ if (!this.operator.delete(value, current)) {
19561
+ return false;
19562
+ }
19563
+ this.map.set(key, current);
19564
+ this.size_--;
19565
+ return true;
19566
+ };
19567
+ Multimap.prototype.clear = function () {
19568
+ this.map.clear();
19569
+ this.size_ = 0;
19570
+ };
19571
+ Multimap.prototype.keys = function () {
19572
+ return this.map.keys();
19573
+ };
19574
+ Multimap.prototype.entries = function () {
19575
+ var self = this;
19576
+ function gen() {
19577
+ var _a, _b, _c, key, values, values_2, values_2_1, value, e_4_1, e_5_1;
19578
+ var e_5, _d, e_4, _e;
19579
+ return __generator(this, function (_f) {
19580
+ switch (_f.label) {
19581
+ case 0:
19582
+ _f.trys.push([0, 11, 12, 13]);
19583
+ _a = __values(self.map.entries()), _b = _a.next();
19584
+ _f.label = 1;
19585
+ case 1:
19586
+ if (!!_b.done) return [3 /*break*/, 10];
19587
+ _c = __read(_b.value, 2), key = _c[0], values = _c[1];
19588
+ _f.label = 2;
19589
+ case 2:
19590
+ _f.trys.push([2, 7, 8, 9]);
19591
+ values_2 = (e_4 = void 0, __values(values)), values_2_1 = values_2.next();
19592
+ _f.label = 3;
19593
+ case 3:
19594
+ if (!!values_2_1.done) return [3 /*break*/, 6];
19595
+ value = values_2_1.value;
19596
+ return [4 /*yield*/, [key, value]];
19597
+ case 4:
19598
+ _f.sent();
19599
+ _f.label = 5;
19600
+ case 5:
19601
+ values_2_1 = values_2.next();
19602
+ return [3 /*break*/, 3];
19603
+ case 6: return [3 /*break*/, 9];
19604
+ case 7:
19605
+ e_4_1 = _f.sent();
19606
+ e_4 = { error: e_4_1 };
19607
+ return [3 /*break*/, 9];
19608
+ case 8:
19609
+ try {
19610
+ if (values_2_1 && !values_2_1.done && (_e = values_2.return)) _e.call(values_2);
19611
+ }
19612
+ finally { if (e_4) throw e_4.error; }
19613
+ return [7 /*endfinally*/];
19614
+ case 9:
19615
+ _b = _a.next();
19616
+ return [3 /*break*/, 1];
19617
+ case 10: return [3 /*break*/, 13];
19618
+ case 11:
19619
+ e_5_1 = _f.sent();
19620
+ e_5 = { error: e_5_1 };
19621
+ return [3 /*break*/, 13];
19622
+ case 12:
19623
+ try {
19624
+ if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
19625
+ }
19626
+ finally { if (e_5) throw e_5.error; }
19627
+ return [7 /*endfinally*/];
19628
+ case 13: return [2 /*return*/];
19629
+ }
19630
+ });
19631
+ }
19632
+ return gen();
19633
+ };
19634
+ Multimap.prototype.values = function () {
19635
+ var self = this;
19636
+ function gen() {
19637
+ var _a, _b, _c, value, e_6_1;
19638
+ var e_6, _d;
19639
+ return __generator(this, function (_e) {
19640
+ switch (_e.label) {
19641
+ case 0:
19642
+ _e.trys.push([0, 5, 6, 7]);
19643
+ _a = __values(self.entries()), _b = _a.next();
19644
+ _e.label = 1;
19645
+ case 1:
19646
+ if (!!_b.done) return [3 /*break*/, 4];
19647
+ _c = __read(_b.value, 2), value = _c[1];
19648
+ return [4 /*yield*/, value];
19649
+ case 2:
19650
+ _e.sent();
19651
+ _e.label = 3;
19652
+ case 3:
19653
+ _b = _a.next();
19654
+ return [3 /*break*/, 1];
19655
+ case 4: return [3 /*break*/, 7];
19656
+ case 5:
19657
+ e_6_1 = _e.sent();
19658
+ e_6 = { error: e_6_1 };
19659
+ return [3 /*break*/, 7];
19660
+ case 6:
19661
+ try {
19662
+ if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
19663
+ }
19664
+ finally { if (e_6) throw e_6.error; }
19665
+ return [7 /*endfinally*/];
19666
+ case 7: return [2 /*return*/];
19667
+ }
19668
+ });
19669
+ }
19670
+ return gen();
19671
+ };
19672
+ Multimap.prototype.forEach = function (callback, thisArg) {
19673
+ var e_7, _a;
19674
+ try {
19675
+ for (var _b = __values(this.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
19676
+ var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
19677
+ callback.call(thisArg === undefined ? this : thisArg, value, key, this);
19678
+ }
19679
+ }
19680
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
19681
+ finally {
19682
+ try {
19683
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
19684
+ }
19685
+ finally { if (e_7) throw e_7.error; }
19686
+ }
19687
+ };
19688
+ Multimap.prototype[Symbol.iterator] = function () {
19689
+ return this.entries();
19690
+ };
19691
+ Multimap.prototype.asMap = function () {
19692
+ var e_8, _a;
19693
+ var ret = new Map();
19694
+ try {
19695
+ for (var _b = __values(this.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
19696
+ var key = _c.value;
19697
+ ret.set(key, this.operator.clone(this.get(key)));
19698
+ }
19699
+ }
19700
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
19701
+ finally {
19702
+ try {
19703
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
19704
+ }
19705
+ finally { if (e_8) throw e_8.error; }
19706
+ }
19707
+ return ret;
19708
+ };
19709
+ return Multimap;
19710
+ }());
19711
+ multimap.Multimap = Multimap;
19712
+
19713
+ var __extends$1 = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
19714
+ var extendStatics = function (d, b) {
19715
+ extendStatics = Object.setPrototypeOf ||
19716
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
19717
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
19718
+ return extendStatics(d, b);
19719
+ };
19720
+ return function (d, b) {
19721
+ extendStatics(d, b);
19722
+ function __() { this.constructor = d; }
19723
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
19724
+ };
19725
+ })();
19726
+ Object.defineProperty(arraymultimap, "__esModule", { value: true });
19727
+ arraymultimap.ArrayMultimap = void 0;
19728
+ var multimap_1$1 = multimap;
19729
+ var ArrayMultimap = /** @class */ (function (_super) {
19730
+ __extends$1(ArrayMultimap, _super);
19731
+ function ArrayMultimap(iterable) {
19732
+ return _super.call(this, new ArrayOperator(), iterable) || this;
19733
+ }
19734
+ Object.defineProperty(ArrayMultimap.prototype, Symbol.toStringTag, {
19735
+ get: function () {
19736
+ return "ArrayMultimap";
19737
+ },
19738
+ enumerable: false,
19739
+ configurable: true
19740
+ });
19741
+ return ArrayMultimap;
19742
+ }(multimap_1$1.Multimap));
19743
+ arraymultimap.ArrayMultimap = ArrayMultimap;
19744
+ var ArrayOperator = /** @class */ (function () {
19745
+ function ArrayOperator() {
19746
+ }
19747
+ ArrayOperator.prototype.create = function () {
19748
+ return [];
19749
+ };
19750
+ ArrayOperator.prototype.clone = function (collection) {
19751
+ return collection.slice();
19752
+ };
19753
+ ArrayOperator.prototype.add = function (value, collection) {
19754
+ collection.push(value);
19755
+ return true;
19756
+ };
19757
+ ArrayOperator.prototype.size = function (collection) {
19758
+ return collection.length;
19759
+ };
19760
+ ArrayOperator.prototype.delete = function (value, collection) {
19761
+ var index = collection.indexOf(value);
19762
+ if (index > -1) {
19763
+ collection.splice(index, 1);
19764
+ return true;
19765
+ }
19766
+ return false;
19767
+ };
19768
+ ArrayOperator.prototype.has = function (value, collection) {
19769
+ return collection.includes(value);
19770
+ };
19771
+ return ArrayOperator;
19772
+ }());
19773
+
19774
+ var setmultimap = {};
19775
+
19776
+ var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
19777
+ var extendStatics = function (d, b) {
19778
+ extendStatics = Object.setPrototypeOf ||
19779
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
19780
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
19781
+ return extendStatics(d, b);
19782
+ };
19783
+ return function (d, b) {
19784
+ extendStatics(d, b);
19785
+ function __() { this.constructor = d; }
19786
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
19787
+ };
19788
+ })();
19789
+ Object.defineProperty(setmultimap, "__esModule", { value: true });
19790
+ setmultimap.SetMultimap = void 0;
19791
+ var multimap_1 = multimap;
19792
+ var SetMultimap = /** @class */ (function (_super) {
19793
+ __extends(SetMultimap, _super);
19794
+ function SetMultimap(iterable) {
19795
+ return _super.call(this, new SetOperator(), iterable) || this;
19796
+ }
19797
+ Object.defineProperty(SetMultimap.prototype, Symbol.toStringTag, {
19798
+ get: function () {
19799
+ return "SetMultimap";
19800
+ },
19801
+ enumerable: false,
19802
+ configurable: true
19803
+ });
19804
+ return SetMultimap;
19805
+ }(multimap_1.Multimap));
19806
+ setmultimap.SetMultimap = SetMultimap;
19807
+ var SetOperator = /** @class */ (function () {
19808
+ function SetOperator() {
19809
+ }
19810
+ SetOperator.prototype.create = function () {
19811
+ return new Set();
19812
+ };
19813
+ SetOperator.prototype.clone = function (collection) {
19814
+ return new Set(collection);
19815
+ };
19816
+ SetOperator.prototype.add = function (value, collection) {
19817
+ var prev = collection.size;
19818
+ collection.add(value);
19819
+ return prev !== collection.size;
19820
+ };
19821
+ SetOperator.prototype.size = function (collection) {
19822
+ return collection.size;
19823
+ };
19824
+ SetOperator.prototype.delete = function (value, collection) {
19825
+ return collection.delete(value);
19826
+ };
19827
+ SetOperator.prototype.has = function (value, collection) {
19828
+ return collection.has(value);
19829
+ };
19830
+ return SetOperator;
19831
+ }());
19832
+
19833
+ (function (exports) {
19834
+ Object.defineProperty(exports, "__esModule", { value: true });
19835
+ exports.SetMultimap = exports.ArrayMultimap = void 0;
19836
+ var arraymultimap_1 = arraymultimap;
19837
+ Object.defineProperty(exports, "ArrayMultimap", { enumerable: true, get: function () { return arraymultimap_1.ArrayMultimap; } });
19838
+ var setmultimap_1 = setmultimap;
19839
+ Object.defineProperty(exports, "SetMultimap", { enumerable: true, get: function () { return setmultimap_1.SetMultimap; } });
19840
+ }(src));
19841
+
19391
19842
  /**
19392
19843
  * a basic texture cache object
19393
19844
  * @ignore
@@ -19398,7 +19849,8 @@ class TextureCache {
19398
19849
  * @ignore
19399
19850
  */
19400
19851
  constructor(max_size) {
19401
- this.cache = new Map();
19852
+ // cache uses an array to allow for duplicated key
19853
+ this.cache = new src.ArrayMultimap();
19402
19854
  this.tinted = new Map();
19403
19855
  this.units = new Map();
19404
19856
  this.max_size = max_size || Infinity;
@@ -19432,13 +19884,29 @@ class TextureCache {
19432
19884
  * @ignore
19433
19885
  */
19434
19886
  get(image, atlas) {
19435
- if (!this.cache.has(image)) {
19887
+ var entry;
19888
+
19889
+ if (typeof atlas === "undefined") {
19890
+ entry = this.cache.get(image)[0];
19891
+ } else {
19892
+ // manage cases where a specific atlas is specified
19893
+ this.cache.forEach((value, key) => {
19894
+ var _atlas = value.getAtlas();
19895
+ if (key === image && _atlas[0].width === atlas.framewidth && _atlas[0].height === atlas.frameheight) {
19896
+ entry = value;
19897
+ }
19898
+ });
19899
+ }
19900
+
19901
+ if (typeof entry === "undefined") {
19436
19902
  if (!atlas) {
19437
19903
  atlas = createAtlas(image.width, image.height, image.src ? getBasename(image.src) : undefined);
19438
19904
  }
19439
- this.set(image, new TextureAtlas(atlas, image, false));
19905
+ entry = new TextureAtlas(atlas, image, false);
19906
+ this.set(image, entry);
19440
19907
  }
19441
- return this.cache.get(image);
19908
+
19909
+ return entry;
19442
19910
  }
19443
19911
 
19444
19912
  /**
@@ -19483,7 +19951,7 @@ class TextureCache {
19483
19951
  "(" + width + "x" + height + ")"
19484
19952
  );
19485
19953
  }
19486
- this.cache.set(image, texture);
19954
+ return this.cache.put(image, texture);
19487
19955
  }
19488
19956
 
19489
19957
  /**
@@ -25381,6 +25849,8 @@ class TMXTileMap {
25381
25849
  if (isCollisionGroup && !settings.name && obj.body) {
25382
25850
  // configure the body accordingly
25383
25851
  obj.body.collisionType = collision.types.WORLD_SHAPE;
25852
+ // mark collision shapes as static
25853
+ obj.body.isStatic = true;
25384
25854
  }
25385
25855
 
25386
25856
  //apply group opacity value to the child objects if group are merged
@@ -31374,10 +31844,10 @@ class BasePlugin {
31374
31844
  * this can be overridden by the plugin
31375
31845
  * @public
31376
31846
  * @type {string}
31377
- * @default "10.4.0"
31847
+ * @default "10.5.0"
31378
31848
  * @name plugin.Base#version
31379
31849
  */
31380
- this.version = "10.4.0";
31850
+ this.version = "10.5.0";
31381
31851
  }
31382
31852
  }
31383
31853
 
@@ -34517,6 +34987,225 @@ class Trigger extends Renderable {
34517
34987
 
34518
34988
  }
34519
34989
 
34990
+ /**
34991
+ * @classdesc
34992
+ * A Draggable base object
34993
+ * @see DropTarget
34994
+ * @augments Renderable
34995
+ */
34996
+ class Draggable extends Renderable {
34997
+ /**
34998
+ * @param {number} x the x coordinates of the draggable object
34999
+ * @param {number} y the y coordinates of the draggable object
35000
+ * @param {number} width draggable object width
35001
+ * @param {number} height draggable object height
35002
+ */
35003
+ constructor(x, y, width, height) {
35004
+ super(x, y, width, height);
35005
+ this.isKinematic = false;
35006
+ this.dragging = false;
35007
+ this.dragId = null;
35008
+ this.grabOffset = new Vector2d(0, 0);
35009
+ this.initEvents();
35010
+ }
35011
+
35012
+ /**
35013
+ * Initializes the events the modules needs to listen to
35014
+ * It translates the pointer events to me.events
35015
+ * in order to make them pass through the system and to make
35016
+ * this module testable. Then we subscribe this module to the
35017
+ * transformed events.
35018
+ * @name initEvents
35019
+ * @memberof Draggable
35020
+ * @function
35021
+ * @private
35022
+ */
35023
+ initEvents() {
35024
+ registerPointerEvent("pointerdown", this, (e) => { emit(DRAGSTART, e, this); });
35025
+ registerPointerEvent("pointerup", this, (e) => { emit(DRAGEND, e, this); });
35026
+ registerPointerEvent("pointercancel", this, (e) => { emit(DRAGEND, e, this); });
35027
+ on(POINTERMOVE, this.dragMove.bind(this));
35028
+ on(DRAGSTART, (e, draggable) => {
35029
+ if (draggable === this) {
35030
+ this.dragStart(e);
35031
+ }
35032
+ });
35033
+ on(DRAGEND, (e, draggable) => {
35034
+ if (draggable === this) {
35035
+ this.dragEnd(e);
35036
+ }
35037
+ });
35038
+ }
35039
+
35040
+ /**
35041
+ * Gets called when the user starts dragging the entity
35042
+ * @name dragStart
35043
+ * @memberof Draggable
35044
+ * @function
35045
+ * @param {object} e the pointer event
35046
+ * @returns {boolean} false if the object is being dragged
35047
+ */
35048
+ dragStart(e) {
35049
+ if (this.dragging === false) {
35050
+ this.dragging = true;
35051
+ this.grabOffset.set(e.gameX, e.gameY);
35052
+ this.grabOffset.sub(this.pos);
35053
+ return false;
35054
+ }
35055
+ }
35056
+
35057
+ /**
35058
+ * Gets called when the user drags this entity around
35059
+ * @name dragMove
35060
+ * @memberof Draggable
35061
+ * @function
35062
+ * @param {object} e the pointer event
35063
+ */
35064
+ dragMove(e) {
35065
+ if (this.dragging === true) {
35066
+ this.pos.set(e.gameX, e.gameY, this.pos.z); //TODO : z ?
35067
+ this.pos.sub(this.grabOffset);
35068
+ }
35069
+ }
35070
+
35071
+ /**
35072
+ * Gets called when the user stops dragging the entity
35073
+ * @name dragEnd
35074
+ * @memberof Draggable
35075
+ * @function
35076
+ * @returns {boolean} false if the object stopped being dragged
35077
+ */
35078
+ dragEnd() {
35079
+ if (this.dragging === true) {
35080
+ this.dragging = false;
35081
+ return false;
35082
+ }
35083
+ }
35084
+
35085
+ /**
35086
+ * Destructor
35087
+ * @name destroy
35088
+ * @memberof Draggable
35089
+ * @function
35090
+ * @private
35091
+ */
35092
+ destroy() {
35093
+ off(POINTERMOVE, this.dragMove);
35094
+ off(DRAGSTART, this.dragStart);
35095
+ off(DRAGEND, this.dragEnd);
35096
+ releasePointerEvent("pointerdown", this);
35097
+ releasePointerEvent("pointerup", this);
35098
+ releasePointerEvent("pointercancel", this);
35099
+ super.destroy();
35100
+ }
35101
+ }
35102
+ /**
35103
+ * @classdesc
35104
+ * a base drop target object
35105
+ * @see Draggable
35106
+ * @augments Renderable
35107
+ */
35108
+ class DropTarget extends Renderable {
35109
+ /**
35110
+ * @param {number} x the x coordinates of the drop target
35111
+ * @param {number} y the y coordinates of the drop target
35112
+ * @param {number} width drop target width
35113
+ * @param {number} height drop target height
35114
+ */
35115
+ constructor(x, y, width, height) {
35116
+ super(x, y, width, height);
35117
+
35118
+ this.isKinematic = false;
35119
+
35120
+ /**
35121
+ * constant for the overlaps method
35122
+ * @public
35123
+ * @constant
35124
+ * @type {string}
35125
+ * @name CHECKMETHOD_OVERLAP
35126
+ * @memberof DropTarget
35127
+ */
35128
+ this.CHECKMETHOD_OVERLAP = "overlaps";
35129
+
35130
+ /**
35131
+ * constant for the contains method
35132
+ * @public
35133
+ * @constant
35134
+ * @type {string}
35135
+ * @name CHECKMETHOD_CONTAINS
35136
+ * @memberof DropTarget
35137
+ */
35138
+ this.CHECKMETHOD_CONTAINS = "contains";
35139
+
35140
+ /**
35141
+ * the checkmethod we want to use
35142
+ * @public
35143
+ * @constant
35144
+ * @type {string}
35145
+ * @name checkMethod
35146
+ * @default "overlaps"
35147
+ * @memberof DropTarget
35148
+ */
35149
+ this.checkMethod = this.CHECKMETHOD_OVERLAP;
35150
+
35151
+ on(DRAGEND, this.checkOnMe, this);
35152
+
35153
+ }
35154
+
35155
+ /**
35156
+ * Sets the collision method which is going to be used to check a valid drop
35157
+ * @name setCheckMethod
35158
+ * @memberof DropTarget
35159
+ * @function
35160
+ * @param {string} checkMethod the checkmethod (defaults to CHECKMETHOD_OVERLAP)
35161
+ */
35162
+ setCheckMethod(checkMethod) {
35163
+ // We can improve this check,
35164
+ // because now you can use every method in theory
35165
+ if (typeof(this.getBounds()[this.checkMethod]) === "function") {
35166
+ this.checkMethod = checkMethod;
35167
+ }
35168
+ }
35169
+
35170
+ /**
35171
+ * Checks if a dropped entity is dropped on the current entity
35172
+ * @name checkOnMe
35173
+ * @memberof DropTarget
35174
+ * @function
35175
+ * @param {object} e the triggering event
35176
+ * @param {Draggable} draggable the draggable object that is dropped
35177
+ */
35178
+ checkOnMe(e, draggable) {
35179
+ if (draggable && this.getBounds()[this.checkMethod](draggable.getBounds())) {
35180
+ // call the drop method on the current entity
35181
+ this.drop(draggable);
35182
+ }
35183
+ }
35184
+
35185
+ /**
35186
+ * Gets called when a draggable entity is dropped on the current entity
35187
+ * @name drop
35188
+ * @memberof DropTarget
35189
+ * @function
35190
+ * @param {Draggable} draggable the draggable object that is dropped
35191
+ */
35192
+ drop() {
35193
+
35194
+ }
35195
+
35196
+ /**
35197
+ * Destructor
35198
+ * @name destroy
35199
+ * @memberof DropTarget
35200
+ * @function
35201
+ * @private
35202
+ */
35203
+ destroy() {
35204
+ off(DRAGEND, this.checkOnMe);
35205
+ super.destroy();
35206
+ }
35207
+ }
35208
+
34520
35209
  /**
34521
35210
  * @classdesc
34522
35211
  * Particle Container Object.
@@ -35571,226 +36260,6 @@ class Entity extends Renderable {
35571
36260
 
35572
36261
  }
35573
36262
 
35574
- /**
35575
- * @classdesc
35576
- * Used to make a game entity draggable
35577
- * @augments Entity
35578
- */
35579
- class DraggableEntity extends Entity {
35580
- /**
35581
- * @param {number} x the x coordinates of the entity object
35582
- * @param {number} y the y coordinates of the entity object
35583
- * @param {object} settings Entity properties (see {@link Entity})
35584
- */
35585
- constructor(x, y, settings) {
35586
- super(x, y, settings);
35587
- this.dragging = false;
35588
- this.dragId = null;
35589
- this.grabOffset = new Vector2d(0, 0);
35590
- this.onPointerEvent = registerPointerEvent;
35591
- this.removePointerEvent = releasePointerEvent;
35592
- this.initEvents();
35593
- }
35594
-
35595
- /**
35596
- * Initializes the events the modules needs to listen to
35597
- * It translates the pointer events to me.events
35598
- * in order to make them pass through the system and to make
35599
- * this module testable. Then we subscribe this module to the
35600
- * transformed events.
35601
- * @name initEvents
35602
- * @memberof DraggableEntity
35603
- * @function
35604
- */
35605
- initEvents() {
35606
- /**
35607
- * @ignore
35608
- */
35609
- this.mouseDown = function (e) {
35610
- this.translatePointerEvent(e, DRAGSTART);
35611
- };
35612
- /**
35613
- * @ignore
35614
- */
35615
- this.mouseUp = function (e) {
35616
- this.translatePointerEvent(e, DRAGEND);
35617
- };
35618
- this.onPointerEvent("pointerdown", this, this.mouseDown.bind(this));
35619
- this.onPointerEvent("pointerup", this, this.mouseUp.bind(this));
35620
- this.onPointerEvent("pointercancel", this, this.mouseUp.bind(this));
35621
- on(POINTERMOVE, this.dragMove, this);
35622
- on(DRAGSTART, this.dragStart, this);
35623
- on(DRAGEND, this.dragEnd, this);
35624
- }
35625
-
35626
- /**
35627
- * Translates a pointer event to a me.event
35628
- * @name translatePointerEvent
35629
- * @memberof DraggableEntity
35630
- * @function
35631
- * @param {object} e the pointer event you want to translate
35632
- * @param {string} translation the me.event you want to translate the event to
35633
- */
35634
- translatePointerEvent(e, translation) {
35635
- emit(translation, e);
35636
- }
35637
-
35638
- /**
35639
- * Gets called when the user starts dragging the entity
35640
- * @name dragStart
35641
- * @memberof DraggableEntity
35642
- * @function
35643
- * @param {object} e the pointer event
35644
- * @returns {boolean} false if the object is being dragged
35645
- */
35646
- dragStart(e) {
35647
- if (this.dragging === false) {
35648
- this.dragging = true;
35649
- this.grabOffset.set(e.gameX, e.gameY);
35650
- this.grabOffset.sub(this.pos);
35651
- return false;
35652
- }
35653
- }
35654
-
35655
- /**
35656
- * Gets called when the user drags this entity around
35657
- * @name dragMove
35658
- * @memberof DraggableEntity
35659
- * @function
35660
- * @param {object} e the pointer event
35661
- */
35662
- dragMove(e) {
35663
- if (this.dragging === true) {
35664
- this.pos.set(e.gameX, e.gameY, this.pos.z); //TODO : z ?
35665
- this.pos.sub(this.grabOffset);
35666
- }
35667
- }
35668
-
35669
- /**
35670
- * Gets called when the user stops dragging the entity
35671
- * @name dragEnd
35672
- * @memberof DraggableEntity
35673
- * @function
35674
- * @returns {boolean} false if the object stopped being dragged
35675
- */
35676
- dragEnd() {
35677
- if (this.dragging === true) {
35678
- this.dragging = false;
35679
- return false;
35680
- }
35681
- }
35682
-
35683
- /**
35684
- * Destructor
35685
- * @name destroy
35686
- * @memberof DraggableEntity
35687
- * @function
35688
- */
35689
- destroy() {
35690
- off(POINTERMOVE, this.dragMove);
35691
- off(DRAGSTART, this.dragStart);
35692
- off(DRAGEND, this.dragEnd);
35693
- this.removePointerEvent("pointerdown", this);
35694
- this.removePointerEvent("pointerup", this);
35695
- }
35696
- }
35697
-
35698
- /**
35699
- * @classdesc
35700
- * Used to make a game entity a droptarget
35701
- * @augments Entity
35702
- */
35703
- class DroptargetEntity extends Entity {
35704
- /**
35705
- * @param {number} x the x coordinates of the entity object
35706
- * @param {number} y the y coordinates of the entity object
35707
- * @param {object} settings Entity properties (see {@link Entity})
35708
- */
35709
- constructor(x, y, settings) {
35710
- super(x, y, settings);
35711
- /**
35712
- * constant for the overlaps method
35713
- * @public
35714
- * @constant
35715
- * @type {string}
35716
- * @name CHECKMETHOD_OVERLAP
35717
- * @memberof DroptargetEntity
35718
- */
35719
- this.CHECKMETHOD_OVERLAP = "overlaps";
35720
- /**
35721
- * constant for the contains method
35722
- * @public
35723
- * @constant
35724
- * @type {string}
35725
- * @name CHECKMETHOD_CONTAINS
35726
- * @memberof DroptargetEntity
35727
- */
35728
- this.CHECKMETHOD_CONTAINS = "contains";
35729
- /**
35730
- * the checkmethod we want to use
35731
- * @public
35732
- * @constant
35733
- * @type {string}
35734
- * @name checkMethod
35735
- * @memberof DroptargetEntity
35736
- */
35737
- this.checkMethod = null;
35738
- on(DRAGEND, this.checkOnMe, this);
35739
- this.checkMethod = this[this.CHECKMETHOD_OVERLAP];
35740
- }
35741
-
35742
- /**
35743
- * Sets the collision method which is going to be used to check a valid drop
35744
- * @name setCheckMethod
35745
- * @memberof DroptargetEntity
35746
- * @function
35747
- * @param {string} checkMethod the checkmethod (defaults to CHECKMETHOD_OVERLAP)
35748
- */
35749
- setCheckMethod(checkMethod) {
35750
- // We can improve this check,
35751
- // because now you can use every method in theory
35752
- if (typeof(this[checkMethod]) !== "undefined") {
35753
- this.checkMethod = this[checkMethod];
35754
- }
35755
- }
35756
-
35757
- /**
35758
- * Checks if a dropped entity is dropped on the current entity
35759
- * @name checkOnMe
35760
- * @memberof DroptargetEntity
35761
- * @function
35762
- * @param {object} e the triggering event
35763
- * @param {object} draggableEntity the draggable entity that is dropped
35764
- */
35765
- checkOnMe(e, draggableEntity) {
35766
- if (draggableEntity && this.checkMethod(draggableEntity.getBounds())) {
35767
- // call the drop method on the current entity
35768
- this.drop(draggableEntity);
35769
- }
35770
- }
35771
-
35772
- /**
35773
- * Gets called when a draggable entity is dropped on the current entity
35774
- * @name drop
35775
- * @memberof DroptargetEntity
35776
- * @function
35777
- * @param {object} draggableEntity the draggable entity that is dropped
35778
- */
35779
- drop() {
35780
-
35781
- }
35782
-
35783
- /**
35784
- * Destructor
35785
- * @name destroy
35786
- * @memberof DroptargetEntity
35787
- * @function
35788
- */
35789
- destroy() {
35790
- off(DRAGEND, this.checkOnMe);
35791
- }
35792
- }
35793
-
35794
36263
  /**
35795
36264
  * placeholder for all deprecated classes and corresponding alias for backward compatibility
35796
36265
  */
@@ -35874,13 +36343,48 @@ Object.defineProperty(Renderer.prototype, "Texture", {
35874
36343
  }
35875
36344
  });
35876
36345
 
35877
- var deprecated = /*#__PURE__*/Object.freeze({
35878
- __proto__: null,
35879
- warning: warning
35880
- });
36346
+
36347
+ /**
36348
+ * @classdesc
36349
+ * Used to make a game entity draggable
36350
+ * @augments Entity
36351
+ * @deprecated since 10.5.0
36352
+ * @see Draggable
36353
+ */
36354
+ class DraggableEntity extends Draggable {
36355
+ /**
36356
+ * @param {number} x the x coordinates of the draggable object
36357
+ * @param {number} y the y coordinates of the draggable object
36358
+ * @param {object} settings Entity properties (see {@link Entity})
36359
+ */
36360
+ constructor(x, y, settings) {
36361
+ warning("DraggableEntity", "Draggable", "10.5.0");
36362
+ super(x, y, settings.width, settings.height);
36363
+ }
36364
+ }
36365
+
36366
+ /**
36367
+ * @classdesc
36368
+ * Used to make a game entity a droptarget
36369
+ * @augments Entity
36370
+ * @deprecated since 10.5.0
36371
+ * @see DropTarget
36372
+ */
36373
+ class DroptargetEntity extends DropTarget {
36374
+ /**
36375
+ * @param {number} x the x coordinates of the draggable object
36376
+ * @param {number} y the y coordinates of the draggable object
36377
+ * @param {object} settings Entity properties (see {@link Entity})
36378
+ */
36379
+ constructor(x, y, settings) {
36380
+ warning("DroptargetEntity", "DropTarget", "10.5.0");
36381
+ super(x, y, settings.width, settings.height);
36382
+ }
36383
+ }
35881
36384
 
35882
36385
  // ES5 polyfills
35883
36386
 
36387
+
35884
36388
  /**
35885
36389
  * current melonJS version
35886
36390
  * @static
@@ -35888,7 +36392,7 @@ var deprecated = /*#__PURE__*/Object.freeze({
35888
36392
  * @name version
35889
36393
  * @type {string}
35890
36394
  */
35891
- const version = "10.4.0";
36395
+ const version = "10.5.0";
35892
36396
 
35893
36397
 
35894
36398
  /**
@@ -35995,4 +36499,4 @@ device$1.onReady(function () {
35995
36499
  }
35996
36500
  });
35997
36501
 
35998
- export { BitmapText, BitmapTextData, Body, Bounds$1 as Bounds, Camera2d, CanvasRenderer, Collectable, Color, ColorLayer, Container, DraggableEntity, DroptargetEntity, Ellipse, Entity, GLShader, GUI_Object, ImageLayer, Line, math as Math, Matrix2d, Matrix3d, NineSliceSprite, ObservableVector2d, ObservableVector3d, Particle, ParticleEmitter, ParticleEmitterSettings, Pointer, Polygon, QuadTree, Rect, Renderable, Renderer, Sprite, Stage, TMXHexagonalRenderer, TMXIsometricRenderer, TMXLayer, TMXOrthogonalRenderer, TMXRenderer, TMXStaggeredRenderer, TMXTileMap, TMXTileset, TMXTilesetGroup, Text, TextureAtlas, Tile, Trigger, Tween, Vector2d, Vector3d, WebGLCompositor, WebGLRenderer, World, audio, boot, collision, deprecated, device$1 as device, event, game, initialized, input, level, loader, plugin, plugins, pool, save, skipAutoInit, state, timer$1 as timer, utils, version, video };
36502
+ export { BitmapText, BitmapTextData, Body, Bounds$1 as Bounds, Camera2d, CanvasRenderer, Collectable, Color, ColorLayer, Container, Draggable, DraggableEntity, DropTarget, DroptargetEntity, Ellipse, Entity, GLShader, GUI_Object, ImageLayer, Line, math as Math, Matrix2d, Matrix3d, NineSliceSprite, ObservableVector2d, ObservableVector3d, Particle, ParticleEmitter, ParticleEmitterSettings, Pointer, Polygon, QuadTree, Rect, Renderable, Renderer, Sprite, Stage, TMXHexagonalRenderer, TMXIsometricRenderer, TMXLayer, TMXOrthogonalRenderer, TMXRenderer, TMXStaggeredRenderer, TMXTileMap, TMXTileset, TMXTilesetGroup, Text, TextureAtlas, Tile, Trigger, Tween, Vector2d, Vector3d, WebGLCompositor, WebGLRenderer, World, audio, boot, collision, device$1 as device, event, game, initialized, input, level, loader, plugin, plugins, pool, save, skipAutoInit, state, timer$1 as timer, utils, version, video, warning };