构造器和build虚方法分离,在create内调用build

This commit is contained in:
kuangthree 2024-01-06 22:29:14 +08:00
parent 9c987a59c5
commit 03dd4cd2b7
4 changed files with 12 additions and 9 deletions

View File

@ -12,14 +12,13 @@ export class Card extends HTMLDivElement {
* @param {true} [noclick]
*/
// @ts-ignore
constructor(position, info, noclick) {
constructor(position) {
/**
* @type {this}
*/
// @ts-ignore
const card = ui.create.div('.card', position);
Object.setPrototypeOf(card, Card.prototype);
card.build(info, noclick);
return card;
}
build(info, noclick) {
@ -28,6 +27,7 @@ export class Card extends HTMLDivElement {
card.buildIntro(noclick);
card.buildProperty();
card.buildEventListener(info);
return this;
}
buildEventListener(info) {
let card = this;

View File

@ -29,7 +29,7 @@ export class Dialog extends HTMLDivElement {
else if (argument == 'noforcebutton') noForceButton = true;
else dialog.add(argument);
});
if (!hidden) dialog.open();
//if (!hidden) dialog.open();
if (!lib.config.touchscreen) dialog.contentContainer.onscroll = ui.update;
if (!noTouchScroll) {
dialog.contentContainer.ontouchstart = ui.click.dialogtouchStart;

View File

@ -8,17 +8,15 @@ import { UI as ui } from '../../ui/index.js';
export class Player extends HTMLDivElement {
/**
* @param {HTMLDivElement|DocumentFragment} [position]
* @param {true} [noclick]
*/
// @ts-ignore
constructor(position, noclick) {
constructor(position) {
/**
* @type {this}
*/
// @ts-ignore
const player = ui.create.div('.player', position);
Object.setPrototypeOf(player, Player.prototype);
player.build(noclick);
return player;
}
/**
@ -174,6 +172,7 @@ export class Player extends HTMLDivElement {
player.buildProperty();
player.buildExtra();
player.buildEventListener(noclick);
return this;
}
buildNode() {
let player = this;

View File

@ -8655,7 +8655,11 @@ class Create extends Uninstantable {
return dialog;
}
static dialog() {
return new lib.element.Dialog(...arguments);
let dialog = new lib.element.Dialog(...arguments);
if(!Array.from(arguments).includes('hidden')){
dialog.open();
}
return dialog;
}
static line2() {
var node = ui.create.line.apply(this, arguments);
@ -9898,7 +9902,7 @@ class Create extends Uninstantable {
dialog.buttons.add(next.firstChild);
}
}
static player(position, noclick) { return new lib.element.Player(position, noclick) }
static player(position, noclick) { return new lib.element.Player(position).build(noclick); }
static connectPlayers(ip) {
ui.updateConnectPlayerPositions();
game.connectPlayers = [];
@ -10047,7 +10051,7 @@ class Create extends Uninstantable {
// ui.updatehl();
}
}
static card(position, info, noclick) { return new lib.element.Card(position, info, noclick)}
static card(position, info, noclick) { return new lib.element.Card(position).build(info, noclick);}
static cardsAsync() {
if (lib.onfree) {
_status.waitingForCards = Array.from(arguments);