@vpmedia/phaser 1.0.1 → 1.0.3

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 (112) hide show
  1. package/README.md +20 -3
  2. package/dist/phaser.cjs +1 -1
  3. package/dist/phaser.cjs.LICENSE.txt +1 -1
  4. package/dist/phaser.cjs.map +1 -1
  5. package/dist/phaser.js +1 -1
  6. package/dist/phaser.js.LICENSE.txt +1 -1
  7. package/dist/phaser.js.map +1 -1
  8. package/package.json +23 -17
  9. package/src/index.js +142 -0
  10. package/src/phaser/core/animation.js +355 -0
  11. package/src/phaser/core/animation_manager.js +238 -0
  12. package/src/phaser/core/animation_parser.js +133 -0
  13. package/src/phaser/core/array_set.js +107 -0
  14. package/src/phaser/core/cache.js +558 -0
  15. package/src/phaser/core/const.js +106 -0
  16. package/src/phaser/core/device.js +67 -0
  17. package/src/phaser/core/device_util.js +388 -0
  18. package/src/phaser/core/dom.js +207 -0
  19. package/src/phaser/core/event_manager.js +243 -0
  20. package/src/phaser/core/factory.js +74 -0
  21. package/src/phaser/core/frame.js +75 -0
  22. package/src/phaser/core/frame_data.js +84 -0
  23. package/src/phaser/core/frame_util.js +33 -0
  24. package/src/phaser/core/game.js +412 -0
  25. package/src/phaser/core/input.js +401 -0
  26. package/src/phaser/core/input_button.js +102 -0
  27. package/src/phaser/core/input_handler.js +687 -0
  28. package/src/phaser/core/input_mouse.js +289 -0
  29. package/src/phaser/core/input_mspointer.js +197 -0
  30. package/src/phaser/core/input_pointer.js +427 -0
  31. package/src/phaser/core/input_touch.js +157 -0
  32. package/src/phaser/core/loader.js +1057 -0
  33. package/src/phaser/core/loader_parser.js +109 -0
  34. package/src/phaser/core/raf.js +46 -0
  35. package/src/phaser/core/raf_fb.js +75 -0
  36. package/src/phaser/core/raf_to.js +34 -0
  37. package/src/phaser/core/scale_manager.js +806 -0
  38. package/src/phaser/core/scene.js +65 -0
  39. package/src/phaser/core/scene_manager.js +309 -0
  40. package/src/phaser/core/signal.js +175 -0
  41. package/src/phaser/core/signal_binding.js +69 -0
  42. package/src/phaser/core/sound.js +538 -0
  43. package/src/phaser/core/sound_manager.js +364 -0
  44. package/src/phaser/core/stage.js +108 -0
  45. package/src/phaser/core/time.js +203 -0
  46. package/src/phaser/core/timer.js +276 -0
  47. package/src/phaser/core/timer_event.js +21 -0
  48. package/src/phaser/core/tween.js +329 -0
  49. package/src/phaser/core/tween_data.js +258 -0
  50. package/src/phaser/core/tween_easing.js +341 -0
  51. package/src/phaser/core/tween_manager.js +185 -0
  52. package/src/phaser/core/world.js +18 -0
  53. package/src/phaser/display/bitmap_text.js +322 -0
  54. package/src/phaser/display/button.js +194 -0
  55. package/src/phaser/display/canvas/buffer.js +36 -0
  56. package/src/phaser/display/canvas/graphics.js +227 -0
  57. package/src/phaser/display/canvas/masker.js +39 -0
  58. package/src/phaser/display/canvas/pool.js +126 -0
  59. package/src/phaser/display/canvas/renderer.js +123 -0
  60. package/src/phaser/display/canvas/tinter.js +144 -0
  61. package/src/phaser/display/canvas/util.js +159 -0
  62. package/src/phaser/display/display_object.js +597 -0
  63. package/src/phaser/display/graphics.js +723 -0
  64. package/src/phaser/display/graphics_data.js +27 -0
  65. package/src/phaser/display/graphics_data_util.js +15 -0
  66. package/src/phaser/display/group.js +227 -0
  67. package/src/phaser/display/image.js +288 -0
  68. package/src/phaser/display/sprite_batch.js +15 -0
  69. package/src/phaser/display/sprite_util.js +250 -0
  70. package/src/phaser/display/text.js +1089 -0
  71. package/src/phaser/display/webgl/abstract_filter.js +25 -0
  72. package/src/phaser/display/webgl/base_texture.js +68 -0
  73. package/src/phaser/display/webgl/blend_manager.js +35 -0
  74. package/src/phaser/display/webgl/earcut.js +662 -0
  75. package/src/phaser/display/webgl/earcut_node.js +28 -0
  76. package/src/phaser/display/webgl/fast_sprite_batch.js +242 -0
  77. package/src/phaser/display/webgl/filter_manager.js +46 -0
  78. package/src/phaser/display/webgl/filter_texture.js +61 -0
  79. package/src/phaser/display/webgl/graphics.js +624 -0
  80. package/src/phaser/display/webgl/graphics_data.js +42 -0
  81. package/src/phaser/display/webgl/mask_manager.js +36 -0
  82. package/src/phaser/display/webgl/render_texture.js +81 -0
  83. package/src/phaser/display/webgl/renderer.js +234 -0
  84. package/src/phaser/display/webgl/shader/complex.js +74 -0
  85. package/src/phaser/display/webgl/shader/fast.js +97 -0
  86. package/src/phaser/display/webgl/shader/normal.js +225 -0
  87. package/src/phaser/display/webgl/shader/primitive.js +72 -0
  88. package/src/phaser/display/webgl/shader/strip.js +77 -0
  89. package/src/phaser/display/webgl/shader_manager.js +89 -0
  90. package/src/phaser/display/webgl/sprite_batch.js +320 -0
  91. package/src/phaser/display/webgl/stencil_manager.js +170 -0
  92. package/src/phaser/display/webgl/texture.js +117 -0
  93. package/src/phaser/display/webgl/texture_util.js +34 -0
  94. package/src/phaser/display/webgl/util.js +78 -0
  95. package/src/phaser/geom/circle.js +186 -0
  96. package/src/phaser/geom/ellipse.js +65 -0
  97. package/src/phaser/geom/line.js +190 -0
  98. package/src/phaser/geom/matrix.js +147 -0
  99. package/src/phaser/geom/point.js +164 -0
  100. package/src/phaser/geom/polygon.js +140 -0
  101. package/src/phaser/geom/rectangle.js +306 -0
  102. package/src/phaser/geom/rounded_rectangle.js +36 -0
  103. package/src/phaser/geom/util/circle.js +122 -0
  104. package/src/phaser/geom/util/ellipse.js +34 -0
  105. package/src/phaser/geom/util/line.js +135 -0
  106. package/src/phaser/geom/util/matrix.js +53 -0
  107. package/src/phaser/geom/util/point.js +296 -0
  108. package/src/phaser/geom/util/polygon.js +28 -0
  109. package/src/phaser/geom/util/rectangle.js +229 -0
  110. package/src/phaser/geom/util/rounded_rectangle.js +32 -0
  111. package/src/phaser/util/math.js +297 -0
  112. package/src/phaser/util/string.js +32 -0
@@ -0,0 +1,558 @@
1
+ /**
2
+ * @author Andras Csizmadia <andras@vpmedia.hu>
3
+ * @author Richard Davey <rich@photonstorm.com>
4
+ * @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
5
+ */
6
+ import Texture from '../display/webgl/texture';
7
+ import BaseTexture from '../display/webgl/base_texture';
8
+ import Signal from './signal';
9
+ import Frame from './frame';
10
+ import FrameData from './frame_data';
11
+ import { XMLData, JSONData, JSONDataHash, JSONDataPyxel } from './animation_parser';
12
+ import { TEXTURE_ATLAS_XML_STARLING, TEXTURE_ATLAS_JSON_PYXEL } from './const';
13
+ import { jsonBitmapFont, xmlBitmapFont } from './loader_parser';
14
+
15
+ export const CANVAS = 1;
16
+ export const IMAGE = 2;
17
+ export const TEXTURE = 3;
18
+ export const SOUND = 4;
19
+ export const TEXT = 5;
20
+ export const PHYSICS = 6;
21
+ export const TILEMAP = 7;
22
+ export const BINARY = 8;
23
+ export const BITMAPDATA = 9;
24
+ export const BITMAPFONT = 10;
25
+ export const JSON = 11;
26
+ export const XML = 12;
27
+ export const VIDEO = 13;
28
+ export const SHADER = 14;
29
+ export const RENDER_TEXTURE = 15;
30
+
31
+ export default class {
32
+
33
+ constructor(game) {
34
+ this.game = game;
35
+ this.autoResolveURL = false;
36
+ this._cache = {
37
+ canvas: {},
38
+ image: {},
39
+ texture: {},
40
+ sound: {},
41
+ video: {},
42
+ text: {},
43
+ json: {},
44
+ xml: {},
45
+ physics: {},
46
+ tilemap: {},
47
+ binary: {},
48
+ bitmapData: {},
49
+ bitmapFont: {},
50
+ shader: {},
51
+ renderTexture: {},
52
+ };
53
+ this._urlMap = {};
54
+ this._urlResolver = new Image();
55
+ this._urlTemp = null;
56
+ this.onSoundUnlock = new Signal();
57
+ this._cacheMap = [];
58
+ this._cacheMap[CANVAS] = this._cache.canvas;
59
+ this._cacheMap[IMAGE] = this._cache.image;
60
+ this._cacheMap[TEXTURE] = this._cache.texture;
61
+ this._cacheMap[SOUND] = this._cache.sound;
62
+ this._cacheMap[TEXT] = this._cache.text;
63
+ this._cacheMap[PHYSICS] = this._cache.physics;
64
+ this._cacheMap[TILEMAP] = this._cache.tilemap;
65
+ this._cacheMap[BINARY] = this._cache.binary;
66
+ this._cacheMap[BITMAPDATA] = this._cache.bitmapData;
67
+ this._cacheMap[BITMAPFONT] = this._cache.bitmapFont;
68
+ this._cacheMap[JSON] = this._cache.json;
69
+ this._cacheMap[XML] = this._cache.xml;
70
+ this._cacheMap[VIDEO] = this._cache.video;
71
+ this._cacheMap[SHADER] = this._cache.shader;
72
+ this._cacheMap[RENDER_TEXTURE] = this._cache.renderTexture;
73
+ this.addDefaultImage();
74
+ this.addMissingImage();
75
+ }
76
+
77
+ addDefaultImage() {
78
+ const img = new Image();
79
+ img.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAQMAAABJtOi3AAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAABVJREFUeF7NwIEAAAAAgKD9qdeocAMAoAABm3DkcAAAAABJRU5ErkJggg==';
80
+ const obj = this.addImage('__default', null, img);
81
+ obj.base.skipRender = true; // invisible texture
82
+ window.PhaserRegistry.CACHE_DEFAULT_IMAGE = new Texture(obj.base);
83
+ }
84
+
85
+ addMissingImage() {
86
+ const img = new Image();
87
+ img.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJ9JREFUeNq01ssOwyAMRFG46v//Mt1ESmgh+DFmE2GPOBARKb2NVjo+17PXLD8a1+pl5+A+wSgFygymWYHBb0FtsKhJDdZlncG2IzJ4ayoMDv20wTmSMzClEgbWYNTAkQ0Z+OJ+A/eWnAaR9+oxCF4Os0H8htsMUp+pwcgBBiMNnAwF8GqIgL2hAzaGFFgZauDPKABmowZ4GL369/0rwACp2yA/ttmvsQAAAABJRU5ErkJggg==';
88
+ const obj = this.addImage('__missing', null, img);
89
+ window.PhaserRegistry.CACHE_MISSING_IMAGE = new Texture(obj.base);
90
+ }
91
+
92
+ addImage(key, url, data) {
93
+ if (this.checkImageKey(key)) {
94
+ this.removeImage(key);
95
+ }
96
+ /* if (!data.complete) {
97
+ console.warn('Cache addImage %s is incomplete', key);
98
+ } */
99
+ const img = {
100
+ key,
101
+ url,
102
+ data,
103
+ base: new BaseTexture(data),
104
+ frame: new Frame(0, 0, 0, data.width, data.height, key),
105
+ frameData: new FrameData(),
106
+ };
107
+ img.frameData.addFrame(new Frame(0, 0, 0, data.width, data.height, url));
108
+ this._cache.image[key] = img;
109
+ this._resolveURL(url, img);
110
+ return img;
111
+ }
112
+
113
+ addTextureAtlas(key, url, data, atlasData, format) {
114
+ const obj = {
115
+ key,
116
+ url,
117
+ data,
118
+ base: new BaseTexture(data),
119
+ };
120
+ if (format === TEXTURE_ATLAS_XML_STARLING) {
121
+ obj.frameData = XMLData(this.game, atlasData, key);
122
+ } else if (format === TEXTURE_ATLAS_JSON_PYXEL) {
123
+ obj.frameData = JSONDataPyxel(this.game, atlasData, key);
124
+ } else if (Array.isArray(atlasData.frames)) {
125
+ // Let's just work it out from the frames array
126
+ obj.frameData = JSONData(this.game, atlasData, key);
127
+ } else {
128
+ obj.frameData = JSONDataHash(this.game, atlasData, key);
129
+ }
130
+ this._cache.image[key] = obj;
131
+ this._resolveURL(url, obj);
132
+ }
133
+
134
+ addSound(key, url, data, webAudio = true, audioTag = false) {
135
+ const decoded = audioTag;
136
+ this._cache.sound[key] = {
137
+ url,
138
+ data,
139
+ isDecoding: false,
140
+ decoded,
141
+ webAudio,
142
+ audioTag,
143
+ locked: this.game.sound.touchLocked,
144
+ };
145
+ this._resolveURL(url, this._cache.sound[key]);
146
+ }
147
+
148
+ addText(key, url, data) {
149
+ this._cache.text[key] = { url, data };
150
+ this._resolveURL(url, this._cache.text[key]);
151
+ }
152
+
153
+ addBinary(key, binaryData) {
154
+ this._cache.binary[key] = binaryData;
155
+ }
156
+
157
+ addBitmapFont(key, url, data, atlasData, atlasType, xSpacing = 0, ySpacing = 0) {
158
+ const obj = {
159
+ url,
160
+ data,
161
+ font: null,
162
+ base: new BaseTexture(data),
163
+ };
164
+ if (atlasType === 'json') {
165
+ obj.font = jsonBitmapFont(atlasData, obj.base, xSpacing, ySpacing);
166
+ } else {
167
+ obj.font = xmlBitmapFont(atlasData, obj.base, xSpacing, ySpacing);
168
+ }
169
+ this._cache.bitmapFont[key] = obj;
170
+ this._resolveURL(url, obj);
171
+ }
172
+
173
+ addJSON(key, url, data) {
174
+ this._cache.json[key] = { url, data };
175
+ this._resolveURL(url, this._cache.json[key]);
176
+ }
177
+
178
+ addXML(key, url, data) {
179
+ this._cache.xml[key] = { url, data };
180
+ this._resolveURL(url, this._cache.xml[key]);
181
+ }
182
+
183
+ // SOUND
184
+
185
+ reloadSound(key) {
186
+ const scope = this;
187
+ const sound = this.getSound(key);
188
+ if (sound) {
189
+ sound.data.src = sound.url;
190
+ sound.data.addEventListener('canplaythrough', () => scope.reloadSoundComplete(key), false);
191
+ sound.data.load();
192
+ }
193
+ }
194
+
195
+ reloadSoundComplete(key) {
196
+ const sound = this.getSound(key);
197
+ if (sound) {
198
+ sound.locked = false;
199
+ this.onSoundUnlock.dispatch(key);
200
+ }
201
+ }
202
+
203
+ updateSound(key, property, value) {
204
+ const sound = this.getSound(key);
205
+ if (sound) {
206
+ sound[property] = value;
207
+ }
208
+ }
209
+
210
+ decodedSound(key, data) {
211
+ const sound = this.getSound(key);
212
+ sound.data = data;
213
+ sound.decoded = true;
214
+ sound.isDecoding = false;
215
+ }
216
+
217
+ isSoundDecoded(key) {
218
+ const sound = this.getItem(key, SOUND, 'isSoundDecoded');
219
+ if (sound) {
220
+ return sound.decoded;
221
+ }
222
+ return null;
223
+ }
224
+
225
+ isSoundReady(key) {
226
+ const sound = this.getItem(key, SOUND, 'isSoundDecoded');
227
+ if (sound) {
228
+ return (sound.decoded && !this.game.sound.touchLocked);
229
+ }
230
+ return false;
231
+ }
232
+
233
+ // CHECK
234
+
235
+ checkKey(cache, key) {
236
+ if (this._cacheMap[cache][key]) {
237
+ return true;
238
+ }
239
+ return false;
240
+ }
241
+
242
+ checkURL(url) {
243
+ if (this._urlMap[this._resolveURL(url)]) {
244
+ return true;
245
+ }
246
+ return false;
247
+ }
248
+
249
+ checkCanvasKey(key) {
250
+ return this.checkKey(CANVAS, key);
251
+ }
252
+
253
+ checkImageKey(key) {
254
+ return this.checkKey(IMAGE, key);
255
+ }
256
+
257
+ checkTextureKey(key) {
258
+ return this.checkKey(TEXTURE, key);
259
+ }
260
+
261
+ checkSoundKey(key) {
262
+ return this.checkKey(SOUND, key);
263
+ }
264
+
265
+ checkTextKey(key) {
266
+ return this.checkKey(TEXT, key);
267
+ }
268
+
269
+ checkTilemapKey(key) {
270
+ return this.checkKey(TILEMAP, key);
271
+ }
272
+
273
+ checkBinaryKey(key) {
274
+ return this.checkKey(BINARY, key);
275
+ }
276
+
277
+ checkBitmapDataKey(key) {
278
+ return this.checkKey(BITMAPDATA, key);
279
+ }
280
+
281
+ checkBitmapFontKey(key) {
282
+ return this.checkKey(BITMAPFONT, key);
283
+ }
284
+
285
+ checkJSONKey(key) {
286
+ return this.checkKey(JSON, key);
287
+ }
288
+
289
+ checkXMLKey(key) {
290
+ return this.checkKey(XML, key);
291
+ }
292
+
293
+ // TODO video shader rendertexture physics
294
+
295
+ // GET
296
+
297
+ getItem(key, cache, method, property = null) {
298
+ if (this.checkKey(cache, key)) {
299
+ if (!property) {
300
+ return this._cacheMap[cache][key];
301
+ }
302
+ return this._cacheMap[cache][key][property];
303
+ }
304
+ return null;
305
+ }
306
+
307
+ getCanvas(key) {
308
+ return this.getItem(key, CANVAS, 'getCanvas', 'canvas');
309
+ }
310
+
311
+ getImage(key = '__default', full = false) {
312
+ let img = this.getItem(key, IMAGE, 'getImage');
313
+ if (img === null) {
314
+ img = this.getItem('__missing', IMAGE, 'getImage');
315
+ }
316
+ if (full) {
317
+ return img;
318
+ }
319
+ return img.data;
320
+ }
321
+
322
+ getTextureFrame(key) {
323
+ return this.getItem(key, TEXTURE, 'getTextureFrame', 'frame');
324
+ }
325
+
326
+ getSound(key) {
327
+ return this.getItem(key, SOUND, 'getSound');
328
+ }
329
+
330
+ getSoundData(key) {
331
+ return this.getItem(key, SOUND, 'getSoundData', 'data');
332
+ }
333
+
334
+ getText(key) {
335
+ return this.getItem(key, TEXT, 'getText', 'data');
336
+ }
337
+
338
+ getTilemapData(key) {
339
+ return this.getItem(key, TILEMAP, 'getTilemapData');
340
+ }
341
+
342
+ getBinary(key) {
343
+ return this.getItem(key, BINARY, 'getBinary');
344
+ }
345
+
346
+ getBitmapData(key) {
347
+ return this.getItem(key, BITMAPDATA, 'getBitmapData', 'data');
348
+ }
349
+
350
+ getBitmapFont(key) {
351
+ return this.getItem(key, BITMAPFONT, 'getBitmapFont');
352
+ }
353
+
354
+ getJSON(key, isClone = false) {
355
+ const data = this.getItem(key, JSON, 'getJSON', 'data');
356
+ return isClone ? JSON.parse(JSON.stringify(data)) : data;
357
+ }
358
+
359
+ getXML(key) {
360
+ return this.getItem(key, XML, 'getXML', 'data');
361
+ }
362
+
363
+ getVideo(key) {
364
+ return this.getItem(key, VIDEO, 'getVideo');
365
+ }
366
+
367
+ getShader(key) {
368
+ return this.getItem(key, SHADER, 'getShader', 'data');
369
+ }
370
+
371
+ getRenderTexture(key) {
372
+ return this.getItem(key, RENDER_TEXTURE, 'getRenderTexture');
373
+ }
374
+
375
+ // FRAME
376
+
377
+ getBaseTexture(key, cache = IMAGE) {
378
+ return this.getItem(key, cache, 'getBaseTexture', 'base');
379
+ }
380
+
381
+ getFrame(key, cache = IMAGE) {
382
+ return this.getItem(key, cache, 'getFrame', 'frame');
383
+ }
384
+
385
+ getFrameCount(key, cache = IMAGE) {
386
+ const data = this.getFrameData(key, cache);
387
+ if (data) {
388
+ return data.total;
389
+ }
390
+ return 0;
391
+ }
392
+
393
+ getFrameData(key, cache = IMAGE) {
394
+ return this.getItem(key, cache, 'getFrameData', 'frameData');
395
+ }
396
+
397
+ hasFrameData(key, cache = IMAGE) {
398
+ return (this.getItem(key, cache, '', 'frameData') !== null);
399
+ }
400
+
401
+ updateFrameData(key, frameData, cache = IMAGE) {
402
+ if (this._cacheMap[cache][key]) {
403
+ this._cacheMap[cache][key].frameData = frameData;
404
+ }
405
+ }
406
+
407
+ getFrameByIndex(key, index, cache = IMAGE) {
408
+ const data = this.getFrameData(key, cache);
409
+ if (data) {
410
+ return data.getFrame(index);
411
+ }
412
+ return null;
413
+ }
414
+
415
+ getFrameByName(key, name, cache = IMAGE) {
416
+ const data = this.getFrameData(key, cache);
417
+ if (data) {
418
+ return data.getFrameByName(name);
419
+ }
420
+ return null;
421
+ }
422
+
423
+ getURL(url) {
424
+ const resolvedURL = this._resolveURL(url);
425
+ if (resolvedURL) {
426
+ return this._urlMap[resolvedURL];
427
+ }
428
+ console.warn('Cache invalid url', resolvedURL);
429
+ return null;
430
+ }
431
+
432
+ getKeys(cache = IMAGE) {
433
+ const result = [];
434
+ if (this._cacheMap[cache]) {
435
+ const keys = Object.keys(this._cacheMap[cache]);
436
+ for (let i = 0; i < keys.length; i += 1) {
437
+ const key = keys[i];
438
+ if (key !== '__default' && key !== '__missing') {
439
+ result.push(key);
440
+ }
441
+ }
442
+ }
443
+ return result;
444
+ }
445
+
446
+ // REMOVE
447
+
448
+ removeCanvas(key) {
449
+ delete this._cache.canvas[key];
450
+ }
451
+
452
+ removeImage(key, destroyBaseTexture = true) {
453
+ const img = this.getImage(key, true);
454
+ if (destroyBaseTexture && img.base) {
455
+ img.base.destroy();
456
+ }
457
+ delete this._cache.image[key];
458
+ }
459
+
460
+ removeSound(key) {
461
+ delete this._cache.sound[key];
462
+ }
463
+
464
+ removeText(key) {
465
+ delete this._cache.text[key];
466
+ }
467
+
468
+ removePhysics(key) {
469
+ delete this._cache.physics[key];
470
+ }
471
+
472
+ removeTilemap(key) {
473
+ delete this._cache.tilemap[key];
474
+ }
475
+
476
+ removeBinary(key) {
477
+ delete this._cache.binary[key];
478
+ }
479
+
480
+ removeBitmapData(key) {
481
+ delete this._cache.bitmapData[key];
482
+ }
483
+
484
+ removeBitmapFont(key) {
485
+ delete this._cache.bitmapFont[key];
486
+ }
487
+
488
+ removeJSON(key) {
489
+ delete this._cache.json[key];
490
+ }
491
+
492
+ removeXML(key) {
493
+ delete this._cache.xml[key];
494
+ }
495
+
496
+ removeVideo(key) {
497
+ delete this._cache.video[key];
498
+ }
499
+
500
+ removeShader(key) {
501
+ delete this._cache.shader[key];
502
+ }
503
+
504
+ removeRenderTexture(key) {
505
+ delete this._cache.renderTexture[key];
506
+ }
507
+
508
+ removeSpriteSheet(key) {
509
+ delete this._cache.spriteSheet[key];
510
+ }
511
+
512
+ removeTextureAtlas(key) {
513
+ delete this._cache.atlas[key];
514
+ }
515
+
516
+ clearGLTextures() {
517
+ const keys = Object.keys(this._cache.image);
518
+ for (let i = 0; i < keys.length; i += 1) {
519
+ const key = keys[i];
520
+ this._cache.image[key].base._glTextures = [];
521
+ }
522
+ }
523
+
524
+ _resolveURL(url, data) {
525
+ if (!this.autoResolveURL) {
526
+ return null;
527
+ }
528
+ this._urlResolver.src = this.game.load.baseURL + url;
529
+ this._urlTemp = this._urlResolver.src;
530
+ // Ensure no request is actually made
531
+ this._urlResolver.src = '';
532
+ // Record the URL to the map
533
+ if (data) {
534
+ this._urlMap[this._urlTemp] = data;
535
+ }
536
+ return this._urlTemp;
537
+ }
538
+
539
+ destroy() {
540
+ for (let i = 0; i < this._cacheMap.length; i += 1) {
541
+ const cache = this._cacheMap[i];
542
+ const keys = cache ? Object.keys(cache) : [];
543
+ for (let j = 0; j < keys.length; j += 1) {
544
+ const key = keys[j];
545
+ if (key !== '__default' && key !== '__missing') {
546
+ if (cache[key].destroy) {
547
+ cache[key].destroy();
548
+ }
549
+ delete cache[key];
550
+ }
551
+ }
552
+ }
553
+ this._urlMap = null;
554
+ this._urlResolver = null;
555
+ this._urlTemp = null;
556
+ }
557
+
558
+ }
@@ -0,0 +1,106 @@
1
+ /**
2
+ * @author Andras Csizmadia <andras@vpmedia.hu>
3
+ * @author Richard Davey <rich@photonstorm.com>
4
+ * @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
5
+ */
6
+ // rectangle
7
+ export const TOP_LEFT = 0;
8
+ export const TOP_CENTER = 1;
9
+ export const TOP_RIGHT = 2;
10
+ export const LEFT_TOP = 3;
11
+ export const LEFT_CENTER = 4;
12
+ export const LEFT_BOTTOM = 5;
13
+ export const CENTER = 6;
14
+ export const RIGHT_TOP = 7;
15
+ export const RIGHT_CENTER = 8;
16
+ export const RIGHT_BOTTOM = 9;
17
+ export const BOTTOM_LEFT = 10;
18
+ export const BOTTOM_CENTER = 11;
19
+ export const BOTTOM_RIGHT = 12;
20
+ // scale modes
21
+ export const SCALE_LINEAR = 0;
22
+ export const SCALE_NEAREST = 1;
23
+ // scale manager modes
24
+ export const SCALE_EXACT_FIT = 0;
25
+ export const SCALE_OFF = 1;
26
+ export const SCALE_SHOW_ALL = 2;
27
+ export const SCALE_RESIZE = 3;
28
+ export const SCALE_USER = 4;
29
+ // times
30
+ export const TIME_MINUTE = 60000;
31
+ export const TIME_SECOND = 1000;
32
+ export const TIME_HALF = 500;
33
+ export const TIME_QUARTER = 250;
34
+ // tween statuses
35
+ export const TWEEN_PENDING = 0;
36
+ export const TWEEN_RUNNING = 1;
37
+ export const TWEEN_LOOPED = 2;
38
+ export const TWEEN_COMPLETE = 3;
39
+ // blend modes
40
+ export const BLEND_NORMAL = 0;
41
+ export const BLEND_ADD = 1;
42
+ export const BLEND_MULTIPLY = 2;
43
+ export const BLEND_SCREEN = 3;
44
+ export const BLEND_OVERLAY = 4;
45
+ export const BLEND_DARKEN = 5;
46
+ export const BLEND_LIGHTEN = 6;
47
+ export const BLEND_COLOR_DODGE = 7;
48
+ export const BLEND_COLOR_BURN = 8;
49
+ export const BLEND_HARD_LIGHT = 9;
50
+ export const BLEND_SOFT_LIGHT = 10;
51
+ export const BLEND_DIFFERENCE = 11;
52
+ export const BLEND_EXCLUSION = 12;
53
+ export const BLEND_HUE = 13;
54
+ export const BLEND_SATURATION = 14;
55
+ export const BLEND_COLOR = 15;
56
+ export const BLEND_LUMINOSITY = 16;
57
+ // render modes
58
+ export const RENDER_AUTO = 0;
59
+ export const RENDER_CANVAS = 1;
60
+ export const RENDER_WEBGL = 2;
61
+ export const RENDER_HEADLESS = 3;
62
+ // pointer modes
63
+ export const POINTER_CURSOR = 1;
64
+ export const POINTER_CONTACT = 2;
65
+ // input modes
66
+ export const MOUSE_OVERRIDES_TOUCH = 0;
67
+ export const TOUCH_OVERRIDES_MOUSE = 1;
68
+ export const MOUSE_TOUCH_COMBINE = 2;
69
+ // game objects
70
+ export const GROUP = 7;
71
+ export const SPRITE = 0;
72
+ export const SPRITE_BATCH = 17;
73
+ export const BUTTON = 1;
74
+ export const IMAGE = 2;
75
+ export const GRAPHICS = 3;
76
+ export const TEXT = 4;
77
+ export const BITMAP_TEXT = 6;
78
+ export const TILE_SPRITE = 5;
79
+ export const RENDER_TEXTURE = 8;
80
+ export const FILTER_CANVAS = 14;
81
+ export const FILTER_WEBGL = 15;
82
+ export const POINTER = 19;
83
+ export const GEOM_POLYGON = 12;
84
+ export const GEOM_RECTANGLE = 22;
85
+ export const GEOM_CIRCLE = 21;
86
+ export const GEOM_ELLIPSE = 16;
87
+ export const GEOM_ROUNDED_RECTANGLE = 26;
88
+ export const GEOM_LINE = 23;
89
+ export const GEOM_MATRIX = 24;
90
+ export const GEOM_POINT = 25;
91
+ export const BITMAP_DATA = 13; // deprecated
92
+ export const TILEMAP = 9; // deprecated
93
+ export const TILEMAP_LAYER = 10; // deprecated
94
+ export const EMITTER = 11; // deprecated
95
+ export const RETROFONT = 18; // deprecated
96
+ export const ROPE = 20; // deprecated
97
+ export const CREATURE = 27; // deprecated
98
+ export const VIDEO = 28; // deprecated
99
+ export const PENDING_ATLAS = -1;
100
+ // sprite sheet atlas
101
+ export const TEXTURE_ATLAS_JSON_ARRAY = 0;
102
+ export const TEXTURE_ATLAS_JSON_HASH = 1;
103
+ export const TEXTURE_ATLAS_XML_STARLING = 2;
104
+ export const PHYSICS_LIME_CORONA_JSON = 3; // deprecated
105
+ export const PHYSICS_PHASER_JSON = 4; // deprecated
106
+ export const TEXTURE_ATLAS_JSON_PYXEL = 5;