diff --git a/CCDebugger.js b/CCDebugger.js index 3fdb0cb1f2..8dbe061d8a 100644 --- a/CCDebugger.js +++ b/CCDebugger.js @@ -24,9 +24,11 @@ ****************************************************************************/ // for cc.DebugMode.INFO_FOR_WEB_PAGE -var logList; var Enum = require('./cocos2d/core/platform/CCEnum'); +var getTypedFormatter = require('./DebugInfos').getTypedFormatter; + +var logList; /** * !#en Enum for debug modes. @@ -330,17 +332,8 @@ cc._throw = CC_EDITOR ? Editor.error : function (error) { }; function genLogFunc(func, type) { - return function (id) { - 'use strict'; - var msg = cc._LogInfos.raw(id, type); - if (arguments.length === 1) { - func(msg); - } - else if (arguments.length === 2) { - func(CC_DEBUG ? cc.js.formatStr(msg, arguments[1]) : msg + ' Arguments: ' + arguments[1]); - } - else { - func(cc._LogInfos.format(msg, cc.js.shiftArguments.apply(null, arguments))); - } + var formatter = getTypedFormatter(type); + return function () { + func(formatter.apply(null, arguments)); }; } diff --git a/DebugInfos.js b/DebugInfos.js index 3b51bd2f74..a9ceee9509 100644 --- a/DebugInfos.js +++ b/DebugInfos.js @@ -1,5 +1,7 @@ +var logs; + if (CC_DEBUG) { - var logs = { + logs = { // Common "0100": "%s not yet implemented.", //ActionManager: 1000 @@ -698,38 +700,32 @@ if (CC_DEBUG) { // AudioEngine: 8400 "8400": "Wrong type arguments, 'filePath' must be a String.", // cc.audioEngine.play }; - cc._LogInfos = logs; +} +else { + logs = {}; +} - var errorMapUrl = 'https://github.com/cocos-creator/engine/blob/master/EngineErrorMap.md'; +const ERROR_MAP_URL = 'https://github.com/cocos-creator/engine/blob/master/EngineErrorMap.md'; - function raw (id, type) { - return CC_DEBUG ? cc._LogInfos[id] : `${type} ${id}, please go to ${errorMapUrl}#${id} to see details.`; - } - - function format (msg, argsArray) { - return CC_DEBUG ? cc.js.formatStr.apply(null, [msg].concat(argsArray)) : msg + ' Arguments: ' + argsArray.join(', '); - } - - cc._LogInfos.e = function () { - var msg = raw(arguments[0], 'ERROR'); +function getTypedFormatter (type) { + return function () { + var id = arguments[0]; + var msg = CC_DEBUG ? (logs[id] || 'unknown id') : `${type} ${id}, please go to ${ERROR_MAP_URL}#${id} to see details.`; if (arguments.length === 1) { return msg; } + else if (arguments.length === 2) { + return CC_DEBUG ? cc.js.formatStr(msg, arguments[1]) : + msg + ' Arguments: ' + arguments[1]; + } else { - return format(msg, cc.js.shiftArguments.apply(null, arguments)); + var argsArray = cc.js.shiftArguments.apply(null, arguments); + return CC_DEBUG ? cc.js.formatStr.apply(null, [msg].concat(argsArray)) : + msg + ' Arguments: ' + argsArray.join(', '); } }; - cc._LogInfos.raw = raw; - cc._LogInfos.format = format; } -// module.exports = false; - -// // Only Node.JS has a process variable that is of [[Class]] process -// try { -// module.exports = Object.prototype.toString.call(global.process) === '[object process]'; -// module.exports = logs; -// } catch (e) { - -// cc._LogInfos = logs; -// } +logs.e = getTypedFormatter('ERROR'); +logs.getTypedFormatter = getTypedFormatter; +module.exports = cc._LogInfos = logs; diff --git a/index.js b/index.js index eee5acd80b..cafb809e25 100644 --- a/index.js +++ b/index.js @@ -156,11 +156,9 @@ if (CC_DEV) { } // output all info before initialized +require('./DebugInfos'); require('./CCDebugger'); cc._initDebugSetting(cc.DebugMode.INFO); -if (CC_DEBUG) { - require('./DebugInfos'); -} // polyfills /* require('./polyfill/bind'); */ diff --git a/jsb/index.js b/jsb/index.js index 81cd0bf33e..c105efbc9e 100644 --- a/jsb/index.js +++ b/jsb/index.js @@ -76,13 +76,9 @@ require('../cocos2d/core/utils/find'); require('../cocos2d/core/utils/mutable-forward-iterator'); require('../cocos2d/core/event'); require('../cocos2d/core/event-manager/CCEvent'); +require('../DebugInfos'); require('../CCDebugger'); -if (CC_DEBUG) { - //Debug Info ID map - require('../DebugInfos'); -} - // Mark memory model var macro = require('../cocos2d/core/platform/CCMacro');