Hi,这是我开发的新工具,能够帮助查找插件冲突。
最新版本的下载连结在
Github上。下载完后双击打开
conflict-finder即可使用。
本工具是利用分析插件的执行顺序及写法来判断冲突,加密混淆过或写法比较特别的插件无法正确的被判断。找到插件之间的冲突后,本工具能够建议插件的摆放位置,藉由调换顺序来解决某些部分的冲突。
然而,不是所有的插件冲突都可以藉由调换顺序来解决,RPG Maker常见的几种插件冲突有:
覆盖(Overwrite)
A插件
- const _Game_Player_searchLimit = Game_Player.prototype.searchLimit;Game_Player.prototype.searchLimit = function() { if (this.isDashing()) { return 999; } return _Game_Player_searchLimit.call(this);};复制代码
复制代码B插件
- Game_Party.prototype.maxItems = function(item) { return 999;};复制代码
复制代码A插件的作用完全被覆盖而失效了。如果是不小心覆盖的,就可能会导致错误发生。当A插件使用了别名(Alias)进行了补丁(Patching),而B插件是直接覆盖时,藉由调换两者顺序,可能可以让两个插件都能有作用。但是如果两者都是覆盖的写法,那则无法简单进行调换来解决。
另一种是:
过时(Outdated)
原始
- Game_Character.prototype.searchLimit = function() { return 12;};复制代码
复制代码A插件
- const _GamePlayer_searchLimit = Game_Player.prototype.searchLimit;Game_Player.prototype.searchLimit = function() { if (this.isDashing()) { return 999; } return _GamePlayer_searchLimit.call(this);};复制代码
复制代码B插件
- Game_Character.prototype.searchLimit = function() { return 0;};复制代码
复制代码因为
Game_Player本身没有
searchLimit方法,而是继承自
Game_Character,所以A插件的
searchLimit 储存着的是
Game_Character的
searchLimit。当B插件后来再修改了
searchLimit,A插件的
searchLimit仍然是旧的,调换两者的顺序也能解决此问题。
利用一种函数式的别名补丁方法,可以避免发生此问题:
- /** * Automatically choose whether to alias itself or the parent class. * * @param {Object} aliasClass - Use "Foo.prototype" for instance methods and "Foo" for static methods. * @param {string} methodName - The name of the method to alias. * @returns {Function} - The aliased method, callable with "call" or "apply". */PluginManager.alias = function(aliasClass, methodName) { if (aliasClass.hasOwnProperty(methodName)) { return aliasClass[methodName]; } else { const superClass = Object.getPrototypeOf(aliasClass); const superMethod = function(...args) { return superClass[methodName].apply(this, args); }; return superMethod; }};复制代码
复制代码将
- const _GamePlayer_searchLimit = Game_Player.prototype.searchLimit;复制代码
复制代码改成
- const _GamePlayer_searchLimit = PluginManager.alias(Game_Player.prototype, "searchLimit");复制代码
复制代码即可自动判断当前类别有没有此方法,没有的话,则会在调用时自动呼叫父类的方法来获取最新的状态。
本帖来自P1论坛作者moonyoulove,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:
https://rpg.blue/forum.php?mod=viewthread&tid=496622 若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。