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