|  |  | 
 |  |  |     DEVICE_SELECTED_EFFECT_PADDING, | 
 |  |  |     DEVICE_SELECTED_EFFECT_COLOR, | 
 |  |  |     POINT_ROUTE_DIRECTION, | 
 |  |  |     DEVICE_SPRITE_TINT_DARK, | 
 |  |  | } from './constants'; | 
 |  |  | import { getRouteList } from './http'; | 
 |  |  | import PointRoute from "./PointRoute"; | 
 |  |  | 
 |  |  |  | 
 |  |  | export function setThemeMode(param) { | 
 |  |  |     themeMode = param; | 
 |  |  |     if (mapContainer) { | 
 |  |  |         // mapContainer.children.forEach(child => { | 
 |  |  |         //     const deviceType = child.data?.type; | 
 |  |  |         //     if (deviceType) { | 
 |  |  |         //         if (themeMode === 'dark') { | 
 |  |  |         //             const tint = DEVICE_SPRITE_TINT_DARK[deviceType] | 
 |  |  |         //             if (tint) { | 
 |  |  |         //                 child.tint = tint; | 
 |  |  |         //             } | 
 |  |  |         //         } else { | 
 |  |  |         //             DEVICE_SPRITE_TINT[deviceType] != null && (child.tint = DEVICE_SPRITE_TINT[deviceType]); | 
 |  |  |         //         } | 
 |  |  |         //     } | 
 |  |  |         // }) | 
 |  |  |     } | 
 |  |  | } | 
 |  |  |  | 
 |  |  |  | 
 |  |  | 
 |  |  |     } | 
 |  |  | } | 
 |  |  |  | 
 |  |  | export const generateSprite = (deviceType, source) => { | 
 |  |  | export const generateSprite = (deviceType, texture) => { | 
 |  |  |     let sprite; | 
 |  |  |     switch (deviceType) { | 
 |  |  |         case DEVICE_TYPE.SHELF: | 
 |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         case DEVICE_TYPE.AGV: | 
 |  |  |             if (source) { | 
 |  |  |                 sprite = new PIXI.Sprite(PIXI.Texture.from(source, { resourceOptions: { scale: 1 } })); | 
 |  |  |             if (texture) { | 
 |  |  |                 sprite = new PIXI.Sprite(PIXI.Texture.from(texture, { resourceOptions: { scale: 1 } })); | 
 |  |  |             } | 
 |  |  |             sprite.width = 300; | 
 |  |  |             sprite.height = 500; | 
 |  |  |             sprite.width = 400; | 
 |  |  |             sprite.height = 700; | 
 |  |  |             sprite.zIndex = DEVICE_Z_INDEX.AGV; | 
 |  |  |             break | 
 |  |  |         case DEVICE_TYPE.POINT: | 
 |  |  | 
 |  |  |         default: | 
 |  |  |             break; | 
 |  |  |     } | 
 |  |  |     DEVICE_SPRITE_TINT[deviceType] != null && (sprite.tint = DEVICE_SPRITE_TINT[deviceType]); | 
 |  |  |     const tintType = themeMode === 'dark' ? DEVICE_SPRITE_TINT_DARK : DEVICE_SPRITE_TINT; | 
 |  |  |     tintType[deviceType] != null && (sprite.tint = tintType[deviceType]); | 
 |  |  |  | 
 |  |  |     if (sprite && deviceType !== DEVICE_TYPE.AGV) { | 
 |  |  |         sprite.blendMode = PIXI.BLEND_MODES.MULTIPLY; | 
 |  |  | 
 |  |  |  | 
 |  |  | function onSpriteMouseOver(event) { | 
 |  |  |     if (tooltip) { | 
 |  |  |         app.stage.removeChild(tooltip); | 
 |  |  |         app?.stage.removeChild(tooltip); | 
 |  |  |     } | 
 |  |  |     tooltip = createSpriteTooltip(this);// this => sprite | 
 |  |  |     tooltip.x = event.data.global.x + 10; | 
 |  |  | 
 |  |  |  | 
 |  |  | function onSpriteMouseOut() { | 
 |  |  |     if (tooltip && tooltip.parent) { | 
 |  |  |         tooltip.parent.removeChild(tooltip); | 
 |  |  |         tooltip.parent?.removeChild(tooltip); | 
 |  |  |         tooltip = null; | 
 |  |  |     } | 
 |  |  | } | 
 |  |  | 
 |  |  |         effectTicker = null; | 
 |  |  |     } | 
 |  |  |     if (effectCircle) { | 
 |  |  |         mapContainer.removeChild(effectCircle); | 
 |  |  |         mapContainer?.removeChild(effectCircle); | 
 |  |  |         effectCircle = null; | 
 |  |  |     } | 
 |  |  |     selectedSprite = null; | 
 |  |  | 
 |  |  |             const pointRoute = new PointRoute(POINT_ROUTE_DIRECTION[route.direction]); | 
 |  |  |             pointRoute.setPoint(startPoint, endPoint); | 
 |  |  |             pointRoute.clear(); | 
 |  |  |             pointRoute.lineStyle(8, themeMode === 'light' ? '#2d3436' : '#dcdde1'); | 
 |  |  |             pointRoute.lineStyle(Math.max(7, 2 * (1 / mapContainer.scale.x)), themeMode === 'light' ? '#ced6e0' : '#535c68'); | 
 |  |  |             pointRoute.moveTo(startPoint.position.x, startPoint.position.y); | 
 |  |  |             pointRoute.lineTo(endPoint.position.x, endPoint.position.y); | 
 |  |  |             pointRoute.alpha = 1; | 
 |  |  | 
 |  |  | } | 
 |  |  |  | 
 |  |  | export const rotationParseNum = (num) => { | 
 |  |  |     return num * Math.PI / 180; | 
 |  |  |     return num * (Math.PI / 180); | 
 |  |  | } | 
 |  |  |  | 
 |  |  | const animateRotation = (sprite, targetRotation, rotationOffset = 0) => { | 
 |  |  |     if (!mapContainer || !sprite) { | 
 |  |  |         return; | 
 |  |  |     } | 
 |  |  |     // origin | 
 |  |  |     let currentRotation = sprite.rotation + rotationOffset; | 
 |  |  |     // target | 
 |  |  |     targetRotation += rotationOffset; | 
 |  |  |  | 
 |  |  |     // diff | 
 |  |  |     let rotationDifference = targetRotation - currentRotation; | 
 |  |  |     if (rotationDifference === 0) { | 
 |  |  |         return; | 
 |  |  |     } | 
 |  |  |     rotationDifference = ((rotationDifference + Math.PI) % (2 * Math.PI)) - Math.PI; | 
 |  |  |  | 
 |  |  |     // destination | 
 |  |  |     const endRotation = sprite.rotation + rotationDifference; | 
 |  |  |  | 
 |  |  |     new TWEEDLE.Tween(sprite) | 
 |  |  |         .to({ rotation: endRotation }, 1000) | 
 |  |  |         .easing(TWEEDLE.Easing.Linear.None) | 
 |  |  |         .onUpdate(() => { | 
 |  |  |             // agv | 
 |  |  |             if (sprite.updateTextRotation) { | 
 |  |  |                 sprite.updateTextRotation(); | 
 |  |  |             } | 
 |  |  |         }) | 
 |  |  |         .start(); | 
 |  |  | }; | 
 |  |  |  | 
 |  |  | export const incrementSpriteNo = (str, incrementValue) => { | 
 |  |  |     const match = str.match(/(\D*)(\d+)/); | 
 |  |  | 
 |  |  | // dynamic graphic ---------------- | 
 |  |  |  | 
 |  |  | export const generateDynamicGraphic = (curZone, data, setCurSprite) => { | 
 |  |  |     // console.log("ws", curZone, data); | 
 |  |  |  | 
 |  |  |     for (const agv of data.agvVos) { | 
 |  |  |         showAgvSprite(curZone, agv, setCurSprite) | 
 |  |  |     for (const agvVo of data.agvVos) { | 
 |  |  |         showAgvSprite(curZone, agvVo, setCurSprite); | 
 |  |  |         drawerAgvPath(curZone, agvVo); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | } | 
 |  |  |  | 
 |  |  | const showAgvSprite = (curZone, agv, setCurSprite) => { | 
 |  |  |     const { agvNo, code, direction, backpack, battery, ...rest } = agv; | 
 |  |  |     if (!code) { return } | 
 |  |  | const agvRotationOffsetDegrees = 0; | 
 |  |  | const agvRotationOffset = rotationParseNum(agvRotationOffsetDegrees); | 
 |  |  |  | 
 |  |  | const showAgvSprite = (curZone, agvVo, setCurSprite) => { | 
 |  |  |     const { agvNo, code, direction, battery, backpack } = agvVo; | 
 |  |  |     if (!code) { return; } | 
 |  |  |     const codeSprite = querySprite(DEVICE_TYPE.POINT, code); | 
 |  |  |     if (!codeSprite) { return } | 
 |  |  |     if (!codeSprite) { return; } | 
 |  |  |  | 
 |  |  |     const targetRotation = rotationParseNum(direction); | 
 |  |  |     const backpackCount = backpack?.filter(item => item.loaded === true).length || 0; | 
 |  |  |  | 
 |  |  |     let agvSprite = querySprite(DEVICE_TYPE.AGV, agvNo); | 
 |  |  |     if (!agvSprite) { | 
 |  |  |         agvSprite = generateSprite(DEVICE_TYPE.AGV, | 
 |  |  |             generateAgvSpriteTexture(getAgvStatusMode(backpack.filter(item => item.loaded === true).length, battery)) | 
 |  |  |         ); | 
 |  |  |         const agvStatusMode = getAgvStatusMode(backpackCount, battery); | 
 |  |  |         const agvTexture = generateAgvSpriteTexture(agvStatusMode); | 
 |  |  |         agvSprite = generateSprite(DEVICE_TYPE.AGV, agvTexture); | 
 |  |  |  | 
 |  |  |         initSprite(agvSprite, DEVICE_TYPE.AGV); | 
 |  |  |  | 
 |  |  |         agvSprite.data.no = agvNo; | 
 |  |  |         agvSprite.data.backpackCount = backpackCount; | 
 |  |  |         agvSprite.data.battery = battery; | 
 |  |  |  | 
 |  |  |         agvSprite.position.set(codeSprite.position.x, codeSprite.position.y); | 
 |  |  |         agvSprite.rotation = rotationParseNum(direction); | 
 |  |  |         agvSprite.rotation = targetRotation + agvRotationOffset; | 
 |  |  |         mapContainer.addChild(agvSprite); | 
 |  |  |         beInsight(agvSprite, setCurSprite); | 
 |  |  |         // agv no on sprite | 
 |  |  |  | 
 |  |  |         // agvNo sprite | 
 |  |  |         const agvText = new PIXI.Text(agvNo.toString(), { | 
 |  |  |             fontSize: 60, | 
 |  |  |             fill: 0x000000, | 
 |  |  |         }); | 
 |  |  |         agvText.anchor.set(0.5, 0.5); | 
 |  |  |         agvText.position.set(0, 0); | 
 |  |  |         agvSprite.addChild(agvText); | 
 |  |  |  | 
 |  |  |         agvSprite.updateTextRotation = () => { | 
 |  |  |             if (agvText && agvSprite) { | 
 |  |  |                 agvText.rotation = -agvSprite.rotation; | 
 |  |  |             } | 
 |  |  |         }; | 
 |  |  |         agvSprite.updateTextRotation(); | 
 |  |  |  | 
 |  |  |     } else { | 
 |  |  |         const prevBackpackCount = agvSprite.data.backpackCount; | 
 |  |  |         const prevBattery = agvSprite.data.battery; | 
 |  |  |  | 
 |  |  |         if (backpackCount !== prevBackpackCount || battery !== prevBattery) { | 
 |  |  |             const agvStatusMode = getAgvStatusMode(backpackCount, battery); | 
 |  |  |             const agvTexture = generateAgvSpriteTexture(agvStatusMode); | 
 |  |  |             agvSprite.texture = PIXI.Texture.from(agvTexture, { resourceOptions: { scale: 1 } }); | 
 |  |  |             // update backpackCount and battery | 
 |  |  |             agvSprite.data.backpackCount = backpackCount; | 
 |  |  |             agvSprite.data.battery = battery; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         animateRotation(agvSprite, targetRotation, agvRotationOffset); | 
 |  |  |     } | 
 |  |  | } | 
 |  |  |  | 
 |  |  |     new TWEEDLE.Tween(agvSprite.position) | 
 |  |  |         .to({ | 
 |  |  |             x: codeSprite.position.x, | 
 |  |  |             y: codeSprite.position.y | 
 |  |  |         }, 1000) | 
 |  |  |         .easing(TWEEDLE.Easing.Linear.None) | 
 |  |  |         .start(); | 
 |  |  | } | 
 |  |  |  | 
 |  |  | const drawerAgvPath = (curZone, agvVo) => { | 
 |  |  |     if (!mapContainer) { | 
 |  |  |         return; | 
 |  |  |     } | 
 |  |  |     const { agvNo, code: curCode, dynamicRoute } = agvVo; | 
 |  |  |  | 
 |  |  |     const agvPathName = 'agvPath-' + agvNo; | 
 |  |  |     let agvPath = mapContainer.getChildByName(agvPathName); | 
 |  |  |     if (agvPath) { | 
 |  |  |         mapContainer.removeChild(agvPath); | 
 |  |  |     } | 
 |  |  |     agvPath = new PIXI.Graphics(); | 
 |  |  |     agvPath.name = agvPathName; | 
 |  |  |     agvPath.lineStyle(Math.max(20, 4 * (1 / mapContainer.scale.x)), 0x2f68ac, 0.8); | 
 |  |  |     agvPath.zIndex = DEVICE_Z_INDEX.DYNAMIC_ROUTE; | 
 |  |  |     // agvPath.blendMode = PIXI.BLEND_MODES.NORMAL; | 
 |  |  |  | 
 |  |  |     let firstNode = true; | 
 |  |  |     for (let i = Math.max(0, dynamicRoute.indexOf(curCode)); i < dynamicRoute.length; i++) { | 
 |  |  |         const node = dynamicRoute[i]; | 
 |  |  |         const codeSprite = querySprite(DEVICE_TYPE.POINT, node); | 
 |  |  |         if (!codeSprite) { continue }; | 
 |  |  |         const { x, y } = codeSprite.position; | 
 |  |  |         if (firstNode) { | 
 |  |  |             agvPath.moveTo(x, y); | 
 |  |  |             firstNode = false; | 
 |  |  |         } else { | 
 |  |  |             agvPath.lineTo(x, y); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     mapContainer.addChild(agvPath); | 
 |  |  | } |