| | |
| | | .start(); |
| | | } |
| | | |
| | | export const findAreaSpriteById = (areaId) => { |
| | | if (!mapContainer || areaId == null) { |
| | | return null; |
| | | } |
| | | const targetId = String(areaId); |
| | | for (let i = 0; i < mapContainer.children.length; i += 1) { |
| | | const child = mapContainer.children[i]; |
| | | if (child?.data?.type === DEVICE_TYPE.AREA && String(child.data?.id) === targetId) { |
| | | return child; |
| | | } |
| | | } |
| | | return null; |
| | | }; |
| | | |
| | | export const clearMapData = () => { |
| | | if (!mapContainer) { |
| | | return; |
| | |
| | | clearAreas(); |
| | | setShowAreas(false); |
| | | }; |
| | | |
| | | export const focusAreaSprite = (sprite) => { |
| | | if (!sprite || !app || !mapContainer) { |
| | | return; |
| | | } |
| | | |
| | | const data = sprite.data || {}; |
| | | const start = data.start; |
| | | const end = data.end; |
| | | const currentScale = Math.abs(mapContainer.scale.x || 1); |
| | | const boundsBefore = sprite.getBounds(); |
| | | const width = start && end ? Math.abs(end.x - start.x) : boundsBefore.width / currentScale; |
| | | const height = start && end ? Math.abs(end.y - start.y) : boundsBefore.height / currentScale; |
| | | |
| | | const paddedWidth = (width || 1000) * 1.25; |
| | | const paddedHeight = (height || 1000) * 1.25; |
| | | const viewportWidth = app.renderer.width || 1920; |
| | | const viewportHeight = app.renderer.height || 1080; |
| | | |
| | | let focusScale = Math.min( |
| | | (viewportWidth * 0.65) / paddedWidth, |
| | | (viewportHeight * 0.65) / paddedHeight |
| | | ); |
| | | focusScale = Math.min(Math.max(focusScale, 0.03), 0.25); |
| | | |
| | | mapContainer.scale.set(MAP_MIRROR ? -focusScale : focusScale, focusScale); |
| | | mapContainer.position.set(0, 0); |
| | | |
| | | const bounds = sprite.getBounds(); |
| | | const centerX = bounds.x + bounds.width / 2; |
| | | const centerY = bounds.y + bounds.height / 2; |
| | | |
| | | const targetPos = { |
| | | x: viewportWidth / 2 - centerX, |
| | | y: viewportHeight / 2 - centerY, |
| | | }; |
| | | |
| | | new TWEEDLE.Tween(mapContainer.position) |
| | | .easing(TWEEDLE.Easing.Quadratic.Out) |
| | | .to(targetPos, 500) |
| | | .start(); |
| | | }; |