From f8b3c29ab8fa8fbbfc2231b9099f01b80f8757b6 Mon Sep 17 00:00:00 2001 From: shijian <2954700422@qq.com> Date: Thu, 11 Jan 2024 00:26:22 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=85=B3=E4=BA=8Epromise?= =?UTF-8?q?=E7=9A=84=E9=94=99=E8=AF=AF=E5=A0=86=E6=A0=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- noname/init/index.js | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/noname/init/index.js b/noname/init/index.js index a3b9a5456..b0a625b66 100644 --- a/noname/init/index.js +++ b/noname/init/index.js @@ -752,10 +752,32 @@ function setServerIndex() { } function setWindowListener() { + /** + * @type { [Error, NodeJS.CallSite[]][] } + */ + const errorList = []; + // 这他娘的能捕获浏览器控制台里的输入值,尽量别用 + // 在火狐里无效 + Error.prepareStackTrace = function (e, stack) { + errorList.push([e, stack]); + }; // 但愿有用 - window.addEventListener("unhandledrejection", (error) => { - // 希望error.reason能是个正常的error - throw error.reason; + window.addEventListener("unhandledrejection", error => { + error.promise.catch(e => { + const result = errorList.find(v => v[0] === e); + if (result) { + // @ts-ignore + window.onerror( + result[0].message, + // @ts-ignore + result[1][0].getScriptNameOrSourceURL(), + // @ts-ignore + result[1][0].getLineNumber(), + // @ts-ignore + result[1][0].getColumnNumber(), + result[0]); + } + }); }); window.onkeydown = function (e) { @@ -857,6 +879,7 @@ function setWindowListener() { }; window.onerror = function (msg, src, line, column, err) { + errorList.length = 0; const winPath = window.__dirname ? ('file:///' + (__dirname.replace(new RegExp('\\\\', 'g'), '/') + '/')) : ''; let str = `错误文件: ${typeof src == 'string' ? decodeURI(src).replace(lib.assetURL, '').replace(winPath, '') : '未知文件'}`; str += `\n错误信息: ${msg}`; From e02fb4ebb2a884978c06f49e74d30efb8206c1ac Mon Sep 17 00:00:00 2001 From: shijian <2954700422@qq.com> Date: Thu, 11 Jan 2024 00:28:58 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E5=BF=98=E4=BA=86=E6=94=B9=E4=B8=80?= =?UTF-8?q?=E5=8F=A5=E8=AF=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- noname/init/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noname/init/index.js b/noname/init/index.js index b0a625b66..2f4e4e07d 100644 --- a/noname/init/index.js +++ b/noname/init/index.js @@ -761,7 +761,7 @@ function setWindowListener() { Error.prepareStackTrace = function (e, stack) { errorList.push([e, stack]); }; - // 但愿有用 + // 已经有用了 window.addEventListener("unhandledrejection", error => { error.promise.catch(e => { const result = errorList.find(v => v[0] === e); From c576ced96c19b75ed046a114bcfc2fc7f2b9a750 Mon Sep 17 00:00:00 2001 From: shijian <2954700422@qq.com> Date: Thu, 11 Jan 2024 00:34:55 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=86=99=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- noname/init/index.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/noname/init/index.js b/noname/init/index.js index 2f4e4e07d..3ec0452ba 100644 --- a/noname/init/index.js +++ b/noname/init/index.js @@ -758,24 +758,22 @@ function setWindowListener() { const errorList = []; // 这他娘的能捕获浏览器控制台里的输入值,尽量别用 // 在火狐里无效 - Error.prepareStackTrace = function (e, stack) { - errorList.push([e, stack]); + Error.prepareStackTrace = function (e, stackTraces) { + errorList.push([e, stackTraces]); }; // 已经有用了 - window.addEventListener("unhandledrejection", error => { - error.promise.catch(e => { + window.addEventListener("unhandledrejection", PromiseRejectionEvent => { + PromiseRejectionEvent.promise.catch(e => { const result = errorList.find(v => v[0] === e); if (result) { // @ts-ignore window.onerror( result[0].message, - // @ts-ignore - result[1][0].getScriptNameOrSourceURL(), - // @ts-ignore - result[1][0].getLineNumber(), - // @ts-ignore - result[1][0].getColumnNumber(), - result[0]); + result[1][0].getScriptNameOrSourceURL() || void 0, + result[1][0].getLineNumber() || void 0, + result[1][0].getColumnNumber() || void 0, + result[0] + ); } }); }); From 57d08d09822eb1784cb9425075c0aeb08caf821e Mon Sep 17 00:00:00 2001 From: shijian <2954700422@qq.com> Date: Thu, 11 Jan 2024 00:35:46 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=86=99=E6=B3=952?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- noname/init/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/noname/init/index.js b/noname/init/index.js index 3ec0452ba..7a5e3ad12 100644 --- a/noname/init/index.js +++ b/noname/init/index.js @@ -762,8 +762,8 @@ function setWindowListener() { errorList.push([e, stackTraces]); }; // 已经有用了 - window.addEventListener("unhandledrejection", PromiseRejectionEvent => { - PromiseRejectionEvent.promise.catch(e => { + window.addEventListener("unhandledrejection", promiseRejectionEvent => { + promiseRejectionEvent.promise.catch(e => { const result = errorList.find(v => v[0] === e); if (result) { // @ts-ignore From cda9e7f06308fda3d99f634ad87c065fcb07f668 Mon Sep 17 00:00:00 2001 From: shijian <2954700422@qq.com> Date: Thu, 11 Jan 2024 16:31:31 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=BA=9Bjsdoc?= =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- node_modules/noname-typings/type.d.ts | 1 + noname/library/element/dialog.js | 65 ++++++++++++++++++++++----- noname/library/index.js | 1 + noname/ui/index.js | 40 +++++++++++++++++ 4 files changed, 95 insertions(+), 12 deletions(-) diff --git a/node_modules/noname-typings/type.d.ts b/node_modules/noname-typings/type.d.ts index 847852a74..2ca05dbe7 100644 --- a/node_modules/noname-typings/type.d.ts +++ b/node_modules/noname-typings/type.d.ts @@ -31,6 +31,7 @@ declare type GameEvent = import('../../noname/library/index.js').GameEvent; declare type GameEventPromise = import('../../noname/library/index.js').GameEventPromise; declare type Player = import('../../noname/library/index.js').Player; declare type VCard = import('../../noname/library/index.js').VCard; +declare type Control = import('../../noname/library/index.js').Control; declare type Video = import('../../noname/game/index.js').Video; declare type Videos = import('../../noname/game/index.js').Videos; diff --git a/noname/library/element/dialog.js b/noname/library/element/dialog.js index ed819d971..5db38f405 100644 --- a/noname/library/element/dialog.js +++ b/noname/library/element/dialog.js @@ -6,6 +6,23 @@ import { status as _status } from '../../status/index.js'; import { UI as ui } from '../../ui/index.js'; export class Dialog extends HTMLDivElement { + /** @type { HTMLDivElement } */ + contentContainer; + /** @type { HTMLDivElement } */ + content; + /** @type { HTMLDivElement } */ + bar1; + /** @type { HTMLDivElement } */ + bar2; + /** @type { Button[] } */ + buttons; + /** @type { boolean } */ + static; + /** @type { boolean } */ + noforcebutton; + /** @type { boolean } */ + noopen; + // @ts-ignore constructor(...args) { if (args[0] instanceof Dialog) { @@ -18,7 +35,7 @@ export class Dialog extends HTMLDivElement { let noTouchScroll = false; let forceButton = false; let noForceButton = false; - /** @type {this} */ + /** @type { this } */ // @ts-ignore const dialog = ui.create.div('.dialog'); Object.setPrototypeOf(dialog, Dialog.prototype); @@ -40,6 +57,7 @@ export class Dialog extends HTMLDivElement { if (!noTouchScroll) { dialog.contentContainer.ontouchstart = ui.click.dialogtouchStart; dialog.contentContainer.ontouchmove = ui.click.touchScroll; + // @ts-ignore dialog.contentContainer.style.webkitOverflowScrolling = 'touch'; dialog.ontouchstart = ui.click.dragtouchdialog; } @@ -52,15 +70,21 @@ export class Dialog extends HTMLDivElement { dialog._args = args; return dialog; } + /** + * + * @param { string | HTMLDivElement | Card[] | Player[] } item + * @param {*} [noclick] + * @param { boolean } [zoom] + */ add(item, noclick, zoom) { if (typeof item == 'string') { if (item.startsWith('###')) { - var items = item.slice(3).split('###'); + const items = item.slice(3).split('###'); this.add(items[0], noclick, zoom); this.addText(items[1], items[1].length <= 20, zoom); } else if (noclick) { - var strstr = item; + const strstr = item; item = ui.create.div('', this.content); item.innerHTML = strstr; } @@ -68,17 +92,23 @@ export class Dialog extends HTMLDivElement { item = ui.create.caption(item, this.content); } } + // @ts-ignore else if (['div', 'fragment'].includes(get.objtype(item))) { + // @ts-ignore this.content.appendChild(item); } + // @ts-ignore else if (get.itemtype(item) == 'cards') { - var buttons = ui.create.div('.buttons', this.content); + const buttons = ui.create.div('.buttons', this.content); if (zoom) buttons.classList.add('smallzoom'); + // @ts-ignore this.buttons = this.buttons.concat(ui.create.buttons(item, 'card', buttons, noclick)); } + // @ts-ignore else if (get.itemtype(item) == 'players') { var buttons = ui.create.div('.buttons', this.content); if (zoom) buttons.classList.add('smallzoom'); + // @ts-ignore this.buttons = this.buttons.concat(ui.create.buttons(item, 'player', buttons, noclick)); } else if (item[1] == 'textbutton') { @@ -87,6 +117,7 @@ export class Dialog extends HTMLDivElement { else { var buttons = ui.create.div('.buttons', this.content); if (zoom) buttons.classList.add('smallzoom'); + // @ts-ignore this.buttons = this.buttons.concat(ui.create.buttons(item[0], item[1], buttons, noclick)); } if (this.buttons.length) { @@ -101,6 +132,10 @@ export class Dialog extends HTMLDivElement { ui.update(); return item; } + /** + * @param { string } str + * @param { boolean } [center] + */ addText(str, center) { if (str && str.startsWith('