phaser/src/cache/BaseCache.js

117 lines
2.2 KiB
JavaScript
Raw Normal View History

var Class = require('../utils/Class');
2017-10-04 23:09:12 +00:00
var CustomMap = require('../structs/Map');
var EventDispatcher = require('../events/EventDispatcher');
var Events = require('./events');
var BaseCache = new Class({
initialize:
2017-10-04 23:09:12 +00:00
/**
* [description]
*
* @class BaseCache
* @memberOf Phaser.Cache
* @constructor
* @since 3.0.0
*/
function BaseCache ()
{
2017-10-04 23:09:12 +00:00
/**
* [description]
*
* @property {Phaser.Structs.Map} entries
*/
this.entries = new CustomMap();
2017-10-04 23:09:12 +00:00
/**
* [description]
*
* @property {Phaser.Events.EventDispatcher} events
*/
this.events = new EventDispatcher();
},
2017-10-04 23:09:12 +00:00
/**
* [description]
*
* @method Phaser.Cache.BaseCache#add
* @fires CacheAddEvent
* @since 3.0.0
*
* @param {string} key [description]
* @param {any} data [description]
*/
add: function (key, data)
{
this.entries.set(key, data);
this.events.dispatch(new Events.CACHE_ADD_EVENT(this, key, data));
},
2017-10-04 23:09:12 +00:00
/**
* [description]
*
* @method Phaser.Cache.BaseCache#has
* @since 3.0.0
*
* @param {string} key [description]
*
2017-10-04 23:09:12 +00:00
* @return {boolean} [description]
*/
has: function (key)
{
return this.entries.has(key);
},
2017-10-04 23:09:12 +00:00
/**
* [description]
*
* @method Phaser.Cache.BaseCache#get
* @since 3.0.0
*
* @param {string} key [description]
*
2017-10-04 23:09:12 +00:00
* @return {any} [description]
*/
get: function (key)
{
return this.entries.get(key);
},
2017-10-04 23:09:12 +00:00
/**
* [description]
*
* @method Phaser.Cache.BaseCache#remove
* @fires CacheRemoveEvent
* @since 3.0.0
*
* @param {string} key [description]
*/
remove: function (key)
{
var entry = this.get(key);
if (entry)
{
this.entries.delete(key);
this.events.dispatch(new Events.CACHE_REMOVE_EVENT(this, key, entry.data));
}
},
2017-10-04 23:09:12 +00:00
/**
* [description]
*
* @method Phaser.Cache.BaseCache#destroy
* @since 3.0.0
*/
destroy: function ()
{
this.entries.clear();
}
});
module.exports = BaseCache;