From 494672b1c424e8f9124b64fadf82fac04b1df3ac Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Tue, 14 Apr 2015 18:21:23 +0800 Subject: [PATCH 1/4] Update -x timeline and parser --- extensions/cocostudio/action/CCActionFrame.js | 16 +- .../cocostudio/loader/parsers/action-2.x.js | 35 ++- .../loader/parsers/timelineParser-2.x.js | 51 +++- .../cocostudio/timeline/ActionTimeline.js | 28 +++ extensions/cocostudio/timeline/Frame.js | 232 ++++++++++++++++-- 5 files changed, 321 insertions(+), 41 deletions(-) diff --git a/extensions/cocostudio/action/CCActionFrame.js b/extensions/cocostudio/action/CCActionFrame.js index 04c1dfa450..755cbbd578 100644 --- a/extensions/cocostudio/action/CCActionFrame.js +++ b/extensions/cocostudio/action/CCActionFrame.js @@ -99,9 +99,9 @@ ccs.FrameEaseType = { Circ_EaseOut : 20, Circ_EaseInOut : 21, - Elastic_EaesIn : 22, - Elastic_EaesOut : 23, - Elastic_EaesInOut : 24, + Elastic_EaseIn : 22, + Elastic_EaseOut : 23, + Elastic_EaseInOut : 24, Back_EaseIn : 25, Back_EaseOut : 26, @@ -109,7 +109,9 @@ ccs.FrameEaseType = { Bounce_EaseIn : 28, Bounce_EaseOut : 29, - Bounce_EaseInOut : 30 + Bounce_EaseInOut : 30, + + TWEEN_EASING_MAX: 1000 }; @@ -227,13 +229,13 @@ ccs.ActionFrame = ccs.Class.extend(/** @lends ccs.ActionFrame# */{ case ccs.FrameEaseType.Circ_EaseInOut: resultAction = action.easing(cc.easeCircleActionInOut()); break; - case ccs.FrameEaseType.Elastic_EaesIn: + case ccs.FrameEaseType.Elastic_EaseIn: resultAction = action.easing(cc.easeElasticIn()); break; - case ccs.FrameEaseType.Elastic_EaesOut: + case ccs.FrameEaseType.Elastic_EaseOut: resultAction = action.easing(cc.easeElasticOut()); break; - case ccs.FrameEaseType.Elastic_EaesInOut: + case ccs.FrameEaseType.Elastic_EaseInOut: resultAction = action.easing(cc.easeElasticInOut()); break; case ccs.FrameEaseType.Back_EaseIn: diff --git a/extensions/cocostudio/loader/parsers/action-2.x.js b/extensions/cocostudio/loader/parsers/action-2.x.js index d7ff403256..58d5801c5c 100644 --- a/extensions/cocostudio/loader/parsers/action-2.x.js +++ b/extensions/cocostudio/loader/parsers/action-2.x.js @@ -65,14 +65,14 @@ deferred: function(json, resourcePath, action, file){ var animationlist = json["Content"]["Content"]["AnimationList"]; var length = animationlist ? animationlist.length : 0; - for (var i = 0; i < length; i++) { - var animationdata = animationlist[i]; - var info = { name: null, startIndex: null, endIndex: null }; - info.name = animationdata["Name"]; - info.startIndex = animationdata["StartIndex"]; - info.endIndex = animationdata["EndIndex"]; - action.addAnimationInfo(info); - } + for (var i = 0; i < length; i++){ + var animationdata = animationlist[i]; + var info = { name: null, startIndex: null, endIndex: null }; + info.name = animationdata["Name"]; + info.startIndex = animationdata["StartIndex"]; + info.endIndex = animationdata["EndIndex"]; + action.addAnimationInfo(info); + } } }); @@ -220,7 +220,7 @@ }, { name: "ActionValue", - handle: function(options){ + handle: function (options) { var frame = new ccs.InnerActionFrame(); var innerActionType = options["InnerActionType"]; @@ -229,6 +229,10 @@ var singleFrameIndex = options["SingleFrameIndex"]; + var frameIndex = options["FrameIndex"]; + if(frameIndex !== undefined) + frame.setFrameIndex(frameIndex); + frame.setInnerActionType(ccs.InnerActionType[innerActionType]); frame.setSingleFrameIndex(singleFrameIndex); @@ -240,6 +244,15 @@ } ]; + var loadEasingDataWithFlatBuffers = function(frame, options){ + var type = options["Type"]; + frame.setTweenType(type); + var points = options["Points"]; + if(points){ + frame.setEasingParams(points); + } + }; + frameList.forEach(function(item){ parser.registerParser(item.name, function(options, resourcePath){ var timeline = new ccs.Timeline(); @@ -252,6 +265,10 @@ frame.setFrameIndex(frameData["FrameIndex"]); var tween = frameData["Tween"] != null ? frameData["Tween"] : true; frame.setTween(tween); + //https://github.com/cocos2d/cocos2d-x/pull/11388/files + var easingData = options["EasingData"]; + if(easingData) + loadEasingDataWithFlatBuffers(frame, easingData); timeline.addFrame(frame); }); } diff --git a/extensions/cocostudio/loader/parsers/timelineParser-2.x.js b/extensions/cocostudio/loader/parsers/timelineParser-2.x.js index 542fb9b5eb..fe4bd63ef8 100644 --- a/extensions/cocostudio/loader/parsers/timelineParser-2.x.js +++ b/extensions/cocostudio/loader/parsers/timelineParser-2.x.js @@ -111,7 +111,13 @@ node.setTag(json["Tag"] || 0); - node.setUserObject(new ccs.ActionTimelineData(json["ActionTag"] || 0)); + var actionTag = json["ActionTag"] || 0; + var extensionData = new ccs.ObjectExtensionData(); + var customProperty = json["UserData"]; + if(customProperty !== undefined) + extensionData.setCustomProperty(customProperty); + extensionData.setActionTag(actionTag); + node.setUserObject(extensionData); node.setCascadeColorEnabled(true); node.setCascadeOpacityEnabled(true); @@ -175,6 +181,16 @@ } }); + var blendData = json["BlendFunc"]; + if(json["BlendFunc"]) { + var blendFunc = cc.BlendFunc.ALPHA_PREMULTIPLIED; + if (blendData["Src"] !== undefined) + blendFunc.src = blendData["Src"]; + if (blendData["Dst"] !== undefined) + blendFunc.dst = blendData["Dst"]; + node.setBlendFunc(new cc.BlendFunc()); + } + if(json["FlipX"]) node.setFlippedX(true); if(json["FlipY"]) @@ -203,6 +219,16 @@ node = new cc.ParticleSystem(path); self.generalAttributes(node, json); !cc.sys.isNative && node.setDrawMode(cc.ParticleSystem.TEXTURE_MODE); + + var blendData = json["BlendFunc"]; + if(json["BlendFunc"]){ + var blendFunc = cc.BlendFunc.ALPHA_PREMULTIPLIED; + if(blendData["Src"] !== undefined) + blendFunc.src = blendData["Src"]; + if(blendData["Dst"] !== undefined) + blendFunc.dst = blendData["Dst"]; + node.setBlendFunc(new cc.BlendFunc()); + } }); return node; }; @@ -227,7 +253,12 @@ var actionTag = json["ActionTag"] || 0; widget.setActionTag(actionTag); - widget.setUserObject(new ccs.ActionTimelineData(actionTag)); + var extensionData = new ccs.ObjectExtensionData(); + var customProperty = json["UserData"]; + if(customProperty !== undefined) + extensionData.setCustomProperty(customProperty); + extensionData.setActionTag(actionTag); + widget.setUserObject(extensionData); var rotationSkewX = json["RotationSkewX"]; if (rotationSkewX) @@ -492,6 +523,16 @@ } widget.setTextVerticalAlignment(v_alignment); + if(json["OutlineEnabled"] && json["OutlineColor"]) + widget.enableOutline(getColor(json["OutlineColor"]), json["OutlineSize"] || 0); + + if(json["ShadowEnabled"] && json["ShadowColor"]) + widget.enableShadow( + getColor(json["ShadowColor"]), + cc.size(getParam(json["ShadowOffsetX"], 2), getParam(json["ShadowOffsetY"], -2)), + json["ShadowBlurRadius"] || 0 + ); + //todo check it var isCustomSize = json["IsCustomSize"]; if(isCustomSize != null) @@ -1157,6 +1198,9 @@ parser.generalAttributes(obj.node, json); if(obj.action && obj.node){ obj.action.tag = obj.node.tag; + var InnerActionSpeed = json["InnerActionSpeed"]; + if(InnerActionSpeed !== undefined) + obj.action.setTimeSpeed(InnerActionSpeed); obj.node.runAction(obj.action); obj.action.gotoFrameAndPause(0); } @@ -1245,7 +1289,8 @@ var r = json["R"] != null ? json["R"] : 255; var g = json["G"] != null ? json["G"] : 255; var b = json["B"] != null ? json["B"] : 255; - return cc.color(r, g, b); + var a = json["A"] != null ? json["A"] : 255; + return cc.color(r, g, b, a); }; var setContentSize = function(node, size){ diff --git a/extensions/cocostudio/timeline/ActionTimeline.js b/extensions/cocostudio/timeline/ActionTimeline.js index 0bada129ee..9109c60ea7 100644 --- a/extensions/cocostudio/timeline/ActionTimeline.js +++ b/extensions/cocostudio/timeline/ActionTimeline.js @@ -60,6 +60,34 @@ ccs.ActionTimelineData = ccs.Class.extend({ }); +ccs.ObjectExtensionData = ccs.Class.extend({ + + _customProperty: null, + _timelineData: null, + + ctor: function(){ + this._init(); + }, + + _init: function(){ + this._timelineData = new ccs.ActionTimelineData(0); + return true; + }, + + setActionTag: function(actionTag){ + this._timelineData.setActionTag(actionTag); + }, + + getActionTag: function(){ + return this._timelineData.getActionTag(); + } +}); + +ccs.ObjectExtensionData.create = function(){ + var ret = new ccs.ObjectExtensionData(); + return ret; +}; + /** * Create new ActionTimelineData. * diff --git a/extensions/cocostudio/timeline/Frame.js b/extensions/cocostudio/timeline/Frame.js index 460bbf86d2..b76f1e1328 100644 --- a/extensions/cocostudio/timeline/Frame.js +++ b/extensions/cocostudio/timeline/Frame.js @@ -33,12 +33,15 @@ ccs.Frame = ccs.Class.extend({ _tween: null, _timeline: null, _node: null, + _tweenType: null, + _easingParam: null, ctor: function(){ this._frameIndex = 0; this._tween = true; this._timeline = null; this._node = null; + this._easingParam = []; }, _emitEvent: function(){ @@ -50,6 +53,8 @@ ccs.Frame = ccs.Class.extend({ _cloneProperty: function(frame){ this._frameIndex = frame.getFrameIndex(); this._tween = frame.isTween(); + this._tweenType = frame.getTweenType(); + this.setEasingParams(frame.getEasingParams()); }, /** @@ -131,6 +136,15 @@ ccs.Frame = ccs.Class.extend({ * @param {number} percent */ apply: function(percent){ + if(!this._tween) + return; + if(this._tweenType !== ccs.FrameEaseType.TWEEN_EASING_MAX && this._tweenType !== ccs.FrameEaseType.Linear) + percent = this.tweenPercent(percent); + this._onApply(percent); + }, + + _onApply: function(percent){ + }, /** @@ -140,6 +154,140 @@ ccs.Frame = ccs.Class.extend({ * @return {ccs.Frame} */ clone: function(){ // = 0 + }, + + tweenPercent: function(percent){ + return this._tweenTo(percent, this._tweenType, this._easingParam); + }, + + setEasingParams: function(easingParams){ + if(easingParams){ + this._easingParam.length = 0; + for(var i=0; i Date: Tue, 14 Apr 2015 18:26:54 +0800 Subject: [PATCH 2/4] Update -x timeline and parser --- .../cocostudio/loader/parsers/action-2.x.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/extensions/cocostudio/loader/parsers/action-2.x.js b/extensions/cocostudio/loader/parsers/action-2.x.js index 58d5801c5c..8e27788733 100644 --- a/extensions/cocostudio/loader/parsers/action-2.x.js +++ b/extensions/cocostudio/loader/parsers/action-2.x.js @@ -65,14 +65,14 @@ deferred: function(json, resourcePath, action, file){ var animationlist = json["Content"]["Content"]["AnimationList"]; var length = animationlist ? animationlist.length : 0; - for (var i = 0; i < length; i++){ - var animationdata = animationlist[i]; - var info = { name: null, startIndex: null, endIndex: null }; - info.name = animationdata["Name"]; - info.startIndex = animationdata["StartIndex"]; - info.endIndex = animationdata["EndIndex"]; - action.addAnimationInfo(info); - } + for (var i = 0; i < length; i++){ + var animationdata = animationlist[i]; + var info = { name: null, startIndex: null, endIndex: null }; + info.name = animationdata["Name"]; + info.startIndex = animationdata["StartIndex"]; + info.endIndex = animationdata["EndIndex"]; + action.addAnimationInfo(info); + } } }); From 51af269ed9e2f152d4e932dbf38f585669c800b7 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Wed, 15 Apr 2015 15:21:44 +0800 Subject: [PATCH 3/4] Update -x timeline and parser --- extensions/cocostudio/loader/parsers/action-2.x.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/extensions/cocostudio/loader/parsers/action-2.x.js b/extensions/cocostudio/loader/parsers/action-2.x.js index 8e27788733..dfe69dc51f 100644 --- a/extensions/cocostudio/loader/parsers/action-2.x.js +++ b/extensions/cocostudio/loader/parsers/action-2.x.js @@ -249,6 +249,9 @@ frame.setTweenType(type); var points = options["Points"]; if(points){ + points = points.map(function(p){ + return cc.p(p["X"], p["Y"]); + }); frame.setEasingParams(points); } }; @@ -266,7 +269,7 @@ var tween = frameData["Tween"] != null ? frameData["Tween"] : true; frame.setTween(tween); //https://github.com/cocos2d/cocos2d-x/pull/11388/files - var easingData = options["EasingData"]; + var easingData = frameData["EasingData"]; if(easingData) loadEasingDataWithFlatBuffers(frame, easingData); timeline.addFrame(frame); From 8d8c2004a203e547c8cbfe09b2c00b2b34092aa1 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Wed, 15 Apr 2015 15:38:16 +0800 Subject: [PATCH 4/4] Update -x timeline and parser --- extensions/cocostudio/loader/parsers/timelineParser-2.x.js | 2 +- extensions/cocostudio/timeline/ActionTimeline.js | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/extensions/cocostudio/loader/parsers/timelineParser-2.x.js b/extensions/cocostudio/loader/parsers/timelineParser-2.x.js index fe4bd63ef8..cae39cfa3d 100644 --- a/extensions/cocostudio/loader/parsers/timelineParser-2.x.js +++ b/extensions/cocostudio/loader/parsers/timelineParser-2.x.js @@ -188,7 +188,7 @@ blendFunc.src = blendData["Src"]; if (blendData["Dst"] !== undefined) blendFunc.dst = blendData["Dst"]; - node.setBlendFunc(new cc.BlendFunc()); + node.setBlendFunc(blendFunc); } if(json["FlipX"]) diff --git a/extensions/cocostudio/timeline/ActionTimeline.js b/extensions/cocostudio/timeline/ActionTimeline.js index 9109c60ea7..3712238878 100644 --- a/extensions/cocostudio/timeline/ActionTimeline.js +++ b/extensions/cocostudio/timeline/ActionTimeline.js @@ -66,10 +66,6 @@ ccs.ObjectExtensionData = ccs.Class.extend({ _timelineData: null, ctor: function(){ - this._init(); - }, - - _init: function(){ this._timelineData = new ccs.ActionTimelineData(0); return true; }, @@ -84,8 +80,7 @@ ccs.ObjectExtensionData = ccs.Class.extend({ }); ccs.ObjectExtensionData.create = function(){ - var ret = new ccs.ObjectExtensionData(); - return ret; + return new ccs.ObjectExtensionData(); }; /**