diff --git a/cocos/scripting/lua-bindings/manual/cocostudio/lua_cocos2dx_csloader_manual.cpp b/cocos/scripting/lua-bindings/manual/cocostudio/lua_cocos2dx_csloader_manual.cpp index 1989ded113..c59a41f5c9 100644 --- a/cocos/scripting/lua-bindings/manual/cocostudio/lua_cocos2dx_csloader_manual.cpp +++ b/cocos/scripting/lua-bindings/manual/cocostudio/lua_cocos2dx_csloader_manual.cpp @@ -64,6 +64,72 @@ tolua_lerror: return 0; } +int lua_cocos2dx_csloader_CSLoader_createNode(lua_State* tolua_S) +{ + int argc = 0; + bool ok = true; +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertable(tolua_S,1,"cc.CSLoader",0,&tolua_err)) goto tolua_lerror; +#endif + + argc = lua_gettop(tolua_S)-1; + + do + { + if (argc == 2) + { + std::string filename; + ok &= luaval_to_std_string(tolua_S, 2,&filename, "cc.CSLoader:createNode"); + if (!ok) { break; } + +#if COCOS2D_DEBUG >= 1 + if (!toluafix_isfunction(tolua_S,3,"LUA_FUNCTION",0,&tolua_err) ) + { + goto tolua_lerror; + } +#endif + + LUA_FUNCTION handler = ( toluafix_ref_function(tolua_S,3,0)); + auto callback = [handler, tolua_S](cocos2d::Ref* ref){ + if (nullptr == ref) + return; + toluafix_pushusertype_ccobject(tolua_S, ref->_ID, &(ref->_luaID), (void*)ref,"cc.Ref"); + LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 1); + }; + + cocos2d::Node* ret = cocos2d::CSLoader::createNode(filename, callback); + ScriptHandlerMgr::getInstance()->addCustomHandler((void*)ret, handler); + object_to_luaval(tolua_S, "cc.Node",(cocos2d::Node*)ret); + return 1; + } + } while (0); + ok = true; + do + { + if (argc == 1) + { + std::string filename; + ok &= luaval_to_std_string(tolua_S, 2,&filename, "cc.CSLoader:createNode"); + if (!ok) { break; } + cocos2d::Node* ret = cocos2d::CSLoader::createNode(filename); + object_to_luaval(tolua_S, "cc.Node",(cocos2d::Node*)ret); + return 1; + } + } while (0); + ok = true; + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d", "cc.CSLoader:createNode",argc, 1); + return 0; +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_csloader_CSLoader_createNode'.",&tolua_err); +#endif + return 0; +} + int register_all_cocos2dx_csloader_manual(lua_State* L) { lua_pushstring(L, "cc.CSLoader"); @@ -71,6 +137,7 @@ int register_all_cocos2dx_csloader_manual(lua_State* L) if (lua_istable(L,-1)) { tolua_function(L, "createTimeline", lua_cocos2dx_csloader_CSLoader_createTimeline); + tolua_function(L, "createNode", lua_cocos2dx_csloader_CSLoader_createNode); } lua_pop(L, 1); diff --git a/tests/lua-tests/src/CocoStudioTest/CocoStudioActionTimelineTest/CocoStudioActionTimelineTest.lua b/tests/lua-tests/src/CocoStudioTest/CocoStudioActionTimelineTest/CocoStudioActionTimelineTest.lua index 1e3212dc19..f07bf95df2 100644 --- a/tests/lua-tests/src/CocoStudioTest/CocoStudioActionTimelineTest/CocoStudioActionTimelineTest.lua +++ b/tests/lua-tests/src/CocoStudioTest/CocoStudioActionTimelineTest/CocoStudioActionTimelineTest.lua @@ -5,9 +5,13 @@ local TimelineTestIndex = { TEST_ACTION_TIMELINE = 1, TEST_CHANGE_PLAY_SECTION = 2, - --TEST_TIMELINE_FRAME_EVENT = 3, - TEST_TIMELINE_PERFORMACE = 3, - TEST_ACTION_TIMELINE_EASE = 4, + TEST_TIMELINE_FRAME_EVENT = 3, + TEST_TIMELINE_PERFORMACE = 4, + TEST_TIMELINE_ANIMATION_LIST = 5, + TEST_TIMELINE_PROJECT_NODE = 6, + TEST_PROJECT_NODE_FOR_SIMULATOR = 7, + TEST_TIMELINE_NODE_LOADED_CALLBACK = 8, + TEST_ACTION_TIMELINE_EASE = 9, } local timelineSceneIdx = TimelineTestIndex.TEST_ACTION_TIMELINE @@ -63,12 +67,20 @@ function TimelineTestLayer.title(idx) return "Test ActionTimeline" elseif TimelineTestIndex.TEST_CHANGE_PLAY_SECTION == idx then return "Test Change Play Section" - --elseif TimelineTestIndex.TEST_TIMELINE_FRAME_EVENT == idx then - -- return "Test Frame Event" + elseif TimelineTestIndex.TEST_TIMELINE_FRAME_EVENT == idx then + return "Test Frame Event" elseif TimelineTestIndex.TEST_TIMELINE_PERFORMACE == idx then return "Test ActionTimeline performance" elseif TimelineTestIndex.TEST_ACTION_TIMELINE_EASE == idx then return "Test ActionTimelineEase" + elseif TimelineTestIndex.TEST_TIMELINE_ANIMATION_LIST == idx then + return "Test ActionTimeline AnimationList" + elseif TimelineTestIndex.TEST_TIMELINE_PROJECT_NODE == idx then + return "Test ActionTimeline ProjectNode" + elseif TimelineTestIndex.TEST_PROJECT_NODE_FOR_SIMULATOR == idx then + return "Test ProjectNode for Simalator" + elseif TimelineTestIndex.TEST_TIMELINE_NODE_LOADED_CALLBACK == idx then + return "Test node loaded call back" end end @@ -420,6 +432,237 @@ function TestTimelinePerformance.create() return layer end +------------------------------------------- +---TestTimelineAnimationList +------------------------------------------- +local TestTimelineAnimationList = class("TestTimelineAnimationList",TimelineTestLayer) +TestTimelineAnimationList.__index = TestTimelineAnimationList + +function TestTimelineAnimationList.extend(target) + local t = tolua.getpeer(target) + if not t then + t = {} + tolua.setpeer(target, t) + end + setmetatable(t, TestTimelineAnimationList) + return target +end + +function TestTimelineAnimationList:onEnter() + local node = cc.CSLoader:createNode("ActionTimeline/DemoPlayer.csb") + local action = cc.CSLoader:createTimeline("ActionTimeline/DemoPlayer.csb") + local standInfo = ccs.AnimationInfo("stand", 0, 40) + local walkInfo = ccs.AnimationInfo("walk", 41, 81) + action:addAnimationInfo(standInfo) + action:addAnimationInfo(walkInfo) + node:runAction(action) + action:play("walk", true) + + node:setScale(0.2) + node:setPosition(150,100) + self:addChild(node) +end + +function TestTimelineAnimationList.restartCallback() + ccs.ArmatureDataManager:destroyInstance() + local newScene = TimelineTestScene.create() + newScene:addChild(restartTimelineTest()) + cc.Director:getInstance():replaceScene(newScene) +end + +function TestTimelineAnimationList.create() + local layer = TestTimelineAnimationList.extend(cc.Layer:create()) + + if nil ~= layer then + layer:createMenu() + layer:createToExtensionMenu() + layer:creatTitleAndSubTitle(timelineSceneIdx) + local function onNodeEvent(event) + if "enter" == event then + layer:onEnter() + end + end + layer:registerScriptHandler(onNodeEvent) + end + + return layer +end + + +------------------------------------------- +---TestTimelineProjectNode +------------------------------------------- +local TestTimelineProjectNode = class("TestTimelineProjectNode",TimelineTestLayer) +TestTimelineProjectNode.__index = TestTimelineProjectNode + +function TestTimelineProjectNode.extend(target) + local t = tolua.getpeer(target) + if not t then + t = {} + tolua.setpeer(target, t) + end + setmetatable(t, TestTimelineProjectNode) + return target +end + +function TestTimelineProjectNode:onEnter() + local node = cc.CSLoader:createNode("ActionTimeline/TestAnimation.csb") + local action = cc.CSLoader:createTimeline("ActionTimeline/TestAnimation.csb") + + node:runAction(action) + action:gotoFrameAndPlay(0, true) + + node:setPosition(-300, -300) + self:addChild(node) +end + +function TestTimelineProjectNode.restartCallback() + ccs.ArmatureDataManager:destroyInstance() + local newScene = TimelineTestScene.create() + newScene:addChild(restartTimelineTest()) + cc.Director:getInstance():replaceScene(newScene) +end + +function TestTimelineProjectNode.create() + local layer = TestTimelineProjectNode.extend(cc.Layer:create()) + + if nil ~= layer then + layer:createMenu() + layer:createToExtensionMenu() + layer:creatTitleAndSubTitle(timelineSceneIdx) + local function onNodeEvent(event) + if "enter" == event then + layer:onEnter() + end + end + layer:registerScriptHandler(onNodeEvent) + end + + return layer +end + + +------------------------------------------- +---TestProjectNodeForSimulator +------------------------------------------- +local TestProjectNodeForSimulator = class("TestProjectNodeForSimulator",TimelineTestLayer) +TestProjectNodeForSimulator.__index = TestProjectNodeForSimulator + +function TestProjectNodeForSimulator.extend(target) + local t = tolua.getpeer(target) + if not t then + t = {} + tolua.setpeer(target, t) + end + setmetatable(t, TestProjectNodeForSimulator) + return target +end + +function TestProjectNodeForSimulator:onEnter() + local node = cc.CSLoader:getInstance():createNodeWithFlatBuffersForSimulator("ActionTimeline/TestAnimation.csd") + local action = ccs.ActionTimelineCache:getInstance():createActionWithFlatBuffersForSimulator("ActionTimeline/TestAnimation.csd") + + node:runAction(action) + action:gotoFrameAndPlay(0, true) + + node:setPosition(-300, -300) + self:addChild(node) + + --test for when ProjectNode file lost + local lackProjectNodefileNode = cc.CSLoader:getInstance():createNodeWithFlatBuffersForSimulator("ActionTimeline/TestNullProjectNode.csd") + local lackProjectNodefileAction = ccs.ActionTimelineCache:getInstance():createActionWithFlatBuffersForSimulator("ActionTimeline/TestNullProjectNode.csd") + lackProjectNodefileNode:runAction(lackProjectNodefileAction) + lackProjectNodefileAction:gotoFrameAndPlay(0) + self:addChild(lackProjectNodefileNode) +end + +function TestProjectNodeForSimulator.restartCallback() + ccs.ArmatureDataManager:destroyInstance() + local newScene = TimelineTestScene.create() + newScene:addChild(restartTimelineTest()) + cc.Director:getInstance():replaceScene(newScene) +end + +function TestProjectNodeForSimulator.create() + local layer = TestProjectNodeForSimulator.extend(cc.Layer:create()) + + if nil ~= layer then + layer:createMenu() + layer:createToExtensionMenu() + layer:creatTitleAndSubTitle(timelineSceneIdx) + local function onNodeEvent(event) + if "enter" == event then + layer:onEnter() + end + end + layer:registerScriptHandler(onNodeEvent) + end + + return layer +end + +------------------------------------------- +---TestTimelineNodeLoadedCallback +------------------------------------------- +local TestTimelineNodeLoadedCallback = class("TestTimelineNodeLoadedCallback",TimelineTestLayer) +TestTimelineNodeLoadedCallback.__index = TestTimelineNodeLoadedCallback + +function TestTimelineNodeLoadedCallback.extend(target) + local t = tolua.getpeer(target) + if not t then + t = {} + tolua.setpeer(target, t) + end + setmetatable(t, TestTimelineNodeLoadedCallback) + return target +end + +function TestTimelineNodeLoadedCallback:onEnter() + local node = cc.CSLoader:createNode("ActionTimeline/DemoPlayer.csb", function(object) + if nil ~= object then + print("object type is ", tolua.type(object)) + print("node name = ",object:getName()) + print("node parent name = ", object:getParent():getName()) + end + end) + local action = cc.CSLoader:createTimeline("ActionTimeline/DemoPlayer.csb") + node:runAction(action) + action:gotoFrameAndPlay(0) + + node:setScale(0.2) + node:setPosition(VisibleRect:center()) + + self:addChild(node) +end + +function TestTimelineNodeLoadedCallback.restartCallback() + ccs.ArmatureDataManager:destroyInstance() + local newScene = TimelineTestScene.create() + newScene:addChild(restartTimelineTest()) + cc.Director:getInstance():replaceScene(newScene) +end + +function TestTimelineNodeLoadedCallback.create() + local layer = TestTimelineNodeLoadedCallback.extend(cc.Layer:create()) + + if nil ~= layer then + layer:createMenu() + layer:createToExtensionMenu() + layer:creatTitleAndSubTitle(timelineSceneIdx) + local function onNodeEvent(event) + if "enter" == event then + layer:onEnter() + end + end + layer:registerScriptHandler(onNodeEvent) + end + + return layer +end + +------------------------------------------- +---TestActionTimelineEase +------------------------------------------- local TestActionTimelineEase = class("TestActionTimelineEase",TimelineTestLayer) TestActionTimelineEase.__index = TestActionTimelineEase @@ -470,8 +713,12 @@ local actionlineSceneArr = { TestActionTimeline.create, TestChangePlaySection.create, - --TestTimelineFrameEvent.create, + TestTimelineFrameEvent.create, TestTimelinePerformance.create, + TestTimelineAnimationList.create, + TestTimelineProjectNode.create, + TestProjectNodeForSimulator.create, + TestTimelineNodeLoadedCallback.create, TestActionTimelineEase.create, } diff --git a/tools/tolua/cocos2dx_csloader.ini b/tools/tolua/cocos2dx_csloader.ini index a4710ed473..874930fb1c 100644 --- a/tools/tolua/cocos2dx_csloader.ini +++ b/tools/tolua/cocos2dx_csloader.ini @@ -36,7 +36,7 @@ classes = CSLoader # will apply to all class names. This is a convenience wildcard to be able to skip similar named # functions from all classes. -skip = CSLoader::[nodeFromXML nodeFromProtocolBuffers createTimeline nodeWithFlatBuffers createActionTimelineNode] +skip = CSLoader::[nodeFromXML nodeFromProtocolBuffers createTimeline nodeWithFlatBuffers createActionTimelineNode ^createNode$] rename_functions =