卡牌图片支持根据牌的具体信息(如花色、点数等)改变

This commit is contained in:
kuangthree 2024-02-14 16:54:58 +08:00
parent 0295ae9c37
commit 2b418c5717
3 changed files with 33 additions and 22 deletions

View File

@ -4657,6 +4657,17 @@ export class Get extends Uninstantable {
if (eff > 0 && target.hujia > 0) return eff / 1.3; if (eff > 0 && target.hujia > 0) return eff / 1.3;
return eff; return eff;
} }
/**
*
* @param {any} source 如果参数是function执行此函数并返回结果传参为此方法剩余的参数如果参数不是function直接返回结果
* @returns 返回的结果
*/
static dynamicVariable(source){
if(typeof source == 'function'){
return source.call(...(arguments.slice(1)));
}
return source;
}
static recoverEffect(target, player, viewer) { static recoverEffect(target, player, viewer) {
if (target.hp == target.maxHp) return 0; if (target.hp == target.maxHp) return 0;
if (!player) { if (!player) {

View File

@ -329,7 +329,7 @@ export class Card extends HTMLDivElement {
if (info.cardimage) { if (info.cardimage) {
bg = info.cardimage; bg = info.cardimage;
} }
var img = lib.card[bg].image; var img = get.dynamicVariable(lib.card[bg].image,this);
if (img) { if (img) {
if (img.startsWith('db:')) { if (img.startsWith('db:')) {
img = img.slice(3); img = img.slice(3);
@ -378,7 +378,7 @@ export class Card extends HTMLDivElement {
} }
} }
} }
else if (lib.card[bg].image == 'background') { else if (get.dynamicVariable(lib.card[bg].image,this) == 'background') {
if (card[3]) this.node.background.setBackground(bg + '_' + get.natureList(card[3])[0], 'card'); if (card[3]) this.node.background.setBackground(bg + '_' + get.natureList(card[3])[0], 'card');
else this.node.background.setBackground(bg, 'card'); else this.node.background.setBackground(bg, 'card');
} }
@ -393,12 +393,12 @@ export class Card extends HTMLDivElement {
this.setBackgroundDB(img); this.setBackgroundDB(img);
} }
} }
else if (lib.card[bg].image) { else if (get.dynamicVariable(lib.card[bg].image,this)) {
if (lib.card[bg].image.startsWith('character:')) { if (get.dynamicVariable(lib.card[bg].image,this).startsWith('character:')) {
this.setBackground(lib.card[bg].image.slice(10), 'character'); this.setBackground(get.dynamicVariable(lib.card[bg].image,this).slice(10), 'character');
} }
else { else {
this.setBackground(lib.card[bg].image); this.setBackground(get.dynamicVariable(lib.card[bg].image,this));
} }
} }
else { else {
@ -437,12 +437,12 @@ export class Card extends HTMLDivElement {
this.node.avatar.setBackgroundDB(img); this.node.avatar.setBackgroundDB(img);
} }
} }
else if (lib.card[bg].image) { else if (get.dynamicVariable(lib.card[bg].image,this)) {
if (lib.card[bg].image.startsWith('character:')) { if (get.dynamicVariable(lib.card[bg].image,this).startsWith('character:')) {
this.node.avatar.setBackground(lib.card[bg].image.slice(10), 'character'); this.node.avatar.setBackground(get.dynamicVariable(lib.card[bg].image,this).slice(10), 'character');
} }
else { else {
this.node.avatar.setBackground(lib.card[bg].image); this.node.avatar.setBackground(get.dynamicVariable(lib.card[bg].image,this));
} }
} }
else { else {
@ -455,11 +455,11 @@ export class Card extends HTMLDivElement {
} }
} }
} }
else if (lib.card[bg].image == 'card') { else if (get.dynamicVariable(lib.card[bg].image,this) == 'card') {
if (card[3]) this.setBackground(bg + '_' + get.natureList(card[3])[0], 'card'); if (card[3]) this.setBackground(bg + '_' + get.natureList(card[3])[0], 'card');
else this.setBackground(bg, 'card'); else this.setBackground(bg, 'card');
} }
else if (typeof lib.card[bg].image == 'string' && !lib.card[bg].fullskin) { else if (typeof get.dynamicVariable(lib.card[bg].image,this) == 'string' && !lib.card[bg].fullskin) {
if (img) { if (img) {
if (img.startsWith('ext:')) { if (img.startsWith('ext:')) {
this.setBackgroundImage(img.replace(/^ext:/, 'extension/')); this.setBackgroundImage(img.replace(/^ext:/, 'extension/'));
@ -470,7 +470,7 @@ export class Card extends HTMLDivElement {
} }
} }
else { else {
this.setBackground(lib.card[bg].image); this.setBackground(get.dynamicVariable(lib.card[bg].image,this));
} }
} }
else { else {

View File

@ -314,7 +314,7 @@ export class Create extends Uninstantable {
} }
else bg = ui.create.div(node); else bg = ui.create.div(node);
node.classList.add('tempimage'); node.classList.add('tempimage');
let img = lib.card[cardName].image; let img = get.dynamicVariable(lib.card[cardName].image,card);
if (img) { if (img) {
if (img.startsWith('db:')) { if (img.startsWith('db:')) {
img = img.slice(3); img = img.slice(3);
@ -342,7 +342,7 @@ export class Create extends Uninstantable {
} }
} }
} }
else if (lib.card[cardName].image == 'background') { else if (get.dynamicVariable(lib.card[cardName].image,card) == 'background') {
if (cardNature) bg.setBackground(cardName + '_' + cardNature, 'card'); if (cardNature) bg.setBackground(cardName + '_' + cardNature, 'card');
else bg.setBackground(cardName, 'card'); else bg.setBackground(cardName, 'card');
} }
@ -356,12 +356,12 @@ export class Create extends Uninstantable {
bg.setBackgroundDB(img); bg.setBackgroundDB(img);
} }
} }
else if (lib.card[cardName].image) { else if (get.dynamicVariable(lib.card[cardName].image,card)) {
if (lib.card[cardName].image.startsWith('character:')) { if (get.dynamicVariable(lib.card[cardName].image,card).startsWith('character:')) {
bg.setBackground(lib.card[cardName].image.slice(10), 'character'); bg.setBackground(get.dynamicVariable(lib.card[cardName].image,card).slice(10), 'character');
} }
else { else {
bg.setBackground(lib.card[cardName].image); bg.setBackground(get.dynamicVariable(lib.card[cardName].image,card));
} }
} }
else { else {
@ -374,11 +374,11 @@ export class Create extends Uninstantable {
} }
} }
} }
else if (lib.card[cardName].image == 'card') { else if (get.dynamicVariable(lib.card[cardName].image,card) == 'card') {
if (cardNature) bg.setBackground(cardName + '_' + cardNature, 'card'); if (cardNature) bg.setBackground(cardName + '_' + cardNature, 'card');
else bg.setBackground(cardName, 'card'); else bg.setBackground(cardName, 'card');
} }
else if (typeof lib.card[cardName].image == 'string' && !lib.card[cardName].fullskin) { else if (typeof get.dynamicVariable(lib.card[cardName].image,card) == 'string' && !lib.card[cardName].fullskin) {
if (img) { if (img) {
if (img.startsWith('ext:')) { if (img.startsWith('ext:')) {
bg.setBackgroundImage(img.replace(/^ext:/, 'extension/')); bg.setBackgroundImage(img.replace(/^ext:/, 'extension/'));
@ -389,7 +389,7 @@ export class Create extends Uninstantable {
} }
} }
else { else {
bg.setBackground(lib.card[cardName].image); bg.setBackground(get.dynamicVariable(lib.card[cardName].image,card));
} }
} }
else { else {