forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrameData.js
More file actions
182 lines (137 loc) · 3.98 KB
/
Copy pathFrameData.js
File metadata and controls
182 lines (137 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/**
* FrameData
*
* FrameData is a container for Frame objects, which are the internal representation of animation data in Phaser.
*
* @package Phaser.Animation.FrameData
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
*/
Phaser.Animation.FrameData = function () {
};
Phaser.Animation.FrameData.prototype = {
/**
* Local frame container.
* @type {Phaser.Frame[]}
* @private
*/
_frames: [],
/**
* Local frameName<->index container.
* @private
*/
_frameNames: [],
/**
* Add a new frame.
* @param frame {Frame} The frame you want to add.
* @return {Frame} The frame you just added.
*/
addFrame: function (frame) {
frame.index = this._frames.length;
this._frames.push(frame);
if (frame.name !== '') {
this._frameNames[frame.name] = frame.index;
}
return frame;
},
/**
* Get a frame by its index.
* @param index {number} Index of the frame you want to get.
* @return {Frame} The frame you want.
*/
getFrame: function (index) {
if (this._frames[index]) {
return this._frames[index];
}
return null;
},
/**
* Get a frame by its name.
* @param name {string} Name of the frame you want to get.
* @return {Frame} The frame you want.
*/
getFrameByName: function (name) {
if (this._frameNames[name] !== '') {
return this._frames[this._frameNames[name]];
}
return null;
},
/**
* Check whether there's a frame with given name.
* @param name {string} Name of the frame you want to check.
* @return {bool} True if frame with given name found, otherwise return false.
*/
checkFrameName: function (name) {
if (this._frameNames[name] == null) {
return false;
}
return true;
},
/**
* Get ranges of frames in an array.
* @param start {number} Start index of frames you want.
* @param end {number} End index of frames you want.
* @param [output] {Frame[]} result will be added into this array.
* @return {Frame[]} Ranges of specific frames in an array.
*/
getFrameRange: function (start, end, output) {
if (typeof output === "undefined") { output = []; }
for (var i = start; i <= end; i++) {
output.push(this._frames[i]);
}
return output;
},
/**
* Get all indexes of frames by giving their name.
* @param [output] {number[]} result will be added into this array.
* @return {number[]} Indexes of specific frames in an array.
*/
getFrameIndexes: function (output) {
if (typeof output === "undefined") { output = []; }
for (var i = 0; i < this._frames.length; i++) {
output.push(i);
}
return output;
},
/**
* Get the frame indexes by giving the frame names.
* @param [output] {number[]} result will be added into this array.
* @return {number[]} Names of specific frames in an array.
*/
getFrameIndexesByName: function (input) {
var output = [];
for (var i = 0; i < input.length; i++) {
if (this.getFrameByName(input[i])) {
output.push(this.getFrameByName(input[i]).index);
}
}
return output;
},
/**
* Get all frames in this frame data.
* @return {Frame[]} All the frames in an array.
*/
getAllFrames: function () {
return this._frames;
},
/**
* Get All frames with specific ranges.
* @param range {number[]} Ranges in an array.
* @return {Frame[]} All frames in an array.
*/
getFrames: function (range) {
var output = [];
for (var i = 0; i < range.length; i++) {
output.push(this._frames[i]);
}
return output;
}
};
Object.defineProperty(Phaser.Animation.FrameData.prototype, "total", {
get: function () {
return this._frames.length;
},
enumerable: true,
configurable: true
});