From 4b0e0b68330c42ddc69669638e774354ef4eea37 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期三, 09 十月 2024 16:46:17 +0800
Subject: [PATCH] #
---
zy-acs-flow/src/map/tool.js | 96 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 96 insertions(+), 0 deletions(-)
diff --git a/zy-acs-flow/src/map/tool.js b/zy-acs-flow/src/map/tool.js
index 63bf3cd..2a9ced4 100644
--- a/zy-acs-flow/src/map/tool.js
+++ b/zy-acs-flow/src/map/tool.js
@@ -72,6 +72,14 @@
};
}
+export const markSprite = (sprite) => {
+ sprite.alpha = 0.5;
+}
+
+export const unMarkSprite = (sprite) => {
+ sprite.alpha = 1;
+}
+
export const beMovable = (sprite) => {
sprite.off('pointerup');
sprite.off('pointermove');
@@ -109,6 +117,94 @@
}
+export const spriteListBeMovable = (selectedSprites, endFn) => {
+ if (selectedSprites && selectedSprites.length > 0) {
+ let batchMove = false;
+ let batchMoveStartPos = null;
+
+ const batchMoving = (event) => {
+ const scale = mapContainer.scale.x;
+ if (batchMove && batchMoveStartPos) {
+ // offset move val
+ var mouseMovement = {
+ x: (event.global.x - batchMoveStartPos.x) / scale,
+ y: (event.global.y - batchMoveStartPos.y) / scale
+ };
+ for (let sprite of selectedSprites) {
+ sprite.position.x = sprite.batchMoveStartPos.x + mouseMovement.x;
+ sprite.position.y = sprite.batchMoveStartPos.y + mouseMovement.y;
+ }
+ }
+ }
+
+ const batchMoveEnd = (event) => {
+ batchMove = false;
+ batchMoveStartPos = null;
+ selectedSprites.forEach(child => {
+ unMarkSprite(child);
+ })
+ selectedSprites = [];
+ mapContainer.parent.off('mousedown');
+ mapContainer.parent.off('mousemove');
+ mapContainer.parent.off('mouseup');
+
+ if (endFn) {
+ endFn();
+ }
+ }
+
+ const batchMoveStart = (event) => {
+ batchMoveStartPos = { x: event.data.global.clone().x, y: event.data.global.clone().y };
+ selectedSprites.forEach(child => {
+ child.batchMoveStartPos = { x: child.position.x, y: child.position.y };
+ })
+
+ batchMove = true;
+ mapContainer.parent.off('mousemove');
+ mapContainer.parent.on('mousemove', batchMoving);
+
+ mapContainer.parent.off('mouseup');
+ mapContainer.parent.on('mouseup', batchMoveEnd);
+ }
+
+ mapContainer.parent.off('mousedown')
+ mapContainer.parent.on('mousedown', batchMoveStart);
+ }
+}
+
+export const isSpriteInSelectionBox = (sprite, selectionBox) => {
+ const spriteBounds = sprite.getBounds();
+ const boxBounds = selectionBox.getBounds();
+
+ return spriteBounds.x + spriteBounds.width > boxBounds.x
+ && spriteBounds.x < boxBounds.x + boxBounds.width
+ && spriteBounds.y + spriteBounds.height > boxBounds.y
+ && spriteBounds.y < boxBounds.y + boxBounds.height;
+}
+
+export const clearMapData = () => {
+ if (!mapContainer) {
+ return;
+ }
+ let childList = [];
+ mapContainer.children.forEach(child => {
+ if (child.data?.uuid) {
+ childList.push(child);
+ }
+ })
+ if (childList.length > 0) {
+ childList.forEach(child => {
+ mapContainer.removeChild(child);
+ child.destroy({ children: true, texture: false, baseTexture: false });
+ })
+ childList.forEach((child, index) => {
+ childList[index] = null;
+ });
+ childList = [];
+ }
+}
+
+
export const generateID = () => {
return Date.now().toString(36) + Math.random().toString(36).substring(2);
}
--
Gitblit v1.9.1