2018-02-12 16:01:20 +00:00
|
|
|
/**
|
2024-02-19 17:12:18 +00:00
|
|
|
* @author Richard Davey <rich@phaser.io>
|
|
|
|
* @copyright 2013-2024 Phaser Studio Inc.
|
2019-05-10 15:15:04 +00:00
|
|
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
2018-02-12 16:01:20 +00:00
|
|
|
*/
|
|
|
|
|
2018-01-30 00:55:27 +00:00
|
|
|
var Class = require('../utils/Class');
|
|
|
|
var DataManager = require('./DataManager');
|
2018-05-15 11:51:50 +00:00
|
|
|
var PluginCache = require('../plugins/PluginCache');
|
2019-01-18 13:41:43 +00:00
|
|
|
var SceneEvents = require('../scene/events');
|
2018-01-30 00:55:27 +00:00
|
|
|
|
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
|
2018-10-10 09:49:13 +00:00
|
|
|
* @memberof Phaser.Data
|
2018-02-12 22:16:18 +00:00
|
|
|
* @constructor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-05-23 07:09:24 +00:00
|
|
|
* @param {Phaser.Scene} scene - A reference to the Scene that this DataManager belongs to.
|
2018-02-12 22:16:18 +00:00
|
|
|
*/
|
2018-01-30 00:55:27 +00:00
|
|
|
var DataManagerPlugin = new Class({
|
|
|
|
|
|
|
|
Extends: DataManager,
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
|
|
|
function DataManagerPlugin (scene)
|
|
|
|
{
|
2018-04-14 16:39:24 +00:00
|
|
|
DataManager.call(this, scene, scene.sys.events);
|
2018-04-13 16:12:17 +00:00
|
|
|
|
2018-02-12 22:16:18 +00:00
|
|
|
/**
|
2018-05-23 07:18:49 +00:00
|
|
|
* A reference to the Scene that this DataManager belongs to.
|
2018-02-12 22:16:18 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Data.DataManagerPlugin#scene
|
|
|
|
* @type {Phaser.Scene}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-30 00:55:27 +00:00
|
|
|
this.scene = scene;
|
|
|
|
|
2018-02-12 22:16:18 +00:00
|
|
|
/**
|
2018-05-23 07:18:49 +00:00
|
|
|
* A reference to the Scene's Systems.
|
2018-02-12 22:16:18 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Data.DataManagerPlugin#systems
|
|
|
|
* @type {Phaser.Scenes.Systems}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-30 00:55:27 +00:00
|
|
|
this.systems = scene.sys;
|
|
|
|
|
2019-01-18 13:41:43 +00:00
|
|
|
scene.sys.events.once(SceneEvents.BOOT, this.boot, this);
|
|
|
|
scene.sys.events.on(SceneEvents.START, this.start, this);
|
2018-01-30 00:55:27 +00:00
|
|
|
},
|
|
|
|
|
2018-04-17 01:34:07 +00:00
|
|
|
/**
|
|
|
|
* This method is called automatically, only once, when the Scene is first created.
|
|
|
|
* Do not invoke it directly.
|
|
|
|
*
|
|
|
|
* @method Phaser.Data.DataManagerPlugin#boot
|
|
|
|
* @private
|
|
|
|
* @since 3.5.1
|
|
|
|
*/
|
|
|
|
boot: function ()
|
|
|
|
{
|
|
|
|
this.events = this.systems.events;
|
2018-04-17 11:25:45 +00:00
|
|
|
|
2019-01-18 13:41:43 +00:00
|
|
|
this.events.once(SceneEvents.DESTROY, this.destroy, this);
|
2018-04-17 01:34:07 +00:00
|
|
|
},
|
|
|
|
|
2018-02-12 22:16:18 +00:00
|
|
|
/**
|
2018-04-13 16:12:17 +00:00
|
|
|
* This method is called automatically by the Scene when it is starting up.
|
|
|
|
* It is responsible for creating local systems, properties and listening for Scene events.
|
|
|
|
* Do not invoke it directly.
|
2018-02-12 22:16:18 +00:00
|
|
|
*
|
2018-04-13 16:12:17 +00:00
|
|
|
* @method Phaser.Data.DataManagerPlugin#start
|
|
|
|
* @private
|
2018-04-15 11:44:47 +00:00
|
|
|
* @since 3.5.0
|
2018-02-12 22:16:18 +00:00
|
|
|
*/
|
2018-04-13 16:12:17 +00:00
|
|
|
start: function ()
|
2018-01-30 00:55:27 +00:00
|
|
|
{
|
2019-01-18 13:41:43 +00:00
|
|
|
this.events.once(SceneEvents.SHUTDOWN, this.shutdown, this);
|
2018-01-30 00:55:27 +00:00
|
|
|
},
|
|
|
|
|
2018-02-12 22:16:18 +00:00
|
|
|
/**
|
2018-04-13 16:12:17 +00:00
|
|
|
* The Scene that owns this plugin is shutting down.
|
|
|
|
* We need to kill and reset all internal properties as well as stop listening to Scene events.
|
2018-02-12 22:16:18 +00:00
|
|
|
*
|
2018-04-13 16:12:17 +00:00
|
|
|
* @method Phaser.Data.DataManagerPlugin#shutdown
|
|
|
|
* @private
|
2018-04-15 11:44:47 +00:00
|
|
|
* @since 3.5.0
|
2018-02-12 22:16:18 +00:00
|
|
|
*/
|
2018-04-13 16:12:17 +00:00
|
|
|
shutdown: function ()
|
2018-01-30 00:55:27 +00:00
|
|
|
{
|
2019-01-18 13:41:43 +00:00
|
|
|
this.systems.events.off(SceneEvents.SHUTDOWN, this.shutdown, this);
|
2018-01-30 00:55:27 +00:00
|
|
|
},
|
|
|
|
|
2018-02-12 22:16:18 +00:00
|
|
|
/**
|
2018-04-13 16:12:17 +00:00
|
|
|
* The Scene that owns this plugin is being destroyed.
|
|
|
|
* We need to shutdown and then kill off all external references.
|
2018-02-12 22:16:18 +00:00
|
|
|
*
|
2018-04-13 16:12:17 +00:00
|
|
|
* @method Phaser.Data.DataManagerPlugin#destroy
|
2018-04-15 11:44:47 +00:00
|
|
|
* @since 3.5.0
|
2018-02-12 22:16:18 +00:00
|
|
|
*/
|
2018-04-13 16:12:17 +00:00
|
|
|
destroy: function ()
|
2018-01-30 00:55:27 +00:00
|
|
|
{
|
2018-04-13 16:12:17 +00:00
|
|
|
DataManager.prototype.destroy.call(this);
|
|
|
|
|
2019-01-18 13:41:43 +00:00
|
|
|
this.events.off(SceneEvents.START, this.start, this);
|
2018-01-30 00:55:27 +00:00
|
|
|
|
2018-04-13 16:12:17 +00:00
|
|
|
this.scene = null;
|
|
|
|
this.systems = null;
|
2018-01-30 00:55:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2018-05-15 11:51:50 +00:00
|
|
|
PluginCache.register('DataManagerPlugin', DataManagerPlugin, 'data');
|
2018-01-30 00:55:27 +00:00
|
|
|
|
|
|
|
module.exports = DataManagerPlugin;
|