Merge pull request #12998 from pandamicro/v3.7.1

Add BoneNode/SkeletonNode/SkinNode JS bindings
This commit is contained in:
pandamicro 2015-07-24 23:42:38 +08:00
commit a666658764
8 changed files with 237 additions and 10 deletions

View File

@ -1692,6 +1692,61 @@ bool jsval_to_vector_v3fc4bt2f(JSContext* cx, JS::HandleValue v, std::vector<coc
return ok;
}
bool jsval_to_std_map_string_string(JSContext* cx, JS::HandleValue v, std::map<std::string, std::string>* ret)
{
if (v.isNullOrUndefined())
{
return true;
}
JS::RootedObject tmp(cx, v.toObjectOrNull());
if (!tmp)
{
CCLOG("%s", "jsval_to_std_map_string_string: the jsval is not an object.");
return false;
}
JS::RootedObject it(cx, JS_NewPropertyIterator(cx, tmp));
std::map<std::string, std::string>& dict = *ret;
while (true)
{
JS::RootedId idp(cx);
JS::RootedValue key(cx);
if (! JS_NextProperty(cx, it, idp.address()) || ! JS_IdToValue(cx, idp, &key))
{
return false; // error
}
if (key.isNullOrUndefined())
{
break; // end of iteration
}
if (!key.isString())
{
continue; // only take account of string key
}
JSStringWrapper keyWrapper(key.toString(), cx);
JS::RootedValue value(cx);
JS_GetPropertyById(cx, tmp, idp, &value);
if (value.isString())
{
JSStringWrapper valueWapper(value.toString(), cx);
dict[keyWrapper.get()] = valueWapper.get();
}
else
{
CCASSERT(false, "jsval_to_std_map_string_string: not supported map type");
}
}
return true;
}
// native --> jsval
jsval ccarray_to_jsval(JSContext* cx, __Array *arr)
@ -2763,4 +2818,27 @@ jsval vector_vec2_to_jsval(JSContext *cx, const std::vector<cocos2d::Vec2>& v)
++i;
}
return OBJECT_TO_JSVAL(jsretArr);
}
jsval std_map_string_string_to_jsval(JSContext* cx, const std::map<std::string, std::string>& v)
{
JS::RootedObject proto(cx);
JS::RootedObject parent(cx);
JS::RootedObject jsRet(cx, JS_NewObject(cx, NULL, proto, parent));
for (auto iter = v.begin(); iter != v.end(); ++iter)
{
JS::RootedValue element(cx);
std::string key = iter->first;
std::string obj = iter->second;
element = std_string_to_jsval(cx, obj);
if (!key.empty())
{
JS_SetProperty(cx, jsRet, key.c_str(), element);
}
}
return OBJECT_TO_JSVAL(jsRet);
}

View File

@ -192,6 +192,7 @@ bool jsval_to_cctex2f(JSContext* cx, JS::HandleValue vp, cocos2d::Tex2F* ret);
bool jsval_to_v3fc4bt2f(JSContext* cx, JS::HandleValue v, cocos2d::V3F_C4B_T2F* ret);
bool jsval_to_v3fc4bt2f_quad(JSContext* cx, JS::HandleValue v, cocos2d::V3F_C4B_T2F_Quad* ret);
bool jsval_to_vector_v3fc4bt2f(JSContext* cx, JS::HandleValue v, std::vector<cocos2d::V3F_C4B_T2F>* ret);
bool jsval_to_std_map_string_string(JSContext* cx, JS::HandleValue v, std::map<std::string, std::string>* ret);
template <class T>
bool jsval_to_ccmap_string_key(JSContext *cx, JS::HandleValue v, cocos2d::Map<std::string, T>* ret)
@ -340,6 +341,7 @@ jsval vector3_to_jsval(JSContext *cx, const cocos2d::Vec3& v);
jsval vector4_to_jsval(JSContext *cx, const cocos2d::Vec4& v);
jsval blendfunc_to_jsval(JSContext *cx, const cocos2d::BlendFunc& v);
jsval vector_vec2_to_jsval(JSContext *cx, const std::vector<cocos2d::Vec2>& v);
jsval std_map_string_string_to_jsval(JSContext* cx, const std::map<std::string, std::string>& v);
#endif /* __JS_MANUAL_CONVERSIONS_H__ */

View File

@ -66,4 +66,8 @@ ccs.Sprite.extend = ccs.Sprite.extend || cc.Sprite.extend;
* @extends ccs.Class
*/
ccs.Component = ccs.Component || cc.Component;
ccs.Component.extend = ccs.Component.extend || cc.Component.extend;
ccs.Component.extend = ccs.Component.extend || cc.Component.extend;
ccs.SkinNode = cc.Node;
ccs.BoneNode.extend = cc.Class.extend;
ccs.SkeletonNode.extend = cc.Class.extend;

View File

@ -98,6 +98,15 @@ ccs.ActionTimelineData.prototype._ctor = function(actionTag) {
}
};
ccs.ObjectExtensionData.prototype._ctor = function() {
ccs.ObjectExtensionData.prototype.init.call(this);
ccs.ComExtensionData.prototype._ctor = function() {
ccs.ComExtensionData.prototype.init.call(this);
};
ccs.BoneNode.prototype._ctor = function (length) {
ccs.BoneNode.prototype.init.call(this);
length !== undefined && this.setDebugDrawLength(length);
};
ccs.SkeletonNode.prototype._ctor = function () {
ccs.SkeletonNode.prototype.init.call(this);
};

View File

@ -112,12 +112,16 @@
node.setTag(json["Tag"] || 0);
var actionTag = json["ActionTag"] || 0;
var extensionData = new ccs.ObjectExtensionData();
var extensionData = new ccs.ComExtensionData();
var customProperty = json["UserData"];
if(customProperty !== undefined)
extensionData.setCustomProperty(customProperty);
extensionData.setActionTag(actionTag);
node.setUserObject(extensionData);
if (node.getComponent("ComExtensionData"))
{
node.removeComponent("ComExtensionData");
}
node.addComponent(extensionData);
node.setCascadeColorEnabled(true);
node.setCascadeOpacityEnabled(true);
@ -284,12 +288,16 @@
var actionTag = json["ActionTag"] || 0;
widget.setActionTag(actionTag);
var extensionData = new ccs.ObjectExtensionData();
var extensionData = new ccs.ComExtensionData();
var customProperty = json["UserData"];
if(customProperty !== undefined)
extensionData.setCustomProperty(customProperty);
extensionData.setActionTag(actionTag);
widget.setUserObject(extensionData);
if (widget.getComponent("ComExtensionData"))
{
widget.removeComponent("ComExtensionData");
}
widget.addComponent(extensionData);
var rotationSkewX = json["RotationSkewX"];
if (rotationSkewX)
@ -1291,6 +1299,28 @@
return node;
};
parser.initBoneNode = function(json, resourcePath){
var node = new ccs.BoneNode();
var length = json["Length"];
if(length !== undefined)
node.setDebugDrawLength(length);
var blendFunc = json["BlendFunc"];
if(blendFunc)
node.setBlendFunc(new cc.BlendFunc(blendFunc["Src"] || 0, blendFunc["Dst"] || 0));
parser.generalAttributes(node, json);
return node;
};
parser.initSkeletonNode = function(json){
var node = new ccs.SkeletonNode();
parser.generalAttributes(node, json);
return node;
};
var loadedPlist = {};
var loadTexture = function(json, resourcePath, cb){
if(json != null){
@ -1571,6 +1601,8 @@
{name: "GameMapObjectData", handle: parser.initGameMap},
{name: "ProjectNodeObjectData", handle: parser.initProjectNode},
{name: "ArmatureNodeObjectData", handle: parser.initArmature},
{name: "BoneNodeObjectData", handle: parser.initBoneNode},
{name: "SkeletonNodeObjectData", handle: parser.initSkeletonNode},
{name: "Sprite3DObjectData", handle: parser.initSprite3D},
{name: "Particle3DObjectData", handle: parser.initParticle3D},

File diff suppressed because one or more lines are too long

@ -1 +1 @@
Subproject commit 473c1cfbbf164c04f1d7b173fdcd63418ff15067
Subproject commit ebdde87eda9c03a2d8b8153aef3ac86dacea0981

View File

@ -27,7 +27,7 @@ headers = %(cocosdir)s/cocos/editor-support/cocostudio/CocoStudio.h %(cocosdir)s
# what classes to produce code for. You can use regular expressions here. When testing the regular
# expression, it will be enclosed in "^$", like this: "^Menu*$".
classes = Armature ArmatureAnimation Skin Bone ColliderDetector ColliderBody ArmatureDataManager InputDelegate ComController ComAudio ComAttribute ComRender ActionManagerEx SceneReader GUIReader BatchNode ActionObject BaseData Tween ColliderFilter DisplayManager DecorativeDisplay ProcessBase AnimationData MovementData ContourData TextureData ActionTimelineData ActionTimeline ActionTimelineCache Frame TextureFrame RotationFrame SkewFrame VisibleFrame RotationSkewFrame PositionFrame ScaleFrame AnchorPointFrame InnerActionFrame ColorFrame AlphaFrame EventFrame ZOrderFrame NodeReader Timeline CSLoader ComExtensionData
classes = Armature ArmatureAnimation Skin Bone ColliderDetector ColliderBody ArmatureDataManager InputDelegate ComController ComAudio ComAttribute ComRender ActionManagerEx SceneReader GUIReader BatchNode ActionObject BaseData Tween ColliderFilter DisplayManager DecorativeDisplay ProcessBase AnimationData MovementData ContourData TextureData ActionTimelineData ActionTimeline ActionTimelineCache Frame TextureFrame RotationFrame SkewFrame VisibleFrame RotationSkewFrame PositionFrame ScaleFrame AnchorPointFrame InnerActionFrame ColorFrame AlphaFrame EventFrame ZOrderFrame NodeReader Timeline CSLoader ComExtensionData BoneNode SkeletonNode
# what should we skip? in the format ClassName::[function function]
# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also
@ -80,4 +80,4 @@ abstract_classes = ColliderDetector ColliderBody ArmatureDataManager InputDelega
# Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'.
script_control_cpp = no
classes_need_extend = Armature ComController
classes_need_extend = Armature ComController BoneNode SkinNode SkeletonNode