From 2426c8b0101e39818a7c20d4504d0d91e18d5c43 Mon Sep 17 00:00:00 2001 From: oc Date: Tue, 30 Apr 2019 20:22:06 +0800 Subject: [PATCH] canEquip -> equipCondition --- _docs/script.md | 32 +++++++++++++++++++++++++++++++- _server/table/comment.js | 4 ++-- libs/control.js | 1 - libs/items.js | 6 +++--- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/_docs/script.md b/_docs/script.md index 96a48838..0e8c7206 100644 --- a/_docs/script.md +++ b/_docs/script.md @@ -224,7 +224,11 @@ function () { - 清晰明了。很容易方便知道自己修改过什么,尤其是可以和系统原有代码进行对比。 - 方便整理成新的插件,给其他的塔使用。 -如果我想对xxx文件中的yyy函数进行重写,其模式一般是:`core.xxx.yyy = function (参数列表) { ... }` +一般而言,复写规则如下: + +**对xxx文件中的yyy函数进行复写,规则是`core.xxx.yyy = function (参数列表) { ... }`。** + +但是,对于`registerXXX`所注册的函数是无效的,例如直接复写`core.control._animationFrame_globalAnimate`函数是没有效果的。对于这种情况引入的函数,需要注册同名函数,可参见最下面的样例。 下面是几个例子,从简单到复杂。 @@ -317,6 +321,32 @@ core.maps.drawMap = function (floorId, callback) { 详见[call和apply的用法](https://www.jianshu.com/p/80ea0d1c04f8)。 +### 复写全局动画绘制函数 + +全局动画绘制在`control.js`的`_animationFrame_globalAnimate`函数。 + +注意到此函数是由`registerAnimationFrame`注册的,因此直接复写是无效的。 + +其在control.js的注册的定义如下: + +```js +// 注册全局动画函数 +this.registerAnimationFrame("globalAnimate", true, this._animationFrame_globalAnimate); +``` + +因此,可以在插件中自行注册一个**同名**的函数来覆盖原始的内容。 + +```js +// 插件中复写全局动画绘制函数 +this.myGlobalAnimate = function (timestamp) { + // ...... 实际复写的函数内容 +} + +// 注册同名(globalAnimate)函数来覆盖系统原始内容 +core.registerAnimationFrame("globalAnimate", true, "myGlobalAnimate"); +``` + + ========================================================================================== [继续阅读下一章:API列表](api) diff --git a/_server/table/comment.js b/_server/table/comment.js index d5d72cf8..ef03953d 100644 --- a/_server/table/comment.js +++ b/_server/table/comment.js @@ -81,12 +81,12 @@ var comment_c456ea59_6018_45ef_8bcc_211a24c627dc = { "_lint": true, "_data": "当前能否使用该道具,仅对cls为tools或constants有效。" }, - "canEquip": { + "equipCondition": { "_leaf": true, "_type": "textarea", "_string": true, "_lint": true, - "_data": "当前能否装备某个装备,仅对cls为equips有效。\n与canUseItemEffect不同,这里null代表可以装备。" + "_data": "能装备某个装备的条件,仅对cls为equips有效。\n与canUseItemEffect不同,这里null代表可以装备。" } } }, diff --git a/libs/control.js b/libs/control.js index fb836179..d3289e37 100644 --- a/libs/control.js +++ b/libs/control.js @@ -189,7 +189,6 @@ control.prototype._animationFrame_animate = function (timestamp) { control.prototype._animationFrame_heroMoving = function (timestamp) { if (core.status.heroMoving <= 0) return; - var x=core.getHeroLoc('x'), y=core.getHeroLoc('y'), direction = core.getHeroLoc('direction'); // 换腿 if (timestamp - core.animateFrame.moveTime > (core.values.moveSpeed||100)) { core.animateFrame.leftLeg = !core.animateFrame.leftLeg; diff --git a/libs/items.js b/libs/items.js index 15ce13ac..13030de5 100644 --- a/libs/items.js +++ b/libs/items.js @@ -11,9 +11,9 @@ items.prototype._init = function () { this.itemEffectTip = items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a.itemEffectTip; this.useItemEffect = items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a.useItemEffect; this.canUseItemEffect = items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a.canUseItemEffect; - if (!items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a.canEquip) - items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a.canEquip = {}; - this.equipCondition = items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a.canEquip; + if (!items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a.equipCondition) + items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a.equipCondition = {}; + this.equipCondition = items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a.equipCondition; } ////// 获得所有道具 //////