Skip to content

Commit 93a8266

Browse files
committed
Merge pull request cocos2d#2643 from VisualSJ/develop-3.3beta
Develop 3.3beta json parser
2 parents fd6b1cb + 055d55b commit 93a8266

File tree

6 files changed

+135
-26
lines changed

6 files changed

+135
-26
lines changed

extensions/cocostudio/loader/load.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ ccs.load = function(file){
180180

181181
object.node = ccs._load(file);
182182
object.action = ccs._load(file, "action");
183+
if(object.action && object.action.tag === -1 && object.node)
184+
object.action.tag = object.node.tag;
183185
return object;
184186
};
185187

extensions/cocostudio/loader/parsers/action-2.x.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
action.setDuration(json["Duration"]);
4545
action.setTimeSpeed(json["Speed"] || 1);
46+
4647
//The process of analysis
4748
var timelines = json["Timelines"];
4849
timelines.forEach(function(timeline){
@@ -59,6 +60,21 @@
5960
cache[file] = action;
6061
cache[file].retain();
6162
return action.clone();
63+
},
64+
65+
deferred: function(json, resourcePath, action, file){
66+
if(cc.sys.isNative) {
67+
var animationlist = json["Content"]["Content"]["AnimationList"];
68+
var length = animationlist ? animationlist.length : 0;
69+
for (var i = 0; i < length; i++) {
70+
var animationdata = animationlist[i];
71+
var info = { name: null, startIndex: null, endIndex: null };
72+
info.name = animationdata["Name"];
73+
info.startIndex = animationdata["StartIndex"];
74+
info.endIndex = animationdata["EndIndex"];
75+
action.addAnimationInfo(info);
76+
}
77+
}
6278
}
6379

6480
});
@@ -201,6 +217,26 @@
201217
var frame = new ccs.ZOrderFrame();
202218
var zorder = options["Value"];
203219
frame.setZOrder(zorder);
220+
return frame;
221+
}
222+
},
223+
{
224+
name: "ActionValue",
225+
handle: function(options){
226+
227+
var frame = new ccs.InnerActionFrame();
228+
var innerActionType = options["InnerActionType"];
229+
230+
var currentAnimationFrame = options["CurrentAniamtionName"];
231+
232+
var singleFrameIndex = options["SingleFrameIndex"];
233+
234+
frame.setInnerActionType(ccs.InnerActionType[innerActionType]);
235+
frame.setSingleFrameIndex(singleFrameIndex);
236+
237+
frame.setEnterWithName(true);
238+
frame.setAnimationName(currentAnimationFrame);
239+
204240
return frame;
205241
}
206242
}

extensions/cocostudio/loader/parsers/timelineParser-2.x.js

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,10 @@
280280

281281
var scale = json["Scale"];
282282
if(scale != null){
283-
widget.setScaleX(scale["ScaleX"] || 1);
284-
widget.setScaleY(scale["ScaleY"] || 1);
283+
var scaleX = getParam(scale["ScaleX"], 1);
284+
var scaleY = getParam(scale["ScaleY"], 1);
285+
widget.setScaleX(scaleX);
286+
widget.setScaleY(scaleY);
285287
}
286288

287289
var anchorPoint = json["AnchorPoint"];
@@ -372,7 +374,7 @@
372374

373375
this.widgetAttributes(widget, json);
374376

375-
var clipEnabled = json["ClipAple"];
377+
var clipEnabled = json["ClipAble"];
376378
if(clipEnabled != null)
377379
widget.setClippingEnabled(clipEnabled);
378380

@@ -387,7 +389,7 @@
387389
if(backGroundScale9Enabled != null)
388390
widget.setBackGroundImageScale9Enabled(backGroundScale9Enabled);
389391

390-
var opacity = json["Alpha"] || 255;
392+
var opacity = getParam(json["Alpha"], 255);
391393
widget.setOpacity(opacity);
392394

393395
loadTexture(json["FileData"], resourcePath, function(path, type){
@@ -640,8 +642,7 @@
640642
this.widgetAttributes(widget, json);
641643

642644
var clipEnabled = json["ClipAble"];
643-
if(clipEnabled)
644-
widget.setClippingEnabled(true);
645+
widget.setClippingEnabled(clipEnabled);
645646

646647
var colorType = getParam(json["ComboBoxIndex"], 0);
647648
widget.setBackGroundColorType(colorType);
@@ -681,7 +682,9 @@
681682

682683
var colorVector = json["ColorVector"];
683684
if(colorVector){
684-
widget.setBackGroundColorVector(cc.p(colorVector["ScaleX"] || 1, colorVector["ScaleY"] || 1));
685+
var colorVectorX = getParam(colorVector["ScaleX"], 1);
686+
var colorVectorY = getParam(colorVector["ScaleY"], 1);
687+
widget.setBackGroundColorVector(cc.p(colorVectorX, colorVectorY));
685688
}
686689

687690
loadTexture(json["FileData"], resourcePath, function(path, type){
@@ -690,8 +693,8 @@
690693

691694
var innerNodeSize = json["InnerNodeSize"];
692695
var innerSize = cc.size(
693-
innerNodeSize["width"] || 0,
694-
innerNodeSize["height"] || 0
696+
innerNodeSize["Width"] || 0,
697+
innerNodeSize["Height"] || 0
695698
);
696699
widget.setInnerContainerSize(innerSize);
697700

@@ -822,9 +825,8 @@
822825

823826
this.widgetAttributes(widget, json);
824827

825-
var clipEnabled = json["ClipAble"];
826-
if(clipEnabled)
827-
widget.setClippingEnabled(true);
828+
var clipEnabled = json["ClipAble"] || false;
829+
widget.setClippingEnabled(clipEnabled);
828830

829831
var backGroundScale9Enabled = json["Scale9Enable"];
830832
if(backGroundScale9Enabled){
@@ -859,7 +861,7 @@
859861

860862
var colorVector = json["ColorVector"];
861863
if(colorVector != null && colorVector["ScaleX"] != null && colorVector["ScaleY"] != null)
862-
widget.setBackGroundColorVector(colorVector["ScaleX"], colorVector["ScaleY"]);
864+
widget.setBackGroundColorVector(cc.p(colorVector["ScaleX"], colorVector["ScaleY"]));
863865
if(bgColorOpacity != null)
864866
widget.setBackGroundColorOpacity(bgColorOpacity);
865867

@@ -885,9 +887,8 @@
885887

886888
this.widgetAttributes(widget, json);
887889

888-
var clipEnabled = json["ClipAble"];
889-
if(clipEnabled)
890-
widget.setClippingEnabled(true);
890+
var clipEnabled = json["ClipAble"] || false;
891+
widget.setClippingEnabled(clipEnabled);
891892

892893
var colorType = getParam(json["ComboBoxIndex"], 0);
893894
widget.setBackGroundColorType(colorType);
@@ -927,7 +928,7 @@
927928
else if (horizontalType == "Align_Right")
928929
widget.setGravity(ccui.ListView.GRAVITY_RIGHT);
929930
else if (horizontalType == "Align_HorizontalCenter")
930-
widget.setGravity(ccui.ListView.GRAVITY_CENTER_VERTICAL);
931+
widget.setGravity(ccui.ListView.GRAVITY_CENTER_HORIZONTAL);
931932
}
932933

933934

@@ -955,7 +956,7 @@
955956

956957
var colorVector = json["ColorVector"];
957958
if(colorVector != null && colorVector["ScaleX"] != null && colorVector["ScaleY"] != null)
958-
widget.setBackGroundColorVector(colorVector["ScaleX"], colorVector["ScaleY"]);
959+
widget.setBackGroundColorVector(cc.p(colorVector["ScaleX"], colorVector["ScaleY"]));
959960
if(bgColorOpacity != null)
960961
widget.setBackGroundColorOpacity(bgColorOpacity);
961962

@@ -1130,6 +1131,8 @@
11301131
loadTexture(json["FileData"], resourcePath, function(path, type){
11311132
if(type == 0)
11321133
node = new cc.TMXTiledMap(path);
1134+
1135+
parser.generalAttributes(node, json);
11331136
});
11341137

11351138
return node;
@@ -1145,9 +1148,16 @@
11451148
var projectFile = json["FileData"];
11461149
if(projectFile != null && projectFile["Path"]){
11471150
var file = resourcePath + projectFile["Path"];
1148-
if(cc.loader.getRes(file))
1149-
return ccs._load(file);
1150-
else
1151+
if(cc.loader.getRes(file)){
1152+
var obj = ccs.load(file);
1153+
parser.generalAttributes(obj.node, json);
1154+
if(obj.action && obj.node){
1155+
obj.action.tag = obj.node.tag;
1156+
obj.node.runAction(obj.action);
1157+
obj.action.gotoFrameAndPause(0);
1158+
}
1159+
return obj.node;
1160+
} else
11511161
cc.log("%s need to be preloaded", file);
11521162
}
11531163
};
@@ -1176,6 +1186,8 @@
11761186

11771187
var currentAnimationName = json["CurrentAnimationName"];
11781188

1189+
parser.generalAttributes(node, json);
1190+
11791191
loadTexture(json["FileData"], resourcePath, function(path, type){
11801192
var plists, pngs;
11811193
var armJson = cc.loader.getRes(path);
@@ -1241,6 +1253,7 @@
12411253

12421254
var register = [
12431255
{name: "SingleNodeObjectData", handle: parser.initSingleNode},
1256+
{name: "LayerObjectData", handle: parser.initSingleNode},
12441257
{name: "SpriteObjectData", handle: parser.initSprite},
12451258
{name: "ParticleObjectData", handle: parser.initParticle},
12461259
{name: "PanelObjectData", handle: parser.initPanel},

extensions/cocostudio/timeline/ActionTimeline.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ ccs.ActionTimeline = cc.Action.extend({
374374
}
375375

376376
this._time += delta * this._timeSpeed;
377-
this._currentFrame = this._time / this._frameInternal;
377+
this._currentFrame = this._time / this._frameInternal | 0;
378378

379379
this._stepToFrame(this._currentFrame);
380380

extensions/cocostudio/timeline/Frame.js

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,11 @@ ccs.InnerActionFrame = ccs.Frame.extend({
859859
_innerActionType: null,
860860
_startFrameIndex: null,
861861

862+
_endFrameIndex:0,
863+
_singleFrameIndex: 0,
864+
_enterWithName: false,
865+
_animationName: "",
866+
862867
ctor: function(){
863868
ccs.Frame.prototype.ctor.call(this);
864869

@@ -871,7 +876,62 @@ ccs.InnerActionFrame = ccs.Frame.extend({
871876
* @param {ccs.Frame} nextFrame
872877
*/
873878
onEnter: function(nextFrame){
874-
//override
879+
var innerActiontimeline = this._node.getActionByTag(this._node.getTag());
880+
if (/*ccs.InnerActionType.SingleFrame*/"SingleFrame" == this._innerActionType){
881+
innerActiontimeline.gotoFrameAndPause(this._singleFrameIndex);
882+
return;
883+
}
884+
885+
var innerStart = this._startFrameIndex;
886+
var innerEnd = this._endFrameIndex;
887+
if (this._enterWithName){
888+
if (this._animationName == "-- ALL --"){
889+
innerStart = 0;
890+
innerEnd = innerActiontimeline.getDuration();
891+
} else if(innerActiontimeline.IsAnimationInfoExists(this._animationName)) {
892+
var info = innerActiontimeline.getAnimationInfo(this._animationName);
893+
innerStart = info.startIndex;
894+
innerEnd = info.endIndex;
895+
}else{
896+
cc.log("Animation %s not exists!", this._animationName);
897+
}
898+
}
899+
900+
var duration = this._timeline.getActionTimeline().getDuration();
901+
var odddiff = duration - this._frameIndex - innerEnd + innerStart;
902+
if (odddiff < 0){
903+
innerEnd += odddiff;
904+
}
905+
906+
if (ccs.InnerActionType.NoLoopAction == this._innerActionType){
907+
innerActiontimeline.gotoFrameAndPlay(innerStart, innerEnd, false);
908+
}else if (ccs.InnerActionType.LoopAction == this._innerActionType){
909+
innerActiontimeline.gotoFrameAndPlay(innerStart, innerEnd, true);
910+
}
911+
},
912+
913+
setAnimationName: function(animationName){
914+
if(!this._enterWithName){
915+
cc.log(" cannot set aniamtioname when enter frame with index. setEnterWithName true firstly!");
916+
}else{
917+
this._animationName = animationName;
918+
}
919+
},
920+
921+
setSingleFrameIndex: function(frameIndex){
922+
this._singleFrameIndex = frameIndex;
923+
},
924+
925+
getSingleFrameIndex: function(){
926+
return this._startFrameIndex;
927+
},
928+
929+
setEnterWithName: function(isEnterWithName){
930+
this._enterWithName = isEnterWithName;
931+
},
932+
933+
getEnterWithName: function(){
934+
return this._enterWithName;
875935
},
876936

877937
/**

extensions/cocostudio/timeline/Timeline.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,10 @@ ccs.Timeline = ccs.Class.extend({
134134
* @param {cc.Node} node
135135
*/
136136
setNode: function(node){
137-
for (var i=0; i<this._frames.length; i++)
138-
{
137+
for (var i=0; i<this._frames.length; i++){
139138
var frame = this._frames[i];
140139
frame.setNode(node);
141140
}
142-
143141
},
144142

145143
/**

0 commit comments

Comments
 (0)