mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 13:13:43 +00:00
Cache.checkKey added - allows you to pass in a Cache type and a key and return a boolean.
Cache.checkCanvasKey(key) - Check if a Canvas key exists in the cache (thanks to @delta11 for the proposal) Cache.checkTextureKey(key) - Check if a Texture key exists in the cache (thanks to @delta11 for the proposal) Cache.checkSoundKey(key) - Check if a Sound key exists in the cache (thanks to @delta11 for the proposal) Cache.checkTextKey(key) - Check if a Text key exists in the cache (thanks to @delta11 for the proposal) Cache.checkPhysicsKey(key) - Check if a Physics key exists in the cache (thanks to @delta11 for the proposal) Cache.checkTilemapKey(key) - Check if a Tilemap key exists in the cache (thanks to @delta11 for the proposal) Cache.checkBinaryKey(key) - Check if a Binary key exists in the cache (thanks to @delta11 for the proposal) Cache.checkBitmapDataKey(key) - Check if a BitmapData key exists in the cache (thanks to @delta11 for the proposal) Cache.checkBitmapFontKey(key) - Check if a BitmapFont key exists in the cache (thanks to @delta11 for the proposal) Cache.checkJSONKey(key) - Check if a JSON key exists in the cache (thanks to @delta11 for the proposal)
This commit is contained in:
parent
cfadaf3e70
commit
da75a22e82
3 changed files with 189 additions and 6 deletions
11
README.md
11
README.md
|
@ -99,6 +99,17 @@ Version 2.0.5 - "Tanchico" - in development
|
|||
* Mouse.stopOnGameOut boolean controls if Pointer.stop will be called if the mouse leaves the game canvas (defaults to false)
|
||||
* Tilemap.searchTileIndex allows you to search for the first tile matching the given index, with optional skip and reverse parameters.
|
||||
* Tilemap.layer is a getter/setter to the current layer object (which can be changed with Tilemap.setLayer)
|
||||
* Cache.checkKey added - allows you to pass in a Cache type and a key and return a boolean.
|
||||
* Cache.checkCanvasKey(key) - Check if a Canvas key exists in the cache (thanks to @delta11 for the proposal)
|
||||
* Cache.checkTextureKey(key) - Check if a Texture key exists in the cache (thanks to @delta11 for the proposal)
|
||||
* Cache.checkSoundKey(key) - Check if a Sound key exists in the cache (thanks to @delta11 for the proposal)
|
||||
* Cache.checkTextKey(key) - Check if a Text key exists in the cache (thanks to @delta11 for the proposal)
|
||||
* Cache.checkPhysicsKey(key) - Check if a Physics key exists in the cache (thanks to @delta11 for the proposal)
|
||||
* Cache.checkTilemapKey(key) - Check if a Tilemap key exists in the cache (thanks to @delta11 for the proposal)
|
||||
* Cache.checkBinaryKey(key) - Check if a Binary key exists in the cache (thanks to @delta11 for the proposal)
|
||||
* Cache.checkBitmapDataKey(key) - Check if a BitmapData key exists in the cache (thanks to @delta11 for the proposal)
|
||||
* Cache.checkBitmapFontKey(key) - Check if a BitmapFont key exists in the cache (thanks to @delta11 for the proposal)
|
||||
* Cache.checkJSONKey(key) - Check if a JSON key exists in the cache (thanks to @delta11 for the proposal)
|
||||
|
||||
|
||||
### New Plugins
|
||||
|
|
11
build/phaser.d.ts
vendored
11
build/phaser.d.ts
vendored
|
@ -1289,7 +1289,18 @@ declare module Phaser {
|
|||
addText(key: string, url: string, data: Object): void;
|
||||
addTextureAtlas(key: string, url: string, data: Object, atlasData: Object, format: number): void;
|
||||
addTilemap(key: string, url: string, mapData: Object, format: number): void;
|
||||
checkKey(type: number, key: string): boolean;
|
||||
checkCanvasKey(key: string): boolean;
|
||||
checkImageKey(key: string): boolean;
|
||||
checkTextureKey(key: string): boolean;
|
||||
checkSoundKey(key: string): boolean;
|
||||
checkTextKey(key: string): boolean;
|
||||
checkPhysicsKey(key: string): boolean;
|
||||
checkTilemapKey(key: string): boolean;
|
||||
checkBinaryKey(key: string): boolean;
|
||||
checkBitmapDataKey(key: string): boolean;
|
||||
checkBitmapFontKey(key: string): boolean;
|
||||
checkJSONKey(key: string): boolean;
|
||||
decodedSound(key: string, data: Object): void;
|
||||
destroy(): void;
|
||||
getBinary(key: string): Object;
|
||||
|
|
|
@ -93,6 +93,23 @@ Phaser.Cache = function (game) {
|
|||
*/
|
||||
this.onSoundUnlock = new Phaser.Signal();
|
||||
|
||||
/**
|
||||
* @property {array} _cacheMap - Const to cache object look-up array.
|
||||
*/
|
||||
this._cacheMap = [];
|
||||
|
||||
this._cacheMap[Phaser.Cache.CANVAS] = this._canvases;
|
||||
this._cacheMap[Phaser.Cache.IMAGE] = this._images;
|
||||
this._cacheMap[Phaser.Cache.TEXTURE] = this._textures;
|
||||
this._cacheMap[Phaser.Cache.SOUND] = this._sounds;
|
||||
this._cacheMap[Phaser.Cache.TEXT] = this._text;
|
||||
this._cacheMap[Phaser.Cache.PHYSICS] = this._physics;
|
||||
this._cacheMap[Phaser.Cache.TILEMAP] = this._tilemaps;
|
||||
this._cacheMap[Phaser.Cache.BINARY] = this._binary;
|
||||
this._cacheMap[Phaser.Cache.BITMAPDATA] = this._bitmapDatas;
|
||||
this._cacheMap[Phaser.Cache.BITMAPFONT] = this._bitmapFont;
|
||||
this._cacheMap[Phaser.Cache.JSON] = this._json;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -632,7 +649,39 @@ Phaser.Cache.prototype = {
|
|||
},
|
||||
|
||||
/**
|
||||
* Checks if an image key exists.
|
||||
* Checks if a key for the given cache object type exists.
|
||||
*
|
||||
* @method Phaser.Cache#checkKey
|
||||
* @param {number} type - The Cache type to check against. I.e. Phaser.Cache.CANVAS, Phaser.Cache.IMAGE, Phaser.Cache.JSON, etc.
|
||||
* @param {string} key - Asset key of the image to check is in the Cache.
|
||||
* @return {boolean} True if the key exists, otherwise false.
|
||||
*/
|
||||
checkKey: function (type, key) {
|
||||
|
||||
if (this._cacheMap[type][key])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if the given key exists in the Canvas Cache.
|
||||
*
|
||||
* @method Phaser.Cache#checkCanvasKey
|
||||
* @param {string} key - Asset key of the image to check is in the Cache.
|
||||
* @return {boolean} True if the key exists, otherwise false.
|
||||
*/
|
||||
checkCanvasKey: function (key) {
|
||||
|
||||
return this.checkKey(Phaser.Cache.CANVAS, key);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if the given key exists in the Image Cache. Note that this also includes Texture Atlases, Sprite Sheets and Retro Fonts.
|
||||
*
|
||||
* @method Phaser.Cache#checkImageKey
|
||||
* @param {string} key - Asset key of the image to check is in the Cache.
|
||||
|
@ -640,12 +689,124 @@ Phaser.Cache.prototype = {
|
|||
*/
|
||||
checkImageKey: function (key) {
|
||||
|
||||
if (this._images[key])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return this.checkKey(Phaser.Cache.IMAGE, key);
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if the given key exists in the Texture Cache.
|
||||
*
|
||||
* @method Phaser.Cache#checkTextureKey
|
||||
* @param {string} key - Asset key of the image to check is in the Cache.
|
||||
* @return {boolean} True if the key exists, otherwise false.
|
||||
*/
|
||||
checkTextureKey: function (key) {
|
||||
|
||||
return this.checkKey(Phaser.Cache.TEXTURE, key);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if the given key exists in the Sound Cache.
|
||||
*
|
||||
* @method Phaser.Cache#checkSoundKey
|
||||
* @param {string} key - Asset key of the image to check is in the Cache.
|
||||
* @return {boolean} True if the key exists, otherwise false.
|
||||
*/
|
||||
checkSoundKey: function (key) {
|
||||
|
||||
return this.checkKey(Phaser.Cache.SOUND, key);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if the given key exists in the Text Cache.
|
||||
*
|
||||
* @method Phaser.Cache#checkTextKey
|
||||
* @param {string} key - Asset key of the image to check is in the Cache.
|
||||
* @return {boolean} True if the key exists, otherwise false.
|
||||
*/
|
||||
checkTextKey: function (key) {
|
||||
|
||||
return this.checkKey(Phaser.Cache.TEXT, key);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if the given key exists in the Physics Cache.
|
||||
*
|
||||
* @method Phaser.Cache#checkPhysicsKey
|
||||
* @param {string} key - Asset key of the image to check is in the Cache.
|
||||
* @return {boolean} True if the key exists, otherwise false.
|
||||
*/
|
||||
checkPhysicsKey: function (key) {
|
||||
|
||||
return this.checkKey(Phaser.Cache.PHYSICS, key);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if the given key exists in the Tilemap Cache.
|
||||
*
|
||||
* @method Phaser.Cache#checkTilemapKey
|
||||
* @param {string} key - Asset key of the image to check is in the Cache.
|
||||
* @return {boolean} True if the key exists, otherwise false.
|
||||
*/
|
||||
checkTilemapKey: function (key) {
|
||||
|
||||
return this.checkKey(Phaser.Cache.TILEMAP, key);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if the given key exists in the Binary Cache.
|
||||
*
|
||||
* @method Phaser.Cache#checkBinaryKey
|
||||
* @param {string} key - Asset key of the image to check is in the Cache.
|
||||
* @return {boolean} True if the key exists, otherwise false.
|
||||
*/
|
||||
checkBinaryKey: function (key) {
|
||||
|
||||
return this.checkKey(Phaser.Cache.BINARY, key);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if the given key exists in the BitmapData Cache.
|
||||
*
|
||||
* @method Phaser.Cache#checkBitmapDataKey
|
||||
* @param {string} key - Asset key of the image to check is in the Cache.
|
||||
* @return {boolean} True if the key exists, otherwise false.
|
||||
*/
|
||||
checkBitmapDataKey: function (key) {
|
||||
|
||||
return this.checkKey(Phaser.Cache.BITMAPDATA, key);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if the given key exists in the BitmapFont Cache.
|
||||
*
|
||||
* @method Phaser.Cache#checkBitmapFontKey
|
||||
* @param {string} key - Asset key of the image to check is in the Cache.
|
||||
* @return {boolean} True if the key exists, otherwise false.
|
||||
*/
|
||||
checkBitmapFontKey: function (key) {
|
||||
|
||||
return this.checkKey(Phaser.Cache.BITMAPFONT, key);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if the given key exists in the JSON Cache.
|
||||
*
|
||||
* @method Phaser.Cache#checkJSONKey
|
||||
* @param {string} key - Asset key of the image to check is in the Cache.
|
||||
* @return {boolean} True if the key exists, otherwise false.
|
||||
*/
|
||||
checkJSONKey: function (key) {
|
||||
|
||||
return this.checkKey(Phaser.Cache.JSON, key);
|
||||
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in a new issue