Merge pull request #12182 from VisualSJ/v3-jsb

[ci skip] Synchronization studio parser
This commit is contained in:
pandamicro 2015-06-11 17:35:15 +08:00
commit 12de53726d
7 changed files with 61 additions and 34 deletions

View File

@ -36,7 +36,7 @@ ccs._load = (function(){
var json = cc.loader.getRes(file);
if(!json)
return cc.log("%s is not exists", file);
return cc.log("%s does not exist", file);
var ext = extname(file).toLocaleLowerCase();
if(ext !== "json" && ext !== "exportjson")
return cc.log("%s load error, must be json file", file);

View File

@ -51,11 +51,11 @@
if(parser)
frame = parser.call(self, timeline, resourcePath);
else
cc.log("parser is not exists : %s", timeline["frameType"]);
cc.log("parser does not exist : %s", timeline["frameType"]);
if(frame)
action.addTimeline(frame);
if(timeline["frameType"] == "ColorFrame"){
if(timeline["frameType"] === "ColorFrame"){
action.addTimeline(
self.parsers["AlphaFrame"].call(self, timeline, resourcePath)
);
@ -235,4 +235,4 @@
load.registerParser("action", "*", parser);
})(ccs._load, ccs._parser);
})(ccs._load, ccs._parser);

View File

@ -149,8 +149,16 @@
frame.setAnchorPoint(cc.p(anchorx, anchory));
return frame;
}
},
{
},{
name: "AnchorPoint",
handle: function(options){
var frame = new ccs.AnchorPointFrame();
var anchorx = options["X"];
var anchory = options["Y"];
frame.setAnchorPoint(cc.p(anchorx, anchory));
return frame;
}
},{
name: "InnerAction",
handle: function(options){
var frame = new ccs.InnerActionFrame();
@ -186,11 +194,20 @@
{
name: "FileData",
handle: function(options, resourcePath){
var frame = new ccs.TextureFrame();
var texture = options["TextureFile"];
var frame, texture, plist, path, spriteFrame;
frame = new ccs.TextureFrame();
texture = options["TextureFile"];
if(texture != null) {
var path = texture["Path"];
var spriteFrame = cc.spriteFrameCache.getSpriteFrame(path);
plist = texture["Plist"];
path = texture["Path"];
spriteFrame = cc.spriteFrameCache.getSpriteFrame(path);
if(!spriteFrame && plist){
if(cc.loader.getRes(resourcePath + plist)){
cc.spriteFrameCache.addSpriteFrames(resourcePath + plist);
}else{
cc.log("%s need to be preloaded", resourcePath + plist);
}
}
if(spriteFrame == null){
path = resourcePath + path;
}
@ -249,11 +266,13 @@
var type = options["Type"];
frame.setTweenType(type);
var points = options["Points"];
var result = [];
if(points){
points = points.map(function(p){
return cc.p(p["X"], p["Y"]);
points.forEach(function(p){
result.push(p["X"]);
result.push(p["Y"]);
});
frame.setEasingParams(points);
frame.setEasingParams(result);
}
};

View File

@ -41,7 +41,7 @@
* @returns {*}
*/
widgetFromJsonFile: function(file){
var json = cc.loader.getRes(file);
var json = cc.loader.getRes(cc.path.join(cc.loader.resPath, file));
if(json)
this._fileDesignSizes[file] = cc.size(json["designWidth"]||0, json["designHeight"]||0);
@ -91,9 +91,9 @@
* @returns {Number}
*/
getVersionInteger: function(version){
if(!version || typeof version != "string") return 0;
if(!version || typeof version !== "string") return 0;
var arr = version.split(".");
if (arr.length != 4)
if (arr.length !== 4)
return 0;
var num = 0;
arr.forEach(function(n, i){
@ -199,7 +199,7 @@
getNodeByTag: function(tag){
if (this._node == null)
return null;
if (this._node.getTag() == tag)
if (this._node.getTag() === tag)
return this._node;
return this._nodeByTag(this._node, tag);
},
@ -211,7 +211,7 @@
var children = parent.getChildren();
for (var i = 0; i < children.length; i++) {
var child = children[i];
if (child && child.getTag() == tag) {
if (child && child.getTag() === tag) {
retNode = child;
break;
} else {

View File

@ -92,9 +92,9 @@
"CCSprite": function(node, component, resourcePath){
var child = new cc.Sprite();
loadTexture(component["fileData"], resourcePath, function(path, type){
if(type == 0)
if(type === 0)
child.setTexture(path);
else if(type == 1){
else if(type === 1){
var spriteFrame = cc.spriteFrameCache.getSpriteFrame(path);
child.setSpriteFrame(spriteFrame);
}
@ -106,7 +106,7 @@
"CCTMXTiledMap": function(node, component, resourcePath){
var child = null;
loadTexture(component["fileData"], resourcePath, function(path, type){
if(type == 0)
if(type === 0)
child = new cc.TMXTiledMap(path);
});
var render = new ccs.ComRender(child, "CCTMXTiledMap");
@ -116,7 +116,7 @@
"CCParticleSystemQuad": function(node, component, resourcePath){
var child = null;
loadTexture(component["fileData"], resourcePath, function(path, type){
if(type == 0)
if(type === 0)
child = new cc.ParticleSystem(path);
else
cc.log("unknown resourcetype on CCParticleSystemQuad!");
@ -129,7 +129,7 @@
"CCArmature": function(node, component, resourcePath){
var child = null;
loadTexture(component["fileData"], resourcePath, function(path, type){
if(type == 0){
if(type === 0){
var jsonDict = cc.loader.getRes(path);
if (!jsonDict) cc.log("Please load the resource [%s] first!", path);
var armature_data = jsonDict["armature_data"];
@ -153,7 +153,7 @@
"CCComAudio": function(node, component, resourcePath){
var audio = null;
loadTexture(component["fileData"], resourcePath, function(path, type){
if(type == 0){
if(type === 0){
audio = new ccs.ComAudio();
audio.preloadEffect(path);
var name = component["name"];
@ -166,9 +166,9 @@
"CCComAttribute": function(node, component, resourcePath){
var attribute = null;
loadTexture(component["fileData"], resourcePath, function(path, type){
if(type == 0){
if(type === 0){
attribute = new ccs.ComAttribute();
if (path != "")
if (path !== "")
attribute.parse(path);
node.addComponent(attribute);
}else
@ -179,7 +179,7 @@
"CCBackgroundAudio": function(node, component, resourcePath){
var audio = null;
loadTexture(component["fileData"], resourcePath, function(path, type){
if(type == 0){
if(type === 0){
audio = new ccs.ComAudio();
audio.preloadBackgroundMusic(path);
audio.setFile(path);var bLoop = Boolean(component["loop"] || 0);

View File

@ -121,6 +121,8 @@
node.setCascadeColorEnabled(true);
node.setCascadeOpacityEnabled(true);
setLayoutComponent(node, json);
};
parser.parseChild = function(node, children, resourcePath){
@ -327,6 +329,11 @@
if (color != null)
widget.setColor(getColor(color));
setLayoutComponent(widget, json);
};
var setLayoutComponent = function(widget, json){
var layoutComponent = ccui.LayoutComponent.bindLayoutComponent(widget);
if(!layoutComponent)
return;
@ -562,8 +569,11 @@
widget.setUnifySizeEnabled(false);
var color = json["CColor"];
json["CColor"] = null;
widget.setTextColor(getColor(color));
this.widgetAttributes(widget, json, widget.isIgnoreContentAdaptWithSize());
json["CColor"] = color;
return widget;
};
@ -1131,13 +1141,10 @@
var volume = json["Volume"] || 0;
cc.audioEngine.setMusicVolume(volume);
//var name = json["Name"];
var resPath = "";
if(cc.loader.resPath)
resPath = (cc.loader.resPath + "/").replace(/\/\/$/, "/");
loadTexture(json["FileData"], resourcePath, function(path, type){
cc.loader.load(path, function(){
cc.audioEngine.playMusic(resPath + path, loop);
cc.audioEngine.playMusic(path, loop);
});
});
@ -1235,6 +1242,7 @@
node.getAnimation().play(currentAnimationName, -1, isLoop);
});
node.setColor(getColor(json["CColor"]));
return node;
};

View File

@ -186,7 +186,7 @@
widget.pushBackCustomItem(child);
} else {
if(!(widget instanceof ccui.Layout)) {
if(child.getPositionType() == ccui.Widget.POSITION_PERCENT) {
if(child.getPositionType() === ccui.Widget.POSITION_PERCENT) {
var position = child.getPositionPercent();
var anchor = widget.getAnchorPoint();
child.setPositionPercent(cc.p(position.x + anchor.x, position.y + anchor.y));
@ -203,7 +203,7 @@
var getPath = function(res, type, path, cb){
if(path){
if(type == 0)
if(type === 0)
cb(res + path, type);
else
cb(path, type);