kill main.log

This commit is contained in:
unamed 2022-02-02 00:37:45 +08:00
parent 1ad1e12df6
commit e5b04eadd5
9 changed files with 46 additions and 45 deletions

View File

@ -3,7 +3,7 @@
var _isset = function (val) { 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 false;
} }
return true return true
@ -16,26 +16,26 @@
xhr.overrideMimeType(mimeType); xhr.overrideMimeType(mimeType);
if (_isset(responseType)) if (_isset(responseType))
xhr.responseType = responseType; xhr.responseType = responseType;
xhr.onload = function(e) { xhr.onload = function (e) {
if (xhr.status==200) { if (xhr.status == 200) {
if (_isset(success)) { if (_isset(success)) {
success(xhr.response); success(xhr.response);
} }
} }
else { else {
if (_isset(error)) if (_isset(error))
error("HTTP "+xhr.status); error("HTTP " + xhr.status);
} }
}; };
xhr.onabort = function () { xhr.onabort = function () {
if (_isset(error)) if (_isset(error))
error("Abort"); error("Abort");
} }
xhr.ontimeout = function() { xhr.ontimeout = function () {
if (_isset(error)) if (_isset(error))
error("Timeout"); error("Timeout");
} }
xhr.onerror = function() { xhr.onerror = function () {
if (_isset(error)) if (_isset(error))
error("Error on Connection"); error("Error on Connection");
} }
@ -46,7 +46,7 @@
var postsomething = function (data, _ip, callback) { 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) { _http("POST", _ip, data, function (data) {
if (data.slice(0, 6) == 'error:') { if (data.slice(0, 6) == 'error:') {
@ -56,14 +56,14 @@
callback(null, data); callback(null, data);
} }
}, function (e) { }, function (e) {
if (window.main != null && main.log) main.log(e); if (window.main != null) console.log(e);
else console.log(e); else console.log(e);
callback(e+":请检查启动服务是否处于正常运行状态。"); callback(e + ":请检查启动服务是否处于正常运行状态。");
}, "text/plain; charset=x-user-defined"); }, "text/plain; charset=x-user-defined");
} }
fs.readFile = function (filename, encoding, callback) { fs.readFile = function (filename, encoding, callback) {
if (typeof(filename) != typeof('')) if (typeof (filename) != typeof (''))
throw 'Type Error in fs.readFile'; throw 'Type Error in fs.readFile';
if (encoding == 'utf-8') { if (encoding == 'utf-8') {
//读文本文件 //读文本文件
@ -91,7 +91,7 @@
} }
fs.writeFile = function (filename, datastr, encoding, callback) { 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'; throw 'Type Error in fs.writeFile';
if (encoding == 'utf-8') { if (encoding == 'utf-8') {
//写文本文件 //写文本文件
@ -121,14 +121,14 @@
} }
fs.writeMultiFiles = function (filenames, datastrs, callback) { 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) { fs.readdir = function (path, callback) {
//callback:function(err, data) //callback:function(err, data)
//path:支持"/"做分隔符,不以"/"结尾 //path:支持"/"做分隔符,不以"/"结尾
//data:[filename1,filename2,..] filename是字符串,只包含文件不包含目录 //data:[filename1,filename2,..] filename是字符串,只包含文件不包含目录
if (typeof(path) != typeof('')) if (typeof (path) != typeof (''))
throw 'Type Error in fs.readdir'; throw 'Type Error in fs.readdir';
var data = ''; var data = '';
data += 'name=' + path; data += 'name=' + path;
@ -150,7 +150,7 @@
*/ */
fs.mkdir = function (path, callback) { fs.mkdir = function (path, callback) {
//callback:function(err, data) //callback:function(err, data)
if (typeof(path) != typeof('')) if (typeof (path) != typeof (''))
throw 'Type Error in fs.readdir'; throw 'Type Error in fs.readdir';
var data = ''; var data = '';
data += 'name=' + path; data += 'name=' + path;
@ -163,7 +163,7 @@
* @param {() => {err: string, data}} callback * @param {() => {err: string, data}} callback
*/ */
fs.moveFile = function (src, dest, 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'; throw 'Type Error in fs.readdir';
var data = ''; var data = '';
data += 'src=' + src + "&dest=" + dest; data += 'src=' + src + "&dest=" + dest;
@ -176,7 +176,7 @@
* @param {() => {err: string, data}} callback * @param {() => {err: string, data}} callback
*/ */
fs.deleteFile = function (path, callback) { fs.deleteFile = function (path, callback) {
if (typeof(path) != typeof('')) if (typeof (path) != typeof (''))
throw 'Type Error in fs.readdir'; throw 'Type Error in fs.readdir';
var data = ''; var data = '';
data += 'name=' + path; data += 'name=' + path;

View File

@ -107,7 +107,7 @@ actions.prototype.doRegisteredAction = function (action) {
} }
catch (e) { catch (e) {
console.error(e); console.error(e);
main.log("ERROR in actions[" + actions[i].name + "]."); console.error("ERROR in actions[" + actions[i].name + "].");
} }
} }
return false; return false;

View File

@ -89,7 +89,7 @@ control.prototype._setRequestAnimationFrame = function () {
} }
catch (e) { catch (e) {
console.error(e); console.error(e);
main.log("ERROR in requestAnimationFrame[" + b.name + "]:已自动注销该项。"); console.error("ERROR in requestAnimationFrame[" + b.name + "]:已自动注销该项。");
core.unregisterAnimationFrame(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); core.doFunc(core.control.weathers[type].frameFunc, core.control, timestamp, core.animateFrame.weather.level);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
main.log("ERROR in weather[" + type + "]:已自动注销该项。"); console.error("ERROR in weather[" + type + "]:已自动注销该项。");
core.unregisterWeather(type); core.unregisterWeather(type);
} }
} }
@ -1627,7 +1627,7 @@ control.prototype._doReplayAction = function (action) {
if (core.doFunc(this.replayActions[i].func, this, action)) return true; if (core.doFunc(this.replayActions[i].func, this, action)) return true;
} catch (e) { } catch (e) {
console.error(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); 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 len = core.status.replay.toReplay.length;
var prevList = core.status.replay.totalList.slice(-len - 11, -len - 1); var prevList = core.status.replay.totalList.slice(-len - 11, -len - 1);
var nextList = core.status.replay.toReplay.slice(0, 10); var nextList = core.status.replay.toReplay.slice(0, 10);
main.log("录像文件出错,当前操作:" + action); console.log("录像文件出错,当前操作:" + action);
main.log("之前的10个操作是\n" + prevList.toString()); console.log("之前的10个操作是\n" + prevList.toString());
main.log("接下来10个操作是\n" + nextList.toString()); console.log("接下来10个操作是\n" + nextList.toString());
core.ui.drawConfirmBox("录像文件出错,你想回到上个节点吗?", function () { core.ui.drawConfirmBox("录像文件出错,你想回到上个节点吗?", function () {
core.status.replay.failed = false; core.status.replay.failed = false;
core.ui.closePanel(); core.ui.closePanel();
@ -2023,7 +2023,7 @@ control.prototype._doSL_save = function (id) {
core.playSound('存档'); core.playSound('存档');
core.drawTip('存档成功!'); core.drawTip('存档成功!');
}, function (err) { }, function (err) {
main.log(err); console.error(err);
alert("存档失败,错误信息:\n" + err); alert("存档失败,错误信息:\n" + err);
}); });
core.removeFlag("__events__"); core.removeFlag("__events__");
@ -2056,7 +2056,7 @@ control.prototype._doSL_load = function (id, callback) {
} }
callback(id, data); callback(id, data);
}, function (err) { }, function (err) {
main.log(err); console.error(err);
alert("无效的存档"); alert("无效的存档");
}) })
} }
@ -2295,7 +2295,7 @@ control.prototype.getSave = function (index, callback) {
} }
callback(core.saves.autosave.data); callback(core.saves.autosave.data);
}, function (err) { }, function (err) {
main.log(err); console.error(err);
callback(null); callback(null);
}); });
} }
@ -2304,7 +2304,7 @@ control.prototype.getSave = function (index, callback) {
core.getLocalForage("save" + index, null, function (data) { core.getLocalForage("save" + index, null, function (data) {
if (callback) callback(data); if (callback) callback(data);
}, function (err) { }, function (err) {
main.log(err); console.error(err);
if (callback) callback(null); if (callback) callback(null);
}); });
} }
@ -2340,7 +2340,7 @@ control.prototype.getSaveIndexes = function (callback) {
var indexes = {}; var indexes = {};
core.keysLocalForage(function (err, keys) { core.keysLocalForage(function (err, keys) {
if (err) { if (err) {
main.log(err); console.error(err);
return callback(indexes); return callback(indexes);
} }
keys.forEach(function (key) { keys.forEach(function (key) {
@ -2678,7 +2678,7 @@ control.prototype.setWeather = function (type, level) {
core.doFunc(this.weathers[type].initFunc, this, level); core.doFunc(this.weathers[type].initFunc, this, level);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
main.log("ERROR in weather[" + type + "]:已自动注销该项。"); console.error("ERROR in weather[" + type + "]:已自动注销该项。");
core.unregisterWeather(type); core.unregisterWeather(type);
} }
} }
@ -2853,7 +2853,7 @@ control.prototype.playBgm = function (bgm, startTime) {
} }
catch (e) { catch (e) {
console.log("无法播放BGM " + bgm); console.log("无法播放BGM " + bgm);
main.log(e); console.error(e);
core.musicStatus.playingBgm = null; core.musicStatus.playingBgm = null;
} }
} }
@ -2908,7 +2908,7 @@ control.prototype.pauseBgm = function () {
} }
catch (e) { catch (e) {
console.log("无法暂停BGM"); console.log("无法暂停BGM");
main.log(e); console.error(e);
} }
this.setMusicBtn(); this.setMusicBtn();
} }
@ -2927,7 +2927,7 @@ control.prototype.resumeBgm = function (resumeTime) {
} }
catch (e) { catch (e) {
console.log("无法恢复BGM"); console.log("无法恢复BGM");
main.log(e); console.error(e);
} }
this.setMusicBtn(); this.setMusicBtn();
} }
@ -2983,7 +2983,7 @@ control.prototype.playSound = function (sound, pitch, callback) {
} }
catch (e) { catch (e) {
console.log("无法播放SE " + sound); 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; if (core.doFunc(this.resizes[i].func, this, obj)) return true;
} catch (e) { } catch (e) {
console.error(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); this.unregisterResize(this.resizes[i].name);
} }
} }

View File

@ -487,7 +487,7 @@ core.prototype._init_plugins = function () {
} }
catch (e) { catch (e) {
console.error(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+");"); // core[funcname] = new Function(parameters, "return core."+name+"."+funcname+"("+parameters+");");
eval("core." + funcname + " = function (" + parameters + ") {\n\treturn core." + name + "." + funcname + "(" + parameters + ");\n}"); eval("core." + funcname + " = function (" + parameters + ") {\n\treturn core." + name + "." + funcname + "(" + parameters + ");\n}");
if (name == 'plugin') { if (name == 'plugin') {
main.log("插件函数转发core." + funcname + " = core.plugin." + funcname); console.error("插件函数转发core." + funcname + " = core.plugin." + funcname);
} }
} }

View File

@ -313,11 +313,11 @@ events.prototype.doSystemEvent = function (type, data, callback) {
} }
catch (e) { catch (e) {
console.error(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); if (this["_sys_" + type]) return this["_sys_" + type](data, callback);
main.log("未知的系统事件: " + type + ""); console.error("未知的系统事件: " + type + "");
if (callback) callback(); if (callback) callback();
} }
@ -731,7 +731,7 @@ events.prototype._changeFloor_getInfo = function (floorId, stair, heroLoc, time)
floorId = core.status.floorId; floorId = core.status.floorId;
} }
if (!core.status.maps[floorId]) { if (!core.status.maps[floorId]) {
main.log("不存在的楼层:" + floorId); console.error("不存在的楼层:" + floorId);
return null; return null;
} }
@ -953,7 +953,7 @@ events.prototype.doEvent = function (data, x, y, prefix) {
} }
catch (e) { catch (e) {
console.error(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); if (this["_action_" + type]) return this["_action_" + type](data, x, y, prefix);

View File

@ -325,7 +325,7 @@ loader.prototype._loadAnimates_sync = function () {
core.http('GET', 'project/animates/' + t + ".animate?v=" + main.version, null, function (content) { core.http('GET', 'project/animates/' + t + ".animate?v=" + main.version, null, function (content) {
core.material.animates[t] = core.loader._loadAnimate(content); core.material.animates[t] = core.loader._loadAnimate(content);
}, function (e) { }, function (e) {
main.log(e); console.error(e);
core.material.animates[t] = null; core.material.animates[t] = null;
}, "text/plain; charset=x-user-defined") }, "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.http('GET', 'project/sounds/' + name + "?v=" + main.version, null, function (data) {
core.loader._loadOneSound_decodeData(name, data); core.loader._loadOneSound_decodeData(name, data);
}, function (e) { }, function (e) {
main.log(e); console.error(e);
core.material.sounds[name] = null; core.material.sounds[name] = null;
}, null, 'arraybuffer'); }, null, 'arraybuffer');
} }
@ -458,7 +458,7 @@ loader.prototype._loadOneSound_decodeData = function (name, data) {
core.musicStatus.audioContext.decodeAudioData(data, function (buffer) { core.musicStatus.audioContext.decodeAudioData(data, function (buffer) {
core.material.sounds[name] = buffer; core.material.sounds[name] = buffer;
}, function (e) { }, function (e) {
main.log(e); console.error(e);
core.material.sounds[name] = null; core.material.sounds[name] = null;
}) })
} }

View File

@ -1270,7 +1270,7 @@ utils.prototype.same = function (a, b) {
utils.prototype.unzip = function (blobOrUrl, success, error, convertToText, onprogress) { utils.prototype.unzip = function (blobOrUrl, success, error, convertToText, onprogress) {
var _error = function (msg) { var _error = function (msg) {
main.log(msg); console.error(msg);
if (error) error(msg); if (error) error(msg);
} }

View File

@ -794,7 +794,7 @@ main.prototype.listen = function () {
main.core.resize(); main.core.resize();
} }
} }
} catch (e) { main.log(e) }; } catch (e) { console.error(e) };
} }
window.onblur = function () { window.onblur = function () {

1
runtime.d.ts vendored
View File

@ -2926,6 +2926,7 @@ type core = {
declare class main { declare class main {
readonly core: core readonly core: core
readonly dom = core.dom
/** 输出内容极不好用建议换成console*/ /** 输出内容极不好用建议换成console*/
log(e: string | Error, error: boolean): void log(e: string | Error, error: boolean): void