Update to core Plugin Manager to separate plugin name from filename

I was reading this topic by Lavra about how plugin names are tied to filename.

So I looked at what's causing this.

From rpg_managers line 2430, I see this (I haven't updated MV since day 1 so I don't know if it's different now)

PluginManager.setup = function(plugins) { plugins.forEach(function(plugin) { if (plugin.status && !this._scripts.contains(plugin.name)) { this.setParameters(plugin.name, plugin.parameters); this.loadScript(plugin.name + '.js'); this._scripts.push(plugin.name); } }, this);};And it seems like the problem stems from the fact that the filename is used as the key for the plugin in the plugin manager.Now, this is strange: why should the filename be used as the key?

One issue is that plugins by default do not have an identifier. The plugin.js file that's generated only stores the name of the file along with the parameters.

Lavra's solution works well as it provides an identifier with which plugin writers use.

But could we have this integrated into the core somehow by default?

Perhaps have a standard annotation that the plugin manager will search for and use.

eg:

@pluginName My Plugin NameAnd then I can query the plugin parameters with

Code:
PluginManager.parameters("My Plugin Name")
That way, no one needs to worry about the name they use for their plugin.As an alternative to specifying an annotation, we could just specify a param:

PluginManager.setup = function(plugins) { plugins.forEach(function(plugin) { var registeredName = plugin.parameters['_PluginName'] || plugin.name; if (plugin.status && !this._scripts.contains(registeredName)) { this.setParameters(registeredName, plugin.parameters); this.loadScript(plugin.name + '.js'); this._scripts.push(registeredName); } }, this);};And now, all I need to include in my plugin is

Code:
@param _PluginName@default My Plugin Name
And again, the following query will work

Code:
PluginManager.parameters("My Plugin Name")
assuming users leave that parameter alone.It would be nice if something like is already planned in a future update so there is a uniform way for scripters to provide an internal name for their plugin without having to worry about end-users' own naming preferences.
It would break my Orange Hud, though 🙁

The add-ons to that plugin can be added multiple times to add more than one element to the hud. If we used a key inside the plugin, it would no longer be possible to add the same plugin twice.
I've been trying to consider the best way to do this for adding it to the MVCommons plugin. My idea right now involves alising when each plugin is loaded, and then finding a way to transparently associate that filename with the plugin that's being loaded. It should be possible to do it transparently if I just search for a call to PluginManager.parameters(".*") and then use that in a separate list to put file name -> name dev uses.

My goal is do get a solution that involves 0 changes for the developer, and jsut seamlessly works for the game dev. If you have any better idea, please let me know. I'm working on several projects right now, but come the 1st of November, my schedule gets incredibly filled up until February, but waiting that long for a solution is not optimal.
It would break my Orange Hud, though 🙁


The add-ons to that plugin can be added multiple times to add more than one element to the hud. If we used a key inside the plugin, it would no longer be possible to add the same plugin twice.
Oh, that's true. In my head I had already rejected the idea that multiple plugins with the same name could exist in one project because to me, that just means someone accidentally added the same plugin twice.


But now that you mention it, I do remember the "variable" input solution you had described before.


However, it wasn't really "adding the same plugin twice" because the plugin manager already ignores duplicate plugins (ie: plugins with same name)


As a compromise, how about using the plugin name as the key if the special annotation or param does not exist?

I've been trying to consider the best way to do this for adding it to the MVCommons plugin. My idea right now involves alising when each plugin is loaded, and then finding a way to transparently associate that filename with the plugin that's being loaded. It should be possible to do it transparently if I just search for a call to PluginManager.parameters(".*") and then use that in a separate list to put file name -> name dev uses.
I haven't run through various test cases or alternative ways to access a plugin's parameters but it seems pretty good.


But I would prefer if people (using MVCommons) continue to "register" plugins explicitly.
As a compromise, how about using the plugin name as the key if the special annotation or param does not exist?
That could work. It would also work as "retro compatibility" with current plugins.
I haven't run through various test cases or alternative ways to access a plugin's parameters but it seems pretty good.

But I would prefer if people (using MVCommons) continue to "register" plugins explicitly.
The Plugin registration is separate from parameter access. Register just keeps a list of plugins and allows you to give an array of plugins that are required (I've also considered enabling allowing version numbers with this), and if a plugin that's required isn't found, he register function will return undefined so that the calling plugin can report an error to the console. As an added optional parameter, you can force the entire game to halt if your plugin an't be registered, should you feel that is necessary.

Plugin parameters retrieval would happen separately. I'd probably end up aliasing the function that loads in the actual script files to get a list of file names, and then also alias the parameters function to check the alternative lookup list to determine what name should be used in place of the one the developer chose. Like I said, I haven't had the time to test this yet, so I'm not 100% sure how hard/easy it'll be, but if you can think of an idea/concept that may help, I'm open to ideas. After all, MVCommons is a community-maintained plugin.
The Plugin registration is separate from parameter access. Register just keeps a list of plugins and allows you to give an array of plugins that are required (I've also considered enabling allowing version numbers with this), and if a plugin that's required isn't found, he register function will return undefined so that the calling plugin can report an error to the console. As an added optional parameter, you can force the entire game to halt if your plugin an't be registered, should you feel that is necessary.


Plugin parameters retrieval would happen separately. I'd probably end up aliasing the function that loads in the actual script files to get a list of file names, and then also alias the parameters function to check the alternative lookup list to determine what name should be used in place of the one the developer chose. Like I said, I haven't had the time to test this yet, so I'm not 100% sure how hard/easy it'll be, but if you can think of an idea/concept that may help, I'm open to ideas. After all, MVCommons is a community-maintained plugin.
Maybe you can just have plugin writers use the name that they used to register their plugin, to access parameters?


After all, if they register a plugin with a particular name, they should be guaranteed that it is theirs and only theirs.


Unless this goes back to the issue Hudell has about unique keys...
Maybe you can just have plugin writers use the name that they used to register their plugin, to access parameters?

After all, if they register a plugin with a particular name, they should be guaranteed that it is theirs and only theirs.

Unless this goes back to the issue Hudell has about unique keys...
My only problem is that I was hoping to be able to make the change completely transparent to plugin developers so that they wouldn't have to change anything in their plugin. 
You can't override PluginManager.setup(), since this function is called before plugins are even loaded. At runtime, you can only access the plugin list via $plugins, which is an array containing 4 properties per entry:

name: Fillename of the plugin, without the trailing ".js".

status: true if the plugin is active, otherwise false.

description: Value of your @plugindesc.

parameters: An object containing your parameters.

So, unless you load the plugin file and parse it, you won't be able to use a custom tag like @pluginName and can only work with either the description or a special parameter that will show up in the maker and probably confuse your users.
It would break my Orange Hud, though 🙁

The add-ons to that plugin can be added multiple times to add more than one element to the hud. If we used a key inside the plugin, it would no longer be possible to add the same plugin twice.
I... actually wouldn't do that, from an HTML5 stance.

What you're essentially doing is you're adding a new script element to the DOM, and each element reads from that JavaScript file multiple times. If you don't check it correctly you'll end up executing the same script multiple times, which is generally bad practice. It's even discouraged by people working with JavaScript. Especially if you're working with event handlers this can become problematic.

I know it's really impractical for the end-user, but requiring them to use a JSON file would be a lot better. If you're going to mess with advanced stuff like HUDs and the likes, you better put some effort in it anyway, and JSON isn't really that hard. It's just impractical.
You can't override PluginManager.setup(), since this function is called before plugins are even loaded. At runtime, you can only access the plugin list via $plugins, which is an array containing 4 properties per entry:


name: Fillename of the plugin, without the trailing ".js".


status: true if the plugin is active, otherwise false.


description: Value of your @plugindesc.


parameters: An object containing your parameters.


So, unless you load the plugin file and parse it, you won't be able to use a custom tag like @pluginName and can only work with either the description or a special parameter that will show up in the maker and probably confuse your users.
My suggestion is to do a complete overwrite of the setup function defined in rpg_manager.js to change the way it processes plugins, though it might not have been clear.
I... actually wouldn't do that, from an HTML5 stance.

What you're essentially doing is you're adding a new script element to the DOM, and each element reads from that JavaScript file multiple times. If you don't check it correctly you'll end up executing the same script multiple times, which is generally bad practice. It's even discouraged by people working with JavaScript. Especially if you're working with event handlers this can become problematic.

I know it's really impractical for the end-user, but requiring them to use a JSON file would be a lot better. If you're going to mess with advanced stuff like HUDs and the likes, you better put some effort in it anyway, and JSON isn't really that hard. It's just impractical.
I do not run the script code twice =)

Original thread: https://forums.rpgmakerweb.com/threads/update-to-core-plugin-manager-to-separate-plugin-name-from-filename.48187/