@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,238 @@
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 Animation from './animation';
7
+
8
+ export default class {
9
+
10
+ constructor(sprite) {
11
+ this.sprite = sprite;
12
+ this.game = sprite.game;
13
+ this.currentFrame = null;
14
+ this.currentAnim = null;
15
+ this.updateIfVisible = true;
16
+ this.isLoaded = false;
17
+ this._frameData = null;
18
+ this._anims = {};
19
+ this._outputFrames = [];
20
+ }
21
+
22
+ destroy() {
23
+ const keys = Object.keys(this._anims);
24
+ for (let i = 0; i < keys.length; i += 1) {
25
+ this._anims[keys[i]].destroy();
26
+ }
27
+ this._anims = {};
28
+ this._outputFrames = [];
29
+ this._frameData = null;
30
+ this.currentAnim = null;
31
+ this.currentFrame = null;
32
+ this.sprite = null;
33
+ this.game = null;
34
+ }
35
+
36
+ loadFrameData(frameData, frame) {
37
+ if (!frameData) {
38
+ return false;
39
+ }
40
+ if (this.isLoaded) {
41
+ // We need to update the frameData that the animations are using
42
+ const keys = Object.keys(this._anims);
43
+ for (let i = 0; i < keys.length; i += 1) {
44
+ const anim = keys[i];
45
+ this._anims[anim].updateFrameData(frameData);
46
+ }
47
+ }
48
+ this._frameData = frameData;
49
+ if (frame === undefined || frame === null) {
50
+ this.frame = 0;
51
+ } else if (typeof frame === 'string') {
52
+ this.frameName = frame;
53
+ } else {
54
+ this.frame = frame;
55
+ }
56
+ this.isLoaded = true;
57
+ return true;
58
+ }
59
+
60
+ copyFrameData(frameData, frame) {
61
+ this._frameData = frameData.clone();
62
+ if (this.isLoaded) {
63
+ // We need to update the frameData that the animations are using
64
+ const keys = Object.keys(this._anims);
65
+ for (let i = 0; i < keys.length; i += 1) {
66
+ const anim = keys[i];
67
+ this._anims[anim].updateFrameData(this._frameData);
68
+ }
69
+ }
70
+ if (frame === undefined || frame === null) {
71
+ this.frame = 0;
72
+ } else if (typeof frame === 'string') {
73
+ this.frameName = frame;
74
+ } else {
75
+ this.frame = frame;
76
+ }
77
+ this.isLoaded = true;
78
+ return true;
79
+ }
80
+
81
+ add(name, frameList, frameRate = 60, loop = false, useNumericIndex = undefined) {
82
+ const frames = frameList || [];
83
+ // If they didn't set the useNumericIndex then let's at least try and guess it
84
+ if (useNumericIndex === undefined) {
85
+ if (frames && typeof frames[0] === 'number') {
86
+ useNumericIndex = true;
87
+ } else {
88
+ useNumericIndex = false;
89
+ }
90
+ }
91
+ this._outputFrames = [];
92
+ this._frameData.getFrameIndexes(frames, useNumericIndex, this._outputFrames);
93
+ this._anims[name] = new Animation(this.game, this.sprite, name, this._frameData, this._outputFrames, frameRate, loop);
94
+ this.currentAnim = this._anims[name];
95
+ if (this.sprite.tilingTexture) {
96
+ this.sprite.refreshTexture = true;
97
+ }
98
+ return this._anims[name];
99
+ }
100
+
101
+ validateFrames(frames, useNumericIndex = false) {
102
+ for (let i = 0; i < frames.length; i += 1) {
103
+ if (useNumericIndex === true) {
104
+ if (frames[i] > this._frameData.total) {
105
+ return false;
106
+ }
107
+ } else if (this._frameData.checkFrameName(frames[i]) === false) {
108
+ return false;
109
+ }
110
+ }
111
+ return true;
112
+ }
113
+
114
+ play(name, frameRate, loop, killOnComplete) {
115
+ if (this._anims[name]) {
116
+ if (this.currentAnim === this._anims[name]) {
117
+ if (this.currentAnim.isPlaying === false) {
118
+ this.currentAnim.paused = false;
119
+ return this.currentAnim.play(frameRate, loop, killOnComplete);
120
+ }
121
+ return this.currentAnim;
122
+ }
123
+ if (this.currentAnim && this.currentAnim.isPlaying) {
124
+ this.currentAnim.stop();
125
+ }
126
+ this.currentAnim = this._anims[name];
127
+ this.currentAnim.paused = false;
128
+ this.currentFrame = this.currentAnim.currentFrame;
129
+ return this.currentAnim.play(frameRate, loop, killOnComplete);
130
+ }
131
+ return null;
132
+ }
133
+
134
+ stop(name, resetFrame = false) {
135
+ if (this.currentAnim && (typeof name !== 'string' || name === this.currentAnim.name)) {
136
+ this.currentAnim.stop(resetFrame);
137
+ }
138
+ }
139
+
140
+ update() {
141
+ if (this.updateIfVisible && !this.sprite.visible) {
142
+ return false;
143
+ }
144
+ if (this.currentAnim && this.currentAnim.update()) {
145
+ this.currentFrame = this.currentAnim.currentFrame;
146
+ return true;
147
+ }
148
+ return false;
149
+ }
150
+
151
+ next(quantity) {
152
+ if (this.currentAnim) {
153
+ this.currentAnim.next(quantity);
154
+ this.currentFrame = this.currentAnim.currentFrame;
155
+ }
156
+ }
157
+
158
+ previous(quantity) {
159
+ if (this.currentAnim) {
160
+ this.currentAnim.previous(quantity);
161
+ this.currentFrame = this.currentAnim.currentFrame;
162
+ }
163
+ }
164
+
165
+ getAnimation(name) {
166
+ if (name && this._anims[name]) {
167
+ return this._anims[name];
168
+ }
169
+ return null;
170
+ }
171
+
172
+ refreshFrame() {
173
+ // TODO
174
+ console.warn('animation_manager.refreshFrame() is not implemented');
175
+ // this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
176
+ }
177
+
178
+ get frameData() {
179
+ return this._frameData;
180
+ }
181
+
182
+ get frameTotal() {
183
+ return this._frameData.total;
184
+ }
185
+
186
+ get paused() {
187
+ return this.currentAnim.isPaused;
188
+ }
189
+
190
+ set paused(value) {
191
+ this.currentAnim.paused = value;
192
+ }
193
+
194
+ get name() {
195
+ if (this.currentAnim) {
196
+ return this.currentAnim.name;
197
+ }
198
+ return null;
199
+ }
200
+
201
+ get frame() {
202
+ if (this.currentFrame) {
203
+ return this.currentFrame.index;
204
+ }
205
+ return 0;
206
+ }
207
+
208
+ set frame(value) {
209
+ if (typeof value === 'number' && this._frameData && this._frameData.getFrame(value) !== null) {
210
+ this.currentFrame = this._frameData.getFrame(value);
211
+ if (this.currentFrame) {
212
+ this.sprite.setFrame(this.currentFrame);
213
+ }
214
+ } else {
215
+ console.warn('Cannot set frame: ' + value);
216
+ }
217
+ }
218
+
219
+ get frameName() {
220
+ if (this.currentFrame) {
221
+ return this.currentFrame.name;
222
+ }
223
+ return null;
224
+ }
225
+
226
+ set frameName(value) {
227
+ if (typeof value === 'string' && this._frameData && this._frameData.getFrameByName(value) !== null) {
228
+ this.currentFrame = this._frameData.getFrameByName(value);
229
+ if (this.currentFrame) {
230
+ this._frameIndex = this.currentFrame.index;
231
+ this.sprite.setFrame(this.currentFrame);
232
+ }
233
+ } else {
234
+ console.warn('Cannot set frameName: ' + value);
235
+ }
236
+ }
237
+
238
+ }
@@ -0,0 +1,133 @@
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 Frame from './frame';
7
+ import FrameData from './frame_data';
8
+
9
+ /**
10
+ *
11
+ * @param {object} game TBD
12
+ * @param {object} key TBD
13
+ * @param {number} frameWidth TBD
14
+ * @param {number} frameHeight TBD
15
+ * @param {number} frameMax TBD
16
+ * @param {number} margin TBD
17
+ * @param {number} spacing TBD
18
+ * @returns {object} TBD
19
+ */
20
+ export function spriteSheet(game, key, frameWidth, frameHeight, frameMax, margin, spacing) {
21
+ let img = key;
22
+ if (typeof key === 'string') {
23
+ img = game.cache.getImage(key);
24
+ }
25
+ if (img === null) {
26
+ return null;
27
+ }
28
+ const width = img.width;
29
+ const height = img.height;
30
+ if (frameWidth <= 0) {
31
+ frameWidth = Math.floor(-width / Math.min(-1, frameWidth));
32
+ }
33
+ if (frameHeight <= 0) {
34
+ frameHeight = Math.floor(-height / Math.min(-1, frameHeight));
35
+ }
36
+ const row = Math.floor((width - margin) / (frameWidth + spacing));
37
+ const column = Math.floor((height - margin) / (frameHeight + spacing));
38
+ let total = row * column;
39
+ if (frameMax !== -1) {
40
+ total = frameMax;
41
+ }
42
+ // Zero or smaller than frame sizes?
43
+ if (width === 0 || height === 0 || width < frameWidth || height < frameHeight || total === 0) {
44
+ console.warn("AnimationParser.spriteSheet: '" + key + "'s width/height zero or width/height < given frameWidth/frameHeight");
45
+ return null;
46
+ }
47
+ // Let's create some frames then
48
+ const data = new FrameData();
49
+ let x = margin;
50
+ let y = margin;
51
+ for (let i = 0; i < total; i += 1) {
52
+ data.addFrame(new Frame(i, x, y, frameWidth, frameHeight, ''));
53
+ x += frameWidth + spacing;
54
+ if (x + frameWidth > width) {
55
+ x = margin;
56
+ y += frameHeight + spacing;
57
+ }
58
+ }
59
+ return data;
60
+ }
61
+
62
+ /**
63
+ *
64
+ * @param {object} game TBD
65
+ * @param {object} json TBD
66
+ * @returns {object} TBD
67
+ */
68
+ export function JSONData(game, json) {
69
+ // Malformed?
70
+ if (!json.frames) {
71
+ console.warn('AnimationParser.JSONData: Invalid Texture Atlas JSON given, missing frames array');
72
+ console.log(json);
73
+ return null;
74
+ }
75
+ // Let's create some frames then
76
+ const data = new FrameData();
77
+ // By this stage frames is a fully parsed array
78
+ const frames = json.frames;
79
+ let newFrame;
80
+ for (let i = 0; i < frames.length; i += 1) {
81
+ newFrame = data.addFrame(new Frame(i, frames[i].frame.x, frames[i].frame.y, frames[i].frame.w, frames[i].frame.h, frames[i].filename));
82
+ if (frames[i].trimmed) {
83
+ newFrame.setTrim(frames[i].trimmed, frames[i].sourceSize.w, frames[i].sourceSize.h, frames[i].spriteSourceSize.x, frames[i].spriteSourceSize.y, frames[i].spriteSourceSize.w, frames[i].spriteSourceSize.h);
84
+ }
85
+ }
86
+ return data;
87
+
88
+ }
89
+
90
+ /**
91
+ *
92
+ */
93
+ export function JSONDataPyxel() {
94
+ // TODO
95
+ console.warn('animation_parser.JSONDataPyxel() is not implemented');
96
+ }
97
+
98
+ /**
99
+ *
100
+ * @param {object} game TBD
101
+ * @param {object} json TBD
102
+ * @returns {object} TBD
103
+ */
104
+ export function JSONDataHash(game, json) {
105
+ if (!json.frames) {
106
+ console.warn('JSONDataHash: Invalid Texture Atlas JSON given, missing frames object', json);
107
+ return null;
108
+ }
109
+ // Let's create some frames then
110
+ const data = new FrameData();
111
+ // By this stage frames is a fully parsed array
112
+ const frames = json.frames;
113
+ let newFrame;
114
+ let i = 0;
115
+ const keys = Object.keys(frames);
116
+ for (let k = 0; k < keys.length; k += 1) {
117
+ const key = keys[k];
118
+ newFrame = data.addFrame(new Frame(i, frames[key].frame.x, frames[key].frame.y, frames[key].frame.w, frames[key].frame.h, key));
119
+ if (frames[key].trimmed) {
120
+ newFrame.setTrim(frames[key].trimmed, frames[key].sourceSize.w, frames[key].sourceSize.h, frames[key].spriteSourceSize.x, frames[key].spriteSourceSize.y, frames[key].spriteSourceSize.w, frames[key].spriteSourceSize.h);
121
+ }
122
+ i += 1;
123
+ }
124
+ return data;
125
+ }
126
+
127
+ /**
128
+ *
129
+ */
130
+ export function XMLData() {
131
+ // TODO
132
+ console.warn('animation_parser.XMLData() is not implemented');
133
+ }
@@ -0,0 +1,107 @@
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
+ export default class {
7
+
8
+ constructor(list = []) {
9
+ this.position = 0;
10
+ this.list = list;
11
+ }
12
+
13
+ add(item) {
14
+ if (!this.exists(item)) {
15
+ this.list.push(item);
16
+ }
17
+ return item;
18
+ }
19
+
20
+ getIndex(item) {
21
+ return this.list.indexOf(item);
22
+ }
23
+
24
+ getByKey(property, value) {
25
+ let i = this.list.length;
26
+ while (i) {
27
+ i -= 1;
28
+ if (this.list[i][property] === value) {
29
+ return this.list[i];
30
+ }
31
+ }
32
+ return null;
33
+ }
34
+
35
+ exists(item) {
36
+ return (this.list.indexOf(item) > -1);
37
+ }
38
+
39
+ reset() {
40
+ this.list.length = 0;
41
+ }
42
+
43
+ remove(item) {
44
+ const idx = this.list.indexOf(item);
45
+ if (idx > -1) {
46
+ this.list.splice(idx, 1);
47
+ return item;
48
+ }
49
+ return null;
50
+ }
51
+
52
+ setAll(key, value) {
53
+ let i = this.list.length;
54
+ while (i) {
55
+ i -= 1;
56
+ if (this.list[i]) {
57
+ this.list[i][key] = value;
58
+ }
59
+ }
60
+ }
61
+
62
+ callAll(key, ...args) {
63
+ let i = this.list.length;
64
+ while (i) {
65
+ i -= 1;
66
+ if (this.list[i] && this.list[i][key]) {
67
+ this.list[i][key].apply(this.list[i], args);
68
+ }
69
+ }
70
+ }
71
+
72
+ removeAll(destroy = false) {
73
+ let i = this.list.length;
74
+ while (i) {
75
+ i -= 1;
76
+ if (this.list[i]) {
77
+ const item = this.remove(this.list[i]);
78
+ if (destroy) {
79
+ item.destroy();
80
+ }
81
+ }
82
+ }
83
+ this.position = 0;
84
+ this.list = [];
85
+ }
86
+
87
+ get total() {
88
+ return this.list.length;
89
+ }
90
+
91
+ get first() {
92
+ this.position = 0;
93
+ if (this.list.length > 0) {
94
+ return this.list[0];
95
+ }
96
+ return null;
97
+ }
98
+
99
+ get next() {
100
+ if (this.position < this.list.length) {
101
+ this.position += 1;
102
+ return this.list[this.position];
103
+ }
104
+ return null;
105
+ }
106
+
107
+ }