mirror of https://github.com/axmolengine/axmol.git
add entry file support
This commit is contained in:
parent
48566b70e0
commit
c973dba4f1
|
@ -3,6 +3,12 @@
|
||||||
"exclude_from_template": [
|
"exclude_from_template": [
|
||||||
"frameworks/runtime-src"
|
"frameworks/runtime-src"
|
||||||
],
|
],
|
||||||
|
"project_replace_project_name": {
|
||||||
|
"src_project_name": "HelloLua",
|
||||||
|
"files": [
|
||||||
|
"res/config.json",
|
||||||
|
".project"]
|
||||||
|
},
|
||||||
"append_dir": [
|
"append_dir": [
|
||||||
{
|
{
|
||||||
"from": "cocos/scripting/lua-bindings/script",
|
"from": "cocos/scripting/lua-bindings/script",
|
||||||
|
|
|
@ -21,9 +21,9 @@ AppDelegate::~AppDelegate()
|
||||||
|
|
||||||
bool AppDelegate::applicationDidFinishLaunching()
|
bool AppDelegate::applicationDidFinishLaunching()
|
||||||
{
|
{
|
||||||
string entryfile ="src/main.lua";
|
|
||||||
#if (COCOS2D_DEBUG>0)
|
#if (COCOS2D_DEBUG>0)
|
||||||
initRuntime(entryfile);
|
initRuntime();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// initialize director
|
// initialize director
|
||||||
|
@ -65,7 +65,7 @@ bool AppDelegate::applicationDidFinishLaunching()
|
||||||
return true;
|
return true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
engine->executeScriptFile(entryfile.c_str());
|
engine->executeScriptFile(ConfigParser::getInstance()->getEntryFile().c_str());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,6 @@ bool ConfigParser::isInit()
|
||||||
|
|
||||||
void ConfigParser::readConfig()
|
void ConfigParser::readConfig()
|
||||||
{
|
{
|
||||||
_initViewSize.setSize(960,640);
|
|
||||||
_viewName="HelloLua";
|
|
||||||
_isInit = true;
|
_isInit = true;
|
||||||
string filecfg = "res/config.json";
|
string filecfg = "res/config.json";
|
||||||
string fullPathFile = FileUtils::getInstance()->fullPathForFilename(filecfg);
|
string fullPathFile = FileUtils::getInstance()->fullPathForFilename(filecfg);
|
||||||
|
@ -34,9 +32,9 @@ void ConfigParser::readConfig()
|
||||||
rapidjson::FileStream inputStream(pFile);
|
rapidjson::FileStream inputStream(pFile);
|
||||||
_docRootjson.ParseStream<0>(inputStream);
|
_docRootjson.ParseStream<0>(inputStream);
|
||||||
fclose(pFile);
|
fclose(pFile);
|
||||||
if (_docRootjson.HasMember("init_view") && _docRootjson["init_view"].IsObject())
|
if (_docRootjson.HasMember("init_cfg") && _docRootjson["init_cfg"].IsObject())
|
||||||
{
|
{
|
||||||
const rapidjson::Value& objectInitView = _docRootjson["init_view"];
|
const rapidjson::Value& objectInitView = _docRootjson["init_cfg"];
|
||||||
if (objectInitView.HasMember("width") && objectInitView.HasMember("height"))
|
if (objectInitView.HasMember("width") && objectInitView.HasMember("height"))
|
||||||
{
|
{
|
||||||
_initViewSize.width = objectInitView["width"].GetUint();
|
_initViewSize.width = objectInitView["width"].GetUint();
|
||||||
|
@ -49,6 +47,9 @@ void ConfigParser::readConfig()
|
||||||
if (objectInitView.HasMember("isLandscape") && objectInitView["isLandscape"].IsBool()) {
|
if (objectInitView.HasMember("isLandscape") && objectInitView["isLandscape"].IsBool()) {
|
||||||
_isLandscape = objectInitView["isLandscape"].GetBool();
|
_isLandscape = objectInitView["isLandscape"].GetBool();
|
||||||
}
|
}
|
||||||
|
if (objectInitView.HasMember("entry") && objectInitView["entry"].IsString()) {
|
||||||
|
_entryfile = objectInitView["entry"].GetString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (_docRootjson.HasMember("simulator_screen_size"))
|
if (_docRootjson.HasMember("simulator_screen_size"))
|
||||||
{
|
{
|
||||||
|
@ -72,18 +73,26 @@ void ConfigParser::readConfig()
|
||||||
|
|
||||||
ConfigParser::ConfigParser(void):_isInit(false),_isLandscape(true)
|
ConfigParser::ConfigParser(void):_isInit(false),_isLandscape(true)
|
||||||
{
|
{
|
||||||
|
_initViewSize.setSize(960,640);
|
||||||
|
_viewName = "HelloLua";
|
||||||
|
_entryfile = "src/main.lua";
|
||||||
}
|
}
|
||||||
|
|
||||||
rapidjson::Document& ConfigParser::getConfigJsonRoot()
|
rapidjson::Document& ConfigParser::getConfigJsonRoot()
|
||||||
{
|
{
|
||||||
return _docRootjson;
|
return _docRootjson;
|
||||||
}
|
}
|
||||||
|
|
||||||
string ConfigParser::getInitViewName()
|
string ConfigParser::getInitViewName()
|
||||||
{
|
{
|
||||||
return _viewName;
|
return _viewName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string ConfigParser::getEntryFile()
|
||||||
|
{
|
||||||
|
return _entryfile;
|
||||||
|
}
|
||||||
|
|
||||||
Size ConfigParser::getInitViewSize()
|
Size ConfigParser::getInitViewSize()
|
||||||
{
|
{
|
||||||
return _initViewSize;
|
return _initViewSize;
|
||||||
|
|
|
@ -33,6 +33,7 @@ public:
|
||||||
int getScreenSizeCount(void);
|
int getScreenSizeCount(void);
|
||||||
cocos2d::Size getInitViewSize();
|
cocos2d::Size getInitViewSize();
|
||||||
string getInitViewName();
|
string getInitViewName();
|
||||||
|
string getEntryFile();
|
||||||
rapidjson::Document& getConfigJsonRoot();
|
rapidjson::Document& getConfigJsonRoot();
|
||||||
const SimulatorScreenSize getScreenSize(int index);
|
const SimulatorScreenSize getScreenSize(int index);
|
||||||
bool isLanscape();
|
bool isLanscape();
|
||||||
|
@ -44,6 +45,7 @@ private:
|
||||||
ScreenSizeArray _screenSizeArray;
|
ScreenSizeArray _screenSizeArray;
|
||||||
cocos2d::Size _initViewSize;
|
cocos2d::Size _initViewSize;
|
||||||
string _viewName;
|
string _viewName;
|
||||||
|
string _entryfile;
|
||||||
bool _isLandscape;
|
bool _isLandscape;
|
||||||
bool _isInit;
|
bool _isInit;
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ THE SOFTWARE.
|
||||||
#include "json/writer.h"
|
#include "json/writer.h"
|
||||||
#include "LuaBasicConversions.h"
|
#include "LuaBasicConversions.h"
|
||||||
#include "VisibleRect.h"
|
#include "VisibleRect.h"
|
||||||
|
#include "ConfigParser.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
|
@ -47,7 +48,6 @@ using namespace cocos2d;
|
||||||
|
|
||||||
std::string g_resourcePath;
|
std::string g_resourcePath;
|
||||||
static rapidjson::Document g_filecfgjson;
|
static rapidjson::Document g_filecfgjson;
|
||||||
static string g_entryfile;
|
|
||||||
extern string getIPAddress();
|
extern string getIPAddress();
|
||||||
const char* getRuntimeVersion()
|
const char* getRuntimeVersion()
|
||||||
{
|
{
|
||||||
|
@ -63,7 +63,7 @@ void startScript(string strDebugArg)
|
||||||
engine->executeString(strDebugArg.c_str());
|
engine->executeString(strDebugArg.c_str());
|
||||||
}
|
}
|
||||||
cocos2d::log("debug args = %s",strDebugArg.c_str());
|
cocos2d::log("debug args = %s",strDebugArg.c_str());
|
||||||
engine->executeScriptFile(g_entryfile.c_str());
|
engine->executeScriptFile(ConfigParser::getInstance()->getEntryFile().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool reloadScript(const string& modulefile)
|
bool reloadScript(const string& modulefile)
|
||||||
|
@ -71,7 +71,7 @@ bool reloadScript(const string& modulefile)
|
||||||
string strfile = modulefile;
|
string strfile = modulefile;
|
||||||
if (strfile.empty())
|
if (strfile.empty())
|
||||||
{
|
{
|
||||||
strfile = g_entryfile;
|
strfile = ConfigParser::getInstance()->getEntryFile().c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto director = Director::getInstance();
|
auto director = Director::getInstance();
|
||||||
|
@ -583,6 +583,14 @@ public:
|
||||||
dReplyParse.AddMember("body",bodyvalue,dReplyParse.GetAllocator());
|
dReplyParse.AddMember("body",bodyvalue,dReplyParse.GetAllocator());
|
||||||
dReplyParse.AddMember("code",0,dReplyParse.GetAllocator());
|
dReplyParse.AddMember("code",0,dReplyParse.GetAllocator());
|
||||||
|
|
||||||
|
}else if (strcmp(strcmd.c_str(),"getEntryfile")==0)
|
||||||
|
{
|
||||||
|
rapidjson::Value bodyvalue(rapidjson::kObjectType);
|
||||||
|
rapidjson::Value entryFileValue(rapidjson::kStringType);
|
||||||
|
entryFileValue.SetString(ConfigParser::getInstance()->getEntryFile().c_str(),dReplyParse.GetAllocator());
|
||||||
|
bodyvalue.AddMember("entryfile",entryFileValue,dReplyParse.GetAllocator());
|
||||||
|
dReplyParse.AddMember("body",bodyvalue,dReplyParse.GetAllocator());
|
||||||
|
dReplyParse.AddMember("code",0,dReplyParse.GetAllocator());
|
||||||
}else if(strcmp(strcmd.c_str(),"getIP")==0)
|
}else if(strcmp(strcmd.c_str(),"getIP")==0)
|
||||||
{
|
{
|
||||||
rapidjson::Value bodyvalue(rapidjson::kObjectType);
|
rapidjson::Value bodyvalue(rapidjson::kObjectType);
|
||||||
|
@ -724,7 +732,7 @@ static void register_runtime_override_function(lua_State* tolua_S)
|
||||||
lua_pop(tolua_S, 1);
|
lua_pop(tolua_S, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool initRuntime(string& entryfile)
|
bool initRuntime()
|
||||||
{
|
{
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||||
#ifndef _DEBUG
|
#ifndef _DEBUG
|
||||||
|
@ -740,7 +748,6 @@ bool initRuntime(string& entryfile)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
g_entryfile = entryfile;
|
|
||||||
vector<string> searchPathArray;
|
vector<string> searchPathArray;
|
||||||
searchPathArray=FileUtils::getInstance()->getSearchPaths();
|
searchPathArray=FileUtils::getInstance()->getSearchPaths();
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
||||||
|
|
|
@ -28,7 +28,7 @@ THE SOFTWARE.
|
||||||
#include <string>
|
#include <string>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
bool initRuntime(string& entryfile);
|
bool initRuntime();
|
||||||
bool startRuntime();
|
bool startRuntime();
|
||||||
|
|
||||||
bool reloadScript(const string& modulefile);
|
bool reloadScript(const string& modulefile);
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
{
|
{
|
||||||
"init_view":{
|
"init_cfg":{
|
||||||
"isLandscape": true,
|
"isLandscape": true,
|
||||||
"name": "HelloLua",
|
"name": "HelloLua",
|
||||||
"width": 960,
|
"width": 960,
|
||||||
"height": 640
|
"height": 640,
|
||||||
|
"entry": "src/main.lua"
|
||||||
},
|
},
|
||||||
"simulator_screen_size": [
|
"simulator_screen_size": [
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue