2013-08-06 02:14:48 +00:00
|
|
|
/// <reference path="../Game.ts" />
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
/**
|
2013-04-18 15:49:08 +00:00
|
|
|
* Phaser - FrameData
|
|
|
|
*
|
|
|
|
* FrameData is a container for Frame objects, the internal representation of animation data in Phaser.
|
2013-04-18 13:16:18 +00:00
|
|
|
*/
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
module Phaser {
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
export class FrameData {
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-05-03 11:32:39 +00:00
|
|
|
/**
|
|
|
|
* FrameData constructor
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
constructor() {
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
this._frames = [];
|
|
|
|
this._frameNames = [];
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 11:32:39 +00:00
|
|
|
/**
|
|
|
|
* Local frame container.
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
private _frames: Frame[];
|
2013-06-03 11:03:34 +00:00
|
|
|
|
2013-05-03 11:32:39 +00:00
|
|
|
/**
|
|
|
|
* Local frameName<->index container.
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
private _frameNames;
|
|
|
|
|
|
|
|
public get total(): number {
|
|
|
|
return this._frames.length;
|
|
|
|
}
|
|
|
|
|
2013-05-03 11:32:39 +00:00
|
|
|
/**
|
|
|
|
* Add a new frame.
|
2013-05-04 11:53:11 +00:00
|
|
|
* @param frame {Frame} The frame you want to add.
|
|
|
|
* @return {Frame} The frame you just added.
|
2013-05-03 11:32:39 +00:00
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public addFrame(frame: Frame): Frame {
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
frame.index = this._frames.length;
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
this._frames.push(frame);
|
2013-04-15 14:42:13 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
if (frame.name !== '')
|
|
|
|
{
|
|
|
|
this._frameNames[frame.name] = frame.index;
|
|
|
|
}
|
|
|
|
|
|
|
|
return frame;
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-15 14:42:13 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 11:32:39 +00:00
|
|
|
/**
|
|
|
|
* Get a frame by its index.
|
2013-05-04 11:53:11 +00:00
|
|
|
* @param index {number} Index of the frame you want to get.
|
|
|
|
* @return {Frame} The frame you want.
|
2013-05-03 11:32:39 +00:00
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public getFrame(index: number): Frame {
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
if (this._frames[index])
|
|
|
|
{
|
|
|
|
return this._frames[index];
|
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
return null;
|
2013-04-15 14:42:13 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-05-03 11:32:39 +00:00
|
|
|
/**
|
|
|
|
* Get a frame by its name.
|
2013-05-04 11:53:11 +00:00
|
|
|
* @param name {string} Name of the frame you want to get.
|
|
|
|
* @return {Frame} The frame you want.
|
2013-05-03 11:32:39 +00:00
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public getFrameByName(name: string): Frame {
|
2013-04-15 14:42:13 +00:00
|
|
|
|
2013-06-03 11:03:34 +00:00
|
|
|
if (this._frameNames[name] !== '')
|
2013-04-18 13:16:18 +00:00
|
|
|
{
|
|
|
|
return this._frames[this._frameNames[name]];
|
|
|
|
}
|
2013-04-15 14:42:13 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
return null;
|
2013-04-12 16:19:56 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-05-03 11:32:39 +00:00
|
|
|
/**
|
|
|
|
* Check whether there's a frame with given name.
|
2013-05-04 11:53:11 +00:00
|
|
|
* @param name {string} Name of the frame you want to check.
|
2013-05-03 11:32:39 +00:00
|
|
|
* @return {boolean} True if frame with given name found, otherwise return false.
|
|
|
|
*/
|
2013-08-08 10:34:33 +00:00
|
|
|
public checkFrameName(name: string): boolean {
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-06-25 14:35:45 +00:00
|
|
|
|
|
|
|
if (this._frameNames[name] == null)
|
2013-04-18 13:16:18 +00:00
|
|
|
{
|
2013-06-25 14:35:45 +00:00
|
|
|
return false;
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-06-25 14:35:45 +00:00
|
|
|
return true;
|
2013-04-12 16:19:56 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-05-03 11:32:39 +00:00
|
|
|
/**
|
|
|
|
* Get ranges of frames in an array.
|
2013-05-04 11:53:11 +00:00
|
|
|
* @param start {number} Start index of frames you want.
|
|
|
|
* @param end {number} End index of frames you want.
|
2013-05-04 16:18:45 +00:00
|
|
|
* @param [output] {Frame[]} result will be added into this array.
|
2013-05-04 11:53:11 +00:00
|
|
|
* @return {Frame[]} Ranges of specific frames in an array.
|
2013-05-03 11:32:39 +00:00
|
|
|
*/
|
2013-08-08 10:34:33 +00:00
|
|
|
public getFrameRange(start: number, end: number, output: Frame[] = []): Frame[] {
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
for (var i = start; i <= end; i++)
|
|
|
|
{
|
|
|
|
output.push(this._frames[i]);
|
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
return output;
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 11:32:39 +00:00
|
|
|
/**
|
|
|
|
* Get all indexes of frames by giving their name.
|
2013-05-04 16:18:45 +00:00
|
|
|
* @param [output] {number[]} result will be added into this array.
|
2013-05-04 11:53:11 +00:00
|
|
|
* @return {number[]} Indexes of specific frames in an array.
|
2013-05-03 11:32:39 +00:00
|
|
|
*/
|
2013-08-08 10:34:33 +00:00
|
|
|
public getFrameIndexes(output: number[] = []): number[] {
|
2013-04-18 13:16:18 +00:00
|
|
|
|
|
|
|
output.length = 0;
|
|
|
|
|
|
|
|
for (var i = 0; i < this._frames.length; i++)
|
|
|
|
{
|
|
|
|
output.push(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return output;
|
2013-04-12 16:19:56 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-05-03 11:32:39 +00:00
|
|
|
/**
|
2013-06-03 11:03:34 +00:00
|
|
|
* Get the frame indexes by giving the frame names.
|
2013-05-04 16:18:45 +00:00
|
|
|
* @param [output] {number[]} result will be added into this array.
|
2013-05-04 11:53:11 +00:00
|
|
|
* @return {number[]} Names of specific frames in an array.
|
2013-05-03 11:32:39 +00:00
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public getFrameIndexesByName(input: string[]): number[] {
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
var output: number[] = [];
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
for (var i = 0; i < input.length; i++)
|
|
|
|
{
|
|
|
|
if (this.getFrameByName(input[i]))
|
|
|
|
{
|
|
|
|
output.push(this.getFrameByName(input[i]).index);
|
|
|
|
}
|
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
return output;
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-05-03 11:32:39 +00:00
|
|
|
/**
|
|
|
|
* Get all frames in this frame data.
|
2013-05-04 11:53:11 +00:00
|
|
|
* @return {Frame[]} All the frames in an array.
|
2013-05-03 11:32:39 +00:00
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public getAllFrames(): Frame[] {
|
|
|
|
return this._frames;
|
2013-04-12 16:19:56 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 11:32:39 +00:00
|
|
|
/**
|
|
|
|
* Get All frames with specific ranges.
|
2013-05-04 11:53:11 +00:00
|
|
|
* @param range {number[]} Ranges in an array.
|
|
|
|
* @return {Frame[]} All frames in an array.
|
2013-05-03 11:32:39 +00:00
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public getFrames(range: number[]) {
|
|
|
|
|
|
|
|
var output: Frame[] = [];
|
|
|
|
|
|
|
|
for (var i = 0; i < range.length; i++)
|
|
|
|
{
|
|
|
|
output.push(this._frames[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return output;
|
|
|
|
|
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|