Skip to content

Commit 3043fd5

Browse files
committed
Added jsdocs and unified the boot process
1 parent ef9ab05 commit 3043fd5

2 files changed

Lines changed: 493 additions & 114 deletions

File tree

src/plugins/PluginCache.js

Lines changed: 105 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@ var corePlugins = {};
1212
// These are the source objects, not instantiated.
1313
var customPlugins = {};
1414

15+
/**
16+
* @typedef {object} CorePluginContainer
17+
*
18+
* @property {string} key - The unique name of this plugin in the core plugin cache.
19+
* @property {function} plugin - The plugin to be stored. Should be the source object, not instantiated.
20+
* @property {string} [mapping] - If this plugin is to be injected into the Scene Systems, this is the property key map used.
21+
* @property {boolean} [custom=false] - Core Scene plugin or a Custom Scene plugin?
22+
*/
23+
24+
/**
25+
* @typedef {object} CustomPluginContainer
26+
*
27+
* @property {string} key - The unique name of this plugin in the custom plugin cache.
28+
* @property {function} plugin - The plugin to be stored. Should be the source object, not instantiated.
29+
*/
30+
1531
var PluginCache = {};
1632

1733
/**
@@ -23,9 +39,10 @@ var PluginCache = {};
2339
* @method Phaser.Plugins.PluginCache.register
2440
* @since 3.8.0
2541
*
26-
* @param {string} key - [description]
27-
* @param {object} plugin - [description]
28-
* @param {string} mapping - [description]
42+
* @param {string} key - A reference used to get this plugin from the plugin cache.
43+
* @param {function} plugin - The plugin to be stored. Should be the core object, not instantiated.
44+
* @param {string} mapping - If this plugin is to be injected into the Scene Systems, this is the property key map used.
45+
* @param {boolean} [custom=false] - Core Scene plugin or a Custom Scene plugin?
2946
*/
3047
PluginCache.register = function (key, plugin, mapping, custom)
3148
{
@@ -34,36 +51,121 @@ PluginCache.register = function (key, plugin, mapping, custom)
3451
corePlugins[key] = { plugin: plugin, mapping: mapping, custom: custom };
3552
};
3653

54+
/**
55+
* Stores a custom plugin in the global plugin cache.
56+
* The key must be unique, within the scope of the cache.
57+
*
58+
* @method Phaser.Plugins.PluginCache.registerCustom
59+
* @since 3.8.0
60+
*
61+
* @param {string} key - A reference used to get this plugin from the plugin cache.
62+
* @param {function} plugin - The plugin to be stored. Should be the core object, not instantiated.
63+
* @param {string} mapping - If this plugin is to be injected into the Scene Systems, this is the property key map used.
64+
*/
3765
PluginCache.registerCustom = function (key, plugin, mapping)
3866
{
3967
customPlugins[key] = { plugin: plugin, mapping: mapping };
4068
};
4169

70+
/**
71+
* Checks if the given key is already being used in the core plugin cache.
72+
*
73+
* @method Phaser.Plugins.PluginCache.hasCore
74+
* @since 3.8.0
75+
*
76+
* @param {string} key - The key to check for.
77+
*
78+
* @return {boolean} `true` if the key is already in use in the core cache, otherwise `false`.
79+
*/
4280
PluginCache.hasCore = function (key)
4381
{
4482
return corePlugins.hasOwnProperty(key);
4583
}
4684

85+
/**
86+
* Checks if the given key is already being used in the custom plugin cache.
87+
*
88+
* @method Phaser.Plugins.PluginCache.hasCustom
89+
* @since 3.8.0
90+
*
91+
* @param {string} key - The key to check for.
92+
*
93+
* @return {boolean} `true` if the key is already in use in the custom cache, otherwise `false`.
94+
*/
4795
PluginCache.hasCustom = function (key)
4896
{
4997
return customPlugins.hasOwnProperty(key);
5098
}
5199

100+
/**
101+
* Returns the core plugin object from the cache based on the given key.
102+
*
103+
* @method Phaser.Plugins.PluginCache.getCore
104+
* @since 3.8.0
105+
*
106+
* @param {string} key - The key of the core plugin to get.
107+
*
108+
* @return {CorePluginContainer} The core plugin object.
109+
*/
52110
PluginCache.getCore = function (key)
53111
{
54112
return corePlugins[key];
55113
}
56114

115+
/**
116+
* Returns the custom plugin object from the cache based on the given key.
117+
*
118+
* @method Phaser.Plugins.PluginCache.getCustom
119+
* @since 3.8.0
120+
*
121+
* @param {string} key - The key of the custom plugin to get.
122+
*
123+
* @return {CustomPluginContainer} The custom plugin object.
124+
*/
57125
PluginCache.getCustom = function (key)
58126
{
59127
return customPlugins[key];
60128
}
61129

130+
/**
131+
* Returns an object from the custom cache based on the given key that can be instantiated.
132+
*
133+
* @method Phaser.Plugins.PluginCache.getCustomClass
134+
* @since 3.8.0
135+
*
136+
* @param {string} key - The key of the custom plugin to get.
137+
*
138+
* @return {function} The custom plugin object.
139+
*/
62140
PluginCache.getCustomClass = function (key)
63141
{
64142
return (customPlugins.hasOwnProperty(key)) ? customPlugins[key].plugin : null;
65143
}
66144

145+
/**
146+
* Removes a core plugin based on the given key.
147+
*
148+
* @method Phaser.Plugins.PluginCache.remove
149+
* @since 3.8.0
150+
*
151+
* @param {string} key - The key of the core plugin to remove.
152+
*/
153+
PluginCache.remove = function (key)
154+
{
155+
if (corePlugins.hasOwnProperty(key))
156+
{
157+
delete corePlugins[key];
158+
}
159+
}
160+
161+
/**
162+
* Removes a custom plugin based on the given key.
163+
*
164+
* @method Phaser.Plugins.PluginCache.removeCustom
165+
* @since 3.8.0
166+
*
167+
* @param {string} key - The key of the custom plugin to remove.
168+
*/
67169
PluginCache.removeCustom = function (key)
68170
{
69171
if (customPlugins.hasOwnProperty(key))

0 commit comments

Comments
 (0)