melonjs 14.0.2 → 14.1.1

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 (219) hide show
  1. package/README.md +2 -0
  2. package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +10 -0
  3. package/dist/melonjs.mjs/_virtual/arraymultimap.js +10 -0
  4. package/dist/melonjs.mjs/_virtual/earcut.js +10 -0
  5. package/dist/melonjs.mjs/_virtual/howler.js +10 -0
  6. package/dist/melonjs.mjs/_virtual/index.js +10 -0
  7. package/dist/melonjs.mjs/_virtual/index2.js +10 -0
  8. package/dist/melonjs.mjs/_virtual/multimap.js +10 -0
  9. package/dist/melonjs.mjs/_virtual/setmultimap.js +10 -0
  10. package/dist/melonjs.mjs/application/application.js +238 -0
  11. package/dist/melonjs.mjs/audio/audio.js +536 -0
  12. package/dist/melonjs.mjs/camera/camera2d.js +731 -0
  13. package/dist/melonjs.mjs/entity/entity.js +247 -0
  14. package/dist/melonjs.mjs/game.js +29 -0
  15. package/dist/melonjs.mjs/geometries/ellipse.js +274 -0
  16. package/dist/melonjs.mjs/geometries/line.js +115 -0
  17. package/dist/melonjs.mjs/geometries/path2d.js +318 -0
  18. package/dist/melonjs.mjs/geometries/point.js +88 -0
  19. package/dist/melonjs.mjs/geometries/poly.js +498 -0
  20. package/dist/melonjs.mjs/geometries/rectangle.js +374 -0
  21. package/dist/melonjs.mjs/geometries/roundrect.js +167 -0
  22. package/dist/melonjs.mjs/index.js +248 -0
  23. package/dist/melonjs.mjs/input/gamepad.js +501 -0
  24. package/dist/melonjs.mjs/input/input.js +26 -0
  25. package/dist/melonjs.mjs/input/keyboard.js +470 -0
  26. package/dist/melonjs.mjs/input/pointer.js +393 -0
  27. package/dist/melonjs.mjs/input/pointerevent.js +818 -0
  28. package/dist/melonjs.mjs/lang/deprecated.js +157 -0
  29. package/dist/melonjs.mjs/level/level.js +297 -0
  30. package/dist/melonjs.mjs/level/tiled/TMXGroup.js +141 -0
  31. package/dist/melonjs.mjs/level/tiled/TMXLayer.js +446 -0
  32. package/dist/melonjs.mjs/level/tiled/TMXObject.js +355 -0
  33. package/dist/melonjs.mjs/level/tiled/TMXTile.js +193 -0
  34. package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +636 -0
  35. package/dist/melonjs.mjs/level/tiled/TMXTileset.js +309 -0
  36. package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +81 -0
  37. package/dist/melonjs.mjs/level/tiled/TMXUtils.js +367 -0
  38. package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +504 -0
  39. package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +218 -0
  40. package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +155 -0
  41. package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +124 -0
  42. package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +107 -0
  43. package/dist/melonjs.mjs/loader/loader.js +801 -0
  44. package/dist/melonjs.mjs/loader/loadingscreen.js +120 -0
  45. package/dist/melonjs.mjs/loader/melonjs_logo.png.js +11 -0
  46. package/dist/melonjs.mjs/math/color.js +616 -0
  47. package/dist/melonjs.mjs/math/math.js +218 -0
  48. package/dist/melonjs.mjs/math/matrix2.js +501 -0
  49. package/dist/melonjs.mjs/math/matrix3.js +679 -0
  50. package/dist/melonjs.mjs/math/observable_vector2.js +469 -0
  51. package/dist/melonjs.mjs/math/observable_vector3.js +559 -0
  52. package/dist/melonjs.mjs/math/vector2.js +526 -0
  53. package/dist/melonjs.mjs/math/vector3.js +567 -0
  54. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +73 -0
  55. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +21 -0
  56. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +324 -0
  57. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +69 -0
  58. package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +691 -0
  59. package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +350 -0
  60. package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +3241 -0
  61. package/dist/melonjs.mjs/particles/emitter.js +265 -0
  62. package/dist/melonjs.mjs/particles/particle.js +186 -0
  63. package/dist/melonjs.mjs/particles/settings.js +319 -0
  64. package/dist/melonjs.mjs/physics/body.js +702 -0
  65. package/dist/melonjs.mjs/physics/bounds.js +459 -0
  66. package/dist/melonjs.mjs/physics/collision.js +132 -0
  67. package/dist/melonjs.mjs/physics/detector.js +194 -0
  68. package/dist/melonjs.mjs/physics/quadtree.js +394 -0
  69. package/dist/melonjs.mjs/physics/response.js +57 -0
  70. package/dist/melonjs.mjs/physics/sat.js +483 -0
  71. package/dist/melonjs.mjs/physics/world.js +219 -0
  72. package/dist/melonjs.mjs/plugin/plugin.js +141 -0
  73. package/dist/melonjs.mjs/renderable/collectable.js +60 -0
  74. package/dist/melonjs.mjs/renderable/colorlayer.js +78 -0
  75. package/dist/melonjs.mjs/renderable/container.js +1016 -0
  76. package/dist/melonjs.mjs/renderable/dragndrop.js +224 -0
  77. package/dist/melonjs.mjs/renderable/imagelayer.js +305 -0
  78. package/dist/melonjs.mjs/renderable/light2d.js +155 -0
  79. package/dist/melonjs.mjs/renderable/nineslicesprite.js +246 -0
  80. package/dist/melonjs.mjs/renderable/renderable.js +781 -0
  81. package/dist/melonjs.mjs/renderable/sprite.js +653 -0
  82. package/dist/melonjs.mjs/renderable/trigger.js +156 -0
  83. package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +212 -0
  84. package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +225 -0
  85. package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +127 -0
  86. package/dist/melonjs.mjs/state/stage.js +236 -0
  87. package/dist/melonjs.mjs/state/state.js +596 -0
  88. package/dist/melonjs.mjs/system/device.js +909 -0
  89. package/dist/melonjs.mjs/system/dom.js +78 -0
  90. package/dist/melonjs.mjs/system/event.js +537 -0
  91. package/dist/melonjs.mjs/system/platform.js +41 -0
  92. package/dist/melonjs.mjs/system/pooling.js +209 -0
  93. package/dist/melonjs.mjs/system/save.js +157 -0
  94. package/dist/melonjs.mjs/system/timer.js +286 -0
  95. package/dist/melonjs.mjs/text/bitmaptext.js +363 -0
  96. package/dist/melonjs.mjs/text/bitmaptextdata.js +198 -0
  97. package/dist/melonjs.mjs/text/glyph.js +65 -0
  98. package/dist/melonjs.mjs/text/text.js +452 -0
  99. package/dist/melonjs.mjs/text/textmetrics.js +175 -0
  100. package/dist/melonjs.mjs/text/textstyle.js +23 -0
  101. package/dist/melonjs.mjs/tweens/easing.js +336 -0
  102. package/dist/melonjs.mjs/tweens/interpolation.js +112 -0
  103. package/dist/melonjs.mjs/tweens/tween.js +479 -0
  104. package/dist/melonjs.mjs/utils/agent.js +76 -0
  105. package/dist/melonjs.mjs/utils/array.js +63 -0
  106. package/dist/melonjs.mjs/utils/file.js +42 -0
  107. package/dist/melonjs.mjs/utils/function.js +70 -0
  108. package/dist/melonjs.mjs/utils/string.js +82 -0
  109. package/dist/melonjs.mjs/utils/utils.js +173 -0
  110. package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +806 -0
  111. package/dist/melonjs.mjs/video/renderer.js +410 -0
  112. package/dist/melonjs.mjs/video/texture/atlas.js +519 -0
  113. package/dist/melonjs.mjs/video/texture/cache.js +143 -0
  114. package/dist/melonjs.mjs/video/texture/canvas_texture.js +144 -0
  115. package/dist/melonjs.mjs/video/video.js +462 -0
  116. package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +142 -0
  117. package/dist/melonjs.mjs/video/webgl/glshader.js +167 -0
  118. package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +10 -0
  119. package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +10 -0
  120. package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +10 -0
  121. package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +10 -0
  122. package/dist/melonjs.mjs/video/webgl/utils/attributes.js +25 -0
  123. package/dist/melonjs.mjs/video/webgl/utils/precision.js +20 -0
  124. package/dist/melonjs.mjs/video/webgl/utils/program.js +67 -0
  125. package/dist/melonjs.mjs/video/webgl/utils/string.js +25 -0
  126. package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +92 -0
  127. package/dist/melonjs.mjs/video/webgl/webgl_compositor.js +494 -0
  128. package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +1035 -0
  129. package/dist/melonjs.module.d.ts +1298 -1359
  130. package/dist/melonjs.module.js +2072 -3520
  131. package/package.json +21 -16
  132. package/src/application/application.js +4 -5
  133. package/src/audio/audio.js +32 -32
  134. package/src/camera/camera2d.js +32 -33
  135. package/src/entity/entity.js +18 -19
  136. package/src/geometries/ellipse.js +17 -18
  137. package/src/geometries/line.js +6 -7
  138. package/src/geometries/path2d.js +33 -34
  139. package/src/geometries/point.js +1 -2
  140. package/src/geometries/poly.js +16 -18
  141. package/src/geometries/rectangle.js +19 -20
  142. package/src/geometries/roundrect.js +9 -10
  143. package/src/input/gamepad.js +15 -15
  144. package/src/input/keyboard.js +12 -12
  145. package/src/input/pointer.js +6 -6
  146. package/src/input/pointerevent.js +12 -12
  147. package/src/lang/deprecated.js +12 -12
  148. package/src/level/level.js +25 -25
  149. package/src/level/tiled/TMXLayer.js +23 -24
  150. package/src/level/tiled/TMXTile.js +6 -7
  151. package/src/level/tiled/TMXTileMap.js +8 -10
  152. package/src/level/tiled/TMXTileset.js +3 -4
  153. package/src/level/tiled/TMXTilesetGroup.js +1 -2
  154. package/src/level/tiled/TMXUtils.js +5 -5
  155. package/src/level/tiled/renderer/TMXHexagonalRenderer.js +3 -4
  156. package/src/level/tiled/renderer/TMXIsometricRenderer.js +3 -4
  157. package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +2 -3
  158. package/src/level/tiled/renderer/TMXRenderer.js +20 -21
  159. package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -2
  160. package/src/loader/loader.js +20 -20
  161. package/src/math/color.js +21 -22
  162. package/src/math/math.js +16 -16
  163. package/src/math/matrix2.js +17 -18
  164. package/src/math/matrix3.js +26 -27
  165. package/src/math/observable_vector2.js +15 -16
  166. package/src/math/observable_vector3.js +17 -18
  167. package/src/math/vector2.js +10 -11
  168. package/src/math/vector3.js +11 -12
  169. package/src/particles/emitter.js +7 -8
  170. package/src/particles/particle.js +3 -4
  171. package/src/physics/body.js +29 -30
  172. package/src/physics/bounds.js +10 -10
  173. package/src/physics/collision.js +2 -2
  174. package/src/physics/detector.js +6 -6
  175. package/src/physics/quadtree.js +18 -23
  176. package/src/physics/sat.js +31 -31
  177. package/src/physics/world.js +6 -7
  178. package/src/plugin/plugin.js +5 -5
  179. package/src/renderable/collectable.js +4 -6
  180. package/src/renderable/colorlayer.js +6 -8
  181. package/src/renderable/container.js +25 -27
  182. package/src/renderable/dragndrop.js +14 -14
  183. package/src/renderable/imagelayer.js +14 -15
  184. package/src/renderable/light2d.js +4 -5
  185. package/src/renderable/nineslicesprite.js +17 -18
  186. package/src/renderable/renderable.js +26 -28
  187. package/src/renderable/sprite.js +29 -30
  188. package/src/renderable/trigger.js +16 -17
  189. package/src/renderable/ui/uibaseelement.js +8 -9
  190. package/src/renderable/ui/uispriteelement.js +8 -8
  191. package/src/renderable/ui/uitextbutton.js +15 -15
  192. package/src/state/stage.js +8 -9
  193. package/src/state/state.js +17 -17
  194. package/src/system/device.js +11 -11
  195. package/src/system/event.js +10 -10
  196. package/src/system/pooling.js +9 -9
  197. package/src/system/save.js +2 -2
  198. package/src/system/timer.js +10 -10
  199. package/src/text/bitmaptext.js +19 -20
  200. package/src/text/bitmaptextdata.js +3 -4
  201. package/src/text/glyph.js +1 -2
  202. package/src/text/text.js +24 -25
  203. package/src/text/textmetrics.js +9 -10
  204. package/src/tweens/tween.js +20 -21
  205. package/src/utils/agent.js +5 -5
  206. package/src/utils/array.js +4 -4
  207. package/src/utils/file.js +2 -2
  208. package/src/utils/function.js +6 -6
  209. package/src/utils/string.js +5 -5
  210. package/src/utils/utils.js +4 -4
  211. package/src/video/canvas/canvas_renderer.js +72 -73
  212. package/src/video/renderer.js +27 -28
  213. package/src/video/texture/atlas.js +22 -22
  214. package/src/video/texture/canvas_texture.js +9 -9
  215. package/src/video/video.js +17 -17
  216. package/src/video/webgl/buffer/vertex.js +1 -2
  217. package/src/video/webgl/glshader.js +12 -12
  218. package/src/video/webgl/webgl_compositor.js +42 -43
  219. package/src/video/webgl/webgl_renderer.js +76 -77
@@ -0,0 +1,479 @@
1
+ /*!
2
+ * melonJS Game Engine - v14.1.1
3
+ * http://www.melonjs.org
4
+ * melonjs is licensed under the MIT License.
5
+ * http://www.opensource.org/licenses/mit-license
6
+ * @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
7
+ */
8
+ import timer from '../system/timer.js';
9
+ import { on, STATE_RESUME, off } from '../system/event.js';
10
+ import game from '../game.js';
11
+ import { Easing } from './easing.js';
12
+ import { Interpolation } from './interpolation.js';
13
+
14
+ /*
15
+ * Tween.js - Licensed under the MIT license
16
+ * https://github.com/tweenjs/tween.js
17
+ */
18
+
19
+ /**
20
+ * @classdesc
21
+ * Javascript Tweening Engine<p>
22
+ * Super simple, fast and easy to use tweening engine which incorporates optimised Robert Penner's equation<p>
23
+ * <a href="https://github.com/sole/Tween.js">https://github.com/sole/Tween.js</a><p>
24
+ * author sole / http://soledadpenades.com<br>
25
+ * author mr.doob / http://mrdoob.com<br>
26
+ * author Robert Eisele / http://www.xarg.org<br>
27
+ * author Philippe / http://philippe.elsass.me<br>
28
+ * author Robert Penner / http://www.robertpenner.com/easing_terms_of_use.html<br>
29
+ * author Paul Lewis / http://www.aerotwist.com/<br>
30
+ * author lechecacharro<br>
31
+ * author Josh Faul / http://jocafa.com/
32
+ */
33
+ class Tween {
34
+
35
+ /**
36
+ * @param {object} object - object on which to apply the tween
37
+ * @example
38
+ * // add a tween to change the object pos.x and pos.y variable to 200 in 3 seconds
39
+ * tween = new me.Tween(myObject.pos).to({
40
+ * x: 200,
41
+ * y: 200,
42
+ * }, {
43
+ * duration: 3000,
44
+ * easing: me.Tween.Easing.Bounce.Out,
45
+ * autoStart : true
46
+ * }).onComplete(myFunc);
47
+ */
48
+ constructor ( object ) {
49
+ this.setProperties(object);
50
+ }
51
+
52
+ /**
53
+ * reset the tween object to default value
54
+ * @ignore
55
+ */
56
+ onResetEvent( object ) {
57
+ this.setProperties(object);
58
+ }
59
+
60
+ /**
61
+ * @ignore
62
+ */
63
+ setProperties(object) {
64
+ this._object = object;
65
+ this._valuesStart = {};
66
+ this._valuesEnd = {};
67
+ this._valuesStartRepeat = {};
68
+ this._duration = 1000;
69
+ this._repeat = 0;
70
+ this._yoyo = false;
71
+ this._reversed = false;
72
+ this._delayTime = 0;
73
+ this._startTime = null;
74
+ this._easingFunction = Easing.Linear.None;
75
+ this._interpolationFunction = Interpolation.Linear;
76
+ this._chainedTweens = [];
77
+ this._onStartCallback = null;
78
+ this._onStartCallbackFired = false;
79
+ this._onUpdateCallback = null;
80
+ this._onCompleteCallback = null;
81
+ // tweens are synchronized with the game update loop
82
+ this._tweenTimeTracker = game.lastUpdate;
83
+
84
+ // reset flags to default value
85
+ this.isPersistent = false;
86
+ // this is not really supported
87
+ this.updateWhenPaused = false;
88
+ // comply with the container contract
89
+ this.isRenderable = false;
90
+
91
+ // Set all starting values present on the target object
92
+ for ( var field in object ) {
93
+ if (typeof object !== "object") {
94
+ this._valuesStart[ field ] = parseFloat(object[field]);
95
+ }
96
+ }
97
+ }
98
+
99
+ /**
100
+ * @ignore
101
+ */
102
+ _resumeCallback(elapsed) {
103
+ if (this._startTime) {
104
+ this._startTime += elapsed;
105
+ }
106
+ }
107
+
108
+
109
+
110
+ /**
111
+ * subscribe to the resume event when added
112
+ * @ignore
113
+ */
114
+ onActivateEvent() {
115
+ on(STATE_RESUME, this._resumeCallback, this);
116
+ }
117
+
118
+ /**
119
+ * Unsubscribe when tween is removed
120
+ * @ignore
121
+ */
122
+ onDeactivateEvent() {
123
+ off(STATE_RESUME, this._resumeCallback);
124
+ }
125
+
126
+ /**
127
+ * object properties to be updated and duration
128
+ * @name to
129
+ * @memberof Tween
130
+ * @public
131
+ * @param {object} properties - hash of properties
132
+ * @param {object|number} [options] - object of tween properties, or a duration if a numeric value is passed
133
+ * @param {number} [options.duration] - tween duration
134
+ * @param {Tween.Easing} [options.easing] - easing function
135
+ * @param {number} [options.delay] - delay amount expressed in milliseconds
136
+ * @param {boolean} [options.yoyo] - allows the tween to bounce back to their original value when finished. To be used together with repeat to create endless loops.
137
+ * @param {number} [options.repeat] - amount of times the tween should be repeated
138
+ * @param {Tween.Interpolation} [options.interpolation] - interpolation function
139
+ * @param {boolean} [options.autoStart] - allow this tween to start automatically. Otherwise call me.Tween.start().
140
+ * @returns {Tween} this instance for object chaining
141
+ */
142
+ to( properties, options ) {
143
+
144
+ this._valuesEnd = properties;
145
+
146
+ if (typeof options !== "undefined") {
147
+ if (typeof options === "number") {
148
+ // for backward compatiblity
149
+ this._duration = options;
150
+ } else if (typeof options === "object") {
151
+ if (options.duration) { this._duration = options.duration; }
152
+ if (options.yoyo) { this.yoyo(options.yoyo); }
153
+ if (options.easing) { this.easing(options.easing); }
154
+ if (options.repeat) { this.repeat(options.repeat); }
155
+ if (options.delay) { this.delay(options.delay); }
156
+ if (options.interpolation) { this.interpolation(options.interpolation); }
157
+
158
+ if (options.autoStart) {
159
+ this.start();
160
+ }
161
+ }
162
+ }
163
+
164
+ return this;
165
+ }
166
+
167
+ /**
168
+ * start the tween
169
+ * @name start
170
+ * @memberof Tween
171
+ * @public
172
+ * @param {number} [time] - the current time when the tween was started
173
+ * @returns {Tween} this instance for object chaining
174
+ */
175
+ start( time = timer.getTime() ) {
176
+
177
+ this._onStartCallbackFired = false;
178
+
179
+ // add the tween to the object pool on start
180
+ game.world.addChild(this);
181
+
182
+ this._startTime = time + this._delayTime;
183
+
184
+ for ( var property in this._valuesEnd ) {
185
+
186
+ // check if an Array was provided as property value
187
+ if ( this._valuesEnd[ property ] instanceof Array ) {
188
+
189
+ if ( this._valuesEnd[ property ].length === 0 ) {
190
+
191
+ continue;
192
+
193
+ }
194
+
195
+ // create a local copy of the Array with the start value at the front
196
+ this._valuesEnd[ property ] = [ this._object[ property ] ].concat( this._valuesEnd[ property ] );
197
+
198
+ }
199
+
200
+ this._valuesStart[ property ] = this._object[ property ];
201
+
202
+ if ( ( this._valuesStart[ property ] instanceof Array ) === false ) {
203
+ this._valuesStart[ property ] *= 1.0; // Ensures we're using numbers, not strings
204
+ }
205
+
206
+ this._valuesStartRepeat[ property ] = this._valuesStart[ property ] || 0;
207
+
208
+ }
209
+
210
+ return this;
211
+ }
212
+
213
+ /**
214
+ * stop the tween
215
+ * @name stop
216
+ * @memberof Tween
217
+ * @public
218
+ * @returns {Tween} this instance for object chaining
219
+ */
220
+ stop() {
221
+ // remove the tween from the world container
222
+ game.world.removeChildNow(this);
223
+ return this;
224
+ }
225
+
226
+ /**
227
+ * delay the tween
228
+ * @name delay
229
+ * @memberof Tween
230
+ * @public
231
+ * @param {number} amount - delay amount expressed in milliseconds
232
+ * @returns {Tween} this instance for object chaining
233
+ */
234
+ delay( amount ) {
235
+
236
+ this._delayTime = amount;
237
+ return this;
238
+
239
+ }
240
+
241
+ /**
242
+ * Repeat the tween
243
+ * @name repeat
244
+ * @memberof Tween
245
+ * @public
246
+ * @param {number} times - amount of times the tween should be repeated
247
+ * @returns {Tween} this instance for object chaining
248
+ */
249
+ repeat( times ) {
250
+
251
+ this._repeat = times;
252
+ return this;
253
+
254
+ }
255
+
256
+ /**
257
+ * Allows the tween to bounce back to their original value when finished.
258
+ * To be used together with repeat to create endless loops.
259
+ * @name yoyo
260
+ * @memberof Tween
261
+ * @public
262
+ * @see Tween#repeat
263
+ * @param {boolean} yoyo
264
+ * @returns {Tween} this instance for object chaining
265
+ */
266
+ yoyo( yoyo ) {
267
+
268
+ this._yoyo = yoyo;
269
+ return this;
270
+
271
+ }
272
+
273
+ /**
274
+ * set the easing function
275
+ * @name easing
276
+ * @memberof Tween
277
+ * @public
278
+ * @param {Tween.Easing} easing - easing function
279
+ * @returns {Tween} this instance for object chaining
280
+ */
281
+ easing( easing ) {
282
+ if (typeof easing !== "function") {
283
+ throw new Error("invalid easing function for me.Tween.easing()");
284
+ }
285
+ this._easingFunction = easing;
286
+ return this;
287
+ }
288
+
289
+ /**
290
+ * set the interpolation function
291
+ * @name interpolation
292
+ * @memberof Tween
293
+ * @public
294
+ * @param {Tween.Interpolation} interpolation - interpolation function
295
+ * @returns {Tween} this instance for object chaining
296
+ */
297
+ interpolation( interpolation ) {
298
+ this._interpolationFunction = interpolation;
299
+ return this;
300
+ }
301
+
302
+ /**
303
+ * chain the tween
304
+ * @name chain
305
+ * @memberof Tween
306
+ * @public
307
+ * @param {...Tween} chainedTween - Tween(s) to be chained
308
+ * @returns {Tween} this instance for object chaining
309
+ */
310
+ chain() {
311
+ this._chainedTweens = arguments;
312
+ return this;
313
+ }
314
+
315
+ /**
316
+ * onStart callback
317
+ * @name onStart
318
+ * @memberof Tween
319
+ * @public
320
+ * @param {Function} onStartCallback - callback
321
+ * @returns {Tween} this instance for object chaining
322
+ */
323
+ onStart( onStartCallback ) {
324
+ this._onStartCallback = onStartCallback;
325
+ return this;
326
+ }
327
+
328
+ /**
329
+ * onUpdate callback
330
+ * @name onUpdate
331
+ * @memberof Tween
332
+ * @public
333
+ * @param {Function} onUpdateCallback - callback
334
+ * @returns {Tween} this instance for object chaining
335
+ */
336
+ onUpdate( onUpdateCallback ) {
337
+ this._onUpdateCallback = onUpdateCallback;
338
+ return this;
339
+ }
340
+
341
+ /**
342
+ * onComplete callback
343
+ * @name onComplete
344
+ * @memberof Tween
345
+ * @public
346
+ * @param {Function} onCompleteCallback - callback
347
+ * @returns {Tween} this instance for object chaining
348
+ */
349
+ onComplete( onCompleteCallback ) {
350
+ this._onCompleteCallback = onCompleteCallback;
351
+ return this;
352
+ }
353
+
354
+ /** @ignore */
355
+ update( dt ) {
356
+
357
+ // the original Tween implementation expect
358
+ // a timestamp and not a time delta
359
+ this._tweenTimeTracker = (game.lastUpdate > this._tweenTimeTracker) ? game.lastUpdate : this._tweenTimeTracker + dt;
360
+ var time = this._tweenTimeTracker;
361
+
362
+ var property;
363
+
364
+ if ( time < this._startTime ) {
365
+
366
+ return true;
367
+
368
+ }
369
+
370
+ if ( this._onStartCallbackFired === false ) {
371
+
372
+ if ( this._onStartCallback !== null ) {
373
+
374
+ this._onStartCallback.call( this._object );
375
+
376
+ }
377
+
378
+ this._onStartCallbackFired = true;
379
+
380
+ }
381
+
382
+ var elapsed = ( time - this._startTime ) / this._duration;
383
+ elapsed = elapsed > 1 ? 1 : elapsed;
384
+
385
+ var value = this._easingFunction( elapsed );
386
+
387
+ for ( property in this._valuesEnd ) {
388
+
389
+ var start = this._valuesStart[ property ] || 0;
390
+ var end = this._valuesEnd[ property ];
391
+
392
+ if ( end instanceof Array ) {
393
+
394
+ this._object[ property ] = this._interpolationFunction( end, value );
395
+
396
+ } else {
397
+
398
+ // Parses relative end values with start as base (e.g.: +10, -3)
399
+ if ( typeof(end) === "string" ) {
400
+ end = start + parseFloat(end);
401
+ }
402
+
403
+ // protect against non numeric properties.
404
+ if ( typeof(end) === "number" ) {
405
+ this._object[ property ] = start + ( end - start ) * value;
406
+ }
407
+
408
+ }
409
+
410
+ }
411
+
412
+ if ( this._onUpdateCallback !== null ) {
413
+
414
+ this._onUpdateCallback.call( this._object, value );
415
+
416
+ }
417
+
418
+ if ( elapsed === 1 ) {
419
+
420
+ if ( this._repeat > 0 ) {
421
+
422
+ if ( isFinite( this._repeat ) ) {
423
+ this._repeat--;
424
+ }
425
+
426
+ // reassign starting values, restart by making startTime = now
427
+ for ( property in this._valuesStartRepeat ) {
428
+
429
+ if ( typeof( this._valuesEnd[ property ] ) === "string" ) {
430
+ this._valuesStartRepeat[ property ] = this._valuesStartRepeat[ property ] + parseFloat(this._valuesEnd[ property ]);
431
+ }
432
+
433
+ if (this._yoyo) {
434
+ var tmp = this._valuesStartRepeat[ property ];
435
+ this._valuesStartRepeat[ property ] = this._valuesEnd[ property ];
436
+ this._valuesEnd[ property ] = tmp;
437
+ }
438
+ this._valuesStart[ property ] = this._valuesStartRepeat[ property ];
439
+
440
+ }
441
+
442
+ if (this._yoyo) {
443
+ this._reversed = !this._reversed;
444
+ }
445
+
446
+ this._startTime = time + this._delayTime;
447
+
448
+ return true;
449
+
450
+ } else {
451
+ // remove the tween from the world container
452
+ game.world.removeChildNow(this);
453
+
454
+ if ( this._onCompleteCallback !== null ) {
455
+
456
+ this._onCompleteCallback.call( this._object );
457
+
458
+ }
459
+
460
+ for ( var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i ++ ) {
461
+
462
+ this._chainedTweens[ i ].start( time );
463
+
464
+ }
465
+
466
+ return false;
467
+
468
+ }
469
+
470
+ }
471
+ return true;
472
+ }
473
+
474
+ // export easing function as static class property
475
+ static get Easing() { return Easing; }
476
+ static get Interpolation() { return Interpolation; }
477
+ }
478
+
479
+ export { Tween as default };
@@ -0,0 +1,76 @@
1
+ /*!
2
+ * melonJS Game Engine - v14.1.1
3
+ * http://www.melonjs.org
4
+ * melonjs is licensed under the MIT License.
5
+ * http://www.opensource.org/licenses/mit-license
6
+ * @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
7
+ */
8
+ import { capitalize } from './string.js';
9
+
10
+ /**
11
+ * a collection of utility functons to ease porting between different user agents.
12
+ * @namespace utils.agent
13
+ */
14
+
15
+ /**
16
+ * Known agent vendors
17
+ * @ignore
18
+ */
19
+ const vendors = [ "ms", "MS", "moz", "webkit", "o" ];
20
+
21
+ /**
22
+ * Get a vendor-prefixed property
23
+ * @public
24
+ * @name prefixed
25
+ * @param {string} name - Property name
26
+ * @param {object} [obj=globalThis] - Object or element reference to access
27
+ * @returns {string} Value of property
28
+ * @memberof utils.agent
29
+ */
30
+ function prefixed(name, obj) {
31
+ obj = obj || globalThis;
32
+ if (name in obj) {
33
+ return obj[name];
34
+ }
35
+
36
+ var uc_name = capitalize(name);
37
+
38
+ var result;
39
+ vendors.some((vendor) => {
40
+ var name = vendor + uc_name;
41
+ return (result = (name in obj) ? obj[name] : undefined);
42
+ });
43
+ return result;
44
+ }
45
+
46
+ /**
47
+ * Set a vendor-prefixed property
48
+ * @public
49
+ * @name setPrefixed
50
+ * @param {string} name - Property name
51
+ * @param {string} value - Property value
52
+ * @param {object} [obj=globalThis] - Object or element reference to access
53
+ * @returns {boolean} true if one of the vendor-prefixed property was found
54
+ * @memberof utils.agent
55
+ */
56
+ function setPrefixed(name, value, obj) {
57
+ obj = obj || globalThis;
58
+ if (name in obj) {
59
+ obj[name] = value;
60
+ return;
61
+ }
62
+
63
+ var uc_name = capitalize(name);
64
+
65
+ vendors.some((vendor) => {
66
+ var name = vendor + uc_name;
67
+ if (name in obj) {
68
+ obj[name] = value;
69
+ return true;
70
+ }
71
+ });
72
+
73
+ return false;
74
+ }
75
+
76
+ export { prefixed, setPrefixed };
@@ -0,0 +1,63 @@
1
+ /*!
2
+ * melonJS Game Engine - v14.1.1
3
+ * http://www.melonjs.org
4
+ * melonjs is licensed under the MIT License.
5
+ * http://www.opensource.org/licenses/mit-license
6
+ * @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
7
+ */
8
+ import { random as random$1, weightedRandom as weightedRandom$1 } from '../math/math.js';
9
+
10
+ /**
11
+ * a collection of array utility functions
12
+ * @namespace utils.array
13
+ */
14
+
15
+ /**
16
+ * Remove the specified object from the given Array
17
+ * @public
18
+ * @memberof utils.array
19
+ * @name remove
20
+ * @param {Array} arr - array from which to remove an object
21
+ * @param {object} obj - to be removed
22
+ * @returns {Array} the modified Array
23
+ * var arr = [ "foo", "bar", "baz" ];
24
+ * // remove "foo" from the array
25
+ * me.utils.array.remove(arr, "foo");
26
+ */
27
+ function remove(arr, obj) {
28
+ var i = Array.prototype.indexOf.call(arr, obj);
29
+ if (i !== -1) {
30
+ Array.prototype.splice.call(arr, i, 1);
31
+ }
32
+ return arr;
33
+ }
34
+
35
+ /**
36
+ * return a random array element
37
+ * @public
38
+ * @memberof utils.array
39
+ * @name random
40
+ * @param {Array} arr - array to pick a element
41
+ * @returns {any} random member of array
42
+ * @example
43
+ * // Select a random array element
44
+ * var arr = [ "foo", "bar", "baz" ];
45
+ * console.log(me.utils.array.random(arr));
46
+ */
47
+ function random(arr) {
48
+ return arr[random$1(0, arr.length)];
49
+ }
50
+
51
+ /**
52
+ * return a weighted random array element, favoring the earlier entries
53
+ * @public
54
+ * @memberof utils.array
55
+ * @name weightedRandom
56
+ * @param {Array} arr - array to pick a element
57
+ * @returns {any} random member of array
58
+ */
59
+ function weightedRandom(arr) {
60
+ return arr[weightedRandom$1(0, arr.length)];
61
+ }
62
+
63
+ export { random, remove, weightedRandom };
@@ -0,0 +1,42 @@
1
+ /*!
2
+ * melonJS Game Engine - v14.1.1
3
+ * http://www.melonjs.org
4
+ * melonjs is licensed under the MIT License.
5
+ * http://www.opensource.org/licenses/mit-license
6
+ * @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
7
+ */
8
+ /**
9
+ * a collection of file utility functions
10
+ * @namespace utils.file
11
+ */
12
+
13
+ // regexp to deal with file name & path
14
+ const REMOVE_PATH = /^.*(\\|\/|\:)/;
15
+ const REMOVE_EXT = /\.[^\.]*$/;
16
+
17
+
18
+ /**
19
+ * return the base name of the file without path info
20
+ * @public
21
+ * @memberof utils.file
22
+ * @name getBasename
23
+ * @param {string} path- - path containing the filename
24
+ * @returns {string} the base name without path information.
25
+ */
26
+ function getBasename(path) {
27
+ return path.replace(REMOVE_PATH, "").replace(REMOVE_EXT, "");
28
+ }
29
+
30
+ /**
31
+ * return the extension of the file in the given path
32
+ * @public
33
+ * @memberof utils.file
34
+ * @name getExtension
35
+ * @param {string} path- - path containing the filename
36
+ * @returns {string} filename extension.
37
+ */
38
+ function getExtension(path) {
39
+ return path.substring(path.lastIndexOf(".") + 1, path.length);
40
+ }
41
+
42
+ export { getBasename, getExtension };