@vpmedia/phaser 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/phaser.cjs.LICENSE.txt +1 -1
- package/dist/phaser.js.LICENSE.txt +1 -1
- package/package.json +2 -3
- package/src/index.js +99 -0
- package/src/phaser/core/animation.js +355 -0
- package/src/phaser/core/animation_manager.js +238 -0
- package/src/phaser/core/animation_parser.js +130 -0
- package/src/phaser/core/array_set.js +108 -0
- package/src/phaser/core/cache.js +558 -0
- package/src/phaser/core/const.js +106 -0
- package/src/phaser/core/device.js +67 -0
- package/src/phaser/core/device_util.js +386 -0
- package/src/phaser/core/dom.js +207 -0
- package/src/phaser/core/event_manager.js +243 -0
- package/src/phaser/core/factory.js +74 -0
- package/src/phaser/core/frame.js +75 -0
- package/src/phaser/core/frame_data.js +84 -0
- package/src/phaser/core/frame_util.js +31 -0
- package/src/phaser/core/game.js +412 -0
- package/src/phaser/core/input.js +401 -0
- package/src/phaser/core/input_button.js +102 -0
- package/src/phaser/core/input_handler.js +687 -0
- package/src/phaser/core/input_mouse.js +289 -0
- package/src/phaser/core/input_mspointer.js +197 -0
- package/src/phaser/core/input_pointer.js +427 -0
- package/src/phaser/core/input_touch.js +157 -0
- package/src/phaser/core/loader.js +946 -0
- package/src/phaser/core/loader_parser.js +105 -0
- package/src/phaser/core/raf.js +46 -0
- package/src/phaser/core/raf_fb.js +75 -0
- package/src/phaser/core/raf_to.js +34 -0
- package/src/phaser/core/scale_manager.js +806 -0
- package/src/phaser/core/scene.js +66 -0
- package/src/phaser/core/scene_manager.js +310 -0
- package/src/phaser/core/signal.js +175 -0
- package/src/phaser/core/signal_binding.js +69 -0
- package/src/phaser/core/sound.js +538 -0
- package/src/phaser/core/sound_manager.js +365 -0
- package/src/phaser/core/stage.js +108 -0
- package/src/phaser/core/time.js +203 -0
- package/src/phaser/core/timer.js +276 -0
- package/src/phaser/core/timer_event.js +21 -0
- package/src/phaser/core/tween.js +329 -0
- package/src/phaser/core/tween_data.js +258 -0
- package/src/phaser/core/tween_easing.js +316 -0
- package/src/phaser/core/tween_manager.js +185 -0
- package/src/phaser/core/world.js +18 -0
- package/src/phaser/display/bitmap_text.js +322 -0
- package/src/phaser/display/button.js +194 -0
- package/src/phaser/display/canvas/buffer.js +36 -0
- package/src/phaser/display/canvas/graphics.js +227 -0
- package/src/phaser/display/canvas/masker.js +39 -0
- package/src/phaser/display/canvas/pool.js +121 -0
- package/src/phaser/display/canvas/renderer.js +123 -0
- package/src/phaser/display/canvas/tinter.js +141 -0
- package/src/phaser/display/canvas/util.js +151 -0
- package/src/phaser/display/display_object.js +597 -0
- package/src/phaser/display/graphics.js +723 -0
- package/src/phaser/display/graphics_data.js +27 -0
- package/src/phaser/display/graphics_data_util.js +14 -0
- package/src/phaser/display/group.js +227 -0
- package/src/phaser/display/image.js +288 -0
- package/src/phaser/display/sprite_batch.js +15 -0
- package/src/phaser/display/sprite_util.js +248 -0
- package/src/phaser/display/text.js +1089 -0
- package/src/phaser/display/webgl/abstract_filter.js +25 -0
- package/src/phaser/display/webgl/base_texture.js +68 -0
- package/src/phaser/display/webgl/blend_manager.js +35 -0
- package/src/phaser/display/webgl/earcut.js +647 -0
- package/src/phaser/display/webgl/earcut_node.js +28 -0
- package/src/phaser/display/webgl/fast_sprite_batch.js +242 -0
- package/src/phaser/display/webgl/filter_manager.js +46 -0
- package/src/phaser/display/webgl/filter_texture.js +61 -0
- package/src/phaser/display/webgl/graphics.js +618 -0
- package/src/phaser/display/webgl/graphics_data.js +42 -0
- package/src/phaser/display/webgl/mask_manager.js +36 -0
- package/src/phaser/display/webgl/render_texture.js +81 -0
- package/src/phaser/display/webgl/renderer.js +234 -0
- package/src/phaser/display/webgl/shader/complex.js +74 -0
- package/src/phaser/display/webgl/shader/fast.js +97 -0
- package/src/phaser/display/webgl/shader/normal.js +225 -0
- package/src/phaser/display/webgl/shader/primitive.js +72 -0
- package/src/phaser/display/webgl/shader/strip.js +77 -0
- package/src/phaser/display/webgl/shader_manager.js +89 -0
- package/src/phaser/display/webgl/sprite_batch.js +320 -0
- package/src/phaser/display/webgl/stencil_manager.js +170 -0
- package/src/phaser/display/webgl/texture.js +117 -0
- package/src/phaser/display/webgl/texture_util.js +32 -0
- package/src/phaser/display/webgl/util.js +74 -0
- package/src/phaser/geom/circle.js +186 -0
- package/src/phaser/geom/ellipse.js +65 -0
- package/src/phaser/geom/line.js +190 -0
- package/src/phaser/geom/matrix.js +147 -0
- package/src/phaser/geom/point.js +164 -0
- package/src/phaser/geom/polygon.js +141 -0
- package/src/phaser/geom/rectangle.js +306 -0
- package/src/phaser/geom/rounded_rectangle.js +36 -0
- package/src/phaser/geom/util/circle.js +115 -0
- package/src/phaser/geom/util/ellipse.js +30 -0
- package/src/phaser/geom/util/line.js +130 -0
- package/src/phaser/geom/util/matrix.js +48 -0
- package/src/phaser/geom/util/point.js +276 -0
- package/src/phaser/geom/util/polygon.js +24 -0
- package/src/phaser/geom/util/rectangle.js +212 -0
- package/src/phaser/geom/util/rounded_rectangle.js +28 -0
- package/src/phaser/util/math.js +279 -0
- package/src/phaser/util/string.js +26 -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,130 @@
|
|
|
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 game
|
|
12
|
+
* @param key
|
|
13
|
+
* @param frameWidth
|
|
14
|
+
* @param frameHeight
|
|
15
|
+
* @param frameMax
|
|
16
|
+
* @param margin
|
|
17
|
+
* @param spacing
|
|
18
|
+
*/
|
|
19
|
+
export function spriteSheet(game, key, frameWidth, frameHeight, frameMax, margin, spacing) {
|
|
20
|
+
let img = key;
|
|
21
|
+
if (typeof key === 'string') {
|
|
22
|
+
img = game.cache.getImage(key);
|
|
23
|
+
}
|
|
24
|
+
if (img === null) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const width = img.width;
|
|
28
|
+
const height = img.height;
|
|
29
|
+
if (frameWidth <= 0) {
|
|
30
|
+
frameWidth = Math.floor(-width / Math.min(-1, frameWidth));
|
|
31
|
+
}
|
|
32
|
+
if (frameHeight <= 0) {
|
|
33
|
+
frameHeight = Math.floor(-height / Math.min(-1, frameHeight));
|
|
34
|
+
}
|
|
35
|
+
const row = Math.floor((width - margin) / (frameWidth + spacing));
|
|
36
|
+
const column = Math.floor((height - margin) / (frameHeight + spacing));
|
|
37
|
+
let total = row * column;
|
|
38
|
+
if (frameMax !== -1) {
|
|
39
|
+
total = frameMax;
|
|
40
|
+
}
|
|
41
|
+
// Zero or smaller than frame sizes?
|
|
42
|
+
if (width === 0 || height === 0 || width < frameWidth || height < frameHeight || total === 0) {
|
|
43
|
+
console.warn("AnimationParser.spriteSheet: '" + key + "'s width/height zero or width/height < given frameWidth/frameHeight");
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
// Let's create some frames then
|
|
47
|
+
const data = new FrameData();
|
|
48
|
+
let x = margin;
|
|
49
|
+
let y = margin;
|
|
50
|
+
for (let i = 0; i < total; i += 1) {
|
|
51
|
+
data.addFrame(new Frame(i, x, y, frameWidth, frameHeight, ''));
|
|
52
|
+
x += frameWidth + spacing;
|
|
53
|
+
if (x + frameWidth > width) {
|
|
54
|
+
x = margin;
|
|
55
|
+
y += frameHeight + spacing;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return data;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
*
|
|
63
|
+
* @param game
|
|
64
|
+
* @param json
|
|
65
|
+
*/
|
|
66
|
+
export function JSONData(game, json) {
|
|
67
|
+
// Malformed?
|
|
68
|
+
if (!json.frames) {
|
|
69
|
+
console.warn('AnimationParser.JSONData: Invalid Texture Atlas JSON given, missing frames array');
|
|
70
|
+
console.log(json);
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
// Let's create some frames then
|
|
74
|
+
const data = new FrameData();
|
|
75
|
+
// By this stage frames is a fully parsed array
|
|
76
|
+
const frames = json.frames;
|
|
77
|
+
let newFrame;
|
|
78
|
+
for (let i = 0; i < frames.length; i += 1) {
|
|
79
|
+
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));
|
|
80
|
+
if (frames[i].trimmed) {
|
|
81
|
+
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);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return data;
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
*
|
|
90
|
+
*/
|
|
91
|
+
export function JSONDataPyxel() {
|
|
92
|
+
// TODO
|
|
93
|
+
console.warn('animation_parser.JSONDataPyxel() is not implemented');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
*
|
|
98
|
+
* @param game
|
|
99
|
+
* @param json
|
|
100
|
+
*/
|
|
101
|
+
export function JSONDataHash(game, json) {
|
|
102
|
+
if (!json.frames) {
|
|
103
|
+
console.warn('JSONDataHash: Invalid Texture Atlas JSON given, missing frames object', json);
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
// Let's create some frames then
|
|
107
|
+
const data = new FrameData();
|
|
108
|
+
// By this stage frames is a fully parsed array
|
|
109
|
+
const frames = json.frames;
|
|
110
|
+
let newFrame;
|
|
111
|
+
let i = 0;
|
|
112
|
+
const keys = Object.keys(frames);
|
|
113
|
+
for (let k = 0; k < keys.length; k += 1) {
|
|
114
|
+
const key = keys[k];
|
|
115
|
+
newFrame = data.addFrame(new Frame(i, frames[key].frame.x, frames[key].frame.y, frames[key].frame.w, frames[key].frame.h, key));
|
|
116
|
+
if (frames[key].trimmed) {
|
|
117
|
+
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);
|
|
118
|
+
}
|
|
119
|
+
i += 1;
|
|
120
|
+
}
|
|
121
|
+
return data;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
*
|
|
126
|
+
*/
|
|
127
|
+
export function XMLData() {
|
|
128
|
+
// TODO
|
|
129
|
+
console.warn('animation_parser.XMLData() is not implemented');
|
|
130
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
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
|
+
/* eslint-disable prefer-spread */
|
|
7
|
+
export default class {
|
|
8
|
+
|
|
9
|
+
constructor(list = []) {
|
|
10
|
+
this.position = 0;
|
|
11
|
+
this.list = list;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
add(item) {
|
|
15
|
+
if (!this.exists(item)) {
|
|
16
|
+
this.list.push(item);
|
|
17
|
+
}
|
|
18
|
+
return item;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
getIndex(item) {
|
|
22
|
+
return this.list.indexOf(item);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
getByKey(property, value) {
|
|
26
|
+
let i = this.list.length;
|
|
27
|
+
while (i) {
|
|
28
|
+
i -= 1;
|
|
29
|
+
if (this.list[i][property] === value) {
|
|
30
|
+
return this.list[i];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
exists(item) {
|
|
37
|
+
return (this.list.indexOf(item) > -1);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
reset() {
|
|
41
|
+
this.list.length = 0;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
remove(item) {
|
|
45
|
+
const idx = this.list.indexOf(item);
|
|
46
|
+
if (idx > -1) {
|
|
47
|
+
this.list.splice(idx, 1);
|
|
48
|
+
return item;
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
setAll(key, value) {
|
|
54
|
+
let i = this.list.length;
|
|
55
|
+
while (i) {
|
|
56
|
+
i -= 1;
|
|
57
|
+
if (this.list[i]) {
|
|
58
|
+
this.list[i][key] = value;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
callAll(key, ...args) {
|
|
64
|
+
let i = this.list.length;
|
|
65
|
+
while (i) {
|
|
66
|
+
i -= 1;
|
|
67
|
+
if (this.list[i] && this.list[i][key]) {
|
|
68
|
+
this.list[i][key].apply(this.list[i], args);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
removeAll(destroy = false) {
|
|
74
|
+
let i = this.list.length;
|
|
75
|
+
while (i) {
|
|
76
|
+
i -= 1;
|
|
77
|
+
if (this.list[i]) {
|
|
78
|
+
const item = this.remove(this.list[i]);
|
|
79
|
+
if (destroy) {
|
|
80
|
+
item.destroy();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
this.position = 0;
|
|
85
|
+
this.list = [];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
get total() {
|
|
89
|
+
return this.list.length;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
get first() {
|
|
93
|
+
this.position = 0;
|
|
94
|
+
if (this.list.length > 0) {
|
|
95
|
+
return this.list[0];
|
|
96
|
+
}
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
get next() {
|
|
101
|
+
if (this.position < this.list.length) {
|
|
102
|
+
this.position += 1;
|
|
103
|
+
return this.list[this.position];
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
}
|