From 28647ecb12f0dc6558c0c299d99e9a450d97fa22 Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@163.com> Date: 星期六, 12 十月 2024 13:50:12 +0800 Subject: [PATCH] # --- zy-acs-flow/src/map/tool.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 42 insertions(+), 0 deletions(-) diff --git a/zy-acs-flow/src/map/tool.js b/zy-acs-flow/src/map/tool.js index ec7e16f..04a40b6 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(); @@ -313,10 +324,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