diff --git a/_server/fs.js b/_server/fs.js index d0110304..0940886c 100644 --- a/_server/fs.js +++ b/_server/fs.js @@ -3,7 +3,7 @@ var _isset = function (val) { - if (val == undefined || val == null || (typeof val=='number' && isNaN(val))) { + if (val == undefined || val == null || (typeof val == 'number' && isNaN(val))) { return false; } return true @@ -16,26 +16,26 @@ xhr.overrideMimeType(mimeType); if (_isset(responseType)) xhr.responseType = responseType; - xhr.onload = function(e) { - if (xhr.status==200) { + xhr.onload = function (e) { + if (xhr.status == 200) { if (_isset(success)) { success(xhr.response); } } else { if (_isset(error)) - error("HTTP "+xhr.status); + error("HTTP " + xhr.status); } }; xhr.onabort = function () { if (_isset(error)) error("Abort"); } - xhr.ontimeout = function() { + xhr.ontimeout = function () { if (_isset(error)) error("Timeout"); } - xhr.onerror = function() { + xhr.onerror = function () { if (_isset(error)) error("Error on Connection"); } @@ -46,7 +46,7 @@ var postsomething = function (data, _ip, callback) { - if (typeof(data) == typeof([][0]) || data == null) data = JSON.stringify({1: 2}); + if (typeof (data) == typeof ([][0]) || data == null) data = JSON.stringify({ 1: 2 }); _http("POST", _ip, data, function (data) { if (data.slice(0, 6) == 'error:') { @@ -56,14 +56,14 @@ callback(null, data); } }, function (e) { - if (window.main != null && main.log) main.log(e); + if (window.main != null) console.log(e); else console.log(e); - callback(e+":请检查启动服务是否处于正常运行状态。"); + callback(e + ":请检查启动服务是否处于正常运行状态。"); }, "text/plain; charset=x-user-defined"); } fs.readFile = function (filename, encoding, callback) { - if (typeof(filename) != typeof('')) + if (typeof (filename) != typeof ('')) throw 'Type Error in fs.readFile'; if (encoding == 'utf-8') { //读文本文件 @@ -91,7 +91,7 @@ } fs.writeFile = function (filename, datastr, encoding, callback) { - if (typeof(filename) != typeof('') || typeof(datastr) != typeof('')) + if (typeof (filename) != typeof ('') || typeof (datastr) != typeof ('')) throw 'Type Error in fs.writeFile'; if (encoding == 'utf-8') { //写文本文件 @@ -121,14 +121,14 @@ } fs.writeMultiFiles = function (filenames, datastrs, callback) { - postsomething('name='+filenames.join(';')+'&value='+datastrs.join(';'), '/writeMultiFiles', callback); + postsomething('name=' + filenames.join(';') + '&value=' + datastrs.join(';'), '/writeMultiFiles', callback); } fs.readdir = function (path, callback) { //callback:function(err, data) //path:支持"/"做分隔符,不以"/"结尾 //data:[filename1,filename2,..] filename是字符串,只包含文件不包含目录 - if (typeof(path) != typeof('')) + if (typeof (path) != typeof ('')) throw 'Type Error in fs.readdir'; var data = ''; data += 'name=' + path; @@ -150,7 +150,7 @@ */ fs.mkdir = function (path, callback) { //callback:function(err, data) - if (typeof(path) != typeof('')) + if (typeof (path) != typeof ('')) throw 'Type Error in fs.readdir'; var data = ''; data += 'name=' + path; @@ -163,7 +163,7 @@ * @param {() => {err: string, data}} callback */ fs.moveFile = function (src, dest, callback) { - if (typeof(src) != typeof('') || typeof(dest) != typeof('')) + if (typeof (src) != typeof ('') || typeof (dest) != typeof ('')) throw 'Type Error in fs.readdir'; var data = ''; data += 'src=' + src + "&dest=" + dest; @@ -176,7 +176,7 @@ * @param {() => {err: string, data}} callback */ fs.deleteFile = function (path, callback) { - if (typeof(path) != typeof('')) + if (typeof (path) != typeof ('')) throw 'Type Error in fs.readdir'; var data = ''; data += 'name=' + path; diff --git a/libs/actions.js b/libs/actions.js index d967f063..206daa57 100644 --- a/libs/actions.js +++ b/libs/actions.js @@ -107,7 +107,7 @@ actions.prototype.doRegisteredAction = function (action) { } catch (e) { console.error(e); - main.log("ERROR in actions[" + actions[i].name + "]."); + console.error("ERROR in actions[" + actions[i].name + "]."); } } return false; diff --git a/libs/control.js b/libs/control.js index 5a8f0f72..fa5a0d63 100644 --- a/libs/control.js +++ b/libs/control.js @@ -89,7 +89,7 @@ control.prototype._setRequestAnimationFrame = function () { } catch (e) { console.error(e); - main.log("ERROR in requestAnimationFrame[" + b.name + "]:已自动注销该项。"); + console.error("ERROR in requestAnimationFrame[" + b.name + "]:已自动注销该项。"); core.unregisterAnimationFrame(b.name); } } @@ -216,7 +216,7 @@ control.prototype._animationFrame_weather = function (timestamp) { core.doFunc(core.control.weathers[type].frameFunc, core.control, timestamp, core.animateFrame.weather.level); } catch (e) { console.error(e); - main.log("ERROR in weather[" + type + "]:已自动注销该项。"); + console.error("ERROR in weather[" + type + "]:已自动注销该项。"); core.unregisterWeather(type); } } @@ -1627,7 +1627,7 @@ control.prototype._doReplayAction = function (action) { if (core.doFunc(this.replayActions[i].func, this, action)) return true; } catch (e) { console.error(e); - main.log("ERROR in replayActions[" + this.replayActions[i].name + "]:已自动注销该项。"); + console.error("ERROR in replayActions[" + this.replayActions[i].name + "]:已自动注销该项。"); core.unregisterReplayAction(this.replayActions[i].name); } } @@ -1675,9 +1675,9 @@ control.prototype._replay_error = function (action, callback) { var len = core.status.replay.toReplay.length; var prevList = core.status.replay.totalList.slice(-len - 11, -len - 1); var nextList = core.status.replay.toReplay.slice(0, 10); - main.log("录像文件出错,当前操作:" + action); - main.log("之前的10个操作是:\n" + prevList.toString()); - main.log("接下来10个操作是:\n" + nextList.toString()); + console.log("录像文件出错,当前操作:" + action); + console.log("之前的10个操作是:\n" + prevList.toString()); + console.log("接下来10个操作是:\n" + nextList.toString()); core.ui.drawConfirmBox("录像文件出错,你想回到上个节点吗?", function () { core.status.replay.failed = false; core.ui.closePanel(); @@ -2023,7 +2023,7 @@ control.prototype._doSL_save = function (id) { core.playSound('存档'); core.drawTip('存档成功!'); }, function (err) { - main.log(err); + console.error(err); alert("存档失败,错误信息:\n" + err); }); core.removeFlag("__events__"); @@ -2056,7 +2056,7 @@ control.prototype._doSL_load = function (id, callback) { } callback(id, data); }, function (err) { - main.log(err); + console.error(err); alert("无效的存档"); }) } @@ -2295,7 +2295,7 @@ control.prototype.getSave = function (index, callback) { } callback(core.saves.autosave.data); }, function (err) { - main.log(err); + console.error(err); callback(null); }); } @@ -2304,7 +2304,7 @@ control.prototype.getSave = function (index, callback) { core.getLocalForage("save" + index, null, function (data) { if (callback) callback(data); }, function (err) { - main.log(err); + console.error(err); if (callback) callback(null); }); } @@ -2340,7 +2340,7 @@ control.prototype.getSaveIndexes = function (callback) { var indexes = {}; core.keysLocalForage(function (err, keys) { if (err) { - main.log(err); + console.error(err); return callback(indexes); } keys.forEach(function (key) { @@ -2678,7 +2678,7 @@ control.prototype.setWeather = function (type, level) { core.doFunc(this.weathers[type].initFunc, this, level); } catch (e) { console.error(e); - main.log("ERROR in weather[" + type + "]:已自动注销该项。"); + console.error("ERROR in weather[" + type + "]:已自动注销该项。"); core.unregisterWeather(type); } } @@ -2853,7 +2853,7 @@ control.prototype.playBgm = function (bgm, startTime) { } catch (e) { console.log("无法播放BGM " + bgm); - main.log(e); + console.error(e); core.musicStatus.playingBgm = null; } } @@ -2908,7 +2908,7 @@ control.prototype.pauseBgm = function () { } catch (e) { console.log("无法暂停BGM"); - main.log(e); + console.error(e); } this.setMusicBtn(); } @@ -2927,7 +2927,7 @@ control.prototype.resumeBgm = function (resumeTime) { } catch (e) { console.log("无法恢复BGM"); - main.log(e); + console.error(e); } this.setMusicBtn(); } @@ -2983,7 +2983,7 @@ control.prototype.playSound = function (sound, pitch, callback) { } catch (e) { console.log("无法播放SE " + sound); - main.log(e); + console.error(e); } } @@ -3254,7 +3254,7 @@ control.prototype._doResize = function (obj) { if (core.doFunc(this.resizes[i].func, this, obj)) return true; } catch (e) { console.error(e); - main.log("ERROR in resizes[" + this.resizes[i].name + "]:已自动注销该项。"); + console.error("ERROR in resizes[" + this.resizes[i].name + "]:已自动注销该项。"); this.unregisterResize(this.resizes[i].name); } } diff --git a/libs/core.js b/libs/core.js index d6906580..8aece0b6 100644 --- a/libs/core.js +++ b/libs/core.js @@ -487,7 +487,7 @@ core.prototype._init_plugins = function () { } catch (e) { console.error(e); - main.log("无法初始化插件" + name); + console.error("无法初始化插件" + name); } } } @@ -522,7 +522,7 @@ core.prototype._forwardFunc = function (name, funcname) { // core[funcname] = new Function(parameters, "return core."+name+"."+funcname+"("+parameters+");"); eval("core." + funcname + " = function (" + parameters + ") {\n\treturn core." + name + "." + funcname + "(" + parameters + ");\n}"); if (name == 'plugin') { - main.log("插件函数转发:core." + funcname + " = core.plugin." + funcname); + console.error("插件函数转发:core." + funcname + " = core.plugin." + funcname); } } diff --git a/libs/events.js b/libs/events.js index e1db9565..84200d0d 100644 --- a/libs/events.js +++ b/libs/events.js @@ -313,11 +313,11 @@ events.prototype.doSystemEvent = function (type, data, callback) { } catch (e) { console.error(e); - main.log("ERROR in systemEvents[" + type + "]"); + console.error("ERROR in systemEvents[" + type + "]"); } } if (this["_sys_" + type]) return this["_sys_" + type](data, callback); - main.log("未知的系统事件: " + type + "!"); + console.error("未知的系统事件: " + type + "!"); if (callback) callback(); } @@ -731,7 +731,7 @@ events.prototype._changeFloor_getInfo = function (floorId, stair, heroLoc, time) floorId = core.status.floorId; } if (!core.status.maps[floorId]) { - main.log("不存在的楼层:" + floorId); + console.error("不存在的楼层:" + floorId); return null; } @@ -953,7 +953,7 @@ events.prototype.doEvent = function (data, x, y, prefix) { } catch (e) { console.error(e); - main.log("ERROR in actions[" + type + "]"); + console.error("ERROR in actions[" + type + "]"); } } if (this["_action_" + type]) return this["_action_" + type](data, x, y, prefix); diff --git a/libs/loader.js b/libs/loader.js index 310a863d..69a4373f 100644 --- a/libs/loader.js +++ b/libs/loader.js @@ -325,7 +325,7 @@ loader.prototype._loadAnimates_sync = function () { core.http('GET', 'project/animates/' + t + ".animate?v=" + main.version, null, function (content) { core.material.animates[t] = core.loader._loadAnimate(content); }, function (e) { - main.log(e); + console.error(e); core.material.animates[t] = null; }, "text/plain; charset=x-user-defined") }); @@ -439,7 +439,7 @@ loader.prototype.loadOneSound = function (name) { core.http('GET', 'project/sounds/' + name + "?v=" + main.version, null, function (data) { core.loader._loadOneSound_decodeData(name, data); }, function (e) { - main.log(e); + console.error(e); core.material.sounds[name] = null; }, null, 'arraybuffer'); } @@ -458,7 +458,7 @@ loader.prototype._loadOneSound_decodeData = function (name, data) { core.musicStatus.audioContext.decodeAudioData(data, function (buffer) { core.material.sounds[name] = buffer; }, function (e) { - main.log(e); + console.error(e); core.material.sounds[name] = null; }) } diff --git a/libs/utils.js b/libs/utils.js index 956340d4..5f50de4d 100644 --- a/libs/utils.js +++ b/libs/utils.js @@ -1270,7 +1270,7 @@ utils.prototype.same = function (a, b) { utils.prototype.unzip = function (blobOrUrl, success, error, convertToText, onprogress) { var _error = function (msg) { - main.log(msg); + console.error(msg); if (error) error(msg); } diff --git a/main.js b/main.js index 9f63e05a..c32f2d11 100644 --- a/main.js +++ b/main.js @@ -794,7 +794,7 @@ main.prototype.listen = function () { main.core.resize(); } } - } catch (e) { main.log(e) }; + } catch (e) { console.error(e) }; } window.onblur = function () { diff --git a/runtime.d.ts b/runtime.d.ts index 28b2e1d8..9dad14c4 100644 --- a/runtime.d.ts +++ b/runtime.d.ts @@ -2926,6 +2926,7 @@ type core = { declare class main { readonly core: core + readonly dom = core.dom /** 输出内容(极不好用,建议换成console)*/ log(e: string | Error, error: boolean): void