From 50480d815fd7687c320866696431baf866a378d2 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Sun, 26 Jul 2015 13:14:25 +0100 Subject: [PATCH] * Cache.getFrame has a new `cache` parameter (that defaults to the Image cache, but can be changed to any other) * Cache.getFrameCount has a new `cache` parameter (that defaults to the Image cache, but can be changed to any other) * Cache.getFrameData has a new `cache` parameter (that defaults to the Image cache, but can be changed to any other) * Cache.hasFrameData has a new `cache` parameter (that defaults to the Image cache, but can be changed to any other) * Cache.getFrameByIndex has a new `cache` parameter (that defaults to the Image cache, but can be changed to any other) * Cache.getFrameByName has a new `cache` parameter (that defaults to the Image cache, but can be changed to any other) re: #1935 --- README.md | 7 +++++++ src/loader/Cache.js | 36 ++++++++++++++++++++++++------------ typescript/phaser.d.ts | 12 ++++++------ 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 3d1a31463..ca1656f8f 100644 --- a/README.md +++ b/README.md @@ -250,6 +250,13 @@ If you are an exceptional JavaScript developer and would like to join the Phaser * TypeScript definitions fixes and updates (thanks @clark-stevenson @shivinsky) * TilemapLayer - Fixed unmatched `context.save` and `context.restore` calls (thanks @MortimerGoro #1934) +* Cache.getFrame has a new `cache` parameter (that defaults to the Image cache, but can be changed to any other) +* Cache.getFrameCount has a new `cache` parameter (that defaults to the Image cache, but can be changed to any other) +* Cache.getFrameData has a new `cache` parameter (that defaults to the Image cache, but can be changed to any other) +* Cache.hasFrameData has a new `cache` parameter (that defaults to the Image cache, but can be changed to any other) +* Cache.getFrameByIndex has a new `cache` parameter (that defaults to the Image cache, but can be changed to any other) +* Cache.getFrameByName has a new `cache` parameter (that defaults to the Image cache, but can be changed to any other) + ### Bug Fixes diff --git a/src/loader/Cache.js b/src/loader/Cache.js index 5401dd0eb..00cc8ac21 100644 --- a/src/loader/Cache.js +++ b/src/loader/Cache.js @@ -1404,11 +1404,14 @@ Phaser.Cache.prototype = { * * @method Phaser.Cache#getFrame * @param {string} key - Asset key of the frame data to retrieve from the Cache. + * @param {integer} [cache=Phaser.Cache.IMAGE] - The cache to search for the item in. * @return {Phaser.Frame} The frame data. */ - getFrame: function (key) { + getFrame: function (key, cache) { - return this.getItem(key, Phaser.Cache.IMAGE, 'getFrame', 'frame'); + if (cache === undefined) { cache = Phaser.Cache.IMAGE; } + + return this.getItem(key, cache, 'getFrame', 'frame'); }, @@ -1417,11 +1420,12 @@ Phaser.Cache.prototype = { * * @method Phaser.Cache#getFrameCount * @param {string} key - Asset key of the FrameData you want. + * @param {integer} [cache=Phaser.Cache.IMAGE] - The cache to search for the item in. * @return {number} Then number of frames. 0 if the image is not found. */ - getFrameCount: function (key) { + getFrameCount: function (key, cache) { - var data = this.getFrameData(key); + var data = this.getFrameData(key, cache); if (data) { @@ -1443,11 +1447,14 @@ Phaser.Cache.prototype = { * * @method Phaser.Cache#getFrameData * @param {string} key - Asset key of the frame data to retrieve from the Cache. + * @param {integer} [cache=Phaser.Cache.IMAGE] - The cache to search for the item in. * @return {Phaser.FrameData} The frame data. */ - getFrameData: function (key) { + getFrameData: function (key, cache) { - return this.getItem(key, Phaser.Cache.IMAGE, 'getFrameData', 'frameData'); + if (cache === undefined) { cache = Phaser.Cache.IMAGE; } + + return this.getItem(key, cache, 'getFrameData', 'frameData'); }, @@ -1456,11 +1463,14 @@ Phaser.Cache.prototype = { * * @method Phaser.Cache#hasFrameData * @param {string} key - Asset key of the frame data to retrieve from the Cache. + * @param {integer} [cache=Phaser.Cache.IMAGE] - The cache to search for the item in. * @return {boolean} True if the given key has frameData in the cache, otherwise false. */ - hasFrameData: function (key) { + hasFrameData: function (key, cache) { - return (this.getItem(key, Phaser.Cache.IMAGE, '', 'frameData') !== null); + if (cache === undefined) { cache = Phaser.Cache.IMAGE; } + + return (this.getItem(key, cache, '', 'frameData') !== null); }, @@ -1489,11 +1499,12 @@ Phaser.Cache.prototype = { * @method Phaser.Cache#getFrameByIndex * @param {string} key - Asset key of the frame data to retrieve from the Cache. * @param {number} index - The index of the frame you want to get. + * @param {integer} [cache=Phaser.Cache.IMAGE] - The cache to search. One of the Cache consts such as `Phaser.Cache.IMAGE` or `Phaser.Cache.SOUND`. * @return {Phaser.Frame} The frame object. */ - getFrameByIndex: function (key, index) { + getFrameByIndex: function (key, index, cache) { - var data = this.getFrameData(key); + var data = this.getFrameData(key, cache); if (data) { @@ -1512,11 +1523,12 @@ Phaser.Cache.prototype = { * @method Phaser.Cache#getFrameByName * @param {string} key - Asset key of the frame data to retrieve from the Cache. * @param {string} name - The name of the frame you want to get. + * @param {integer} [cache=Phaser.Cache.IMAGE] - The cache to search. One of the Cache consts such as `Phaser.Cache.IMAGE` or `Phaser.Cache.SOUND`. * @return {Phaser.Frame} The frame object. */ - getFrameByName: function (key, name) { + getFrameByName: function (key, name, cache) { - var data = this.getFrameData(key); + var data = this.getFrameData(key, cache); if (data) { diff --git a/typescript/phaser.d.ts b/typescript/phaser.d.ts index 382be99dc..b40be909b 100644 --- a/typescript/phaser.d.ts +++ b/typescript/phaser.d.ts @@ -460,11 +460,11 @@ declare module Phaser { getBitmapData(key: string): Phaser.BitmapData; getBitmapFont(key: string): Phaser.RetroFont; getCanvas(key: string): HTMLCanvasElement; - getFrame(key: string): Phaser.Frame; - getFrameByIndex(key: string, index: number): Phaser.Frame; - getFrameByName(key: string, name: string): Phaser.Frame; - getFrameCount(key: string): number; - getFrameData(key: string): Phaser.FrameData; + getFrame(key: string, cache?: number): Phaser.Frame; + getFrameByIndex(key: string, index: number, cache?: number): Phaser.Frame; + getFrameByName(key: string, name: string, cache?: number): Phaser.Frame; + getFrameCount(key: string, cache?: number): number; + getFrameData(key: string, cache?: number): Phaser.FrameData; getImage(key: string, full?: boolean): Phaser.Image; getItem(key: string, cache: number, method?: string, property?: string): any; getJSON(key: string, clone?: boolean): any; @@ -487,7 +487,7 @@ declare module Phaser { getURL(url: string): any; getXML(key: string): any; getVideo(key: string): Phaser.Video; - hasFrameData(key: string): boolean; + hasFrameData(key: string, cache?: number): boolean; isSoundDecoded(key: string): boolean; isSoundReady(key: string): boolean; isSpriteSheet(key: string): boolean;