2012-02-09 14:07:11 +08:00
|
|
|
/****************************************************************************
|
2012-09-24 21:22:20 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-09 01:23:11 +08:00
|
|
|
https://axis-project.github.io/
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2012-09-02 00:38:57 +08:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2012-09-02 00:38:57 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2012-09-02 00:38:57 +08:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
2012-02-09 14:07:11 +08:00
|
|
|
|
|
|
|
#ifndef __SCRIPT_SUPPORT_H__
|
|
|
|
#define __SCRIPT_SUPPORT_H__
|
|
|
|
|
2014-04-30 08:37:36 +08:00
|
|
|
#include "base/ccConfig.h"
|
2014-05-17 05:36:00 +08:00
|
|
|
#include "platform/CCCommon.h"
|
2014-04-30 08:37:36 +08:00
|
|
|
#include "base/CCTouch.h"
|
|
|
|
#include "base/CCEventTouch.h"
|
|
|
|
#include "base/CCEventKeyboard.h"
|
2012-08-25 15:05:59 +08:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <list>
|
2012-02-09 14:07:11 +08:00
|
|
|
|
2015-03-26 22:07:44 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup base
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
#if AX_ENABLE_SCRIPT_BINDING
|
2015-03-27 15:27:08 +08:00
|
|
|
|
|
|
|
typedef struct lua_State lua_State;
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2012-02-09 14:07:11 +08:00
|
|
|
|
2014-03-01 13:30:20 +08:00
|
|
|
class TimerScriptHandler;
|
2013-06-20 14:13:12 +08:00
|
|
|
class Layer;
|
|
|
|
class MenuItem;
|
|
|
|
class CallFunc;
|
|
|
|
class Acceleration;
|
2015-08-27 17:55:38 +08:00
|
|
|
class Action;
|
2012-09-11 14:02:33 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
enum ccScriptType
|
|
|
|
{
|
2012-08-31 21:23:23 +08:00
|
|
|
kScriptTypeNone = 0,
|
|
|
|
kScriptTypeLua,
|
|
|
|
};
|
|
|
|
|
2015-03-25 18:54:33 +08:00
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* This classes is wrapped to store the handler corresponding to the Lua function pointer and assign the handler a
|
|
|
|
* unique id
|
2015-03-28 15:11:51 +08:00
|
|
|
* @js NA
|
2015-03-25 18:54:33 +08:00
|
|
|
*/
|
2014-02-20 10:53:49 +08:00
|
|
|
class ScriptHandlerEntry : public Ref
|
2012-08-28 12:08:15 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-03-25 18:54:33 +08:00
|
|
|
/**
|
|
|
|
* create a ScriptHandlerEntry instance by the handler.
|
|
|
|
*
|
|
|
|
* @param handler corresponding to the Lua function pointer.
|
|
|
|
* @return ScriptHandlerEntry instance.
|
2015-03-26 22:07:44 +08:00
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
2015-03-25 18:54:33 +08:00
|
|
|
*/
|
2013-12-18 17:47:20 +08:00
|
|
|
static ScriptHandlerEntry* create(int handler);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-09-13 13:52:42 +08:00
|
|
|
/**
|
2015-03-25 18:54:33 +08:00
|
|
|
* Destructor of ScriptHandlerEntry.
|
2015-03-26 22:07:44 +08:00
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
2013-09-13 13:52:42 +08:00
|
|
|
*/
|
2014-02-20 21:58:20 +08:00
|
|
|
virtual ~ScriptHandlerEntry();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-03-25 18:54:33 +08:00
|
|
|
/**
|
|
|
|
* Get the handler corresponding to the Lua function pointer.
|
|
|
|
*
|
|
|
|
* @return the handler corresponding to the Lua function pointer.
|
2015-03-26 22:07:44 +08:00
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
2015-03-25 18:54:33 +08:00
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
int getHandler() { return _handler; }
|
|
|
|
|
2015-03-25 18:54:33 +08:00
|
|
|
/**
|
|
|
|
* Get the unique id corresponding to the handler.
|
|
|
|
*
|
|
|
|
* @return the unique id corresponding to the handler.
|
2015-03-26 22:07:44 +08:00
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
2015-03-25 18:54:33 +08:00
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
int getEntryId() { return _entryId; }
|
|
|
|
|
2012-08-28 12:08:15 +08:00
|
|
|
protected:
|
2021-12-25 10:04:45 +08:00
|
|
|
ScriptHandlerEntry(int handler) : _handler(handler)
|
2012-08-28 12:08:15 +08:00
|
|
|
{
|
|
|
|
static int newEntryId = 0;
|
|
|
|
newEntryId++;
|
2013-06-15 14:03:30 +08:00
|
|
|
_entryId = newEntryId;
|
2012-08-28 12:08:15 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
int _handler;
|
|
|
|
int _entryId;
|
2012-08-28 12:08:15 +08:00
|
|
|
};
|
2012-02-09 14:07:11 +08:00
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* The SchedulerScriptHandlerEntry is used to store the handler corresponding to the Lua function pointer and assign the
|
|
|
|
* handler a unique id like ScriptHandlerEntry. Meanwhile,create a timer that named TimerScriptHandler to execute the
|
|
|
|
* Lua function corresponding to the handler in the interval time if the SchedulerScriptHandlerEntry object isn't
|
|
|
|
* paused.
|
2015-03-28 15:11:51 +08:00
|
|
|
* @js NA
|
2012-06-20 18:09:11 +08:00
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
class SchedulerScriptHandlerEntry : public ScriptHandlerEntry
|
2012-02-09 14:07:11 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
2015-03-25 18:54:33 +08:00
|
|
|
* create a SchedulerScriptHandlerEntry object.
|
2021-12-25 10:04:45 +08:00
|
|
|
*
|
2015-03-25 18:54:33 +08:00
|
|
|
* @param handler the index corresponding to the Lua function pointer.
|
2021-12-25 10:04:45 +08:00
|
|
|
* @param interval the interval to execute the Lua function. If the value is 0, then the lua function will be
|
|
|
|
* scheduled every frame.
|
2015-03-25 18:54:33 +08:00
|
|
|
* @param paused if paused is true, then the timer won't be started until it is resumed.
|
|
|
|
* @return a SchedulerScriptHandlerEntry object.
|
2015-03-26 22:07:44 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
2013-09-13 11:41:20 +08:00
|
|
|
*/
|
2013-12-18 17:47:20 +08:00
|
|
|
static SchedulerScriptHandlerEntry* create(int handler, float interval, bool paused);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
2015-03-26 22:07:44 +08:00
|
|
|
* Destructor of SchedulerScriptHandlerEntry.
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
2013-09-13 11:41:20 +08:00
|
|
|
*/
|
2014-02-20 21:58:20 +08:00
|
|
|
virtual ~SchedulerScriptHandlerEntry();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
2015-03-25 18:54:33 +08:00
|
|
|
* Get the pointer of TimerScriptHandler object.
|
|
|
|
*
|
2015-03-26 22:07:44 +08:00
|
|
|
* @return the pointer of TimerScriptHandler object.
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
2013-09-13 11:41:20 +08:00
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
TimerScriptHandler* getTimer() { return _timer; }
|
|
|
|
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
2015-03-25 18:54:33 +08:00
|
|
|
* Get the flag whether paused or not.
|
|
|
|
*
|
|
|
|
* @return the flag whether paused or not.
|
2015-03-26 22:07:44 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
2013-09-13 11:41:20 +08:00
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
bool isPaused() { return _paused; }
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
2015-03-25 18:54:33 +08:00
|
|
|
* Set the markedForDeletion flag true.
|
2015-03-26 22:07:44 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
2013-09-13 11:41:20 +08:00
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
void markedForDeletion() { _markedForDeletion = true; }
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
2015-03-25 18:54:33 +08:00
|
|
|
* Get the flag whether markedForDeletion or not.
|
|
|
|
*
|
|
|
|
* @return the flag whether markedForDeletion or not.
|
2015-03-26 22:07:44 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
2013-09-13 11:41:20 +08:00
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
bool isMarkedForDeletion() { return _markedForDeletion; }
|
|
|
|
|
2012-02-09 14:07:11 +08:00
|
|
|
private:
|
2013-12-18 17:47:20 +08:00
|
|
|
SchedulerScriptHandlerEntry(int handler)
|
2021-12-25 10:04:45 +08:00
|
|
|
: ScriptHandlerEntry(handler), _timer(nullptr), _paused(false), _markedForDeletion(false)
|
|
|
|
{}
|
2013-12-18 17:47:20 +08:00
|
|
|
bool init(float interval, bool paused);
|
2012-02-09 14:07:11 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
TimerScriptHandler* _timer;
|
|
|
|
bool _paused;
|
|
|
|
bool _markedForDeletion;
|
|
|
|
};
|
2012-02-09 14:07:11 +08:00
|
|
|
|
2015-03-25 18:54:33 +08:00
|
|
|
/**
|
|
|
|
* @cond
|
2015-03-28 15:11:51 +08:00
|
|
|
* @js NA
|
2015-03-25 18:54:33 +08:00
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
class TouchScriptHandlerEntry : public ScriptHandlerEntry
|
2012-02-09 14:07:11 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-12-18 17:47:20 +08:00
|
|
|
static TouchScriptHandlerEntry* create(int handler, bool isMultiTouches, int priority, bool swallowsTouches);
|
2015-03-25 18:54:33 +08:00
|
|
|
|
2014-02-20 21:58:20 +08:00
|
|
|
virtual ~TouchScriptHandlerEntry();
|
2015-03-25 18:54:33 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
bool isMultiTouches() { return _isMultiTouches; }
|
2015-03-25 18:54:33 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
int getPriority() { return _priority; }
|
|
|
|
|
|
|
|
bool getSwallowsTouches() { return _swallowsTouches; }
|
2015-03-25 18:54:33 +08:00
|
|
|
|
2012-02-09 14:07:11 +08:00
|
|
|
private:
|
2013-12-18 17:47:20 +08:00
|
|
|
TouchScriptHandlerEntry(int handler)
|
2021-12-25 10:04:45 +08:00
|
|
|
: ScriptHandlerEntry(handler), _isMultiTouches(false), _priority(0), _swallowsTouches(false)
|
|
|
|
{}
|
2013-12-18 17:47:20 +08:00
|
|
|
bool init(bool isMultiTouches, int priority, bool swallowsTouches);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
bool _isMultiTouches;
|
|
|
|
int _priority;
|
|
|
|
bool _swallowsTouches;
|
2012-02-09 14:07:11 +08:00
|
|
|
};
|
|
|
|
|
2015-03-25 18:54:33 +08:00
|
|
|
/**
|
|
|
|
* @endcond
|
2015-03-28 15:11:51 +08:00
|
|
|
* @js NA
|
2015-03-25 18:54:33 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** ScriptEventType enum*/
|
2013-07-02 15:23:51 +08:00
|
|
|
enum ScriptEventType
|
|
|
|
{
|
|
|
|
kNodeEvent = 0,
|
2013-07-04 15:44:42 +08:00
|
|
|
kMenuClickedEvent,
|
2013-07-02 15:23:51 +08:00
|
|
|
kCallFuncEvent,
|
|
|
|
kScheduleEvent,
|
2013-07-22 17:12:53 +08:00
|
|
|
kTouchEvent,
|
2013-07-04 15:44:42 +08:00
|
|
|
kTouchesEvent,
|
|
|
|
kKeypadEvent,
|
2013-07-02 15:23:51 +08:00
|
|
|
kAccelerometerEvent,
|
2013-07-16 09:55:06 +08:00
|
|
|
kControlEvent,
|
2013-07-02 15:23:51 +08:00
|
|
|
kCommonEvent,
|
2014-12-28 11:55:06 +08:00
|
|
|
kComponentEvent,
|
2015-08-27 17:55:38 +08:00
|
|
|
kRestartGame,
|
|
|
|
kScriptActionEvent
|
2013-07-02 15:23:51 +08:00
|
|
|
};
|
|
|
|
|
2015-03-25 18:54:33 +08:00
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* For Lua, Wrapper the script data that should be used to find the handler corresponding to the Lua function by the
|
|
|
|
* nativeobject pointer and store the value pointer which would be converted concretely by the different events,then the
|
|
|
|
* converted data would be passed into the Lua stack.
|
2015-03-28 15:11:51 +08:00
|
|
|
* @js NA
|
2015-03-25 18:54:33 +08:00
|
|
|
*/
|
2013-07-04 15:44:42 +08:00
|
|
|
struct BasicScriptData
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2015-03-25 18:54:33 +08:00
|
|
|
* For Lua, nativeobject is used to get handler corresponding to the Lua function.
|
2015-03-26 22:07:44 +08:00
|
|
|
*
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
2015-03-25 18:54:33 +08:00
|
|
|
*/
|
2013-07-04 15:44:42 +08:00
|
|
|
void* nativeObject;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-03-25 18:54:33 +08:00
|
|
|
/**
|
|
|
|
* A pointer point to the value data which would be converted by different events.
|
2015-03-26 22:07:44 +08:00
|
|
|
*
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
2015-03-25 18:54:33 +08:00
|
|
|
*/
|
2013-07-04 15:44:42 +08:00
|
|
|
void* value;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
2015-03-25 18:54:33 +08:00
|
|
|
* Constructor of BasicScriptData.
|
2015-03-26 22:07:44 +08:00
|
|
|
*
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
2013-09-13 11:41:20 +08:00
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
BasicScriptData(void* inObject, void* inValue = nullptr) : nativeObject(inObject), value(inValue) {}
|
2013-07-04 15:44:42 +08:00
|
|
|
};
|
|
|
|
|
2015-08-27 17:55:38 +08:00
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* For Lua, Wrapper the script data that should be used to find the handler corresponding to the Lua function by the
|
|
|
|
* nativeobject pointer and store the value pointer which would be converted concretely by the different events,then the
|
|
|
|
* converted data would be passed into the Lua stack.
|
2015-08-27 17:55:38 +08:00
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
struct ActionObjectScriptData
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* For Lua, nativeobject is used to get handler corresponding to the Lua function.
|
|
|
|
*
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
void* nativeObject;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-08-27 17:55:38 +08:00
|
|
|
/**
|
|
|
|
* A pointer point to the value data which event action
|
|
|
|
*
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
int* eventType;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-08-27 17:55:38 +08:00
|
|
|
/**
|
|
|
|
* A pointer point to the value data which would be converted by different events.
|
|
|
|
*
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
void* param;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-08-27 17:55:38 +08:00
|
|
|
/**
|
|
|
|
* Constructor of BasicScriptData.
|
|
|
|
*
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
ActionObjectScriptData(void* inObject, int* inValue = nullptr, void* inParam = nullptr)
|
|
|
|
: nativeObject(inObject), eventType(inValue), param(inParam)
|
|
|
|
{}
|
2015-08-27 17:55:38 +08:00
|
|
|
};
|
|
|
|
|
2015-03-25 18:54:33 +08:00
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* For Lua, the SchedulerScriptData is used to find the Lua function pointer by the handler, then call the Lua function
|
|
|
|
* by push the elapse into the Lua stack as a parameter when scheduler update event is triggered.
|
2015-03-28 15:11:51 +08:00
|
|
|
* @js NA
|
2015-03-25 18:54:33 +08:00
|
|
|
*/
|
2013-07-04 15:44:42 +08:00
|
|
|
struct SchedulerScriptData
|
2013-07-02 15:23:51 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2015-03-26 22:07:44 +08:00
|
|
|
* the handler corresponding to the Lua function pointer, only use in the Lua.
|
|
|
|
*
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-02 15:23:51 +08:00
|
|
|
int handler;
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2015-03-26 22:07:44 +08:00
|
|
|
* the parameter would be passed in to the Lua function, only use in the Lua.
|
|
|
|
*
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-02 15:23:51 +08:00
|
|
|
float elapse;
|
2013-07-22 17:12:53 +08:00
|
|
|
// js use
|
|
|
|
void* node;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
2015-09-22 16:08:23 +08:00
|
|
|
* Constructor of SchedulerScriptData.
|
2015-03-26 22:07:44 +08:00
|
|
|
*
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
2013-09-13 11:41:20 +08:00
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
SchedulerScriptData(int inHandler, float inElapse, void* inNode = nullptr)
|
|
|
|
: handler(inHandler), elapse(inElapse), node(inNode)
|
|
|
|
{}
|
2013-07-02 15:23:51 +08:00
|
|
|
};
|
|
|
|
|
2015-03-25 18:54:33 +08:00
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* For Lua, the TouchesScriptData is used to find the Lua function pointer by the nativeObject, then call the Lua
|
|
|
|
* function by push touches data and actionType into the Lua stack as the parameters when the touches event is
|
|
|
|
* triggered.
|
2015-03-28 15:11:51 +08:00
|
|
|
* @js NA
|
2015-03-25 18:54:33 +08:00
|
|
|
*/
|
2013-07-04 15:44:42 +08:00
|
|
|
struct TouchesScriptData
|
2013-07-02 15:23:51 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
|
|
|
* The EventTouch::EventCode type.
|
2015-03-26 22:07:44 +08:00
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
|
|
|
*/
|
2013-09-20 19:19:31 +08:00
|
|
|
EventTouch::EventCode actionType;
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2015-03-26 22:07:44 +08:00
|
|
|
* For Lua, it Used to find the Lua function pointer by the ScriptHandlerMgr.
|
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
|
|
|
*/
|
2013-07-04 15:44:42 +08:00
|
|
|
void* nativeObject;
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
|
|
|
* The vector of Touch.For Lua, it would be convert to the Lua table form to be pushed into the Lua stack.
|
2015-03-26 22:07:44 +08:00
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
|
|
|
*/
|
2013-09-03 18:22:03 +08:00
|
|
|
const std::vector<Touch*>& touches;
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2015-03-26 22:07:44 +08:00
|
|
|
* event information, it is useless for Lua.
|
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
|
|
|
*/
|
2014-03-04 13:42:06 +08:00
|
|
|
Event* event;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
2015-03-25 18:54:33 +08:00
|
|
|
* Constructor of TouchesScriptData.
|
2015-03-26 22:07:44 +08:00
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
2013-09-13 11:41:20 +08:00
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
TouchesScriptData(EventTouch::EventCode inActionType,
|
|
|
|
void* inNativeObject,
|
|
|
|
const std::vector<Touch*>& inTouches,
|
|
|
|
Event* evt)
|
|
|
|
: actionType(inActionType), nativeObject(inNativeObject), touches(inTouches), event(evt)
|
|
|
|
{}
|
2013-07-22 17:12:53 +08:00
|
|
|
};
|
|
|
|
|
2015-03-25 18:54:33 +08:00
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* For Lua, the TouchScriptData is used to find the Lua function pointer by the nativeObject, then call the Lua function
|
|
|
|
* by push touch data and actionType converted to string type into the Lua stack as the parameters when the touch event
|
|
|
|
* is triggered.
|
2015-03-28 15:11:51 +08:00
|
|
|
* @js NA
|
2015-03-25 18:54:33 +08:00
|
|
|
*/
|
2013-07-22 17:12:53 +08:00
|
|
|
struct TouchScriptData
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2015-03-26 22:07:44 +08:00
|
|
|
* The EventTouch::EventCode type.
|
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
|
|
|
*/
|
2013-09-20 19:19:31 +08:00
|
|
|
EventTouch::EventCode actionType;
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2015-03-26 22:07:44 +08:00
|
|
|
* For Lua, it Used to find the Lua function pointer by the ScriptHandlerMgr.
|
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
|
|
|
*/
|
2013-07-22 17:12:53 +08:00
|
|
|
void* nativeObject;
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2015-03-26 22:07:44 +08:00
|
|
|
* touch information. it would be in x,y form to push into the Lua stack.
|
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
|
|
|
*/
|
2013-07-22 17:12:53 +08:00
|
|
|
Touch* touch;
|
2015-03-26 22:07:44 +08:00
|
|
|
/**
|
|
|
|
* event information,it is useless for Lua.
|
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
|
|
|
*/
|
2014-03-04 13:42:06 +08:00
|
|
|
Event* event;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-25 18:54:33 +08:00
|
|
|
* Constructor of TouchScriptData.
|
2015-03-26 22:07:44 +08:00
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
2013-09-13 11:41:20 +08:00
|
|
|
*/
|
2014-03-04 13:42:06 +08:00
|
|
|
TouchScriptData(EventTouch::EventCode inActionType, void* inNativeObject, Touch* inTouch, Event* evt)
|
2021-12-25 10:04:45 +08:00
|
|
|
: actionType(inActionType), nativeObject(inNativeObject), touch(inTouch), event(evt)
|
|
|
|
{}
|
2013-07-02 15:23:51 +08:00
|
|
|
};
|
|
|
|
|
2015-03-25 18:54:33 +08:00
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* For Lua, the KeypadScriptData is used to find the Lua function pointer by the nativeObject, then call the Lua
|
|
|
|
* function by push the actionType converted to string type into the Lua stack as the parameters when the Keypad event
|
|
|
|
* is triggered.
|
2015-03-28 15:11:51 +08:00
|
|
|
* @js NA
|
2015-03-25 18:54:33 +08:00
|
|
|
*/
|
2013-07-04 15:44:42 +08:00
|
|
|
struct KeypadScriptData
|
2013-07-02 15:23:51 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2015-03-26 22:07:44 +08:00
|
|
|
* The specific type of EventKeyboard::KeyCode
|
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
|
|
|
*/
|
2013-09-20 19:19:31 +08:00
|
|
|
EventKeyboard::KeyCode actionType;
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2015-03-26 22:07:44 +08:00
|
|
|
* For Lua, it Used to find the Lua function pointer by the ScriptHandlerMgr.
|
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
|
|
|
*/
|
2013-07-04 15:44:42 +08:00
|
|
|
void* nativeObject;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
2015-03-25 18:54:33 +08:00
|
|
|
* Constructor of KeypadScriptData.
|
2015-03-26 22:07:44 +08:00
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
2013-09-13 11:41:20 +08:00
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
KeypadScriptData(EventKeyboard::KeyCode inActionType, void* inNativeObject)
|
|
|
|
: actionType(inActionType), nativeObject(inNativeObject)
|
|
|
|
{}
|
2013-07-02 15:23:51 +08:00
|
|
|
};
|
|
|
|
|
2015-03-25 18:54:33 +08:00
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* For Lua, the CommonScriptData is used to find the Lua function pointer by the handler, then call the Lua function by
|
|
|
|
* push the eventName, eventSource(if it not nullptr), eventSourceClassName(if it is nullptr or "", and the eventSource
|
|
|
|
* is not nullptr,would give the default string "cc.Ref") into the Lua stack as the parameter when the common event such
|
|
|
|
* as is triggered.
|
2015-03-28 15:11:51 +08:00
|
|
|
* @js NA
|
2015-03-25 18:54:33 +08:00
|
|
|
*/
|
2013-07-04 15:44:42 +08:00
|
|
|
struct CommonScriptData
|
2013-07-02 15:23:51 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2015-03-26 22:07:44 +08:00
|
|
|
* The index to find the corresponding to the Lua function pointer.
|
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
|
|
|
*/
|
2013-07-02 15:23:51 +08:00
|
|
|
int handler;
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2015-03-26 22:07:44 +08:00
|
|
|
* The string value to be pushed into the Lua stack.
|
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
|
|
|
*/
|
2013-07-02 15:23:51 +08:00
|
|
|
char eventName[64];
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2015-03-26 22:07:44 +08:00
|
|
|
* The source object trigger the event,could be nullptr.
|
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
|
|
|
*/
|
2014-02-20 10:53:49 +08:00
|
|
|
Ref* eventSource;
|
2015-03-26 22:07:44 +08:00
|
|
|
/**
|
|
|
|
* The class name of source object trigger the event, could be nullptr.
|
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
|
|
|
*/
|
2013-07-02 15:23:51 +08:00
|
|
|
char eventSourceClassName[64];
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-26 22:07:44 +08:00
|
|
|
* Constructor of CommonScriptData.
|
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
CommonScriptData(int inHandler, const char* inName, Ref* inSource = nullptr, const char* inClassName = nullptr)
|
|
|
|
: handler(inHandler), eventSource(inSource)
|
2013-07-02 15:23:51 +08:00
|
|
|
{
|
2016-06-22 17:48:17 +08:00
|
|
|
if (nullptr == inName)
|
|
|
|
{
|
|
|
|
memset(eventName, 0, sizeof(eventName));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strncpy(eventName, inName, sizeof(eventName));
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
if (nullptr == inClassName)
|
2013-07-02 15:23:51 +08:00
|
|
|
{
|
2016-06-22 17:48:17 +08:00
|
|
|
memset(eventSourceClassName, 0, sizeof(eventSourceClassName));
|
2013-07-02 15:23:51 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-07-03 14:19:00 +08:00
|
|
|
strncpy(eventSourceClassName, inClassName, 64);
|
2013-07-02 15:23:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-03-25 18:54:33 +08:00
|
|
|
/**
|
|
|
|
* The ScriptEvent wrapper the different script data corresponding to the ScriptEventType in to the unified struct.
|
|
|
|
* when the corresponding event is triggered, we could call the `sendEvent` of ScriptEngineProtocol to handle the event.
|
2015-03-28 15:11:51 +08:00
|
|
|
* @js NA
|
2015-03-25 18:54:33 +08:00
|
|
|
*/
|
2013-07-02 15:23:51 +08:00
|
|
|
struct ScriptEvent
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2015-03-26 22:07:44 +08:00
|
|
|
* The specific type of ScriptEventType.
|
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
|
|
|
*/
|
2013-07-02 15:23:51 +08:00
|
|
|
ScriptEventType type;
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2015-03-26 22:07:44 +08:00
|
|
|
* Pointer point to the different data.
|
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
|
|
|
*/
|
2013-07-02 15:23:51 +08:00
|
|
|
void* data;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-03-26 22:07:44 +08:00
|
|
|
/**
|
|
|
|
* Constructor of ScriptEvent.
|
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
ScriptEvent(ScriptEventType inType, void* inData) : type(inType), data(inData) {}
|
2013-07-02 15:23:51 +08:00
|
|
|
};
|
2012-02-09 14:07:11 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2015-03-25 18:54:33 +08:00
|
|
|
* Don't make ScriptEngineProtocol inherits from Object since setScriptEngine is invoked only once in AppDelegate.cpp,
|
2021-12-25 10:04:45 +08:00
|
|
|
* It will affect the lifecycle of ScriptEngine instance, the autorelease pool will be destroyed before destructing
|
|
|
|
* ScriptEngine. So a crash will appear on Win32 if you click the close button.
|
2015-03-28 15:11:51 +08:00
|
|
|
* @js NA
|
2015-03-25 18:54:33 +08:00
|
|
|
*/
|
2022-07-15 19:17:01 +08:00
|
|
|
class AX_DLL ScriptEngineProtocol
|
2012-02-09 14:07:11 +08:00
|
|
|
{
|
|
|
|
public:
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2015-03-26 22:07:44 +08:00
|
|
|
* Constructor of ScriptEngineProtocol.
|
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
ScriptEngineProtocol() {}
|
|
|
|
|
2015-03-26 22:07:44 +08:00
|
|
|
/**
|
|
|
|
* Destructor of ScriptEngineProtocol.
|
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
|
|
|
*/
|
2016-11-09 10:34:50 +08:00
|
|
|
virtual ~ScriptEngineProtocol() {}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-25 18:54:33 +08:00
|
|
|
* Get the specific script type.
|
|
|
|
*
|
|
|
|
* @return the specific script type.
|
2015-03-26 22:07:44 +08:00
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
2013-09-13 11:41:20 +08:00
|
|
|
*/
|
2016-11-09 10:34:50 +08:00
|
|
|
virtual ccScriptType getScriptType() { return kScriptTypeNone; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-12-17 21:53:40 +08:00
|
|
|
/**
|
|
|
|
* Reflect the retain relationship to script scope
|
|
|
|
*/
|
2016-11-09 10:34:50 +08:00
|
|
|
virtual void retainScriptObject(Ref* /*owner*/, Ref* /*target*/) {}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-12-17 21:53:40 +08:00
|
|
|
/**
|
|
|
|
* Add the script object to root object
|
|
|
|
*/
|
2016-11-09 10:34:50 +08:00
|
|
|
virtual void rootScriptObject(Ref* /*target*/) {}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-12-17 21:53:40 +08:00
|
|
|
/**
|
|
|
|
* Reflect the release relationship to script scope
|
|
|
|
*/
|
2016-11-09 10:34:50 +08:00
|
|
|
virtual void releaseScriptObject(Ref* /*owner*/, Ref* /*target*/) {}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-12-17 21:53:40 +08:00
|
|
|
/**
|
|
|
|
* Remove the script object from root object
|
|
|
|
*/
|
2016-11-09 10:34:50 +08:00
|
|
|
virtual void unrootScriptObject(Ref* /*target*/) {}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-12-17 21:53:40 +08:00
|
|
|
/**
|
|
|
|
* Release all children native refs for the given node in script scope
|
|
|
|
*/
|
2016-11-09 10:34:50 +08:00
|
|
|
virtual void releaseAllChildrenRecursive(Node* /*node*/) {}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-12-17 21:53:40 +08:00
|
|
|
/**
|
|
|
|
* Release all native refs for the given owner in script scope
|
|
|
|
*/
|
2022-07-11 17:50:21 +08:00
|
|
|
virtual void releaseAllNativeRefs(axis::Ref* /*owner*/) {}
|
2012-09-10 18:38:18 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2015-03-25 18:54:33 +08:00
|
|
|
* Remove script object,The specific meaning should refer to the ScriptType.
|
|
|
|
* For Lua, @see removeScriptObjectByObject of LuaEngine.
|
2015-03-26 22:07:44 +08:00
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
2013-09-13 11:41:20 +08:00
|
|
|
*/
|
2016-11-09 10:34:50 +08:00
|
|
|
virtual void removeScriptObjectByObject(Ref* /*obj*/) {}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-25 18:54:33 +08:00
|
|
|
* Remove script function handler, only LuaEngine class need to implement this function.
|
|
|
|
* @see removeScriptHandler of LuaEngine.
|
2015-03-26 22:07:44 +08:00
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
2013-09-13 11:41:20 +08:00
|
|
|
*/
|
2016-11-09 10:34:50 +08:00
|
|
|
virtual void removeScriptHandler(int /*handler*/) {}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-25 18:54:33 +08:00
|
|
|
* Reallocate script function handler, only LuaEngine class need to implement this function.
|
|
|
|
* @see reallocateScriptHandler of LuaEngine.
|
2015-03-26 22:07:44 +08:00
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
2013-09-13 11:41:20 +08:00
|
|
|
*/
|
2016-11-09 10:34:50 +08:00
|
|
|
virtual int reallocateScriptHandler(int /*handler*/) { return 0; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2012-02-09 14:07:11 +08:00
|
|
|
/**
|
2015-03-25 18:54:33 +08:00
|
|
|
* Execute script code contained in the given string.
|
|
|
|
*
|
|
|
|
* @param codes holding the valid script code that should be executed.
|
|
|
|
* @return 0 if the string is executed correctly.
|
|
|
|
* @return other if the string is executed wrongly.
|
2015-03-26 22:07:44 +08:00
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
2012-02-09 14:07:11 +08:00
|
|
|
*/
|
|
|
|
virtual int executeString(const char* codes) = 0;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2012-02-09 14:07:11 +08:00
|
|
|
/**
|
2015-03-25 18:54:33 +08:00
|
|
|
* Execute a script file.
|
2021-12-25 10:04:45 +08:00
|
|
|
*
|
2015-03-25 18:54:33 +08:00
|
|
|
* @param filename String object holding the filename of the script file that is to be executed.
|
2021-12-25 10:04:45 +08:00
|
|
|
* @return 0 if it happen the error or it hasn't return value, otherwise it return the value by calling the lua
|
|
|
|
* function.
|
2015-03-26 22:07:44 +08:00
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
2012-02-09 14:07:11 +08:00
|
|
|
*/
|
|
|
|
virtual int executeScriptFile(const char* filename) = 0;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2012-02-09 14:07:11 +08:00
|
|
|
/**
|
2015-03-25 18:54:33 +08:00
|
|
|
* Execute a scripted global function.
|
|
|
|
* The function should not take any parameters and should return an integer.
|
|
|
|
*
|
2021-12-25 10:04:45 +08:00
|
|
|
* @param functionName String object holding the name of the function, in the global script environment, that is to
|
|
|
|
* be executed.
|
2015-03-25 18:54:33 +08:00
|
|
|
* @return The integer value returned from the script function.
|
2015-03-26 22:07:44 +08:00
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
2012-02-09 14:07:11 +08:00
|
|
|
*/
|
|
|
|
virtual int executeGlobalFunction(const char* functionName) = 0;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-03-25 18:54:33 +08:00
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* When trigger a script event ,call this func,add params needed into ScriptEvent object.nativeObject is object
|
|
|
|
* triggering the event, can be nullptr in Lua.
|
2015-03-26 22:07:44 +08:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
2013-09-13 11:41:20 +08:00
|
|
|
*/
|
2020-02-24 23:08:47 +08:00
|
|
|
virtual int sendEvent(const ScriptEvent& evt) = 0;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-25 18:54:33 +08:00
|
|
|
* Handle the assert message.
|
|
|
|
*
|
2013-04-15 22:50:07 +08:00
|
|
|
* @return true if the assert was handled by the script engine, false otherwise.
|
2015-03-26 22:07:44 +08:00
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
2013-04-15 22:50:07 +08:00
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual bool handleAssert(const char* msg) = 0;
|
|
|
|
|
|
|
|
/**
|
2015-03-26 22:07:44 +08:00
|
|
|
* Useless for Lua.
|
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
|
|
|
*/
|
2016-11-09 10:34:50 +08:00
|
|
|
virtual void setCalledFromScript(bool /*callFromScript*/) {}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-26 22:07:44 +08:00
|
|
|
* Useless for Lua.
|
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
|
|
|
*/
|
2014-03-08 11:51:10 +08:00
|
|
|
virtual bool isCalledFromScript() { return false; };
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-03-25 18:54:33 +08:00
|
|
|
/** ConfigType enum. */
|
2013-12-30 20:57:46 +08:00
|
|
|
enum class ConfigType
|
|
|
|
{
|
|
|
|
NONE,
|
|
|
|
COCOSTUDIO
|
|
|
|
};
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2015-03-25 18:54:33 +08:00
|
|
|
* Parse configuration file.
|
2021-12-25 10:04:45 +08:00
|
|
|
*
|
2015-03-25 18:54:33 +08:00
|
|
|
* @param type the specific type value.
|
|
|
|
* @param str the information data.
|
2015-03-26 22:07:44 +08:00
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
2015-03-25 18:54:33 +08:00
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
virtual bool parseConfig(ConfigType type, std::string_view str) = 0;
|
2015-12-03 06:45:13 +08:00
|
|
|
|
|
|
|
/** Root a Reference.
|
|
|
|
It tells the Garbage Collector that the associated Scripting object should not be collected
|
|
|
|
*/
|
2016-11-09 10:34:50 +08:00
|
|
|
virtual void rootObject(Ref* /*obj*/) {}
|
2015-12-03 06:45:13 +08:00
|
|
|
|
|
|
|
/** Unroot a Reference.
|
|
|
|
It tells the Garbage Collector that the associated Scripting object can be collected
|
|
|
|
*/
|
2016-11-09 10:34:50 +08:00
|
|
|
virtual void unrootObject(Ref* /*obj*/) {}
|
2015-12-24 00:54:00 +08:00
|
|
|
|
2017-03-16 09:42:16 +08:00
|
|
|
/** Remove proxy for a native object
|
|
|
|
*/
|
|
|
|
virtual void removeObjectProxy(Ref* obj) {}
|
|
|
|
|
2015-12-24 00:54:00 +08:00
|
|
|
/** Triggers the garbage collector */
|
|
|
|
virtual void garbageCollect() {}
|
2012-02-09 14:07:11 +08:00
|
|
|
};
|
|
|
|
|
2014-06-18 11:51:52 +08:00
|
|
|
class Node;
|
2012-02-09 14:07:11 +08:00
|
|
|
/**
|
2017-01-18 15:41:18 +08:00
|
|
|
* ScriptEngineManager is a singleton which manager an object instance of ScriptEngineProtocol, such as LuaEngine.
|
2015-03-25 18:54:33 +08:00
|
|
|
*
|
|
|
|
* @since v0.99.5-x-0.8.5
|
2015-03-28 15:11:51 +08:00
|
|
|
* @js NA
|
2012-02-09 14:07:11 +08:00
|
|
|
*/
|
2022-07-15 19:17:01 +08:00
|
|
|
class AX_DLL ScriptEngineManager
|
2012-02-09 14:07:11 +08:00
|
|
|
{
|
|
|
|
public:
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2015-03-26 22:07:44 +08:00
|
|
|
* Constructor of ScriptEngineManager.
|
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
|
|
|
*/
|
2019-07-22 09:38:46 +08:00
|
|
|
~ScriptEngineManager();
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2015-03-25 18:54:33 +08:00
|
|
|
* Get the ScriptEngineProtocol object.
|
|
|
|
*
|
|
|
|
* @return the ScriptEngineProtocol object.
|
2015-03-26 22:07:44 +08:00
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
2013-09-13 11:41:20 +08:00
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
ScriptEngineProtocol* getScriptEngine() { return _scriptEngine; }
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
2015-09-22 16:08:23 +08:00
|
|
|
* Set the ScriptEngineProtocol object should be managed.
|
2015-03-25 18:54:33 +08:00
|
|
|
*
|
2015-09-22 16:08:23 +08:00
|
|
|
* @param scriptEngine should be managed.
|
2015-03-26 22:07:44 +08:00
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
2013-09-13 11:41:20 +08:00
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
void setScriptEngine(ScriptEngineProtocol* scriptEngine);
|
|
|
|
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
2015-09-22 16:08:23 +08:00
|
|
|
* Remove the ScriptEngineProtocol object managed.
|
2015-03-26 22:07:44 +08:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
2013-09-13 11:41:20 +08:00
|
|
|
*/
|
2019-07-22 09:38:46 +08:00
|
|
|
void removeScriptEngine();
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
2015-03-25 18:54:33 +08:00
|
|
|
* Get the instance of ScriptEngineManager object.
|
|
|
|
*
|
|
|
|
* @return the instance of ScriptEngineManager object.
|
2015-03-26 22:07:44 +08:00
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
2013-09-13 11:41:20 +08:00
|
|
|
*/
|
2013-07-22 17:19:31 +08:00
|
|
|
static ScriptEngineManager* getInstance();
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
2015-03-25 18:54:33 +08:00
|
|
|
* Destroy the singleton about ScriptEngineManager.
|
2015-03-26 22:07:44 +08:00
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
2013-09-13 11:41:20 +08:00
|
|
|
*/
|
2013-07-22 17:19:31 +08:00
|
|
|
static void destroyInstance();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-18 11:51:52 +08:00
|
|
|
/**
|
2015-03-25 18:54:33 +08:00
|
|
|
* Call the Lua function when the event of node is triggered.
|
2021-12-25 10:04:45 +08:00
|
|
|
*
|
2015-03-26 22:07:44 +08:00
|
|
|
* @param node the nativeobject triggers the event.
|
|
|
|
* @param action the specific type.
|
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
2014-06-18 11:51:52 +08:00
|
|
|
*/
|
|
|
|
static void sendNodeEventToLua(Node* node, int action);
|
2020-02-24 23:08:47 +08:00
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Send a event to lua script
|
|
|
|
*
|
|
|
|
* @param event: the script event
|
|
|
|
*
|
|
|
|
* @lua NA
|
|
|
|
* @js NA
|
|
|
|
*/
|
2020-02-24 23:08:47 +08:00
|
|
|
static int sendEventToLua(const ScriptEvent& event);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2012-02-09 14:07:11 +08:00
|
|
|
private:
|
2021-12-25 10:04:45 +08:00
|
|
|
ScriptEngineManager() : _scriptEngine(nullptr) {}
|
|
|
|
|
|
|
|
ScriptEngineProtocol* _scriptEngine;
|
2012-02-09 14:07:11 +08:00
|
|
|
};
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|
2012-02-09 14:07:11 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
#endif // #if AX_ENABLE_SCRIPT_BINDING
|
2014-02-20 16:40:46 +08:00
|
|
|
|
2015-03-27 15:27:08 +08:00
|
|
|
// end group
|
|
|
|
/// @}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
#endif // __SCRIPT_SUPPORT_H__
|