mirror of https://github.com/axmolengine/axmol.git
Merge branch 'develop' of https://github.com/cocos2d/cocos2d-x into develop_new_fix
This commit is contained in:
commit
7e48dbc572
|
@ -1 +1 @@
|
|||
14c85247a5f8b18ac4e064c8afb58f55b58911f7
|
||||
2ba216b4ae56fa741405d81c01614f325fc19874
|
|
@ -715,7 +715,6 @@ Node* Node::getChildByTag(int tag)
|
|||
|
||||
Node* Node::getChildByName(const std::string& name)
|
||||
{
|
||||
|
||||
for (auto& child : _children)
|
||||
{
|
||||
|
||||
|
@ -733,6 +732,25 @@ Node* Node::getChildByName(const std::string& name)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void Node::enumerateChildrenByName(const std::string& name, const std::function<void(Node* node, bool* stop)>& callback)
|
||||
{
|
||||
for (auto& child : _children)
|
||||
{
|
||||
|
||||
if(child->_name == name)
|
||||
{
|
||||
bool stop = false;
|
||||
callback(child, &stop);
|
||||
if(stop == true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
child->enumerateChildrenByName(name, callback);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* "add" logic MUST only be on this method
|
||||
* If a class want's to extend the 'addChild' behavior it only needs
|
||||
* to override this method
|
||||
|
|
|
@ -647,7 +647,7 @@ public:
|
|||
virtual Node * getChildByTag(int tag);
|
||||
|
||||
/**
|
||||
* Gets a child from the container with its name
|
||||
* get a child node with its name, will recursively search the whole node tree
|
||||
*
|
||||
* @param name A string identifier to find the child node.
|
||||
*
|
||||
|
@ -789,17 +789,26 @@ public:
|
|||
player = parent->getChildByName("player")
|
||||
@endcode
|
||||
*
|
||||
* @return A C string that identifies the node.
|
||||
* @return A string that identifies the node.
|
||||
*/
|
||||
virtual std::string& getName();
|
||||
/**
|
||||
* Changes the string TAG that is used to identify the node easily.
|
||||
* Changes the name that is used to identify the node easily.
|
||||
*
|
||||
* Please refer to getLabel for the sample code.
|
||||
* Please refer to getName for the sample code.
|
||||
*
|
||||
* @param name A string that indentifies the node.
|
||||
*/
|
||||
virtual void setName(const std::string& name);
|
||||
/**
|
||||
* Search the children to perform processing for nodes which share a name.
|
||||
* Note: this function will search the whole node tree recursively.
|
||||
* @param name the name to search for
|
||||
* @param callback, A callback to execute on nodes that match the name parameter. The callback takes the following arguments:
|
||||
* node: A node that matches the name.
|
||||
* stop: A pointer to a Boolean variable. Your callback can set this to true to terminate the enumeration.
|
||||
*/
|
||||
virtual void enumerateChildrenByName(const std::string& name, const std::function<void(Node* node, bool* stop)>& callback);
|
||||
/**
|
||||
* Returns a custom user data pointer
|
||||
*
|
||||
|
|
|
@ -503,10 +503,10 @@ public:
|
|||
for (int i=0;i< sizeof(commands)/sizeof(Console::Command);i++) {
|
||||
_console->addCommand(commands[i]);
|
||||
}
|
||||
_console->listenOnTCP(6001);
|
||||
_console->listenOnTCP(6010);
|
||||
|
||||
_fileserver=new FileServer();
|
||||
_fileserver->listenOnTCP(6002);
|
||||
_fileserver->listenOnTCP(6020);
|
||||
}
|
||||
~ConsoleCustomCommand()
|
||||
{
|
||||
|
|
|
@ -57,6 +57,7 @@ static std::function<Layer*()> createFunctions[] =
|
|||
CL(Test4),
|
||||
CL(Test5),
|
||||
CL(Test6),
|
||||
CL(NodeEnumChildByNameTest),
|
||||
CL(StressTest1),
|
||||
CL(StressTest2),
|
||||
CL(NodeToWorld),
|
||||
|
@ -108,7 +109,7 @@ TestCocosNodeDemo::~TestCocosNodeDemo(void)
|
|||
|
||||
std::string TestCocosNodeDemo::title() const
|
||||
{
|
||||
return "No title";
|
||||
return "Node Test";
|
||||
}
|
||||
|
||||
std::string TestCocosNodeDemo::subtitle() const
|
||||
|
@ -352,6 +353,65 @@ std::string Test6::subtitle() const
|
|||
return "remove/cleanup with children";
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// NodeEnumChildByNameTest
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
void NodeEnumChildByNameTest::onEnter()
|
||||
{
|
||||
TestCocosNodeDemo::onEnter();
|
||||
auto sp10 = Sprite::create(s_pathSister1);
|
||||
auto sp11 = Sprite::create(s_pathSister1);
|
||||
auto sp12 = Sprite::create(s_pathSister1);
|
||||
auto sp20 = Sprite::create(s_pathSister2);
|
||||
auto sp21 = Sprite::create(s_pathSister2);
|
||||
auto sp22 = Sprite::create(s_pathSister2);
|
||||
|
||||
sp10->setPosition(Point(100,60));
|
||||
sp11->setPosition(Point(100,160));
|
||||
sp12->setPosition(Point(100,260));
|
||||
sp20->setPosition(Point(380,60));
|
||||
sp21->setPosition(Point(380,160));
|
||||
sp22->setPosition(Point(380,260));
|
||||
|
||||
sp10->setName("sister1");
|
||||
sp11->setName("sister1");
|
||||
sp12->setName("sister1");
|
||||
sp20->setName("sister2");
|
||||
sp21->setName("sister2");
|
||||
sp22->setName("sister2");
|
||||
|
||||
addChild(sp10);
|
||||
addChild(sp11);
|
||||
addChild(sp12);
|
||||
addChild(sp20);
|
||||
addChild(sp21);
|
||||
addChild(sp22);
|
||||
|
||||
enumerateChildrenByName("sister1",
|
||||
[](Node* node, bool* stop)
|
||||
{
|
||||
auto rot = RotateBy::create(2, 360);
|
||||
auto rot_back = rot->reverse();
|
||||
auto forever1 = RepeatForever::create(Sequence::create(rot, rot_back, NULL));
|
||||
node->runAction(forever1);
|
||||
});
|
||||
enumerateChildrenByName("sister2",
|
||||
[](Node* node, bool* stop)
|
||||
{
|
||||
auto actionUp = JumpBy::create(2, Point(0,0), 80, 4);
|
||||
auto forever2 = RepeatForever::create(Sequence::create(actionUp, NULL));
|
||||
node->runAction(forever2);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
std::string NodeEnumChildByNameTest::subtitle() const
|
||||
{
|
||||
return "Enum child nodes by name";
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// StressTest1
|
||||
|
|
|
@ -263,6 +263,14 @@ protected:
|
|||
Sprite *_sprite;
|
||||
};
|
||||
|
||||
class NodeEnumChildByNameTest : public TestCocosNodeDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(NodeEnumChildByNameTest);
|
||||
virtual void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
class CocosNodeTestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -109,4 +109,4 @@ tags
|
|||
#include
|
||||
!/tools/cocos2d-console/console/bin/
|
||||
!/plugin-x/plugin-x_ios.xcworkspace/
|
||||
|
||||
!/cocos/2d/platform/android/java/res/
|
||||
|
|
|
@ -27,6 +27,7 @@ THE SOFTWARE.
|
|||
import os
|
||||
import sys
|
||||
import re
|
||||
import json
|
||||
|
||||
class CocosFileList:
|
||||
"""
|
||||
|
@ -39,7 +40,10 @@ class CocosFileList:
|
|||
self.excludeConfig=[]
|
||||
self.inludeConfig=[]
|
||||
self.rootDir = ""
|
||||
self.fileList=[]
|
||||
self.fileList_com=[]
|
||||
self.fileList_lua=[]
|
||||
|
||||
self.luaPath ="cocos/scripting/lua-bindings"
|
||||
|
||||
def readIngoreFile(self, fileName):
|
||||
"""
|
||||
|
@ -84,7 +88,10 @@ class CocosFileList:
|
|||
self.__bInclude(item) or
|
||||
self.__bInclude("%s/" %item)
|
||||
):
|
||||
self.fileList.append("%s/" %relativePath)
|
||||
if relativePath.upper().find(self.luaPath.upper())==0:
|
||||
self.fileList_lua.append("%s/" %relativePath)
|
||||
else:
|
||||
self.fileList_com.append("%s/" %relativePath)
|
||||
continue
|
||||
if (
|
||||
self.__bExclude("/%s" %relativePath) or
|
||||
|
@ -105,7 +112,10 @@ class CocosFileList:
|
|||
):
|
||||
continue
|
||||
# print(relativePath)
|
||||
self.fileList.append(relativePath)
|
||||
if relativePath.upper().find(self.luaPath.upper())==0:
|
||||
self.fileList_lua.append(relativePath)
|
||||
else:
|
||||
self.fileList_com.append(relativePath)
|
||||
|
||||
def __bExclude(self, item):
|
||||
bexclude = False
|
||||
|
@ -128,9 +138,8 @@ class CocosFileList:
|
|||
Save content to file with json format.
|
||||
"""
|
||||
f = open(fileName,"w")
|
||||
self.fileList.sort()
|
||||
content = "[\n\"%s\"\n]" % ("\",\n\"".join(self.fileList))
|
||||
f.write(content)
|
||||
content ={'common':self.fileList_com,'lua':self.fileList_lua}
|
||||
json.dump(content,f,sort_keys=True,indent=4)
|
||||
f.close()
|
||||
return True
|
||||
|
||||
|
|
Loading…
Reference in New Issue