Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 43 additions & 12 deletions noname/game/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,21 @@ export class Game extends GameCompatible {
game.$elementGotoAnimData.endPosition.set(element, position); // 元素结束位置以最晚的为主喵
}

function updateDOM() {
// 依照参数选择添加的位置喵
if (position === "first") {
parent.insertBefore(element, parent.firstChild);
} else if (position === "last") {
parent.appendChild(element);
} else if (typeof position == "number") {
parent.insertBefore(element, parent.children[position]);
} else if (parent.contains(position)) {
parent.insertBefore(element, position);
} else {
parent.appendChild(element);
}
}

// 首先是FIRST喵,记录起始位置哦喵
const parentFrom = element.parentElement;
const parentTo = parent;
Expand All @@ -401,6 +416,33 @@ export class Game extends GameCompatible {
throw new Error("要移动的元素没有父元素");
}

// 补丁喵,对于没有移动的操作我们直接返回FULFILLED喵
if (parentFrom === parentTo) {
let notMoved = false;

if (position === "first") {
notMoved = parentTo.firstChild === element;
} else if (position === "last") {
notMoved = parentTo.lastChild === element;
} else if (typeof position == "number") {
notMoved = parentTo.childNodes[position] === element;
} else if (parent.contains(position)) {
notMoved = position === element;
} else {
notMoved = parentTo.lastChild === element;
}

if (notMoved) {
return Promise.resolve();
}
}

// 额外增强喵,对于duration == 0的情况跳过动画喵
if (duration == 0) {
updateDOM();
return Promise.resolve();
}

// @ts-expect-error childNodes是可迭代的
const elements = new Set(parentFrom.childNodes).union(parentTo.childNodes);

Expand All @@ -414,19 +456,8 @@ export class Game extends GameCompatible {
// 如果你需要并发多个动画应该**同步的**调用多次然后使用Promise.all()一起等待哦喵
await new Promise(resolve => resolve(null));

// 依照参数选择添加的位置喵
// 此时将更改实际的DOM结构喵
if (position === "first") {
parent.insertBefore(element, parent.firstChild);
} else if (position === "last") {
parent.appendChild(element);
} else if (typeof position == "number") {
parent.insertBefore(element, parent.children[position]);
} else if (parent.contains(position)) {
parent.insertBefore(element, position);
} else {
parent.appendChild(element);
}
updateDOM();

// 我们再次等待所有节点结构调整完毕喵
await new Promise(resolve => resolve(null));
Expand Down
15 changes: 10 additions & 5 deletions noname/library/element/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -1985,6 +1985,10 @@ player.removeVirtualEquip(card);
* 是否处于拖拽动画中(禁止其他的选择,拖拽)
*/
event.isPlayingAnimation = false;

// 动画时长
const animationDuration = lib.config.animation_choose_to_move ? 300 : 0;

// 初始化触摸点位置和元素偏移量
var touchStartX = 0;
var touchStartY = 0;
Expand Down Expand Up @@ -2388,15 +2392,15 @@ player.removeVirtualEquip(card);
}

// 执行动画喵
aniamtionPromise = game.$elementGoto(curCard, buttons, position);
aniamtionPromise = game.$elementGoto(curCard, buttons, position, animationDuration);
} else {
// 如果拖动到按钮上面,我们交换两个按钮喵
const buttons2 = curCard.parentElement;
const pos1 = card.nextElementSibling || "last";
const pos2 = curCard.nextElementSibling || "last";

// 执行动画喵
aniamtionPromise = game.$elementSwap(curCard, card);
aniamtionPromise = game.$elementSwap(curCard, card, animationDuration);
}

clearSelected();
Expand Down Expand Up @@ -2430,7 +2434,7 @@ player.removeVirtualEquip(card);
const subPromises = [];

for (const element of selected) {
subPromises.push(game.$elementGoto(element, buttons, position));
subPromises.push(game.$elementGoto(element, buttons, position, animationDuration));
}

aniamtionPromise = Promise.all(subPromises);
Expand Down Expand Up @@ -13075,6 +13079,7 @@ player.removeVirtualEquip(card);
}, event.chooseTime);
}
if (event.isMine()) {
const animationDuration = lib.config.animation_choose_to_move ? 300 : 0;
//自动选择
event.switchToAuto = function () {
if (!event.filterOk(event.moved)) {
Expand Down Expand Up @@ -13142,7 +13147,7 @@ player.removeVirtualEquip(card);
if (event.dialog.selectedCard) {
if (card !== event.dialog.selectedCard && event.filterMove(event.dialog.selectedCard, card, event.moved)) {
event.dialog.isBusy = true;
game.$swapElement(card, event.dialog.selectedCard, 300).then(() => {
game.$swapElement(card, event.dialog.selectedCard, animationDuration).then(() => {
event.dialog.isBusy = false;
updateButtons();
});
Expand All @@ -13165,7 +13170,7 @@ player.removeVirtualEquip(card);
let index = Array.from(event.dialog.itemContainers).indexOf(itemContainer) / 2 - 1;
if (event.filterMove(event.dialog.selectedCard, index, event.moved)) {
event.dialog.isBusy = true;
game.$elementGoto(event.dialog.selectedCard, itemContainer, 300).then(() => {
game.$elementGoto(event.dialog.selectedCard, itemContainer, undefined, animationDuration).then(() => {
event.dialog.isBusy = false;
updateButtons();
});
Expand Down
6 changes: 6 additions & 0 deletions noname/library/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3642,6 +3642,12 @@ export class Library {
init: false,
unfrequent: false,
},
animation_choose_to_move: {
name: "移动卡牌动画",
intro: "开启后将启用chooseToMove(观星类)的动画",
init: true,
unfrequent: false,
},
skill_animation_type: {
name: "技能特效",
intro: "开启后觉醒技、限定技将显示全屏文字",
Expand Down