Merge pull request #14180 from pandamicro/v3

Fix issue for web engine upgrade
This commit is contained in:
pandamicro 2015-10-18 22:48:16 +08:00
commit c365fc5883
4 changed files with 91 additions and 31 deletions

View File

@ -757,7 +757,7 @@ bool ScriptingCore::runScript(const char *path, JS::HandleObject global, JSConte
JSAutoCompartment ac(cx, global);
evaluatedOK = JS_ExecuteScript(cx, global, script, &rval);
if (false == evaluatedOK) {
cocos2d::log("(evaluatedOK == JS_FALSE)");
cocos2d::log("Evaluating %s failed (evaluatedOK == JS_FALSE)", path);
JS_ReportPendingException(cx);
}
}

View File

@ -1054,6 +1054,15 @@ var _initSys = function () {
*/
sys.LANGUAGE_POLISH = "pl";
/**
* Unknown language code
* @memberof cc.sys
* @name LANGUAGE_UNKNOWN
* @constant
* @type {Number}
*/
sys.LANGUAGE_UNKNOWN = "unkonwn";
/**
* @memberof cc.sys
* @name OS_IOS
@ -1575,11 +1584,12 @@ cc.game = /** @lends cc.game# */{
jsList: "jsList"
},
// states
_paused: false,//whether the game is paused
_prepareCalled: false,//whether the prepare function has been called
_prepared: false,//whether the engine has prepared
_paused: true,//whether the game is paused
_intervalId: null,//interval target of main
/**
* Config of game
@ -1599,6 +1609,9 @@ cc.game = /** @lends cc.game# */{
*/
onStop: null,
//@Public Methods
// @Game play control
/**
* Set frameRate of game.
* @param frameRate
@ -1620,6 +1633,7 @@ cc.game = /** @lends cc.game# */{
* Pause the game.
*/
pause: function () {
this._paused = true;
cc.director.pause();
},
@ -1627,9 +1641,17 @@ cc.game = /** @lends cc.game# */{
* Resume the game from pause.
*/
resume: function () {
this._paused = false;
cc.director.resume();
},
/**
* Check whether the game is paused.
*/
isPaused: function () {
return this._paused;
},
/**
* Restart game.
*/
@ -1637,6 +1659,7 @@ cc.game = /** @lends cc.game# */{
__restartVM();
},
// @Game loading
/**
* Prepare game.
* @param cb
@ -1662,12 +1685,17 @@ cc.game = /** @lends cc.game# */{
this._prepareCalled = true;
// Load game scripts
var jsList = config[CONFIG_KEY.jsList] || [];
cc.loader.loadJsWithImg("", jsList, function (err) {
if (err) throw new Error(err);
self._prepared = true;
var jsList = config[CONFIG_KEY.jsList];
if (jsList) {
cc.loader.loadJsWithImg(jsList, function (err) {
if (err) throw new Error(err);
self._prepared = true;
if (cb) cb();
});
}
else {
if (cb) cb();
});
}
return;
}
@ -1679,30 +1707,61 @@ cc.game = /** @lends cc.game# */{
},
/**
* Run game.
* Run game with configuration object and onStart function.
* @param {Object|Function} [config] Pass configuration object or onStart function
* @param {onStart} [onStart] onStart function to be executed after game initialized
*/
run: function () {
this.prepare(cc.game.onStart.bind(cc.game));
},
_loadConfig: function () {
var self = this, CONFIG_KEY = self.CONFIG_KEY;
var _init = function(cfg){
cfg[CONFIG_KEY.engineDir] = cfg[CONFIG_KEY.engineDir] || "frameworks/cocos2d-html5";
cfg[CONFIG_KEY.debugMode] = cfg[CONFIG_KEY.debugMode] || 0;
cfg[CONFIG_KEY.frameRate] = cfg[CONFIG_KEY.frameRate] || 60;
cfg[CONFIG_KEY.renderMode] = cfg[CONFIG_KEY.renderMode] || 0;
cfg[CONFIG_KEY.showFPS] = cfg[CONFIG_KEY.showFPS] === false ? false : true;
return cfg;
};
try{
var txt = jsb.fileUtils.getStringFromFile("project.json");
var data = JSON.parse(txt);
this.config = _init(data || {});
}catch(e){
cc.log("Failed to read or parse project.json");
this.config = _init({});
run: function (config, onStart) {
if (typeof config === 'function') {
cc.game.onStart = config;
}
else {
if (config) {
cc.game.config = config;
}
if (typeof onStart === 'function') {
cc.game.onStart = onStart;
}
}
this.prepare(cc.game.onStart && cc.game.onStart.bind(cc.game));
},
//@Private Methods
_loadConfig: function () {
// Load config
// Already loaded
if (this.config) {
this._initConfig(this.config);
}
// Load from project.json
else {
try {
var txt = jsb.fileUtils.getStringFromFile("project.json");
var data = JSON.parse(txt);
this._initConfig(data || {});
} catch (e) {
console.log("Failed to read or parse project.json");
this._initConfig({});
}
}
},
_initConfig: function (config) {
var CONFIG_KEY = this.CONFIG_KEY;
// Configs adjustment
config[CONFIG_KEY.showFPS] = config[CONFIG_KEY.showFPS] || true;
config[CONFIG_KEY.engineDir] = config[CONFIG_KEY.engineDir] || "frameworks/cocos2d-html5";
if (config[CONFIG_KEY.debugMode] == null)
config[CONFIG_KEY.debugMode] = 0;
config[CONFIG_KEY.frameRate] = config[CONFIG_KEY.frameRate] || 60;
if (config[CONFIG_KEY.renderMode] == null)
config[CONFIG_KEY.renderMode] = 0;
this.config = config;
cc.director.setDisplayStats(this.config[CONFIG_KEY.showFPS]);
cc.director.setAnimationInterval(1.0/this.config[CONFIG_KEY.frameRate]);
}

View File

@ -6,6 +6,7 @@ var ccbjs = "";
// so the respath will modify to res,
if (!cc.sys.isNative)
{
cc.game._loadConfig();
if (cc.game.config[cc.game.CONFIG_KEY.engineDir] !== "frameworks/cocos2d-html5") {
ccbjs = "../../js-tests/resjs/";
}

2
web

@ -1 +1 @@
Subproject commit a9f493ae53d20945d8796660363da4e060a68ee2
Subproject commit 6e3797aac97c2dd772fda54996c5677f1acb65bc