forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasePlugin.js
More file actions
173 lines (155 loc) · 6.05 KB
/
Copy pathBasePlugin.js
File metadata and controls
173 lines (155 loc) · 6.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser3-plugin-template/blob/master/LICENSE|MIT License}
*/
var Class = require('../utils/Class');
/**
* @classdesc
* A Global Plugin is installed just once into the Game owned Plugin Manager.
* It can listen for Game events and respond to them.
*
* @class BasePlugin
* @memberOf Phaser.Plugins
* @constructor
* @since 3.8.0
*
* @param {Phaser.Game} game - A reference to the Game instance this plugin is running under.
*/
var BasePlugin = new Class({
initialize:
function BasePlugin (pluginManager)
{
/**
* A handy reference to the Plugin Manager that is responsible for this plugin.
* Can be used as a route to gain access to game systems and events.
*
* @name Phaser.Plugins.BasePlugin#pluginManager
* @type {Phaser.Plugins.PluginManager}
* @protected
* @since 3.8.0
*/
this.pluginManager = pluginManager;
/**
* A reference to the Game instance this plugin is running under.
*
* @name Phaser.Plugins.BasePlugin#game
* @type {Phaser.Game}
* @protected
* @since 3.8.0
*/
this.game = pluginManager.game;
/**
* A reference to the Scene that has installed this plugin.
* Only set if it's a Scene Plugin, otherwise `null`.
* This property is only set when the plugin is instantiated and added to the Scene, not before.
* You cannot use it during the `init` method, but you can during the `boot` method.
*
* @name Phaser.Plugins.BasePlugin#scene
* @type {?Phaser.Scene}
* @protected
* @since 3.8.0
*/
this.scene;
/**
* A reference to the Scene Systems of the Scene that has installed this plugin.
* Only set if it's a Scene Plugin, otherwise `null`.
* This property is only set when the plugin is instantiated and added to the Scene, not before.
* You cannot use it during the `init` method, but you can during the `boot` method.
*
* @name Phaser.Plugins.BasePlugin#systems
* @type {?Phaser.Scenes.Systems}
* @protected
* @since 3.8.0
*/
this.systems;
},
/**
* Called by the PluginManager when this plugin is first instantiated.
* It will never be called again on this instance.
* In here you can set-up whatever you need for this plugin to run.
* If a plugin is set to automatically start then `BasePlugin.start` will be called immediately after this.
*
* @method Phaser.Plugins.BasePlugin#init
* @since 3.8.0
*/
init: function ()
{
},
/**
* Called by the PluginManager when this plugin is started.
* If a plugin is stopped, and then started again, this will get called again.
* Typically called immediately after `BasePlugin.init`.
*
* @method Phaser.Plugins.BasePlugin#start
* @since 3.8.0
*/
start: function ()
{
// Here are the game-level events you can listen to.
// At the very least you should offer a destroy handler for when the game closes down.
// var eventEmitter = this.game.events;
// eventEmitter.once('destroy', this.gameDestroy, this);
// eventEmitter.on('pause', this.gamePause, this);
// eventEmitter.on('resume', this.gameResume, this);
// eventEmitter.on('resize', this.gameResize, this);
// eventEmitter.on('prestep', this.gamePreStep, this);
// eventEmitter.on('step', this.gameStep, this);
// eventEmitter.on('poststep', this.gamePostStep, this);
// eventEmitter.on('prerender', this.gamePreRender, this);
// eventEmitter.on('postrender', this.gamePostRender, this);
},
/**
* Called by the PluginManager when this plugin is stopped.
* The game code has requested that your plugin stop doing whatever it does.
* It is now considered as 'inactive' by the PluginManager.
* Handle that process here (i.e. stop listening for events, etc)
* If the plugin is started again then `BasePlugin.start` will be called again.
*
* @method Phaser.Plugins.BasePlugin#stop
* @since 3.8.0
*/
stop: function ()
{
},
/**
* If this is a Scene Plugin (i.e. installed into a Scene) then this method is called when the Scene boots.
* By this point the plugin properties `scene` and `systems` will have already been set.
* In here you can listen for Scene events and set-up whatever you need for this plugin to run.
*
* @method Phaser.Plugins.BasePlugin#boot
* @since 3.8.0
*/
boot: function ()
{
// Here are the Scene events you can listen to.
// At the very least you should offer a destroy handler for when the Scene closes down.
// var eventEmitter = this.systems.events;
// eventEmitter.once('destroy', this.sceneDestroy, this);
// eventEmitter.on('start', this.sceneStart, this);
// eventEmitter.on('preupdate', this.scenePreUpdate, this);
// eventEmitter.on('update', this.sceneUpdate, this);
// eventEmitter.on('postupdate', this.scenePostUpdate, this);
// eventEmitter.on('pause', this.scenePause, this);
// eventEmitter.on('resume', this.sceneResume, this);
// eventEmitter.on('sleep', this.sceneSleep, this);
// eventEmitter.on('wake', this.sceneWake, this);
// eventEmitter.on('shutdown', this.sceneShutdown, this);
// eventEmitter.on('destroy', this.sceneDestroy, this);
},
/**
* Game instance has been destroyed.
* You must release everything in here, all references, all objects, free it all up.
*
* @method Phaser.Plugins.BasePlugin#destroy
* @since 3.8.0
*/
destroy: function ()
{
this.pluginManager = null;
this.game = null;
this.scene = null;
this.systems = null;
}
});
module.exports = BasePlugin;