From 5a2e6dad91bbfe0c920c63cee341d6390cc944eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=AB=E8=B0=B7=E5=89=91=E4=BB=99?= Date: Mon, 12 May 2025 21:00:48 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A9=E6=89=80=E6=9C=89=E6=80=AA=E7=89=A9?= =?UTF-8?q?=E5=A4=B4=E5=83=8F=EF=BC=8C=E9=83=BD=E5=8F=AF=E4=BB=A5=E6=8B=96?= =?UTF-8?q?=E5=8A=A8=E8=BF=9B=E5=85=A5=E5=AF=8C=E6=96=87=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script-universal_function.js | 6 ++++++ script.js | 10 +++++----- service-worker.js | 4 ++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/script-universal_function.js b/script-universal_function.js index e7a0ebf4..8bb3c890 100644 --- a/script-universal_function.js +++ b/script-universal_function.js @@ -1227,6 +1227,11 @@ function copyString(input) { }); //input.blur(); //取消焦点 } +function cardAOnDragStart(event){ + if (event.dataTransfer) { + event.dataTransfer.setData("card-id", this.dataset.cardid); + } +} //产生一个怪物头像 function createCardA(option) { const t = document.body.querySelector('#template-card-a'); @@ -1234,6 +1239,7 @@ function createCardA(option) { const monster = clone.querySelector(".monster"); if (option?.noTreeCount) monster.querySelector(".count-in-box .evo-tree").remove(); if (option?.noBoxCount) monster.querySelector(".count-in-box").remove(); + monster.ondragstart = cardAOnDragStart; //拖拽怪物头像时,记录怪物id到拖拽 return monster; } //返回文字说明内怪物Card的纯HTML diff --git a/script.js b/script.js index 8227720f..e7a3cb4c 100644 --- a/script.js +++ b/script.js @@ -3744,18 +3744,16 @@ function initialize() { //设置为可以拖放已经编辑好的队伍 function richTextDropHandler(event) { - //console.debug(event); - let isCopy = event.ctrlKey; //默认为按Ctrl是复制,不然是移动 if (controlBox.querySelector("#change-swap-to-copy").checked) isCopy = !isCopy; //勾选后逆向操作 event.dataTransfer.dropEffect = isCopy ? 'copy' : 'move'; let newIcon; - const formStr = event.dataTransfer.getData('from'); - if (formStr) { //从队伍里拖下来的,需要重新创建怪物头像,强制复制 + let dataFormStr, cardId; + if (dataFormStr = event.dataTransfer.getData('from')) { //从队伍里拖下来的,需要重新创建怪物头像,强制复制 event.preventDefault(); - const [teamNum, isAssist, indexInTeam] = JSON.parse(formStr); + const [teamNum, isAssist, indexInTeam] = JSON.parse(dataFormStr); const mon = formation.teams[teamNum][isAssist][indexInTeam]; newIcon = createIndexedIcon('card', mon.id); } else if (draggedNode) { @@ -3771,6 +3769,8 @@ function initialize() { const {type, index} = JSON.parse(indexed); newIcon = createIndexedIcon(type, index); } + } else if (cardId = event.dataTransfer.getData('card-id')) { + newIcon = createIndexedIcon("card", parseInt(cardId, 10)); } // 重置引用 draggedNode = null; diff --git a/service-worker.js b/service-worker.js index bd137678..2ef60f55 100644 --- a/service-worker.js +++ b/service-worker.js @@ -48283,11 +48283,11 @@ const cachesMap = new Map([ ], [ "script-universal_function.js", - "a1fb4b6badef8b98e89665bb74c1c0a5" + "badccac0015ffb68514f04ac8caf6daf" ], [ "script.js", - "57f70ae19d087eaf6c75ab9fef44b30c" + "059a9d5f7ef859e8475205e260996f66" ], [ "solo.html",