| | |
| | | import charge from '/map/charge.svg'; |
| | | import station from '/map/station.svg'; |
| | | import direction from '/map/direction.svg'; |
| | | import point from '/map/point.svg'; |
| | | |
| | | let app, mapContainer, themeMode; |
| | | let selectedSprite, effectTick, effectHalfCircle, effectRectangle; |
| | |
| | | // sprite.height = 63; |
| | | sprite.zIndex = DEVICE_Z_INDEX.DIRECTION; |
| | | break; |
| | | |
| | | case DEVICE_TYPE.POINT: |
| | | sprite = new PIXI.Sprite(PIXI.Texture.from(point, { resourceOptions: { scale: 1 } })); |
| | | // sprite.width = 112; |
| | | // sprite.height = 63; |
| | | sprite.zIndex = DEVICE_Z_INDEX.POINT; |
| | | break |
| | | default: |
| | | break; |
| | | } |
| | | if (sprite) { |
| | | sprite.blendMode = PIXI.BLEND_MODES.MULTIPLY; |
| | | } |
| | | return sprite; |
| | | } |
| | | |
| | | export const initSprite = (sprite, type) => { |
| | | sprite.anchor.set(0.5); |
| | | // sprite.alpha = 1; |
| | | sprite.cursor = 'pointer'; |
| | | sprite.eventMode = 'static'; |
| | | sprite.data = { |
| | |
| | | } |
| | | } |
| | | |
| | | 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(); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | 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; |
| | |
| | | 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')) { |