phaser/src/data/DataManagerPlugin.js

103 lines
2.4 KiB
JavaScript
Raw Normal View History

2018-02-12 16:01:20 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var Class = require('../utils/Class');
var DataManager = require('./DataManager');
var PluginManager = require('../boot/PluginManager');
2018-02-12 22:16:18 +00:00
/**
* @classdesc
* The Data Component features a means to store pieces of data specific to a Game Object, System or Plugin.
* You can then search, query it, and retrieve the data. The parent must either extend EventEmitter,
* or have a property called `events` that is an instance of it.
*
* @class DataManagerPlugin
* @extends Phaser.Data.DataManager
* @memberOf Phaser.Data
* @constructor
* @since 3.0.0
*
* @param {Phaser.Scene} scene - [description]
*/
var DataManagerPlugin = new Class({
Extends: DataManager,
initialize:
function DataManagerPlugin (scene)
{
2018-02-12 22:16:18 +00:00
/**
* [description]
*
* @name Phaser.Data.DataManagerPlugin#scene
* @type {Phaser.Scene}
* @since 3.0.0
*/
this.scene = scene;
2018-02-12 22:16:18 +00:00
/**
* [description]
*
* @name Phaser.Data.DataManagerPlugin#systems
* @type {Phaser.Scenes.Systems}
* @since 3.0.0
*/
this.systems = scene.sys;
if (!scene.sys.settings.isBooted)
{
scene.sys.events.once('boot', this.boot, this);
}
DataManager.call(this, this.scene, scene.sys.events);
},
2018-02-12 22:16:18 +00:00
/**
* [description]
*
* @method Phaser.Data.DataManagerPlugin#boot
* @since 3.0.0
*/
boot: function ()
{
var eventEmitter = this.systems.events;
eventEmitter.on('shutdown', this.shutdownPlugin, this);
eventEmitter.on('destroy', this.destroyPlugin, this);
},
2018-02-12 22:16:18 +00:00
/**
* [description]
*
* @method Phaser.Data.DataManagerPlugin#shutdownPlugin
* @since 3.0.0
*/
shutdownPlugin: function ()
{
// Should we reset the events?
},
2018-02-12 22:16:18 +00:00
/**
* [description]
*
* @method Phaser.Data.DataManagerPlugin#destroyPlugin
* @since 3.0.0
*/
destroyPlugin: function ()
{
this.destroy();
this.scene = undefined;
this.systems = undefined;
}
});
PluginManager.register('DataManagerPlugin', DataManagerPlugin, 'data');
module.exports = DataManagerPlugin;