mirror of https://github.com/axmolengine/axmol.git
Fixed #5563: Make sendNodeEventToXXX as static functions of ScriptEngineManager in CCScriptSupport
This commit is contained in:
parent
d00c9fe70a
commit
94fdff1da9
|
@ -145,7 +145,7 @@ void ClippingNode::onEnter()
|
|||
#if CC_ENABLE_SCRIPT_BINDING
|
||||
if (_scriptType == kScriptTypeJavascript)
|
||||
{
|
||||
if (sendNodeEventToJSExtended(this, kNodeOnEnter))
|
||||
if (ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnEnter))
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1055,7 +1055,7 @@ void Node::onEnter()
|
|||
#if CC_ENABLE_SCRIPT_BINDING
|
||||
if (_scriptType == kScriptTypeJavascript)
|
||||
{
|
||||
if (sendNodeEventToJS(this, kNodeOnEnter))
|
||||
if (ScriptEngineManager::sendNodeEventToJS(this, kNodeOnEnter))
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
@ -1072,7 +1072,7 @@ void Node::onEnter()
|
|||
#if CC_ENABLE_SCRIPT_BINDING
|
||||
if (_scriptType == kScriptTypeLua)
|
||||
{
|
||||
sendNodeEventToLua(this, kNodeOnEnter);
|
||||
ScriptEngineManager::sendNodeEventToLua(this, kNodeOnEnter);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -1082,7 +1082,7 @@ void Node::onEnterTransitionDidFinish()
|
|||
#if CC_ENABLE_SCRIPT_BINDING
|
||||
if (_scriptType == kScriptTypeJavascript)
|
||||
{
|
||||
if (sendNodeEventToJS(this, kNodeOnEnterTransitionDidFinish))
|
||||
if (ScriptEngineManager::sendNodeEventToJS(this, kNodeOnEnterTransitionDidFinish))
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
@ -1094,7 +1094,7 @@ void Node::onEnterTransitionDidFinish()
|
|||
#if CC_ENABLE_SCRIPT_BINDING
|
||||
if (_scriptType == kScriptTypeLua)
|
||||
{
|
||||
sendNodeEventToLua(this, kNodeOnEnterTransitionDidFinish);
|
||||
ScriptEngineManager::sendNodeEventToLua(this, kNodeOnEnterTransitionDidFinish);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -1104,7 +1104,7 @@ void Node::onExitTransitionDidStart()
|
|||
#if CC_ENABLE_SCRIPT_BINDING
|
||||
if (_scriptType == kScriptTypeJavascript)
|
||||
{
|
||||
if (sendNodeEventToJS(this, kNodeOnExitTransitionDidStart))
|
||||
if (ScriptEngineManager::sendNodeEventToJS(this, kNodeOnExitTransitionDidStart))
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
@ -1115,7 +1115,7 @@ void Node::onExitTransitionDidStart()
|
|||
#if CC_ENABLE_SCRIPT_BINDING
|
||||
if (_scriptType == kScriptTypeLua)
|
||||
{
|
||||
sendNodeEventToLua(this, kNodeOnExitTransitionDidStart);
|
||||
ScriptEngineManager::sendNodeEventToLua(this, kNodeOnExitTransitionDidStart);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -1125,7 +1125,7 @@ void Node::onExit()
|
|||
#if CC_ENABLE_SCRIPT_BINDING
|
||||
if (_scriptType == kScriptTypeJavascript)
|
||||
{
|
||||
if (sendNodeEventToJS(this, kNodeOnExit))
|
||||
if (ScriptEngineManager::sendNodeEventToJS(this, kNodeOnExit))
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
@ -1140,7 +1140,7 @@ void Node::onExit()
|
|||
#if CC_ENABLE_SCRIPT_BINDING
|
||||
if (_scriptType == kScriptTypeLua)
|
||||
{
|
||||
sendNodeEventToLua(this, kNodeOnExit);
|
||||
ScriptEngineManager::sendNodeEventToLua(this, kNodeOnExit);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -73,55 +73,6 @@ enum {
|
|||
|
||||
bool nodeComparisonLess(Node* n1, Node* n2);
|
||||
|
||||
|
||||
#if CC_ENABLE_SCRIPT_BINDING
|
||||
|
||||
static bool sendNodeEventToJS(Node* node, int action)
|
||||
{
|
||||
auto scriptEngine = ScriptEngineManager::getInstance()->getScriptEngine();
|
||||
|
||||
if (scriptEngine->isCalledFromScript())
|
||||
{
|
||||
// Should only be invoked at root class Node
|
||||
scriptEngine->setCalledFromScript(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
BasicScriptData data(node,(void*)&action);
|
||||
ScriptEvent scriptEvent(kNodeEvent,(void*)&data);
|
||||
if (scriptEngine->sendEvent(&scriptEvent))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
static bool sendNodeEventToJSExtended(Node* node, int action)
|
||||
{
|
||||
auto scriptEngine = ScriptEngineManager::getInstance()->getScriptEngine();
|
||||
|
||||
if (!scriptEngine->isCalledFromScript())
|
||||
{
|
||||
BasicScriptData data(node,(void*)&action);
|
||||
ScriptEvent scriptEvent(kNodeEvent,(void*)&data);
|
||||
if (scriptEngine->sendEvent(&scriptEvent))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void sendNodeEventToLua(Node* node, int action)
|
||||
{
|
||||
auto scriptEngine = ScriptEngineManager::getInstance()->getScriptEngine();
|
||||
|
||||
BasicScriptData data(node,(void*)&action);
|
||||
ScriptEvent scriptEvent(kNodeEvent,(void*)&data);
|
||||
|
||||
scriptEngine->sendEvent(&scriptEvent);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
class EventListener;
|
||||
|
||||
/** @brief Node is the base element of the Scene Graph. Elements of the Scene Graph must be Node objects or subclasses of it.
|
||||
|
|
|
@ -619,7 +619,7 @@ void ParticleSystem::onEnter()
|
|||
#if CC_ENABLE_SCRIPT_BINDING
|
||||
if (_scriptType == kScriptTypeJavascript)
|
||||
{
|
||||
if (sendNodeEventToJSExtended(this, kNodeOnEnter))
|
||||
if (ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnEnter))
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#if CC_ENABLE_SCRIPT_BINDING
|
||||
|
||||
#include "base/CCScheduler.h"
|
||||
#include "CCNode.h"
|
||||
|
||||
bool CC_DLL cc_assert_script_compatible(const char *msg)
|
||||
{
|
||||
|
@ -162,6 +163,51 @@ void ScriptEngineManager::destroyInstance()
|
|||
}
|
||||
}
|
||||
|
||||
bool ScriptEngineManager::sendNodeEventToJS(Node* node, int action)
|
||||
{
|
||||
auto scriptEngine = getInstance()->getScriptEngine();
|
||||
|
||||
if (scriptEngine->isCalledFromScript())
|
||||
{
|
||||
// Should only be invoked at root class Node
|
||||
scriptEngine->setCalledFromScript(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
BasicScriptData data(node,(void*)&action);
|
||||
ScriptEvent scriptEvent(kNodeEvent,(void*)&data);
|
||||
if (scriptEngine->sendEvent(&scriptEvent))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ScriptEngineManager::sendNodeEventToJSExtended(Node* node, int action)
|
||||
{
|
||||
auto scriptEngine = getInstance()->getScriptEngine();
|
||||
|
||||
if (!scriptEngine->isCalledFromScript())
|
||||
{
|
||||
BasicScriptData data(node,(void*)&action);
|
||||
ScriptEvent scriptEvent(kNodeEvent,(void*)&data);
|
||||
if (scriptEngine->sendEvent(&scriptEvent))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ScriptEngineManager::sendNodeEventToLua(Node* node, int action)
|
||||
{
|
||||
auto scriptEngine = getInstance()->getScriptEngine();
|
||||
|
||||
BasicScriptData data(node,(void*)&action);
|
||||
ScriptEvent scriptEvent(kNodeEvent,(void*)&data);
|
||||
|
||||
scriptEngine->sendEvent(&scriptEvent);
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif // #if CC_ENABLE_SCRIPT_BINDING
|
||||
|
|
|
@ -450,6 +450,7 @@ public:
|
|||
virtual bool parseConfig(ConfigType type, const std::string& str) = 0;
|
||||
};
|
||||
|
||||
class Node;
|
||||
/**
|
||||
ScriptEngineManager is a singleton which holds an object instance of ScriptEngineProtocl
|
||||
It helps cocos2d-x and the user code to find back LuaEngine object
|
||||
|
@ -490,6 +491,21 @@ public:
|
|||
* @lua NA
|
||||
*/
|
||||
static void destroyInstance();
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
static bool sendNodeEventToJS(Node* node, int action);
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
static bool sendNodeEventToJSExtended(Node* node, int action);
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
static void sendNodeEventToLua(Node* node, int action);
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
|
|
|
@ -437,7 +437,7 @@ void Armature::onEnter()
|
|||
#if CC_ENABLE_SCRIPT_BINDING
|
||||
if (_scriptType == kScriptTypeJavascript)
|
||||
{
|
||||
if (sendNodeEventToJSExtended(this, kNodeOnEnter))
|
||||
if (ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnEnter))
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -279,7 +279,7 @@ void Skeleton::onEnter() {
|
|||
#if CC_ENABLE_SCRIPT_BINDING
|
||||
if (_scriptType == kScriptTypeJavascript)
|
||||
{
|
||||
if (sendNodeEventToJSExtended(this, kNodeOnEnter))
|
||||
if (ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnEnter))
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -340,7 +340,7 @@ void ProtectedNode::onEnter()
|
|||
#if CC_ENABLE_SCRIPT_BINDING
|
||||
if (_scriptType == kScriptTypeJavascript)
|
||||
{
|
||||
if (sendNodeEventToJSExtended(this, kNodeOnEnter))
|
||||
if (ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnEnter))
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -105,7 +105,7 @@ void Layout::onEnter()
|
|||
#if CC_ENABLE_SCRIPT_BINDING
|
||||
if (_scriptType == kScriptTypeJavascript)
|
||||
{
|
||||
if (sendNodeEventToJSExtended(this, kNodeOnEnter))
|
||||
if (ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnEnter))
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -71,7 +71,7 @@ void PageView::onEnter()
|
|||
#if CC_ENABLE_SCRIPT_BINDING
|
||||
if (_scriptType == kScriptTypeJavascript)
|
||||
{
|
||||
if (sendNodeEventToJSExtended(this, kNodeOnEnter))
|
||||
if (ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnEnter))
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -98,7 +98,7 @@ void ScrollView::onEnter()
|
|||
#if CC_ENABLE_SCRIPT_BINDING
|
||||
if (_scriptType == kScriptTypeJavascript)
|
||||
{
|
||||
if (sendNodeEventToJSExtended(this, kNodeOnEnter))
|
||||
if (ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnEnter))
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -418,7 +418,7 @@ void TextField::onEnter()
|
|||
#if CC_ENABLE_SCRIPT_BINDING
|
||||
if (_scriptType == kScriptTypeJavascript)
|
||||
{
|
||||
if (sendNodeEventToJSExtended(this, kNodeOnEnter))
|
||||
if (ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnEnter))
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -332,7 +332,7 @@ void EditBox::onEnter(void)
|
|||
#if CC_ENABLE_SCRIPT_BINDING
|
||||
if (_scriptType == kScriptTypeJavascript)
|
||||
{
|
||||
if (sendNodeEventToJSExtended(this, kNodeOnEnter))
|
||||
if (ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnEnter))
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue