fix: vcard without args.
This commit is contained in:
parent
2190dfe083
commit
8b80deb3b3
|
@ -1,128 +1,125 @@
|
|||
import { AI as ai } from '../../ai/index.js';
|
||||
import { Get as get } from '../../get/index.js';
|
||||
import { Game as game } from '../../game/index.js';
|
||||
import { Library as lib } from "../index.js";
|
||||
import { status as _status } from '../../status/index.js';
|
||||
import { UI as ui } from '../../ui/index.js';
|
||||
|
||||
export class VCard {
|
||||
/**
|
||||
* @param { any } [suitOrCard]
|
||||
* @param { number | Card[] } [numberOrCards]
|
||||
* @param { string } [name]
|
||||
* @param { string } [nature]
|
||||
*/
|
||||
constructor(suitOrCard, numberOrCards, name, nature) {
|
||||
|
||||
if (Array.isArray(suitOrCard)) {
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
this.suit = suitOrCard[0];
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.number = suitOrCard[1];
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
this.name = suitOrCard[2];
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
this.nature = suitOrCard[3];
|
||||
}
|
||||
// @ts-ignore
|
||||
else if (get.itemtype(suitOrCard) == 'card') {
|
||||
this.name = get.name(suitOrCard);
|
||||
this.suit = get.suit(suitOrCard);
|
||||
this.color = get.color(suitOrCard);
|
||||
this.number = get.number(suitOrCard);
|
||||
this.nature = get.nature(suitOrCard);
|
||||
/**
|
||||
* @type { boolean }
|
||||
*/
|
||||
this.isCard = true;
|
||||
this.cardid = suitOrCard.cardid;
|
||||
this.wunature = suitOrCard.wunature;
|
||||
/**
|
||||
* @type {Record<string, any>}
|
||||
*/
|
||||
this.storage = get.copy(suitOrCard.storage);
|
||||
if (Array.isArray(numberOrCards)) this.cards = numberOrCards.slice();
|
||||
else this.cards = [suitOrCard];
|
||||
const info = get.info(this, false);
|
||||
if (info) {
|
||||
const autoViewAs = info.autoViewAs;
|
||||
if (typeof autoViewAs == 'string') this.name = autoViewAs;
|
||||
}
|
||||
}
|
||||
else if (suitOrCard && typeof suitOrCard != 'string') {
|
||||
Object.keys(suitOrCard).forEach(key => {
|
||||
/**
|
||||
* @type { PropertyDescriptor }
|
||||
*/
|
||||
// @ts-ignore
|
||||
const propertyDescriptor = Object.getOwnPropertyDescriptor(suitOrCard, key), value = propertyDescriptor.value;
|
||||
if (Array.isArray(value)) this[key] = value.slice();
|
||||
else Object.defineProperty(this, key, propertyDescriptor);
|
||||
});
|
||||
if (Array.isArray(numberOrCards)) {
|
||||
const noCards = !this.cards;
|
||||
/**
|
||||
* @type { Card[] }
|
||||
*/
|
||||
this.cards = numberOrCards.slice();
|
||||
if (noCards) {
|
||||
if (!lib.suits.includes(this.suit)) this.suit = get.suit(this);
|
||||
if (!Object.keys(lib.color).includes(this.color)) this.color = get.color(this);
|
||||
if (typeof this.number != 'number') this.number = get.number(this);
|
||||
if (!this.nature) this.nature = get.nature(this);
|
||||
}
|
||||
}
|
||||
const info = get.info(this, false);
|
||||
if (info) {
|
||||
const autoViewAs = info.autoViewAs;
|
||||
if (typeof autoViewAs == 'string') this.name = autoViewAs;
|
||||
}
|
||||
}
|
||||
if (typeof suitOrCard == 'string') this.suit = suitOrCard;
|
||||
if (typeof numberOrCards == 'number') this.number = numberOrCards;
|
||||
if (typeof name == 'string') this.name = name;
|
||||
if (typeof nature == 'string') this.nature = nature;
|
||||
if (!this.storage) this.storage = {};
|
||||
if (!this.cards) this.cards = [];
|
||||
|
||||
this._args = [suitOrCard, numberOrCards, name, nature];
|
||||
}
|
||||
sameSuitAs(card) {
|
||||
return get.suit(this) == get.suit(card);
|
||||
}
|
||||
differentSuitFrom(card) {
|
||||
return get.suit(this) != get.suit(card);
|
||||
}
|
||||
sameNumberAs(card) {
|
||||
return get.number(this) == get.number(card);
|
||||
}
|
||||
differentNumberFrom(card) {
|
||||
return get.number(this) != get.number(card);
|
||||
}
|
||||
sameNameAs(card) {
|
||||
return get.name(this) == get.name(card);
|
||||
}
|
||||
differentNameFrom(card) {
|
||||
return get.name(this) != get.name(card);
|
||||
}
|
||||
/**
|
||||
* @param { Player } player
|
||||
*/
|
||||
hasNature(nature, player) {
|
||||
const natures = get.natureList(this, player);
|
||||
if (!nature) return natures.length > 0;
|
||||
if (nature == 'linked') return natures.some(n => lib.linked.includes(n));
|
||||
return get.is.sameNature(natures, nature);
|
||||
}
|
||||
hasGaintag(tag) {
|
||||
return this.gaintag && this.gaintag.includes(tag);
|
||||
}
|
||||
}
|
||||
import { AI as ai } from '../../ai/index.js';
|
||||
import { Get as get } from '../../get/index.js';
|
||||
import { Game as game } from '../../game/index.js';
|
||||
import { Library as lib } from "../index.js";
|
||||
import { status as _status } from '../../status/index.js';
|
||||
import { UI as ui } from '../../ui/index.js';
|
||||
|
||||
export class VCard {
|
||||
/**
|
||||
* @param { any } [suitOrCard]
|
||||
* @param { number | Card[] } [numberOrCards]
|
||||
* @param { string } [name]
|
||||
* @param { string } [nature]
|
||||
*/
|
||||
constructor(suitOrCard, numberOrCards, name, nature) {
|
||||
if (Array.isArray(suitOrCard)) {
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
this.suit = suitOrCard[0];
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.number = suitOrCard[1];
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
this.name = suitOrCard[2];
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
this.nature = suitOrCard[3];
|
||||
}
|
||||
// @ts-ignore
|
||||
else if (get.itemtype(suitOrCard) == 'card') {
|
||||
this.name = get.name(suitOrCard);
|
||||
this.suit = get.suit(suitOrCard);
|
||||
this.color = get.color(suitOrCard);
|
||||
this.number = get.number(suitOrCard);
|
||||
this.nature = get.nature(suitOrCard);
|
||||
/**
|
||||
* @type { boolean }
|
||||
*/
|
||||
this.isCard = true;
|
||||
this.cardid = suitOrCard.cardid;
|
||||
this.wunature = suitOrCard.wunature;
|
||||
/**
|
||||
* @type {Record<string, any>}
|
||||
*/
|
||||
this.storage = get.copy(suitOrCard.storage);
|
||||
if (Array.isArray(numberOrCards)) this.cards = numberOrCards.slice();
|
||||
else this.cards = [suitOrCard];
|
||||
const info = get.info(this, false);
|
||||
if (info) {
|
||||
const autoViewAs = info.autoViewAs;
|
||||
if (typeof autoViewAs == 'string') this.name = autoViewAs;
|
||||
}
|
||||
}
|
||||
else if (suitOrCard && typeof suitOrCard != 'string') {
|
||||
Object.keys(suitOrCard).forEach(key => {
|
||||
/**
|
||||
* @type { PropertyDescriptor }
|
||||
*/
|
||||
// @ts-ignore
|
||||
const propertyDescriptor = Object.getOwnPropertyDescriptor(suitOrCard, key), value = propertyDescriptor.value;
|
||||
if (Array.isArray(value)) this[key] = value.slice();
|
||||
else Object.defineProperty(this, key, propertyDescriptor);
|
||||
});
|
||||
if (Array.isArray(numberOrCards)) {
|
||||
const noCards = !this.cards;
|
||||
/**
|
||||
* @type { Card[] }
|
||||
*/
|
||||
this.cards = numberOrCards.slice();
|
||||
if (noCards) {
|
||||
if (!lib.suits.includes(this.suit)) this.suit = get.suit(this);
|
||||
if (!Object.keys(lib.color).includes(this.color)) this.color = get.color(this);
|
||||
if (typeof this.number != 'number') this.number = get.number(this);
|
||||
if (!this.nature) this.nature = get.nature(this);
|
||||
}
|
||||
}
|
||||
const info = get.info(this, false);
|
||||
if (info) {
|
||||
const autoViewAs = info.autoViewAs;
|
||||
if (typeof autoViewAs == 'string') this.name = autoViewAs;
|
||||
}
|
||||
}
|
||||
if (typeof suitOrCard == 'string') this.suit = suitOrCard;
|
||||
if (typeof numberOrCards == 'number') this.number = numberOrCards;
|
||||
if (typeof name == 'string') this.name = name;
|
||||
if (typeof nature == 'string') this.nature = nature;
|
||||
if (!this.storage) this.storage = {};
|
||||
if (!this.cards) this.cards = [];
|
||||
}
|
||||
sameSuitAs(card) {
|
||||
return get.suit(this) == get.suit(card);
|
||||
}
|
||||
differentSuitFrom(card) {
|
||||
return get.suit(this) != get.suit(card);
|
||||
}
|
||||
sameNumberAs(card) {
|
||||
return get.number(this) == get.number(card);
|
||||
}
|
||||
differentNumberFrom(card) {
|
||||
return get.number(this) != get.number(card);
|
||||
}
|
||||
sameNameAs(card) {
|
||||
return get.name(this) == get.name(card);
|
||||
}
|
||||
differentNameFrom(card) {
|
||||
return get.name(this) != get.name(card);
|
||||
}
|
||||
/**
|
||||
* @param { Player } player
|
||||
*/
|
||||
hasNature(nature, player) {
|
||||
const natures = get.natureList(this, player);
|
||||
if (!nature) return natures.length > 0;
|
||||
if (nature == 'linked') return natures.some(n => lib.linked.includes(n));
|
||||
return get.is.sameNature(natures, nature);
|
||||
}
|
||||
hasGaintag(tag) {
|
||||
return this.gaintag && this.gaintag.includes(tag);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue