From bb61bc0c22ae4ef9963ca00d23b5cf0c412f26f5 Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@163.com> Date: 星期六, 12 十月 2024 14:47:35 +0800 Subject: [PATCH] # --- zy-acs-flow/src/map/tool.js | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 45 insertions(+), 2 deletions(-) diff --git a/zy-acs-flow/src/map/tool.js b/zy-acs-flow/src/map/tool.js index fa64cbe..58e6aaf 100644 --- a/zy-acs-flow/src/map/tool.js +++ b/zy-acs-flow/src/map/tool.js @@ -189,6 +189,17 @@ } } +export const copySprite = (sprite) => { + const copiedSprite = generateSprite(sprite.data.type) + initSprite(copiedSprite); + copiedSprite.position.set(sprite.position.x, sprite.position.y); + copiedSprite.scale.set(sprite.scale.x, sprite.scale.y); + copiedSprite.rotation = sprite.rotation; + copiedSprite.data = deepCopy(sprite.data); + copiedSprite.data.uuid = generateID(); + return copiedSprite; +} + export const isSpriteInSelectionBox = (sprite, selectionBox) => { const spriteBounds = sprite.getBounds(); const boxBounds = selectionBox.getBounds(); @@ -234,10 +245,11 @@ } } - export const showSelectedEffect = (sprite) => { + if (!sprite?.texture || !sprite?.texture?.valid) { + return; + } const { width, height } = sprite; - const scale = sprite.scale.x; const sideLen = (Math.max(width, height) + 10) * scale; const color = themeMode === 'light' ? 0x273c75 : 0xffffff; @@ -311,10 +323,41 @@ effectHalfCircle.position.set(sprite.x, sprite.y); } +export const rotationToNum = (rotation) => { + let res = rotation * 180 / Math.PI; + if (res < 0) { + res += 360; + } else if (res > 360) { + res -= 360; + } + return res; +} + +export const rotationParseNum = (num) => { + return num * Math.PI / 180; +} + +export const incrementSpriteNo = (str, incrementValue) => { + const match = str.match(/(\D*)(\d+)/); + if (match) { + const prefix = match[1]; + const numberPart = match[2]; + const newNumber = parseInt(numberPart, 10) + incrementValue; + const paddedNumber = newNumber.toString().padStart(numberPart.length, '0'); + return `${prefix}${paddedNumber}`; + } else { + return str; + } +} + export const generateID = () => { return Date.now().toString(36) + Math.random().toString(36).substring(2); } +export const deepCopy = (data) => { + return JSON.parse(JSON.stringify(data)); +} + export const patchRaLayout = (param) => { const parentElement = document.getElementById('main-content'); if (parentElement && parentElement.classList.contains('RaLayout-content')) { -- Gitblit v1.9.1