mirror of https://github.com/axmolengine/axmol.git
issue #3037:Add assetsmananger lua binding and a releated test sample
This commit is contained in:
parent
6a10910ff3
commit
be1f17ca0f
|
@ -1 +1 @@
|
||||||
1c487d29bdc2d80516e86e2ee93b1664e9f7df2f
|
486af7c751cc94ff5dc25748cdb4bcb183be5dd2
|
|
@ -211,6 +211,7 @@ enum ScriptEventType
|
||||||
kControlEvent,
|
kControlEvent,
|
||||||
kCommonEvent,
|
kCommonEvent,
|
||||||
kTableViewEvent,//Now it's only used in LuaBinding
|
kTableViewEvent,//Now it's only used in LuaBinding
|
||||||
|
kAssetsManagerEvent,//Now it's only used in Lua Binding
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BasicScriptData
|
struct BasicScriptData
|
||||||
|
|
|
@ -252,6 +252,11 @@ int LuaEngine::sendEvent(ScriptEvent* evt)
|
||||||
return handleTableViewEvent(evt->data);
|
return handleTableViewEvent(evt->data);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case kAssetsManagerEvent:
|
||||||
|
{
|
||||||
|
return handleAssetsManagerEvent(evt->data);
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -770,4 +775,47 @@ int LuaEngine::handleTableViewEventReturnArray(void* data,int numResults,Array&
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int LuaEngine::handleAssetsManagerEvent(void* data)
|
||||||
|
{
|
||||||
|
if (nullptr == data)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
BasicScriptData* eventData = static_cast<BasicScriptData*>(data);
|
||||||
|
if (nullptr == eventData->nativeObject || nullptr == eventData->value)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
LuaAssetsManagerEventData* assetsManagerEventData = static_cast<LuaAssetsManagerEventData*>(eventData->value);
|
||||||
|
if (assetsManagerEventData->handlerType < ScriptHandlerMgr::HandlerType::ASSETSMANAGER_PROGRESS || assetsManagerEventData->handlerType > ScriptHandlerMgr::HandlerType::ASSETSMANAGER_ERROR )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)eventData->nativeObject, assetsManagerEventData->handlerType);
|
||||||
|
|
||||||
|
if (0 == handler)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
int ret = 0;
|
||||||
|
switch (assetsManagerEventData->handlerType)
|
||||||
|
{
|
||||||
|
case ScriptHandlerMgr::HandlerType::ASSETSMANAGER_PROGRESS:
|
||||||
|
case ScriptHandlerMgr::HandlerType::ASSETSMANAGER_ERROR:
|
||||||
|
{
|
||||||
|
_stack->pushInt(assetsManagerEventData->value);
|
||||||
|
ret = _stack->executeFunctionByHandler(handler, 1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ScriptHandlerMgr::HandlerType::ASSETSMANAGER_SUCCESS:
|
||||||
|
{
|
||||||
|
ret = _stack->executeFunctionByHandler(handler, 0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -141,6 +141,7 @@ private:
|
||||||
int handlerControlEvent(void* data);
|
int handlerControlEvent(void* data);
|
||||||
int handleTableViewEvent(void* data);
|
int handleTableViewEvent(void* data);
|
||||||
int handleTableViewEventReturnArray(void* data,int numResults,Array& resultArray);
|
int handleTableViewEventReturnArray(void* data,int numResults,Array& resultArray);
|
||||||
|
int handleAssetsManagerEvent(void* data);
|
||||||
void extendWebsocket(lua_State* lua_S);
|
void extendWebsocket(lua_State* lua_S);
|
||||||
void extendGLNode(lua_State* lua_S);
|
void extendGLNode(lua_State* lua_S);
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -95,6 +95,10 @@ public:
|
||||||
TABLECELL_SIZE_FOR_INDEX,
|
TABLECELL_SIZE_FOR_INDEX,
|
||||||
TABLECELL_AT_INDEX,
|
TABLECELL_AT_INDEX,
|
||||||
TABLEVIEW_NUMS_OF_CELLS,
|
TABLEVIEW_NUMS_OF_CELLS,
|
||||||
|
|
||||||
|
ASSETSMANAGER_PROGRESS,
|
||||||
|
ASSETSMANAGER_SUCCESS,
|
||||||
|
ASSETSMANAGER_ERROR,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef int Handler;
|
typedef int Handler;
|
||||||
|
|
|
@ -0,0 +1,164 @@
|
||||||
|
#include "lua_assetsmanager_test_sample.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
#include "tolua_fix.h"
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "cocos2d.h"
|
||||||
|
#include "cocos-ext.h"
|
||||||
|
|
||||||
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
USING_NS_CC;
|
||||||
|
USING_NS_CC_EXT;
|
||||||
|
|
||||||
|
|
||||||
|
static int lua_cocos2dx_createDownloadDir(lua_State* L)
|
||||||
|
{
|
||||||
|
if (nullptr == L)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
int argc = lua_gettop(L);
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
tolua_Error tolua_err;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (0 == argc)
|
||||||
|
{
|
||||||
|
std::string pathToSave = FileUtils::getInstance()->getWritablePath();
|
||||||
|
pathToSave += "tmpdir";
|
||||||
|
|
||||||
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
|
||||||
|
DIR *pDir = NULL;
|
||||||
|
|
||||||
|
pDir = opendir (pathToSave.c_str());
|
||||||
|
if (! pDir)
|
||||||
|
{
|
||||||
|
mkdir(pathToSave.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if ((GetFileAttributesA(pathToSave.c_str())) == INVALID_FILE_ATTRIBUTES)
|
||||||
|
{
|
||||||
|
CreateDirectoryA(pathToSave.c_str(), 0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
tolua_pushstring(L, pathToSave.c_str());
|
||||||
|
CCLOG("the path to save is %s",pathToSave.c_str());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
CCLOG("'createDownloadDir' function wrong number of arguments: %d, was expecting %d\n", argc, 0);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
tolua_lerror:
|
||||||
|
tolua_error(L,"#ferror in function 'createDownloadDir'.",&tolua_err);
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static int lua_cocos2dx_deleteDownloadDir(lua_State* L)
|
||||||
|
{
|
||||||
|
if (nullptr == L)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
int argc = lua_gettop(L);
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
tolua_Error tolua_err;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (1 == argc)
|
||||||
|
{
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
if (!tolua_isstring(L, 1, 0, &tolua_err)) goto tolua_lerror;
|
||||||
|
#endif
|
||||||
|
std::string pathToSave = tolua_tostring(L, 1, "");
|
||||||
|
|
||||||
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
|
||||||
|
std::string command = "rm -r ";
|
||||||
|
// Path may include space.
|
||||||
|
command += "\"" + pathToSave + "\"";
|
||||||
|
system(command.c_str());
|
||||||
|
#else
|
||||||
|
std::string command = "rd /s /q ";
|
||||||
|
// Path may include space.
|
||||||
|
command += "\"" + pathToSave + "\"";
|
||||||
|
system(command.c_str());
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
CCLOG("'resetDownloadDir' function wrong number of arguments: %d, was expecting %d\n", argc, 1);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
tolua_lerror:
|
||||||
|
tolua_error(L,"#ferror in function 'resetDownloadDir'.",&tolua_err);
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static int lua_cocos2dx_addSearchPath(lua_State* L)
|
||||||
|
{
|
||||||
|
if (nullptr == L)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
int argc = lua_gettop(L);
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
tolua_Error tolua_err;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
if (2 == argc)
|
||||||
|
{
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
if (!tolua_isstring(L, 1, 0, &tolua_err) ||
|
||||||
|
!tolua_isboolean(L, 2, 0, &tolua_err))
|
||||||
|
goto tolua_lerror;
|
||||||
|
#endif
|
||||||
|
std::string pathToSave = tolua_tostring(L, 1, "");
|
||||||
|
bool before = tolua_toboolean(L, 2, 0);
|
||||||
|
std::vector<std::string> searchPaths = FileUtils::getInstance()->getSearchPaths();
|
||||||
|
if (before)
|
||||||
|
{
|
||||||
|
searchPaths.insert(searchPaths.begin(), pathToSave);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
searchPaths.push_back(pathToSave);
|
||||||
|
}
|
||||||
|
|
||||||
|
FileUtils::getInstance()->setSearchPaths(searchPaths);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
CCLOG("'addSearchPath' function wrong number of arguments: %d, was expecting %d\n", argc, 2);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
tolua_lerror:
|
||||||
|
tolua_error(L,"#ferror in function 'addSearchPath'.",&tolua_err);
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
int register_assetsmanager_test_sample(lua_State* L)
|
||||||
|
{
|
||||||
|
tolua_open(L);
|
||||||
|
tolua_module(L, NULL, 0);
|
||||||
|
tolua_beginmodule(L, NULL);
|
||||||
|
tolua_function(L, "createDownloadDir", lua_cocos2dx_createDownloadDir);
|
||||||
|
tolua_function(L, "deleteDownloadDir", lua_cocos2dx_deleteDownloadDir);
|
||||||
|
tolua_function(L, "addSearchPath", lua_cocos2dx_addSearchPath);
|
||||||
|
tolua_endmodule(L);
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
#ifndef COCOS2DX_COCOS_SCRIPTING_LUA_BINDINGS_LUA_ASSETSMANAGER_TEST_SAMPLE_H
|
||||||
|
#define COCOS2DX_COCOS_SCRIPTING_LUA_BINDINGS_LUA_ASSETSMANAGER_TEST_SAMPLE_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
#include "tolua++.h"
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The apis which are bound in this file are temporary for the assetsmanager test sample.After the completion of some systems like fileutils,these apis will be deprecated
|
||||||
|
*/
|
||||||
|
TOLUA_API int register_assetsmanager_test_sample(lua_State* tolua_S);
|
||||||
|
|
||||||
|
#endif // #ifndef COCOS2DX_COCOS_SCRIPTING_LUA_BINDINGS_LUA_ASSETSMANAGER_TEST_SAMPLE_H
|
|
@ -1426,6 +1426,125 @@ static void extendBone(lua_State* L)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class LuaAssetsManagerDelegateProtocol:public Object, public AssetsManagerDelegateProtocol
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~LuaAssetsManagerDelegateProtocol()
|
||||||
|
{}
|
||||||
|
|
||||||
|
virtual void onProgress(int percent)
|
||||||
|
{
|
||||||
|
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)this, ScriptHandlerMgr::HandlerType::ASSETSMANAGER_PROGRESS);
|
||||||
|
if (0 != handler)
|
||||||
|
{
|
||||||
|
LuaAssetsManagerEventData eventData(ScriptHandlerMgr::HandlerType::ASSETSMANAGER_PROGRESS,percent);
|
||||||
|
BasicScriptData data((void*)this,&eventData);
|
||||||
|
ScriptEvent event(kAssetsManagerEvent,(void*)&data);
|
||||||
|
LuaEngine::getInstance()->sendEvent(&event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void onSuccess()
|
||||||
|
{
|
||||||
|
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)this, ScriptHandlerMgr::HandlerType::ASSETSMANAGER_SUCCESS);
|
||||||
|
if (0 != handler)
|
||||||
|
{
|
||||||
|
LuaAssetsManagerEventData eventData(ScriptHandlerMgr::HandlerType::ASSETSMANAGER_SUCCESS);
|
||||||
|
BasicScriptData data((void*)this,&eventData);
|
||||||
|
ScriptEvent event(kAssetsManagerEvent,(void*)&data);
|
||||||
|
LuaEngine::getInstance()->sendEvent(&event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void onError(AssetsManager::ErrorCode errorCode)
|
||||||
|
{
|
||||||
|
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)this, ScriptHandlerMgr::HandlerType::ASSETSMANAGER_ERROR);
|
||||||
|
if (0 != handler)
|
||||||
|
{
|
||||||
|
LuaAssetsManagerEventData eventData(ScriptHandlerMgr::HandlerType::ASSETSMANAGER_ERROR, (int)errorCode);
|
||||||
|
BasicScriptData data((void*)this,&eventData);
|
||||||
|
ScriptEvent event(kAssetsManagerEvent,(void*)&data);
|
||||||
|
LuaEngine::getInstance()->sendEvent(&event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static int lua_cocos2dx_AssetsManager_setDelegate(lua_State* L)
|
||||||
|
{
|
||||||
|
if (nullptr == L)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
int argc = 0;
|
||||||
|
AssetsManager* self = nullptr;
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
tolua_Error tolua_err;
|
||||||
|
if (!tolua_isusertype(L,1,"AssetsManager",0,&tolua_err)) goto tolua_lerror;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
self = (AssetsManager*) tolua_tousertype(L,1,0);
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
if (nullptr == self)
|
||||||
|
{
|
||||||
|
tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_AssetsManager_setDelegate'\n", nullptr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
argc = lua_gettop(L) - 1;
|
||||||
|
|
||||||
|
if (2 == argc)
|
||||||
|
{
|
||||||
|
LuaAssetsManagerDelegateProtocol* delegate = dynamic_cast<LuaAssetsManagerDelegateProtocol*>( self->getDelegate());
|
||||||
|
if (nullptr == delegate)
|
||||||
|
{
|
||||||
|
delegate = new LuaAssetsManagerDelegateProtocol();
|
||||||
|
if (nullptr == delegate)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
self->setUserObject(delegate);
|
||||||
|
self->setDelegate(delegate);
|
||||||
|
delegate->release();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (2 == argc)
|
||||||
|
{
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
if (!toluafix_isfunction(L, 2, "LUA_FUNCTION", 0, &tolua_err) ||
|
||||||
|
!tolua_isnumber(L, 3, 0, &tolua_err) )
|
||||||
|
{
|
||||||
|
goto tolua_lerror;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
LUA_FUNCTION handler = toluafix_ref_function(L, 2, 0);
|
||||||
|
ScriptHandlerMgr::HandlerType handlerType = (ScriptHandlerMgr::HandlerType) ((int)tolua_tonumber(L,3,0) + (int)ScriptHandlerMgr::HandlerType::ASSETSMANAGER_PROGRESS);
|
||||||
|
|
||||||
|
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)delegate, handler, handlerType);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CCLOG("'setDelegate' function of AssetsManager has wrong number of arguments: %d, was expecting %d\n", argc, 2);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
tolua_lerror:
|
||||||
|
tolua_error(L,"#ferror in function 'setDelegate'.",&tolua_err);
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static void extendAssetsManager(lua_State* L)
|
||||||
|
{
|
||||||
|
lua_pushstring(L, "AssetsManager");
|
||||||
|
lua_rawget(L, LUA_REGISTRYINDEX);
|
||||||
|
if (lua_istable(L,-1))
|
||||||
|
{
|
||||||
|
tolua_function(L, "setDelegate", lua_cocos2dx_AssetsManager_setDelegate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int register_all_cocos2dx_extension_manual(lua_State* tolua_S)
|
int register_all_cocos2dx_extension_manual(lua_State* tolua_S)
|
||||||
{
|
{
|
||||||
extendScrollView(tolua_S);
|
extendScrollView(tolua_S);
|
||||||
|
@ -1435,5 +1554,6 @@ int register_all_cocos2dx_extension_manual(lua_State* tolua_S)
|
||||||
extendCCBAnimationManager(tolua_S);
|
extendCCBAnimationManager(tolua_S);
|
||||||
extendTableView(tolua_S);
|
extendTableView(tolua_S);
|
||||||
extendBone(tolua_S);
|
extendBone(tolua_S);
|
||||||
|
extendAssetsManager(tolua_S);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,4 +26,15 @@ struct LuaTableViewEventData
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct LuaAssetsManagerEventData
|
||||||
|
{
|
||||||
|
cocos2d::ScriptHandlerMgr::HandlerType handlerType;
|
||||||
|
int value;
|
||||||
|
|
||||||
|
LuaAssetsManagerEventData(cocos2d::ScriptHandlerMgr::HandlerType _handleType, int _value = 0):handlerType(_handleType),value(_value)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // #ifndef COCOS2DX_SCRIPT_LUA_COCOS2DX_SUPPORT_LUA_COCOS2DX_EXTENSION_MANUAL_H
|
#endif // #ifndef COCOS2DX_SCRIPT_LUA_COCOS2DX_SUPPORT_LUA_COCOS2DX_EXTENSION_MANUAL_H
|
||||||
|
|
|
@ -272,3 +272,13 @@ cc.WEBSOCKET_STATE_CONNECTING = 0
|
||||||
cc.WEBSOCKET_STATE_OPEN = 1
|
cc.WEBSOCKET_STATE_OPEN = 1
|
||||||
cc.WEBSOCKET_STATE_CLOSING = 2
|
cc.WEBSOCKET_STATE_CLOSING = 2
|
||||||
cc.WEBSOCKET_STATE_CLOSED = 3
|
cc.WEBSOCKET_STATE_CLOSED = 3
|
||||||
|
|
||||||
|
cc.ASSETSMANAGER_CREATE_FILE = 0
|
||||||
|
cc.ASSETSMANAGER_NETWORK = 1
|
||||||
|
cc.ASSETSMANAGER_NO_NEW_VERSION = 2
|
||||||
|
cc.ASSETSMANAGER_UNCOMPRESS = 3
|
||||||
|
|
||||||
|
cc.ASSETSMANAGER_PROTOCOL_PROGRESS = 0
|
||||||
|
cc.ASSETSMANAGER_PROTOCOL_SUCCESS = 1
|
||||||
|
cc.ASSETSMANAGER_PROTOCOL_ERROR = 2
|
||||||
|
|
||||||
|
|
|
@ -141,6 +141,12 @@ public:
|
||||||
*/
|
*/
|
||||||
void setDelegate(AssetsManagerDelegateProtocol *delegate);
|
void setDelegate(AssetsManagerDelegateProtocol *delegate);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @js NA
|
||||||
|
* @lua NA
|
||||||
|
*/
|
||||||
|
AssetsManagerDelegateProtocol* getDelegate() { return _delegate ;}
|
||||||
|
|
||||||
/** @brief Sets connection time out in seconds
|
/** @brief Sets connection time out in seconds
|
||||||
*/
|
*/
|
||||||
void setConnectionTimeout(unsigned int timeout);
|
void setConnectionTimeout(unsigned int timeout);
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "AppDelegate.h"
|
#include "AppDelegate.h"
|
||||||
#include "CCLuaEngine.h"
|
#include "CCLuaEngine.h"
|
||||||
#include "SimpleAudioEngine.h"
|
#include "SimpleAudioEngine.h"
|
||||||
|
#include "lua_assetsmanager_test_sample.h"
|
||||||
|
|
||||||
using namespace CocosDenshion;
|
using namespace CocosDenshion;
|
||||||
|
|
||||||
|
@ -50,7 +51,13 @@ bool AppDelegate::applicationDidFinishLaunching()
|
||||||
LuaEngine* pEngine = LuaEngine::getInstance();
|
LuaEngine* pEngine = LuaEngine::getInstance();
|
||||||
ScriptEngineManager::getInstance()->setScriptEngine(pEngine);
|
ScriptEngineManager::getInstance()->setScriptEngine(pEngine);
|
||||||
|
|
||||||
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID ||CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||||
|
LuaStack* stack = pEngine->getLuaStack();
|
||||||
|
register_assetsmanager_test_sample(stack->getLuaState());
|
||||||
|
#endif
|
||||||
|
|
||||||
std::vector<std::string> searchPaths = pFileUtils->getSearchPaths();
|
std::vector<std::string> searchPaths = pFileUtils->getSearchPaths();
|
||||||
|
searchPaths.insert(searchPaths.begin(), "Images");
|
||||||
searchPaths.insert(searchPaths.begin(), "cocosbuilderRes");
|
searchPaths.insert(searchPaths.begin(), "cocosbuilderRes");
|
||||||
|
|
||||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_BLACKBERRY
|
#if CC_TARGET_PLATFORM == CC_PLATFORM_BLACKBERRY
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
local AssetManagerModule = {}
|
||||||
|
|
||||||
|
function AssetManagerModule.newScene(backfunc)
|
||||||
|
|
||||||
|
local winSize = cc.Director:getInstance():getWinSize()
|
||||||
|
|
||||||
|
local newScene = cc.Scene:create()
|
||||||
|
local layer = cc.Layer:create()
|
||||||
|
|
||||||
|
local function backToUpdate()
|
||||||
|
local scene = backfunc()
|
||||||
|
if scene ~= nil then
|
||||||
|
cc.Director:getInstance():replaceScene(scene)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--Create BackMneu
|
||||||
|
cc.MenuItemFont:setFontName("Arial")
|
||||||
|
cc.MenuItemFont:setFontSize(24)
|
||||||
|
local backMenuItem = cc.MenuItemFont:create("Back")
|
||||||
|
backMenuItem:setPosition(cc.p(VisibleRect:rightBottom().x - 50, VisibleRect:rightBottom().y + 25))
|
||||||
|
backMenuItem:registerScriptTapHandler(backToUpdate)
|
||||||
|
|
||||||
|
local backMenu = cc.Menu:create()
|
||||||
|
backMenu:setPosition(0, 0)
|
||||||
|
backMenu:addChild(backMenuItem)
|
||||||
|
layer:addChild(backMenu,6)
|
||||||
|
|
||||||
|
local helloLabel = cc.LabelTTF:create("Hello World", "Arial", 38)
|
||||||
|
helloLabel:setPosition(cc.p(winSize.width / 2, winSize.height - 40))
|
||||||
|
layer:addChild(helloLabel, 5)
|
||||||
|
|
||||||
|
local sprite = cc.Sprite:create("background.png")
|
||||||
|
sprite:setAnchorPoint(cc.p(0.5, 0.5))
|
||||||
|
sprite:setPosition(cc.p(winSize.width / 2, winSize.height / 2))
|
||||||
|
layer:addChild(sprite, 0)
|
||||||
|
|
||||||
|
newScene:addChild(layer)
|
||||||
|
cc.Director:getInstance():replaceScene(newScene)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
return AssetManagerModule
|
|
@ -0,0 +1,161 @@
|
||||||
|
local targetPlatform = cc.Application:getInstance():getTargetPlatform()
|
||||||
|
|
||||||
|
local lineSpace = 40
|
||||||
|
local itemTagBasic = 1000
|
||||||
|
local menuItemNames =
|
||||||
|
{
|
||||||
|
"enter",
|
||||||
|
"reset",
|
||||||
|
"update",
|
||||||
|
}
|
||||||
|
|
||||||
|
local winSize = cc.Director:getInstance():getWinSize()
|
||||||
|
|
||||||
|
local function updateLayer()
|
||||||
|
|
||||||
|
local support = false
|
||||||
|
if (cc.PLATFORM_OS_IPHONE == targetPlatform) or (cc.PLATFORM_OS_IPAD == targetPlatform)
|
||||||
|
or (cc.PLATFORM_OS_WINDOWS == targetPlatform) or (cc.PLATFORM_OS_ANDROID == targetPlatform)
|
||||||
|
or (cc.PLATFORM_OS_IPHONE == targetPlatform) then
|
||||||
|
support = true
|
||||||
|
end
|
||||||
|
|
||||||
|
if not support then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local isUpdateItemClicked = false
|
||||||
|
local assetsManager = nil
|
||||||
|
local pathToSave = ""
|
||||||
|
|
||||||
|
local layer = cc.Layer:create()
|
||||||
|
local menu = cc.Menu:create()
|
||||||
|
menu:setPosition(cc.p(0, 0))
|
||||||
|
cc.MenuItemFont:setFontName("Arial")
|
||||||
|
cc.MenuItemFont:setFontSize(24)
|
||||||
|
|
||||||
|
local progressLable = cc.LabelTTF:create("","Arial",30)
|
||||||
|
progressLable:setPosition(cc.p(140,50))
|
||||||
|
layer:addChild(progressLable)
|
||||||
|
|
||||||
|
pathToSave = createDownloadDir()
|
||||||
|
|
||||||
|
local function onError(errorCode)
|
||||||
|
if errorCode == cc.ASSETSMANAGER_NO_NEW_VERSION then
|
||||||
|
progressLable:setString("no new version")
|
||||||
|
elseif errorCode == cc.ASSETSMANAGER_NETWORK then
|
||||||
|
progressLable:setString("network error")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function onProgress( percent )
|
||||||
|
local progress = string.format("downloading %d%%",percent)
|
||||||
|
progressLable:setString(progress)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function onSuccess()
|
||||||
|
progressLable:setString("downloading ok")
|
||||||
|
end
|
||||||
|
|
||||||
|
local function getAssetsManager()
|
||||||
|
if nil == assetsManager then
|
||||||
|
assetsManager = cc.AssetsManager:new("https://raw.github.com/samuele3hu/AssetsManagerTest/master/package.zip",
|
||||||
|
"https://raw.github.com/samuele3hu/AssetsManagerTest/master/version",
|
||||||
|
pathToSave)
|
||||||
|
assetsManager:retain()
|
||||||
|
assetsManager:setDelegate(onError, cc.ASSETSMANAGER_PROTOCOL_ERROR )
|
||||||
|
assetsManager:setDelegate(onProgress, cc.ASSETSMANAGER_PROTOCOL_PROGRESS)
|
||||||
|
assetsManager:setDelegate(onSuccess, cc.ASSETSMANAGER_PROTOCOL_SUCCESS )
|
||||||
|
assetsManager:setConnectionTimeout(3)
|
||||||
|
end
|
||||||
|
|
||||||
|
return assetsManager
|
||||||
|
end
|
||||||
|
|
||||||
|
local function update(sender)
|
||||||
|
|
||||||
|
progressLable:setString("")
|
||||||
|
|
||||||
|
getAssetsManager():update()
|
||||||
|
|
||||||
|
--isUpdateItemClicked = true
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
local function reset(sender)
|
||||||
|
progressLable:setString("")
|
||||||
|
|
||||||
|
deleteDownloadDir(pathToSave)
|
||||||
|
|
||||||
|
getAssetsManager():deleteVersion()
|
||||||
|
|
||||||
|
createDownloadDir()
|
||||||
|
end
|
||||||
|
|
||||||
|
local function reloadModule( moduleName )
|
||||||
|
|
||||||
|
package.loaded[moduleName] = nil
|
||||||
|
|
||||||
|
return require(moduleName)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function enter(sender)
|
||||||
|
|
||||||
|
if not isUpdateItemClicked then
|
||||||
|
addSearchPath(pathToSave,true)
|
||||||
|
end
|
||||||
|
|
||||||
|
assetsManagerModule = reloadModule("luaScript/AssetsManagerTest/AssetsManagerModule")
|
||||||
|
|
||||||
|
assetsManagerModule.newScene(AssetsManagerTestMain)
|
||||||
|
end
|
||||||
|
|
||||||
|
local callbackFuncs =
|
||||||
|
{
|
||||||
|
enter,
|
||||||
|
reset,
|
||||||
|
update,
|
||||||
|
}
|
||||||
|
|
||||||
|
local function menuCallback(tag, menuItem)
|
||||||
|
local scene = nil
|
||||||
|
local nIdx = menuItem:getZOrder() - itemTagBasic
|
||||||
|
local ExtensionsTestScene = CreateExtensionsTestScene(nIdx)
|
||||||
|
if nil ~= ExtensionsTestScene then
|
||||||
|
cc.Director:getInstance():replaceScene(ExtensionsTestScene)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for i = 1, table.getn(menuItemNames) do
|
||||||
|
local item = cc.MenuItemFont:create(menuItemNames[i])
|
||||||
|
item:registerScriptTapHandler(callbackFuncs[i])
|
||||||
|
item:setPosition(winSize.width / 2, winSize.height - i * lineSpace)
|
||||||
|
if not support then
|
||||||
|
item:setEnabled(false)
|
||||||
|
end
|
||||||
|
menu:addChild(item, itemTagBasic + i)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function onNodeEvent(msgName)
|
||||||
|
if nil ~= assetsManager then
|
||||||
|
assetsManager:release()
|
||||||
|
assetsManager = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
layer:registerScriptHandler(onNodeEvent)
|
||||||
|
|
||||||
|
layer:addChild(menu)
|
||||||
|
|
||||||
|
return layer
|
||||||
|
end
|
||||||
|
|
||||||
|
-------------------------------------
|
||||||
|
-- AssetsManager Test
|
||||||
|
-------------------------------------
|
||||||
|
function AssetsManagerTestMain()
|
||||||
|
local scene = cc.Scene:create()
|
||||||
|
scene:addChild(updateLayer())
|
||||||
|
scene:addChild(CreateBackMenuItem())
|
||||||
|
return scene
|
||||||
|
end
|
|
@ -13,6 +13,7 @@ require "luaScript/ActionManagerTest/ActionManagerTest"
|
||||||
require "luaScript/ActionsEaseTest/ActionsEaseTest"
|
require "luaScript/ActionsEaseTest/ActionsEaseTest"
|
||||||
require "luaScript/ActionsProgressTest/ActionsProgressTest"
|
require "luaScript/ActionsProgressTest/ActionsProgressTest"
|
||||||
require "luaScript/ActionsTest/ActionsTest"
|
require "luaScript/ActionsTest/ActionsTest"
|
||||||
|
require "luaScript/AssetsManagerTest/AssetsManagerTest"
|
||||||
require "luaScript/BugsTest/BugsTest"
|
require "luaScript/BugsTest/BugsTest"
|
||||||
require "luaScript/ClickAndMoveTest/ClickAndMoveTest"
|
require "luaScript/ClickAndMoveTest/ClickAndMoveTest"
|
||||||
require "luaScript/CocosDenshionTest/CocosDenshionTest"
|
require "luaScript/CocosDenshionTest/CocosDenshionTest"
|
||||||
|
@ -58,6 +59,7 @@ local _allTests = {
|
||||||
{ isSupported = true, name = "ActionsEaseTest" , create_func = EaseActionsTest },
|
{ isSupported = true, name = "ActionsEaseTest" , create_func = EaseActionsTest },
|
||||||
{ isSupported = true, name = "ActionsProgressTest" , create_func = ProgressActionsTest },
|
{ isSupported = true, name = "ActionsProgressTest" , create_func = ProgressActionsTest },
|
||||||
{ isSupported = true, name = "ActionsTest" , create_func = ActionsTest },
|
{ isSupported = true, name = "ActionsTest" , create_func = ActionsTest },
|
||||||
|
{ isSupported = true, name = "AssetsManagerTest" , create_func = AssetsManagerTestMain },
|
||||||
{ isSupported = false, name = "Box2dTest" , create_func= Box2dTestMain },
|
{ isSupported = false, name = "Box2dTest" , create_func= Box2dTestMain },
|
||||||
{ isSupported = false, name = "Box2dTestBed" , create_func= Box2dTestBedMain },
|
{ isSupported = false, name = "Box2dTestBed" , create_func= Box2dTestBedMain },
|
||||||
{ isSupported = true, name = "BugsTest" , create_func= BugsTestMain },
|
{ isSupported = true, name = "BugsTest" , create_func= BugsTestMain },
|
||||||
|
|
|
@ -44,7 +44,7 @@ skip = CCBReader::[^CCBReader$ addOwnerCallbackName isJSControlled readByte getC
|
||||||
*::[^visit$ copyWith.* onEnter.* onExit.* ^description$ getObjectType .*HSV onTouch.* onAcc.* onKey.* onRegisterTouchListener],
|
*::[^visit$ copyWith.* onEnter.* onExit.* ^description$ getObjectType .*HSV onTouch.* onAcc.* onKey.* onRegisterTouchListener],
|
||||||
EditBox::[(g|s)etDelegate ^keyboard.* touchDownAction getScriptEditBoxHandler registerScriptEditBoxHandler unregisterScriptEditBoxHandler],
|
EditBox::[(g|s)etDelegate ^keyboard.* touchDownAction getScriptEditBoxHandler registerScriptEditBoxHandler unregisterScriptEditBoxHandler],
|
||||||
TableView::[create (g|s)etDataSource$ (g|s)etDelegate],
|
TableView::[create (g|s)etDataSource$ (g|s)etDelegate],
|
||||||
AssetsManager::[setDelegate],
|
AssetsManager::[(g|s)etDelegate],
|
||||||
AssetsManagerDelegateProtocol::[*],
|
AssetsManagerDelegateProtocol::[*],
|
||||||
Control::[removeHandleOfControlEvent addHandleOfControlEvent],
|
Control::[removeHandleOfControlEvent addHandleOfControlEvent],
|
||||||
ControlUtils::[*],
|
ControlUtils::[*],
|
||||||
|
|
|
@ -13,7 +13,7 @@ android_flags = -D_SIZE_T_DEFINED_
|
||||||
clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include
|
clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include
|
||||||
clang_flags = -nostdinc -x c++ -std=c++11
|
clang_flags = -nostdinc -x c++ -std=c++11
|
||||||
|
|
||||||
cocos_headers = -I%(cocosdir)s/cocos/2d -I%(cocosdir)s/cocos/base -I%(cocosdir)s/cocos/gui -I%(cocosdir)s/cocos/physics -I%(cocosdir)s/cocos/2d/platform -I%(cocosdir)s/cocos/2d/platform/android -I%(cocosdir)s/cocos/math/kazmath/include -I%(cocosdir)s/extensions -I%(cocosdir)s/external -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s
|
cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/2d -I%(cocosdir)s/cocos/base -I%(cocosdir)s/cocos/gui -I%(cocosdir)s/cocos/physics -I%(cocosdir)s/cocos/2d/platform -I%(cocosdir)s/cocos/2d/platform/android -I%(cocosdir)s/cocos/math/kazmath/include -I%(cocosdir)s/extensions -I%(cocosdir)s/external -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s
|
||||||
cocos_flags = -DANDROID -DCOCOS2D_JAVASCRIPT
|
cocos_flags = -DANDROID -DCOCOS2D_JAVASCRIPT
|
||||||
|
|
||||||
cxxgenerator_headers =
|
cxxgenerator_headers =
|
||||||
|
@ -26,7 +26,7 @@ headers = %(cocosdir)s/extensions/cocos-ext.h %(cocosdir)s/cocos/editor-support/
|
||||||
|
|
||||||
# what classes to produce code for. You can use regular expressions here. When testing the regular
|
# 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*$".
|
# expression, it will be enclosed in "^$", like this: "^Menu*$".
|
||||||
classes = CCBReader.* CCBAnimationManager.* Scale9Sprite Control.* ControlButton.* ScrollView$ TableView$ TableViewCell$ EditBox$ Armature ArmatureAnimation Skin Bone ArmatureDataManager \w+Data$
|
classes = AssetsManager.* CCBReader.* CCBAnimationManager.* Scale9Sprite Control.* ControlButton.* ScrollView$ TableView$ TableViewCell$ EditBox$ Armature ArmatureAnimation Skin Bone ArmatureDataManager \w+Data$
|
||||||
|
|
||||||
# what should we skip? in the format ClassName::[function function]
|
# 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
|
# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also
|
||||||
|
@ -43,6 +43,8 @@ skip = CCBReader::[^CCBReader$ addOwnerCallbackName isJSControlled readByte getC
|
||||||
*::[^visit$ copyWith.* onEnter.* onExit.* ^description$ getObjectType (g|s)etDelegate .*HSV],
|
*::[^visit$ copyWith.* onEnter.* onExit.* ^description$ getObjectType (g|s)etDelegate .*HSV],
|
||||||
EditBox::[(g|s)etDelegate ^keyboard.* touchDownAction getScriptEditBoxHandler registerScriptEditBoxHandler unregisterScriptEditBoxHandler],
|
EditBox::[(g|s)etDelegate ^keyboard.* touchDownAction getScriptEditBoxHandler registerScriptEditBoxHandler unregisterScriptEditBoxHandler],
|
||||||
TableView::[create (g|s)etDataSource$ (g|s)etDelegate],
|
TableView::[create (g|s)etDataSource$ (g|s)etDelegate],
|
||||||
|
AssetsManager::[(g|s)etDelegate],
|
||||||
|
AssetsManagerDelegateProtocol::[*],
|
||||||
Control::[removeHandleOfControlEvent addHandleOfControlEvent],
|
Control::[removeHandleOfControlEvent addHandleOfControlEvent],
|
||||||
ControlUtils::[*],
|
ControlUtils::[*],
|
||||||
ControlSwitchSprite::[*],
|
ControlSwitchSprite::[*],
|
||||||
|
|
Loading…
Reference in New Issue