phaser/src/cache/BaseCache.js

116 lines
2.1 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 EventEmitter = require('eventemitter3');
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 EventEmitter();
},
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.emit('add', 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.emit('remove', 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;